-
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 7 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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
using System; | ||
using System.Threading; | ||
using Dynamo.Applications; | ||
using Dynamo.Controls; | ||
using Dynamo.Models; | ||
using Dynamo.ViewModels; | ||
using Dynamo.Wpf.Extensions; | ||
using Dynamo.Wpf.ViewModels.Watch3D; | ||
using static System.Windows.Threading.Dispatcher; | ||
|
||
namespace DynamoWPFCLI | ||
{ | ||
|
@@ -16,29 +20,26 @@ static internal void Main(string[] args) | |
{ | ||
var cmdLineArgs = StartupUtils.CommandLineArguments.Parse(args); | ||
var locale = StartupUtils.SetLocale(cmdLineArgs); | ||
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) | ||
{ | ||
|
@@ -56,5 +57,55 @@ static internal void Main(string[] args) | |
} | ||
} | ||
|
||
private static DynamoViewModel StartupDaynamo(StartupUtils.CommandLineArguments cmdLineArgs) | ||
{ | ||
DynamoModel model; | ||
if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) | ||
{ | ||
model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath); | ||
} | ||
else | ||
{ | ||
model = Dynamo.Applications.StartupUtils.MakeModel(true); | ||
} | ||
|
||
model.ShutdownCompleted += (m) => { ShutDown(); }; | ||
|
||
var viewModel = DynamoViewModel.Start( | ||
new DynamoViewModel.StartConfiguration() | ||
{ | ||
DynamoModel = model, | ||
Watch3DViewModel = new DefaultWatch3DViewModel(null, new Watch3DViewModelStartupParams(model)) | ||
{ | ||
Active = false, | ||
CanBeActivated = false | ||
} | ||
}); | ||
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"); | ||
} | ||
} | ||
|
||
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.
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 comment
The 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