-
Notifications
You must be signed in to change notification settings - Fork 635
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
Update WPFCLI to add keep alive startup param handling #12156
Changes from 11 commits
5186144
670ff0d
315868d
7892054
d97b7dc
d43d4b6
ec3237e
d9543da
8dfc68d
252a06f
ec2d1a3
edad905
2e8fb20
9f6e059
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
<Reference Include="Microsoft.Practices.Prism"> | ||
<HintPath>..\..\extern\prism\Microsoft.Practices.Prism.dll</HintPath> | ||
</Reference> | ||
<Reference Include="WindowsBase" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why we need to add this? Would this prevent running WPF CLI on linux based system? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was necessary with the threading model required to load the ViewModel which makes sence since that also will not load on linux |
||
<PackageReference Include="Newtonsoft.Json" Version="8.0.3" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using Dynamo.Applications; | ||
using Dynamo.Models; | ||
using Dynamo.ViewModels; | ||
using Dynamo.Wpf.ViewModels.Watch3D; | ||
using static System.Windows.Threading.Dispatcher; | ||
|
||
namespace DynamoWPFCLI | ||
{ | ||
internal class Program | ||
{ | ||
[STAThread] | ||
static internal void Main(string[] args) | ||
internal static void Main(string[] args) | ||
{ | ||
|
||
try | ||
{ | ||
var cmdLineArgs = StartupUtils.CommandLineArguments.Parse(args); | ||
var locale = StartupUtils.SetLocale(cmdLineArgs); | ||
|
||
if (cmdLineArgs.DisableAnalytics) | ||
{ | ||
Dynamo.Logging.Analytics.DisableAnalytics = true; | ||
} | ||
|
||
DynamoModel model; | ||
if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) | ||
if (cmdLineArgs.KeepAlive) | ||
{ | ||
model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath); | ||
var thread = new Thread(() => RunKeepAlive(cmdLineArgs)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a name for this thread so that is easily visible when debugging like the Scheduler thread? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name added |
||
|
||
thread.SetApartmentState(ApartmentState.STA); | ||
thread.Start(); | ||
|
||
Console.WriteLine("Starting DynamoWPFCLI in keepalive mode"); | ||
Console.ReadLine(); | ||
|
||
ShutDown(); | ||
} | ||
else | ||
{ | ||
model = Dynamo.Applications.StartupUtils.MakeModel(true); | ||
var viewModel = StartupDaynamo(cmdLineArgs); | ||
|
||
var runner = new CommandLineRunnerWPF(viewModel); | ||
runner.Run(cmdLineArgs); | ||
} | ||
var viewModel = DynamoViewModel.Start( | ||
new DynamoViewModel.StartConfiguration() | ||
{ | ||
DynamoModel = model, | ||
Watch3DViewModel = new DefaultWatch3DViewModel(null, new Watch3DViewModelStartupParams(model)) | ||
{ | ||
Active = false, | ||
CanBeActivated = false | ||
} | ||
}); | ||
|
||
var runner = new CommandLineRunnerWPF(viewModel); | ||
runner.Run(cmdLineArgs); | ||
|
||
} | ||
catch (Exception e) | ||
{ | ||
|
@@ -61,5 +61,93 @@ static internal void Main(string[] args) | |
} | ||
} | ||
|
||
/// <summary> | ||
/// Start Dynamo Model and ViewModel per cmdLineArgs parameters. | ||
/// </summary> | ||
/// <param name="cmdLineArgs"></param> | ||
/// <returns></returns> | ||
private static DynamoViewModel StartupDaynamo(StartupUtils.CommandLineArguments cmdLineArgs) | ||
{ | ||
DynamoModel model; | ||
if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) | ||
{ | ||
model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath, cmdLineArgs.AnalyticsInfo); | ||
} | ||
else | ||
{ | ||
model = Dynamo.Applications.StartupUtils.MakeModel(true, string.Empty, cmdLineArgs.AnalyticsInfo); | ||
} | ||
|
||
model.ShutdownCompleted += (m) => { ShutDown(); }; | ||
|
||
var viewModel = DynamoViewModel.Start( | ||
new DynamoViewModel.StartConfiguration() | ||
{ | ||
DynamoModel = model, | ||
Watch3DViewModel = new DefaultWatch3DViewModel(null, new Watch3DViewModelStartupParams(model)) | ||
{ | ||
Active = false, | ||
CanBeActivated = false | ||
} | ||
}); | ||
|
||
cmdLineArgs.ImportedPaths.ToList().ForEach(path => | ||
{ | ||
ImportAssembly(model, path); | ||
}); | ||
|
||
return viewModel; | ||
} | ||
|
||
private static void RunKeepAlive(StartupUtils.CommandLineArguments cmdLineArgs) | ||
{ | ||
try | ||
{ | ||
StartupDaynamo(cmdLineArgs); | ||
|
||
Console.WriteLine("-----------------------------------------"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I realize that we probably want to show the console only in debug mode ? But we can deal with this later in other PR. |
||
Console.WriteLine("DynamoWPFCLI is running in keepalive mode"); | ||
Console.WriteLine("Press Enter to shutdown..."); | ||
|
||
Run(); | ||
} | ||
catch | ||
{ | ||
Console.WriteLine("Server is shutting down due to an error"); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to import an assembly as a node library from a given file path. | ||
/// </summary> | ||
/// <param name="model"></param> | ||
/// <param name="path"></param> | ||
private static void ImportAssembly(DynamoModel model, string path) | ||
{ | ||
try | ||
{ | ||
var filePath = new System.IO.FileInfo(path); | ||
if (!filePath.Exists) | ||
{ | ||
Console.WriteLine($"could not find requested import library at path{path}"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"attempting to import assembly {path}"); | ||
var assembly = System.Reflection.Assembly.LoadFile(path); | ||
model.LoadNodeLibrary(assembly, true); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"exception while trying to load assembly {path}: {e}"); | ||
} | ||
} | ||
|
||
private static void ShutDown() | ||
{ | ||
Environment.Exit(0); | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QilongTang Hi Aaron. Is this the correct way to update the
MakeModel
usage from the obsoleted methodsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes