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

DYN-5733 fix language CLI argument #15739

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 75 additions & 25 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,28 +186,59 @@ public static void PreloadShapeManager(ref string geometryFactoryPath, ref strin
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="cmdLineArgs"></param>
/// <returns></returns>
public static DynamoModel MakeCLIModel(CommandLineArguments cmdLineArgs)
private static DynamoModel PrepareModel(
string cliLocale,
string asmPath,
bool noNetworkMode,
HostAnalyticsInfo analyticsInfo,
bool cliMode = true,
string userDataFolder = "",
string commonDataFolder = "",
bool serviceMode = false)
{
var asmPath = String.IsNullOrEmpty(cmdLineArgs.ASMPath) ? string.Empty : cmdLineArgs.ASMPath;
var normalizedCLILocale = string.IsNullOrEmpty(cliLocale) ? null : cliLocale;
IPathResolver pathResolver = CreatePathResolver(false, string.Empty, string.Empty, string.Empty);
PathManager.Instance.AssignHostPathAndIPathResolver(string.Empty, pathResolver);
DynamoModel.SetUICulture(PreferenceSettings.Instance.Locale);
DynamoModel.SetUICulture(normalizedCLILocale ?? PreferenceSettings.Instance.Locale);
DynamoModel.OnDetectLanguage();

// 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, cmdLineArgs.UserDataFolder, cmdLineArgs.CommonDataFolder,
geometryFactoryPath, preloaderLocation, cmdLineArgs.NoNetworkMode, cmdLineArgs.AnalyticsInfo, cmdLineArgs.ServiceMode);
var model = StartDynamoWithDefaultConfig(
CLImode: cliMode,
userDataFolder: userDataFolder,
commonDataFolder: commonDataFolder,
geometryFactoryPath: geometryFactoryPath,
preloaderLocation: preloaderLocation,
noNetworkMode: noNetworkMode,
info: analyticsInfo,
isServiceMode: serviceMode,
cliLocale: normalizedCLILocale
);
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="cmdLineArgs"></param>
/// <returns></returns>
public static DynamoModel MakeCLIModel(CommandLineArguments cmdLineArgs)
{
var asmPath = string.IsNullOrEmpty(cmdLineArgs.ASMPath) ? string.Empty : cmdLineArgs.ASMPath;
var model = PrepareModel(
cliLocale: cmdLineArgs.Locale,
asmPath: asmPath,
noNetworkMode: cmdLineArgs.NoNetworkMode,
analyticsInfo: cmdLineArgs.AnalyticsInfo,
userDataFolder: cmdLineArgs.UserDataFolder,
commonDataFolder: cmdLineArgs.CommonDataFolder,
serviceMode: cmdLineArgs.ServiceMode);
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 @@ -217,10 +248,12 @@ public static DynamoModel MakeCLIModel(CommandLineArguments cmdLineArgs)
/// <returns></returns>
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, false, new HostAnalyticsInfo() { HostName = hostName });
model.IsASMLoaded = isASMloaded;
var model = PrepareModel(
cliLocale: string.Empty,
asmPath: asmPath,
noNetworkMode: false,
analyticsInfo: new HostAnalyticsInfo() { HostName = hostName },
cliMode: CLImode);
return model;
}

Expand All @@ -234,17 +267,32 @@ public static DynamoModel MakeModel(bool CLImode, string asmPath = "", string ho
/// <returns></returns>
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);
DynamoModel.SetUICulture(PreferenceSettings.Instance.Locale);
DynamoModel.OnDetectLanguage();
var model = PrepareModel(
cliLocale: string.Empty,
asmPath: asmPath,
noNetworkMode: noNetworkMode,
analyticsInfo: info,
cliMode: CLImode);
return model;
}

// 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, noNetworkMode, info);
model.IsASMLoaded = isASMloaded;
/// <summary>
/// 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="CLIlocale">CLI argument to force dynamo locale</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 CLIlocale, bool noNetworkMode, string asmPath = "", HostAnalyticsInfo info = new HostAnalyticsInfo())
{
var model = PrepareModel(
cliLocale: CLIlocale,
asmPath: asmPath,
noNetworkMode: noNetworkMode,
analyticsInfo: info,
cliMode: CLImode);
return model;
}

