Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Dynamo Service Mode as new CLI flag #13659

Merged
merged 20 commits into from
Feb 16, 2023
Merged
53 changes: 42 additions & 11 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public static CommandLineArguments Parse(string[] args)
bool keepAlive = false;
bool showHelp = false;
bool noConsole = false;
bool serviceMode = false;
string userDataFolder = string.Empty;
string commonDataFolder = string.Empty;

Expand Down Expand Up @@ -220,7 +221,9 @@ public static CommandLineArguments Parse(string[] args)
.Add("si=|SI=|sessionId", "Identify Dynamo host analytics session id", si => sessionId = si)
.Add("pi=|PI=|parentId", "Identify Dynamo host analytics parent id", pi => parentId = pi)
.Add("da|DA|disableAnalytics", "Disables analytics in Dynamo for the process liftime", da => disableAnalytics = da != null)
.Add("cr=|CR=|cerLocation", "Specify the crash error report tool location on disk ", cr => cerLocation = cr);
.Add("cr=|CR=|cerLocation", "Specify the crash error report tool location on disk ", cr => cerLocation = cr)
.Add("s|S|service mode", "Service mode, bypasses certain Dynamo launch steps for maximum startup performance", s => serviceMode = s != null);

optionsSet.Parse(args);

if (showHelp)
Expand Down Expand Up @@ -249,7 +252,8 @@ public static CommandLineArguments Parse(string[] args)
CommonDataFolder = commonDataFolder,
DisableAnalytics = disableAnalytics,
AnalyticsInfo = new HostAnalyticsInfo() { HostName = hostname, ParentId = parentId, SessionId = sessionId },
CERLocation = cerLocation
CERLocation = cerLocation,
ServiceMode = serviceMode
};
#endif
}
Expand Down Expand Up @@ -279,6 +283,11 @@ private static void ShowHelp(OptionSet opSet)
public bool DisableAnalytics { get; set; }
public HostAnalyticsInfo AnalyticsInfo { get; set; }
public string CERLocation { get; set; }

