Skip to content

Commit

Permalink
DYN-6232: Add No-network mode (#14526)
Browse files Browse the repository at this point in the history
* remove coreclr-ncalc references

* rename, refactor

* keep disableAnalytics flag while adding nonetwork flag

* cleanup

* fixes

* modify comment

* make nonetworkmode setter inaccessible

* cleanup

* use default property in IStartConfiguration

* review comments

* remove obsolete properties

* restore deleted test
  • Loading branch information
aparajit-pratap authored Oct 30, 2023
1 parent 87232b3 commit 923663e
Show file tree
Hide file tree
Showing 29 changed files with 112 additions and 473 deletions.
7 changes: 5 additions & 2 deletions src/DynamoApplications/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand All @@ -11,4 +11,7 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("72464112-159f-4542-88c9-55734f67074e")]

[assembly:InternalsVisibleTo("IntegrationTests")]
[assembly:InternalsVisibleTo("IntegrationTests")]
[assembly: InternalsVisibleTo("DynamoSandbox")]
[assembly: InternalsVisibleTo("DynamoCLI")]
[assembly: InternalsVisibleTo("DynamoWPFCLI")]
75 changes: 32 additions & 43 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Dynamo.Configuration;
using Dynamo.Core;
using Dynamo.Interfaces;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.Scheduler;
using Dynamo.Updates;
Expand Down Expand Up @@ -52,8 +53,10 @@ internal class CMDLineOptions
public string CommonDataFolder { get; set; } = String.Empty;
[Option("HostName", Required = false, HelpText = "Identify Dynamo variation associated with host.")]
public string HostName { get; set; } = String.Empty;
[Option("DisableAnalytics", Required = false, HelpText = "Disables analytics in Dynamo for the process liftime.")]
[Option("DisableAnalytics", Required = false, HelpText = "Disables analytics in Dynamo for the process lifetime.")]
public bool DisableAnalytics { get; set; }
[Option("NoNetworkMode", Required = false, HelpText = "Disables network traffic in Dynamo at startup. Disables some features such as Notifications, Sign In, and ML Node Autocomplete for process lifetime.")]
public bool NoNetworkMode { get; set; }
[Option('p', "ParentId", Required = false, HelpText = "Identify Dynamo host analytics parent id.")]
public string ParentId { get; set; } = String.Empty;
[Option('s', "SessionId", Required = false, HelpText = "Identify Dynamo host analytics session id.")]
Expand All @@ -64,7 +67,7 @@ internal class CMDLineOptions
public bool ServiceMode { get; set; }
}

public class StartupUtils
public static class StartupUtils
{
//TODO internal?
/// <summary>
Expand Down Expand Up @@ -142,13 +145,22 @@ public static CommandLineArguments Parse(string[] args)
UserDataFolder = cmdArgs.UserDataFolder,
CommonDataFolder = cmdArgs.CommonDataFolder,
DisableAnalytics = cmdArgs.DisableAnalytics,
NoNetworkMode = cmdArgs.NoNetworkMode,
AnalyticsInfo = new HostAnalyticsInfo() { HostName = cmdArgs.HostName, ParentId = cmdArgs.ParentId, SessionId = cmdArgs.SessionId },
CERLocation = cmdArgs.CERLocation,
ServiceMode = cmdArgs.ServiceMode
};
}, errs => new CommandLineArguments());
}

internal void SetDisableAnalytics()
{
if (DisableAnalytics || NoNetworkMode)
{
Analytics.DisableAnalytics = true;
}
}

public string Locale { get; set; }
public string CommandFilePath { get; set; }
public string OpenFilePath { get; set; }
Expand All @@ -164,6 +176,7 @@ public static CommandLineArguments Parse(string[] args)
[Obsolete("This property will be removed in Dynamo 3.0 - please use AnalyticsInfo")]
public string HostName { get; set; }
public bool DisableAnalytics { get; set; }
public bool NoNetworkMode { get; set; }
public HostAnalyticsInfo AnalyticsInfo { get; set; }
public string CERLocation { get; set; }