Expand Down Expand Up @@ -322,7 +370,8 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
string preloaderLocation,
bool noNetworkMode,
HostAnalyticsInfo info = new HostAnalyticsInfo(),
bool isServiceMode = false)
bool isServiceMode = false,
string cliLocale = null)
{

var config = new DynamoModel.DefaultStartConfiguration
Expand All @@ -337,6 +386,7 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
IsServiceMode = isServiceMode,
Preferences = PreferenceSettings.Instance,
NoNetworkMode = noNetworkMode,
CLILocale = cliLocale,
//Breaks all Lucene calls. TI enable this would require a lot of refactoring around Lucene usage in Dynamo.
//IsHeadless = CLImode
};
Expand Down
9 changes: 8 additions & 1 deletion src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public static string Version
/// </summary>
internal bool NoNetworkMode { get; }

/// <summary>
/// Locale forced by cli arguments
/// </summary>
internal string CLILocale { get; set; }

/// <summary>
/// The path manager that configures path information required for
/// Dynamo to function properly. See IPathManager interface for more
Expand Down Expand Up @@ -589,6 +594,7 @@ public struct DefaultStartConfiguration : IStartConfiguration
/// CLIMode indicates if we are running in DynamoCLI or DynamoWPFCLI mode.
/// </summary>
public bool CLIMode { get; set; }
public string CLILocale { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -635,6 +641,7 @@ protected DynamoModel(IStartConfiguration config)
DefaultPythonEngine = defaultStartConfig.DefaultPythonEngine;
CLIMode = defaultStartConfig.CLIMode;
IsServiceMode = defaultStartConfig.IsServiceMode;
CLILocale = defaultStartConfig.CLILocale;
}

if (config is IStartConfigCrashReporter cerConfig)
Expand Down Expand Up @@ -685,7 +692,7 @@ protected DynamoModel(IStartConfiguration config)

if (PreferenceSettings != null)
{
SetUICulture(PreferenceSettings.Locale);
SetUICulture(CLILocale ?? PreferenceSettings.Locale);
PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
PreferenceSettings.MessageLogged += LogMessage;
}
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,8 @@ Dynamo.Models.DynamoModel.CurrentWorkspace.set -> void
Dynamo.Models.DynamoModel.DefaultStartConfiguration
Dynamo.Models.DynamoModel.DefaultStartConfiguration.AuthProvider.get -> Greg.IAuthProvider
Dynamo.Models.DynamoModel.DefaultStartConfiguration.AuthProvider.set -> void
Dynamo.Models.DynamoModel.DefaultStartConfiguration.CLILocale.get -> string
Dynamo.Models.DynamoModel.DefaultStartConfiguration.CLILocale.set -> void
Dynamo.Models.DynamoModel.DefaultStartConfiguration.CLIMode.get -> bool
Dynamo.Models.DynamoModel.DefaultStartConfiguration.CLIMode.set -> void
Dynamo.Models.DynamoModel.DefaultStartConfiguration.Context.get -> string
Expand Down
4 changes: 3 additions & 1 deletion src/DynamoSandbox/DynamoCoreSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DynamoCoreSetup
private readonly string ASMPath;
private readonly HostAnalyticsInfo analyticsInfo;
private readonly bool noNetworkMode;
private readonly string CLILocale;
private const string sandboxWikiPage = @"https://github.com/DynamoDS/Dynamo/wiki/How-to-Utilize-Dynamo-Builds";
private DynamoViewModel viewModel = null;

Expand Down Expand Up @@ -59,6 +60,7 @@ public DynamoCoreSetup(string[] args)
// HostVersion = new Version(3, 3, 0),
//};
noNetworkMode = cmdLineArgs.NoNetworkMode;
CLILocale = cmdLineArgs.Locale;
}

public void RunApplication(Application app)
Expand Down Expand Up @@ -140,7 +142,7 @@ public void RunApplication(Application app)
private void LoadDynamoView()
{
DynamoModel model;
model = StartupUtils.MakeModel(false, noNetworkMode, ASMPath ?? string.Empty, analyticsInfo);
model = StartupUtils.MakeModel(false, CLILocale, noNetworkMode, ASMPath ?? string.Empty, analyticsInfo);
model.CERLocation = CERLocation;

viewModel = DynamoViewModel.Start(
Expand Down
Loading