/// <summary>
/// Boolean indication of launching Dynamo in service mode, this mode is optimized for minimal launch time
/// </summary>
public bool ServiceMode { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -327,7 +336,8 @@ private static IUpdateManager InitializeUpdateManager()
/// </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="commonDataFolder">Path to be used by PathResolver for CommonDataFolder</param>
/// <param name="info">Host analytics info specifying Dynamo launching host related information.</param>
/// <returns></returns>
public static DynamoModel MakeCLIModel(string asmPath, string userDataFolder, string commonDataFolder, HostAnalyticsInfo info = new HostAnalyticsInfo())
{
Expand All @@ -339,6 +349,25 @@ private static IUpdateManager InitializeUpdateManager()
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>
/// <returns></returns>
public static DynamoModel MakeCLIModel(string asmPath, string userDataFolder, string commonDataFolder, HostAnalyticsInfo info = new HostAnalyticsInfo(), bool isServiceMode = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also added a couple of flags last year :). I guess we need to think of something soon to better consolidate all the MakeModel constructs. Perhaps a startup config file where you can enable/disable features/extensions etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, currently the code (constructors) used for CLI are a bit messy

{
// 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);
model.IsASMLoaded = isASMloaded;
return model;
}

/// <summary>
/// Use this overload to construct a DynamoModel when the location of ASM to use is known and host name is known.
/// </summary>
Expand All @@ -359,7 +388,7 @@ public static DynamoModel MakeModel(bool CLImode, string asmPath = "", string ho
/// </summary>
/// <param name="CLImode">CLI mode starts the model in test mode and uses a separate path resolver.</param>
/// <param name="asmPath">Path to directory containing geometry library binaries</param>
/// <param name="info">Host analytics info</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())
{
Expand Down Expand Up @@ -455,19 +484,21 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
string commonDataFolder,
string geometryFactoryPath,
string preloaderLocation,
HostAnalyticsInfo info = new HostAnalyticsInfo())
HostAnalyticsInfo info = new HostAnalyticsInfo(),
bool isServiceMode = false)
{
var config = new DynamoModel.DefaultStartConfiguration()
var config = new DynamoModel.DefaultStartConfiguration
{
GeometryFactoryPath = geometryFactoryPath,
ProcessMode = CLImode ? TaskProcessMode.Synchronous : TaskProcessMode.Asynchronous,
HostAnalyticsInfo = info,
CLIMode = CLImode
CLIMode = CLImode,
AuthProvider = CLImode ? null : new Core.IDSDKManager(),
UpdateManager = CLImode ? null : OSHelper.IsWindows() ? InitializeUpdateManager() : null,
StartInTestMode = CLImode,
PathResolver = CLImode ? new CLIPathResolver(preloaderLocation, userDataFolder, commonDataFolder) as IPathResolver : new SandboxPathResolver(preloaderLocation) as IPathResolver,
IsServiceMode = isServiceMode
};
config.AuthProvider = CLImode ? null : new Core.IDSDKManager();
config.UpdateManager = CLImode ? null : OSHelper.IsWindows() ? InitializeUpdateManager() : null;
config.StartInTestMode = CLImode;
config.PathResolver = CLImode ? new CLIPathResolver(preloaderLocation, userDataFolder, commonDataFolder) as IPathResolver : new SandboxPathResolver(preloaderLocation) as IPathResolver;

var model = DynamoModel.Start(config);
return model;
Expand Down
12 changes: 6 additions & 6 deletions src/DynamoCLI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using Dynamo.Applications;
using Dynamo.Models;
Expand Down Expand Up @@ -29,9 +27,10 @@ static internal void Main(string[] args)

if (cmdLineArgs.KeepAlive)
{
var thread = new Thread(() => RunKeepAlive(cmdLineArgs));

thread.Name = "DynamoModelKeepAlive";
var thread = new Thread(() => RunKeepAlive(cmdLineArgs))
{
Name = "DynamoModelKeepAlive"
};
thread.Start();

if (!useConsole)
Expand Down Expand Up @@ -104,7 +103,8 @@ private static DynamoModel StartupDynamo(StartupUtils.CommandLineArguments cmdLi
model = Dynamo.Applications.StartupUtils.MakeCLIModel(String.IsNullOrEmpty(cmdLineArgs.ASMPath) ? string.Empty : cmdLineArgs.ASMPath,
cmdLineArgs.UserDataFolder,
cmdLineArgs.CommonDataFolder,
cmdLineArgs.AnalyticsInfo);
cmdLineArgs.AnalyticsInfo,
cmdLineArgs.ServiceMode);

if (!string.IsNullOrEmpty(cmdLineArgs.CERLocation))
{
Expand Down
8 changes: 0 additions & 8 deletions src/DynamoCore/Core/AuthenticationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ internal void ToggleLoginState(object o)
}
}

/// <summary>
/// Check if able to toggle login state
/// </summary>
internal bool CanToggleLoginState()
{
return this.LoginState == LoginState.LoggedOut || this.LoginState == LoginState.LoggedIn;
}

internal void Login()
{
if (!HasAuthProvider) return;
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCore/Extensions/StartupParams.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Interfaces;
using Dynamo.Library;
Expand Down Expand Up @@ -111,7 +111,7 @@ public StartupParams(IAuthProvider provider, IPathManager pathManager,
/// </summary>
internal StartupParams(DynamoModel dynamoModel)
{
this.authProvider = dynamoModel.AuthenticationManager.AuthProvider;
this.authProvider = dynamoModel.AuthenticationManager?.AuthProvider;
this.pathManager = dynamoModel.PathManager;
this.libraryLoader = new ExtensionLibraryLoader(dynamoModel);
this.customNodeManager = dynamoModel.CustomNodeManager;
Expand Down
Loading