Expand Down Expand Up @@ -227,22 +240,19 @@ private static IUpdateManager InitializeUpdateManager()
// Preload ASM and display corresponding message on splash screen
DynamoModel.OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenPreLoadingAsm, 10));
var isASMloaded = PreloadASM(asmPath, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(true, userDataFolder, commonDataFolder, geometryFactoryPath, preloaderLocation, info);
var model = StartDynamoWithDefaultConfig(true, userDataFolder, commonDataFolder, geometryFactoryPath, preloaderLocation, false, info);
model.IsASMLoaded = isASMloaded;
return model;
}

/// <summary>
/// Use this overload to construct a DynamoModel in CLI context when the location of ASM to use is known, host analytics info is known and you want to set data paths.
/// </summary>
/// <param name="asmPath">Path to directory containing geometry library binaries</param>
/// <param name="userDataFolder">Path to be used by PathResolver for UserDataFolder</param>
/// <param name="commonDataFolder">Path to be used by PathResolver for CommonDataFolder</param>
/// <param name="info">Host analytics info specifying Dynamo launching host related information.</param>
/// <param name="isServiceMode">Boolean indication of launching Dynamo in service mode, this mode is optimized for minimal launch time.</param>
/// <param name="cmdLineArgs"></param>
/// <returns></returns>
public static DynamoModel MakeCLIModel(string asmPath, string userDataFolder, string commonDataFolder, HostAnalyticsInfo info = new HostAnalyticsInfo(), bool isServiceMode = false)
public static DynamoModel MakeCLIModel(CommandLineArguments cmdLineArgs)
{
var asmPath = String.IsNullOrEmpty(cmdLineArgs.ASMPath) ? string.Empty : cmdLineArgs.ASMPath;
IPathResolver pathResolver = CreatePathResolver(false, string.Empty, string.Empty, string.Empty);
PathManager.Instance.AssignHostPathAndIPathResolver(string.Empty, pathResolver);
DynamoModel.SetUICulture(PreferenceSettings.Instance.Locale);
Expand All @@ -251,7 +261,8 @@ private static IUpdateManager InitializeUpdateManager()
// Preload ASM and display corresponding message on splash screen
DynamoModel.OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenPreLoadingAsm, 10));
var isASMloaded = PreloadASM(asmPath, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(true, userDataFolder, commonDataFolder, geometryFactoryPath, preloaderLocation, info, isServiceMode);
var model = StartDynamoWithDefaultConfig(true, cmdLineArgs.UserDataFolder, cmdLineArgs.CommonDataFolder,
geometryFactoryPath, preloaderLocation, cmdLineArgs.NoNetworkMode, cmdLineArgs.AnalyticsInfo, cmdLineArgs.ServiceMode);
model.IsASMLoaded = isASMloaded;
return model;
}
Expand All @@ -266,7 +277,8 @@ private static IUpdateManager InitializeUpdateManager()
public static DynamoModel MakeModel(bool CLImode, string asmPath = "", string hostName ="")
{
var isASMloaded = PreloadASM(asmPath, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(CLImode, string.Empty, string.Empty, geometryFactoryPath, preloaderLocation, new HostAnalyticsInfo() { HostName = hostName });
var model = StartDynamoWithDefaultConfig(CLImode, string.Empty, string.Empty,
geometryFactoryPath, preloaderLocation, false, new HostAnalyticsInfo() { HostName = hostName });
model.IsASMLoaded = isASMloaded;
return model;
}
Expand All @@ -275,10 +287,11 @@ public static DynamoModel MakeModel(bool CLImode, string asmPath = "", string ho
/// Use this overload to construct a DynamoModel when the location of ASM to use is known and host analytics info is known.
/// </summary>
/// <param name="CLImode">CLI mode starts the model in test mode and uses a separate path resolver.</param>
/// <param name="noNetworkMode">Option to initialize Dynamo in no-network mode</param>
/// <param name="asmPath">Path to directory containing geometry library binaries</param>
/// <param name="info">Host analytics info specifying Dynamo launching host related information.</param>
/// <returns></returns>
public static DynamoModel MakeModel(bool CLImode, string asmPath = "", HostAnalyticsInfo info = new HostAnalyticsInfo())
public static DynamoModel MakeModel(bool CLImode, bool noNetworkMode, string asmPath = "", HostAnalyticsInfo info = new HostAnalyticsInfo())
{
IPathResolver pathResolver = CreatePathResolver(false, string.Empty, string.Empty, string.Empty);
PathManager.Instance.AssignHostPathAndIPathResolver(string.Empty, pathResolver);
Expand All @@ -288,7 +301,8 @@ public static DynamoModel MakeModel(bool CLImode, string asmPath = "", string ho
// Preload ASM and display corresponding message on splash screen
DynamoModel.OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenPreLoadingAsm, 10));
var isASMloaded = PreloadASM(asmPath, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(CLImode, string.Empty, string.Empty, geometryFactoryPath, preloaderLocation, info);
var model = StartDynamoWithDefaultConfig(CLImode, string.Empty, string.Empty, geometryFactoryPath,
preloaderLocation, noNetworkMode, info);
model.IsASMLoaded = isASMloaded;
return model;
}
Expand All @@ -306,33 +320,7 @@ private static IPathResolver CreatePathResolver(bool CLImode, string preloaderLo
IPathResolver pathResolver = CLImode ? new CLIPathResolver(preloaderLocation, userDataFolder, commonDataFolder) as IPathResolver : new SandboxPathResolver(preloaderLocation) as IPathResolver;
return pathResolver;
}

/// <summary>
/// TODO (DYN-2118) remove this method in 3.0 and unify this method with the overload above.
/// Use this overload to construct a DynamoModel when the location of ASM to use is known.
/// </summary>
/// <param name="CLImode">CLI mode starts the model in test mode and uses a seperate path resolver.</param>
/// <param name="asmPath">Path to directory containing geometry library binaries</param>
/// <returns></returns>
[Obsolete("This method will be removed in Dynamo 3.0 - please use the version with more parameters")]
public static DynamoModel MakeModel(bool CLImode, string asmPath)
{
var isASMloaded = PreloadASM(asmPath, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(CLImode, string.Empty, string.Empty, geometryFactoryPath, preloaderLocation);
model.IsASMLoaded = isASMloaded;
return model;
}

//TODO (DYN-2118) remove this method in 3.0 and unify this method with the overload above.
[Obsolete("This method will be removed in Dynamo 3.0 - please use the version with more parameters")]
public static DynamoModel MakeModel(bool CLImode)
{
var isASMloaded = PreloadASM(string.Empty, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(CLImode, string.Empty, string.Empty, geometryFactoryPath, preloaderLocation);
model.IsASMLoaded = isASMloaded;
return model;
}


private static bool PreloadASM(string asmPath, out string geometryFactoryPath, out string preloaderLocation )
{
if (string.IsNullOrEmpty(asmPath) && OSHelper.IsWindows())
Expand Down Expand Up @@ -391,6 +379,7 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
string commonDataFolder,
string geometryFactoryPath,
string preloaderLocation,
bool noNetworkMode,
HostAnalyticsInfo info = new HostAnalyticsInfo(),
bool isServiceMode = false)
{
Expand All @@ -401,13 +390,13 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
ProcessMode = CLImode ? TaskProcessMode.Synchronous : TaskProcessMode.Asynchronous,
HostAnalyticsInfo = info,
CLIMode = CLImode,
//TODO we currently use this like a no network comms flags - work on introducing a new flag or renaming this flag.
AuthProvider = CLImode || Dynamo.Logging.Analytics.DisableAnalytics ? null : new Core.IDSDKManager(),
AuthProvider = CLImode || noNetworkMode ? null : new Core.IDSDKManager(),
UpdateManager = CLImode ? null : OSHelper.IsWindows() ? InitializeUpdateManager() : null,
StartInTestMode = CLImode,
PathResolver = CreatePathResolver(CLImode, preloaderLocation, userDataFolder, commonDataFolder),
IsServiceMode = isServiceMode,
Preferences = PreferenceSettings.Instance
Preferences = PreferenceSettings.Instance,
NoNetworkMode = noNetworkMode
};
var model = DynamoModel.Start(config);
return model;
Expand Down
15 changes: 5 additions & 10 deletions src/DynamoCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading;
using Dynamo.Applications;
using Dynamo.Logging;
using Dynamo.Models;

namespace DynamoCLI
Expand All @@ -11,7 +12,7 @@ internal class Program
private static EventWaitHandle suspendEvent = new AutoResetEvent(false);

[STAThread]
static internal void Main(string[] args)
internal static void Main(string[] args)
{
bool useConsole = true;

Expand All @@ -20,10 +21,8 @@ static internal void Main(string[] args)
var cmdLineArgs = StartupUtils.CommandLineArguments.Parse(args);
useConsole = !cmdLineArgs.NoConsole;
var locale = StartupUtils.SetLocale(cmdLineArgs);
if (cmdLineArgs.DisableAnalytics)
{
Dynamo.Logging.Analytics.DisableAnalytics = true;
}

cmdLineArgs.SetDisableAnalytics();

if (cmdLineArgs.KeepAlive)
{
Expand Down Expand Up @@ -100,11 +99,7 @@ private static void RunKeepAlive(StartupUtils.CommandLineArguments cmdLineArgs)
private static DynamoModel StartupDynamo(StartupUtils.CommandLineArguments cmdLineArgs)
{
DynamoModel model;
model = Dynamo.Applications.StartupUtils.MakeCLIModel(String.IsNullOrEmpty(cmdLineArgs.ASMPath) ? string.Empty : cmdLineArgs.ASMPath,
cmdLineArgs.UserDataFolder,
cmdLineArgs.CommonDataFolder,
cmdLineArgs.AnalyticsInfo,
cmdLineArgs.ServiceMode);
model = StartupUtils.MakeCLIModel(cmdLineArgs);

if (!string.IsNullOrEmpty(cmdLineArgs.CERLocation))
{
Expand Down
12 changes: 0 additions & 12 deletions src/DynamoCore/Configuration/IPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ public interface IPreferences
/// </summary>
string NumberFormat { get; set; }

/// <summary>
/// Indicates whether usage reporting is approved or not.
/// </summary>
[Obsolete("Property will be deprecated in Dynamo 3.0")]
bool IsUsageReportingApproved { get; set; }

/// <summary>
/// Indicates whether Google analytics reporting is approved or not.
/// </summary>
[Obsolete("Property will be deprecated in Dynamo 3.0")]
bool IsAnalyticsReportingApproved { get; set; }

/// <summary>
/// Indicates whether ADP analytics reporting is approved or not.
/// </summary>
Expand Down
13 changes: 0 additions & 13 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,6 @@ internal readonly static Lazy<PreferenceSettings>
/// </summary>
public bool IsFirstRun { get; set; }

/// <summary>
/// Indicates whether usage reporting is approved or not.
/// </summary>
[Obsolete("Property will be deprecated in Dynamo 3.0")]
public bool IsUsageReportingApproved { get { return false; } set { } }

/// <summary>
/// Indicates whether Google analytics reporting is approved or not.
/// </summary>
[Obsolete("Property will be deprecated in Dynamo 3.0")]
public bool IsAnalyticsReportingApproved { get { return false; } set { } }

/// <summary>
/// This defines if the user export file path would include timestamp
/// </summary>
Expand Down Expand Up @@ -868,7 +856,6 @@ public PreferenceSettings()

// Default Settings
IsFirstRun = true;
IsAnalyticsReportingApproved = true;
Locale = Configurations.SupportedLocaleDic.FirstOrDefault().Value;
LibraryWidth = 304;
ConsoleHeight = 0;
Expand Down
24 changes: 15 additions & 9 deletions src/DynamoCore/Extensions/StartupParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ public class StartupParams
public LinterManager LinterManager => linterManager;
private readonly LinterManager linterManager;

/// <summary>
/// True when Dynamo starts up in offline mode.
/// </summary>
public bool NoNetworkMode { get; }

/// <summary>
/// Returns true if ASM/LibG are loaded. May only be valid in sandbox sessions.
/// </summary>
internal bool IsGeometryLibraryLoaded { get; private set; }
internal bool IsGeometryLibraryLoaded { get; }

/// <summary>
/// Initializes a new instance of the <see cref="StartupParams"/> class.
Expand Down Expand Up @@ -111,14 +116,15 @@ public StartupParams(IAuthProvider provider, IPathManager pathManager,
/// </summary>
internal StartupParams(DynamoModel dynamoModel)
{
this.authProvider = dynamoModel.AuthenticationManager?.AuthProvider;
this.pathManager = dynamoModel.PathManager;
this.libraryLoader = new ExtensionLibraryLoader(dynamoModel);
this.customNodeManager = dynamoModel.CustomNodeManager;
this.dynamoVersion = new Version(dynamoModel.Version);
this.preferences = dynamoModel.PreferenceSettings;
this.linterManager = dynamoModel.LinterManager;
this.IsGeometryLibraryLoaded = dynamoModel.IsASMLoaded;
authProvider = dynamoModel.AuthenticationManager?.AuthProvider;
pathManager = dynamoModel.PathManager;
libraryLoader = new ExtensionLibraryLoader(dynamoModel);
customNodeManager = dynamoModel.CustomNodeManager;
dynamoVersion = new Version(dynamoModel.Version);
preferences = dynamoModel.PreferenceSettings;
linterManager = dynamoModel.LinterManager;
IsGeometryLibraryLoaded = dynamoModel.IsASMLoaded;
NoNetworkMode = dynamoModel.NoNetworkMode;
}

}
Expand Down
3 changes: 2 additions & 1 deletion src/DynamoCore/Logging/AnalyticsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AnalyticsService
{
// Use the Analytics.Core interface so that we do not have to load the ADP assembly at this time.
private static IAnalyticsUI adpAnalyticsUI;

/// <summary>
/// Starts the client when DynamoModel is created. This method initializes
/// the Analytics service and application life cycle start is tracked.
Expand Down Expand Up @@ -105,7 +106,7 @@ internal static void ShutDown()
/// Show the ADP dynamic consents dialog.
/// </summary>
/// <param name="host">main window</param>
internal static void ShowADPConsetDialog(IntPtr? host)
internal static void ShowADPConsentDialog(IntPtr? host)
{
if (!Analytics.DisableAnalytics && adpAnalyticsUI != null)
{
Expand Down
14 changes: 0 additions & 14 deletions src/DynamoCore/Logging/DynamoAnalyticsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,6 @@ public bool ReportingAnalytics
}
}

/// <summary>
/// Return if Analytics Client is allowed to send instrumentation info
/// </summary>
public bool ReportingUsage
{
get
{
return preferences != null
&& Service.IsInitialized
&& !Analytics.DisableAnalytics
&& preferences.IsUsageReportingApproved;
}
}

/// <summary>
/// Constructs DynamoAnalyticsClient with given DynamoModel
/// </summary>
Expand Down
Loading

0 comments on commit 923663e

Please sign in to comment.