From 518614467bb3035ec77b67a41de0f99245fd0b41 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Fri, 8 Oct 2021 12:13:18 -0400 Subject: [PATCH 01/12] Update WPFCLI to add keep alive start up param --- src/DynamoWPFCLI/CommandLineRunnerWPF.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs index da6f4c92c6c..b236ac0d1ee 100644 --- a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs +++ b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs @@ -31,7 +31,7 @@ public CommandLineRunnerWPF(DynamoViewModel viewModel) : base(viewModel.Model) private static XmlDocument RunCommandLineArgs(DynamoViewModel viewModel, StartupUtils.CommandLineArguments cmdLineArgs) { var evalComplete = false; - if (string.IsNullOrEmpty(cmdLineArgs.OpenFilePath)) + if (!cmdLineArgs.KeepAlive && string.IsNullOrEmpty(cmdLineArgs.OpenFilePath)) { return null; } @@ -47,6 +47,25 @@ private static XmlDocument RunCommandLineArgs(DynamoViewModel viewModel, Startup ImportAssembly(viewModel.Model, path); }); + // KeepAlive mode -- allow loaded extensions to control the process lifetime + // and issue commands until the extension calls model.Shutdown(). + if (cmdLineArgs.KeepAlive) + { + bool running = true; + + viewModel.Model.ShutdownCompleted += (m) => + { + running = false; + }; + + while (running) + { + Thread.Sleep(3000); + } + + return null; + } + viewModel.OpenCommand.Execute(new Tuple(cmdLineArgs.OpenFilePath, true)); Console.WriteLine("loaded file"); viewModel.Model.EvaluationCompleted += (o, args) => { evalComplete = true; }; From 670ff0d5ca860b9af30e973add1c72c5c07d1ab9 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Fri, 8 Oct 2021 16:15:01 -0400 Subject: [PATCH 02/12] Load View extensions in WPF CLI --- src/DynamoWPFCLI/Program.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index 478ed8be86d..58f9168b4dc 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -1,7 +1,9 @@ using System; using Dynamo.Applications; +using Dynamo.Controls; using Dynamo.Models; using Dynamo.ViewModels; +using Dynamo.Wpf.Extensions; using Dynamo.Wpf.ViewModels.Watch3D; namespace DynamoWPFCLI @@ -36,6 +38,23 @@ static internal void Main(string[] args) } }); + var dynView = new DynamoView(viewModel); + + var sharedViewExtensionLoadedParams = new ViewLoadedParams(dynView, viewModel); + + foreach (var ext in dynView.viewExtensionManager.ViewExtensions) + { + try + { + ext.Loaded(sharedViewExtensionLoadedParams); + Console.WriteLine("loaded " + ext.Name); + } + catch (Exception exc) + { + Console.WriteLine(ext.Name + ": " + exc.Message); + } + } + var runner = new CommandLineRunnerWPF(viewModel); runner.Run(cmdLineArgs); From 315868d9dd7272c0328c62cacac74100f13c9d0e Mon Sep 17 00:00:00 2001 From: Craig Long Date: Mon, 11 Oct 2021 11:27:10 -0400 Subject: [PATCH 03/12] Move keepalvie to new thread --- src/DynamoWPFCLI/CommandLineRunnerWPF.cs | 19 ------- src/DynamoWPFCLI/Program.cs | 68 +++++++++++++++++------- 2 files changed, 50 insertions(+), 37 deletions(-) diff --git a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs index b236ac0d1ee..64633b0bb35 100644 --- a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs +++ b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs @@ -47,25 +47,6 @@ private static XmlDocument RunCommandLineArgs(DynamoViewModel viewModel, Startup ImportAssembly(viewModel.Model, path); }); - // KeepAlive mode -- allow loaded extensions to control the process lifetime - // and issue commands until the extension calls model.Shutdown(). - if (cmdLineArgs.KeepAlive) - { - bool running = true; - - viewModel.Model.ShutdownCompleted += (m) => - { - running = false; - }; - - while (running) - { - Thread.Sleep(3000); - } - - return null; - } - viewModel.OpenCommand.Execute(new Tuple(cmdLineArgs.OpenFilePath, true)); Console.WriteLine("loaded file"); viewModel.Model.EvaluationCompleted += (o, args) => { evalComplete = true; }; diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index 58f9168b4dc..13e4a6f700b 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -1,10 +1,14 @@ using System; +using System.Threading; +using System.Windows; using Dynamo.Applications; +using Dynamo.Configuration; 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 { @@ -18,6 +22,17 @@ static internal void Main(string[] args) { var cmdLineArgs = StartupUtils.CommandLineArguments.Parse(args); var locale = StartupUtils.SetLocale(cmdLineArgs); + + if (cmdLineArgs.KeepAlive) + { + var thread = new Thread(KeepAlive); + + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + + Console.ReadLine(); + } + DynamoModel model; if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) { @@ -38,26 +53,8 @@ static internal void Main(string[] args) } }); - var dynView = new DynamoView(viewModel); - - var sharedViewExtensionLoadedParams = new ViewLoadedParams(dynView, viewModel); - - foreach (var ext in dynView.viewExtensionManager.ViewExtensions) - { - try - { - ext.Loaded(sharedViewExtensionLoadedParams); - Console.WriteLine("loaded " + ext.Name); - } - catch (Exception exc) - { - Console.WriteLine(ext.Name + ": " + exc.Message); - } - } - var runner = new CommandLineRunnerWPF(viewModel); runner.Run(cmdLineArgs); - } catch (Exception e) { @@ -75,5 +72,40 @@ static internal void Main(string[] args) } } + private static void KeepAlive() + { + var model = Dynamo.Applications.StartupUtils.MakeModel(true); + + var viewModel = DynamoViewModel.Start( + new DynamoViewModel.StartConfiguration() + { + DynamoModel = model, + Watch3DViewModel = new DefaultWatch3DViewModel(null, new Watch3DViewModelStartupParams(model)) + { + Active = false, + CanBeActivated = false + } + }); + + var dynView = new DynamoView(viewModel); + + var sharedViewExtensionLoadedParams = new ViewLoadedParams(dynView, viewModel); + + foreach (var ext in dynView.viewExtensionManager.ViewExtensions) + { + try + { + ext.Loaded(sharedViewExtensionLoadedParams); + Console.WriteLine("loaded " + ext.Name); + } + catch (Exception exc) + { + Console.WriteLine(ext.Name + ": " + exc.Message); + } + } + + Run(); + } + } } From 7892054f7516847a68f92b1228d1cd28fbb1d939 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Mon, 11 Oct 2021 17:14:33 -0400 Subject: [PATCH 04/12] Additional changes --- src/DynamoWPFCLI/CommandLineRunnerWPF.cs | 2 +- src/DynamoWPFCLI/DynamoWPFCLI.csproj | 1 + src/DynamoWPFCLI/Program.cs | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs index 64633b0bb35..da6f4c92c6c 100644 --- a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs +++ b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs @@ -31,7 +31,7 @@ public CommandLineRunnerWPF(DynamoViewModel viewModel) : base(viewModel.Model) private static XmlDocument RunCommandLineArgs(DynamoViewModel viewModel, StartupUtils.CommandLineArguments cmdLineArgs) { var evalComplete = false; - if (!cmdLineArgs.KeepAlive && string.IsNullOrEmpty(cmdLineArgs.OpenFilePath)) + if (string.IsNullOrEmpty(cmdLineArgs.OpenFilePath)) { return null; } diff --git a/src/DynamoWPFCLI/DynamoWPFCLI.csproj b/src/DynamoWPFCLI/DynamoWPFCLI.csproj index dc8a8ab49f4..2ed6f2e899d 100644 --- a/src/DynamoWPFCLI/DynamoWPFCLI.csproj +++ b/src/DynamoWPFCLI/DynamoWPFCLI.csproj @@ -52,6 +52,7 @@ + diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index 13e4a6f700b..1f65db0c3cb 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -1,8 +1,6 @@ using System; using System.Threading; -using System.Windows; using Dynamo.Applications; -using Dynamo.Configuration; using Dynamo.Controls; using Dynamo.Models; using Dynamo.ViewModels; From d97b7dc72df5f5d47adaf5054dd7d68519cf0c01 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Mon, 11 Oct 2021 17:14:51 -0400 Subject: [PATCH 05/12] Changes for thumbnail generation --- .../ViewModels/Watch3D/DefaultWatch3DViewModel.cs | 9 ++++++++- src/DynamoWPFCLI/Program.cs | 11 ++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Watch3D/DefaultWatch3DViewModel.cs b/src/DynamoCoreWpf/ViewModels/Watch3D/DefaultWatch3DViewModel.cs index bc185d13bff..9da3001aa5f 100644 --- a/src/DynamoCoreWpf/ViewModels/Watch3D/DefaultWatch3DViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Watch3D/DefaultWatch3DViewModel.cs @@ -195,7 +195,14 @@ internal WorkspaceViewModel CurrentSpaceViewModel { get { - return viewModel.Workspaces.FirstOrDefault(vm => vm.Model == dynamoModel.CurrentWorkspace); + if (viewModel == null) + { + return null; + } + else + { + return viewModel.Workspaces.FirstOrDefault(vm => vm.Model == dynamoModel.CurrentWorkspace); + } } } diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index 1f65db0c3cb..5f23fb83873 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -53,6 +53,7 @@ static internal void Main(string[] args) var runner = new CommandLineRunnerWPF(viewModel); runner.Run(cmdLineArgs); + } catch (Exception e) { @@ -74,15 +75,15 @@ private static void KeepAlive() { var model = Dynamo.Applications.StartupUtils.MakeModel(true); + DefaultWatch3DViewModel defaultWatch3DViewModel = HelixWatch3DViewModel.TryCreateHelixWatch3DViewModel(null, new Watch3DViewModelStartupParams(model), model.Logger); + defaultWatch3DViewModel.Active = false; + defaultWatch3DViewModel.CanBeActivated = false; + var viewModel = DynamoViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = model, - Watch3DViewModel = new DefaultWatch3DViewModel(null, new Watch3DViewModelStartupParams(model)) - { - Active = false, - CanBeActivated = false - } + Watch3DViewModel = defaultWatch3DViewModel }); var dynView = new DynamoView(viewModel); From d43d4b6ad398711302bd784850d7abd3509427b6 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Tue, 12 Oct 2021 17:12:53 -0400 Subject: [PATCH 06/12] Refactor keep alive function --- src/DynamoWPFCLI/Program.cs | 117 ++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 44 deletions(-) diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index 5f23fb83873..7730a7cd0b9 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -23,37 +23,40 @@ static internal void Main(string[] args) if (cmdLineArgs.KeepAlive) { - var thread = new Thread(KeepAlive); + var thread = new Thread(() => RunKeepAlive(cmdLineArgs)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); Console.ReadLine(); - } - - DynamoModel model; - if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) - { - model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath); + + ShutDown(); } else { - model = Dynamo.Applications.StartupUtils.MakeModel(true); - } - var viewModel = DynamoViewModel.Start( - new DynamoViewModel.StartConfiguration() + DynamoModel model; + if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) { - DynamoModel = model, - Watch3DViewModel = new DefaultWatch3DViewModel(null, new Watch3DViewModelStartupParams(model)) + model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath); + } + else + { + model = Dynamo.Applications.StartupUtils.MakeModel(true); + } + var viewModel = DynamoViewModel.Start( + new DynamoViewModel.StartConfiguration() { - Active = false, - CanBeActivated = false - } - }); - - var runner = new CommandLineRunnerWPF(viewModel); - runner.Run(cmdLineArgs); - + DynamoModel = model, + Watch3DViewModel = new DefaultWatch3DViewModel(null, new Watch3DViewModelStartupParams(model)) + { + Active = false, + CanBeActivated = false + } + }); + + var runner = new CommandLineRunnerWPF(viewModel); + runner.Run(cmdLineArgs); + } } catch (Exception e) { @@ -71,39 +74,65 @@ static internal void Main(string[] args) } } - private static void KeepAlive() + private static void RunKeepAlive(StartupUtils.CommandLineArguments cmdLineArgs) { - var model = Dynamo.Applications.StartupUtils.MakeModel(true); - - DefaultWatch3DViewModel defaultWatch3DViewModel = HelixWatch3DViewModel.TryCreateHelixWatch3DViewModel(null, new Watch3DViewModelStartupParams(model), model.Logger); - defaultWatch3DViewModel.Active = false; - defaultWatch3DViewModel.CanBeActivated = false; + try + { + DynamoModel model; + if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) + { + model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath); + } + else + { + model = Dynamo.Applications.StartupUtils.MakeModel(true); + } - var viewModel = DynamoViewModel.Start( - new DynamoViewModel.StartConfiguration() + model.ShutdownCompleted += (m) => { - DynamoModel = model, - Watch3DViewModel = defaultWatch3DViewModel - }); + ShutDown(); + }; - var dynView = new DynamoView(viewModel); + DefaultWatch3DViewModel defaultWatch3DViewModel = HelixWatch3DViewModel.TryCreateHelixWatch3DViewModel(null, new Watch3DViewModelStartupParams(model), model.Logger); + defaultWatch3DViewModel.Active = false; + defaultWatch3DViewModel.CanBeActivated = false; - var sharedViewExtensionLoadedParams = new ViewLoadedParams(dynView, viewModel); + var viewModel = DynamoViewModel.Start( + new DynamoViewModel.StartConfiguration() + { + DynamoModel = model, + Watch3DViewModel = defaultWatch3DViewModel + }); - foreach (var ext in dynView.viewExtensionManager.ViewExtensions) - { - try - { - ext.Loaded(sharedViewExtensionLoadedParams); - Console.WriteLine("loaded " + ext.Name); - } - catch (Exception exc) + var dynView = new DynamoView(viewModel); + + var sharedViewExtensionLoadedParams = new ViewLoadedParams(dynView, viewModel); + + foreach (var ext in dynView.viewExtensionManager.ViewExtensions) { - Console.WriteLine(ext.Name + ": " + exc.Message); + try + { + ext.Loaded(sharedViewExtensionLoadedParams); + Console.WriteLine("loaded " + ext.Name); + } + catch (Exception exc) + { + Console.WriteLine(ext.Name + ": " + exc.Message); + } } + + Run(); + + } + catch + { + Console.WriteLine("Server is shutting down due to an error"); } + } - Run(); + private static void ShutDown() + { + Environment.Exit(0); } } From ec3237e0de72c6578e9267c0df4f3bb46a012e15 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Tue, 9 Nov 2021 11:00:55 -0500 Subject: [PATCH 07/12] Remove Helix and startup of Dynamo View extensions --- src/DynamoWPFCLI/Program.cs | 90 +++++++++++++------------------------ 1 file changed, 31 insertions(+), 59 deletions(-) diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index 7730a7cd0b9..7c344b52abd 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -28,31 +28,14 @@ static internal void Main(string[] args) thread.SetApartmentState(ApartmentState.STA); thread.Start(); + Console.WriteLine("Starting DynamoWPFCLI in keepalive mode"); Console.ReadLine(); ShutDown(); } else { - DynamoModel model; - if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) - { - model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath); - } - else - { - model = Dynamo.Applications.StartupUtils.MakeModel(true); - } - var viewModel = DynamoViewModel.Start( - new DynamoViewModel.StartConfiguration() - { - DynamoModel = model, - Watch3DViewModel = new DefaultWatch3DViewModel(null, new Watch3DViewModelStartupParams(model)) - { - Active = false, - CanBeActivated = false - } - }); + var viewModel = StartupDaynamo(cmdLineArgs); var runner = new CommandLineRunnerWPF(viewModel); runner.Run(cmdLineArgs); @@ -74,55 +57,44 @@ static internal void Main(string[] args) } } - private static void RunKeepAlive(StartupUtils.CommandLineArguments cmdLineArgs) + private static DynamoViewModel StartupDaynamo(StartupUtils.CommandLineArguments cmdLineArgs) { - try + DynamoModel model; + if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) { - 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(); - }; + model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath); + } + else + { + model = Dynamo.Applications.StartupUtils.MakeModel(true); + } - DefaultWatch3DViewModel defaultWatch3DViewModel = HelixWatch3DViewModel.TryCreateHelixWatch3DViewModel(null, new Watch3DViewModelStartupParams(model), model.Logger); - defaultWatch3DViewModel.Active = false; - defaultWatch3DViewModel.CanBeActivated = false; + model.ShutdownCompleted += (m) => { ShutDown(); }; - var viewModel = DynamoViewModel.Start( - new DynamoViewModel.StartConfiguration() + var viewModel = DynamoViewModel.Start( + new DynamoViewModel.StartConfiguration() + { + DynamoModel = model, + Watch3DViewModel = new DefaultWatch3DViewModel(null, new Watch3DViewModelStartupParams(model)) { - DynamoModel = model, - Watch3DViewModel = defaultWatch3DViewModel - }); + Active = false, + CanBeActivated = false + } + }); + return viewModel; + } - var dynView = new DynamoView(viewModel); + private static void RunKeepAlive(StartupUtils.CommandLineArguments cmdLineArgs) + { + try + { + StartupDaynamo(cmdLineArgs); - var sharedViewExtensionLoadedParams = new ViewLoadedParams(dynView, viewModel); + Console.WriteLine("-----------------------------------------"); + Console.WriteLine("DynamoWPFCLI is running in keepalive mode"); + Console.WriteLine("Press Enter to shutdown..."); - foreach (var ext in dynView.viewExtensionManager.ViewExtensions) - { - try - { - ext.Loaded(sharedViewExtensionLoadedParams); - Console.WriteLine("loaded " + ext.Name); - } - catch (Exception exc) - { - Console.WriteLine(ext.Name + ": " + exc.Message); - } - } - Run(); - } catch { From 8dfc68df3dff190da8897eb95e11f6f94dc3bd98 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Fri, 25 Mar 2022 08:52:06 -0400 Subject: [PATCH 08/12] Fix csproj --- src/DynamoWPFCLI/DynamoWPFCLI.csproj | 23 ----------------------- src/DynamoWPFCLI/Program.cs | 2 -- 2 files changed, 25 deletions(-) diff --git a/src/DynamoWPFCLI/DynamoWPFCLI.csproj b/src/DynamoWPFCLI/DynamoWPFCLI.csproj index 308d4a80df6..0a7b885ec57 100644 --- a/src/DynamoWPFCLI/DynamoWPFCLI.csproj +++ b/src/DynamoWPFCLI/DynamoWPFCLI.csproj @@ -13,30 +13,7 @@ ..\..\extern\prism\Microsoft.Practices.Prism.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll - False - - - - - - - - - - - - AssemblySharedInfo.cs - - - - - - - - diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index 3202076b935..df4395ea629 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -1,10 +1,8 @@ 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; From 252a06fe856210c6cac48bc6324aa23b6a2df9b0 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Mon, 4 Apr 2022 10:25:25 -0400 Subject: [PATCH 09/12] Stop using obsolete MakeModel methods --- src/DynamoCLI/CommandLineRunner.cs | 1 - src/DynamoCLI/Program.cs | 4 ++-- src/DynamoWPFCLI/CommandLineRunnerWPF.cs | 2 -- src/DynamoWPFCLI/Program.cs | 11 ++++++++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/DynamoCLI/CommandLineRunner.cs b/src/DynamoCLI/CommandLineRunner.cs index 2a4ba16a593..01ffac484de 100644 --- a/src/DynamoCLI/CommandLineRunner.cs +++ b/src/DynamoCLI/CommandLineRunner.cs @@ -44,7 +44,6 @@ private static XmlDocument RunCommandLineArgs(DynamoModel model, StartupUtils.Co { Console.WriteLine("geometryFilePath option is only available when running DynamoWPFCLI, not DynamoCLI"); } - model.HostAnalyticsInfo = cmdLineArgs.AnalyticsInfo; cmdLineArgs.ImportedPaths.ToList().ForEach(path => { diff --git a/src/DynamoCLI/Program.cs b/src/DynamoCLI/Program.cs index 2fa6946bd5d..ff0f6bd03dd 100644 --- a/src/DynamoCLI/Program.cs +++ b/src/DynamoCLI/Program.cs @@ -21,11 +21,11 @@ static internal void Main(string[] args) DynamoModel model; if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) { - model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath); + model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath, cmdLineArgs.AnalyticsInfo); } else { - model = Dynamo.Applications.StartupUtils.MakeModel(true); + model = Dynamo.Applications.StartupUtils.MakeModel(true, string.Empty, cmdLineArgs.AnalyticsInfo); } var runner = new CommandLineRunner(model); runner.Run(cmdLineArgs); diff --git a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs index da6f4c92c6c..bfe7f378d3b 100644 --- a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs +++ b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs @@ -40,8 +40,6 @@ private static XmlDocument RunCommandLineArgs(DynamoViewModel viewModel, Startup Console.WriteLine("commandFilePath option is only available when running DynamoSandbox, not DynamoWPFCLI"); } - viewModel.Model.HostAnalyticsInfo= cmdLineArgs.AnalyticsInfo; - cmdLineArgs.ImportedPaths.ToList().ForEach(path => { ImportAssembly(viewModel.Model, path); diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index df4395ea629..9bebadb3b8f 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -11,7 +11,7 @@ namespace DynamoWPFCLI internal class Program { [STAThread] - static internal void Main(string[] args) + internal static void Main(string[] args) { try @@ -60,16 +60,21 @@ static internal void Main(string[] args) } } + /// + /// Start Dynamo Model and ViewModel per cmdLineArgs parameters. + /// + /// + /// private static DynamoViewModel StartupDaynamo(StartupUtils.CommandLineArguments cmdLineArgs) { DynamoModel model; if (!String.IsNullOrEmpty(cmdLineArgs.ASMPath)) { - model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath); + model = Dynamo.Applications.StartupUtils.MakeModel(true, cmdLineArgs.ASMPath, cmdLineArgs.AnalyticsInfo); } else { - model = Dynamo.Applications.StartupUtils.MakeModel(true); + model = Dynamo.Applications.StartupUtils.MakeModel(true, string.Empty, cmdLineArgs.AnalyticsInfo); } model.ShutdownCompleted += (m) => { ShutDown(); }; From ec2d1a347554d30bcd4f46ca4714fafcd4b66ab2 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Mon, 4 Apr 2022 10:52:30 -0400 Subject: [PATCH 10/12] Move ImportedPaths handling to Dynamo startup to match CLI keepalive behavior --- src/DynamoWPFCLI/CommandLineRunnerWPF.cs | 5 ---- src/DynamoWPFCLI/Program.cs | 34 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs index bfe7f378d3b..8a932009412 100644 --- a/src/DynamoWPFCLI/CommandLineRunnerWPF.cs +++ b/src/DynamoWPFCLI/CommandLineRunnerWPF.cs @@ -40,11 +40,6 @@ private static XmlDocument RunCommandLineArgs(DynamoViewModel viewModel, Startup Console.WriteLine("commandFilePath option is only available when running DynamoSandbox, not DynamoWPFCLI"); } - cmdLineArgs.ImportedPaths.ToList().ForEach(path => - { - ImportAssembly(viewModel.Model, path); - }); - viewModel.OpenCommand.Execute(new Tuple(cmdLineArgs.OpenFilePath, true)); Console.WriteLine("loaded file"); viewModel.Model.EvaluationCompleted += (o, args) => { evalComplete = true; }; diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index 9bebadb3b8f..deb882de394 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading; using Dynamo.Applications; using Dynamo.Models; @@ -89,6 +90,12 @@ private static DynamoViewModel StartupDaynamo(StartupUtils.CommandLineArguments CanBeActivated = false } }); + + cmdLineArgs.ImportedPaths.ToList().ForEach(path => + { + ImportAssembly(model, path); + }); + return viewModel; } @@ -110,6 +117,33 @@ private static void RunKeepAlive(StartupUtils.CommandLineArguments cmdLineArgs) } } + /// + /// Attempts to import an assembly as a node library from a given file path. + /// + /// + /// + 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); From edad905c35f5e52e659d7970125bcef03001e748 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Mon, 4 Apr 2022 11:00:42 -0400 Subject: [PATCH 11/12] Add thread name for keepAlive --- src/DynamoWPFCLI/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index deb882de394..81c259659e5 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -29,6 +29,7 @@ internal static void Main(string[] args) { var thread = new Thread(() => RunKeepAlive(cmdLineArgs)); + thread.Name = "DynamoModelKeepAlive"; thread.SetApartmentState(ApartmentState.STA); thread.Start(); From 9f6e0596afac09c9c2af6b04cd183a61c34f80b3 Mon Sep 17 00:00:00 2001 From: Craig Long Date: Thu, 7 Apr 2022 20:01:09 -0400 Subject: [PATCH 12/12] Fix test --- src/DynamoCLI/CommandLineRunner.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DynamoCLI/CommandLineRunner.cs b/src/DynamoCLI/CommandLineRunner.cs index 01ffac484de..2d887a21472 100644 --- a/src/DynamoCLI/CommandLineRunner.cs +++ b/src/DynamoCLI/CommandLineRunner.cs @@ -45,6 +45,8 @@ private static XmlDocument RunCommandLineArgs(DynamoModel model, StartupUtils.Co Console.WriteLine("geometryFilePath option is only available when running DynamoWPFCLI, not DynamoCLI"); } + model.HostAnalyticsInfo = cmdLineArgs.AnalyticsInfo; + cmdLineArgs.ImportedPaths.ToList().ForEach(path => { ImportAssembly(model, path);