Skip to content

Commit

Permalink
Add keepalive flag to DynamoCLI, allowing extensions to control engin…
Browse files Browse the repository at this point in the history
…e lifetime (#11090)
  • Loading branch information
mike-d-adsk authored Sep 4, 2020
1 parent 03f84e9 commit 78ec538
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -93,11 +94,13 @@ public static CommandLineArguments Parse(string[] args)

// Generate geometry json file
var geometryFilePath = string.Empty;

// dll paths we'll import before running a graph
var importPaths = new List<string>() ;

var asmPath = string.Empty;

bool keepAlive = false;
bool showHelp = false;
var optionsSet = new OptionSet().Add("o=|O=", "OpenFilePath, Instruct Dynamo to open headless and run a dyn file at this path", o => openfilepath = o)
.Add("c=|C=", "CommandFilePath, Instruct Dynamo to open a commandfile and run the commands it contains at this path," +
Expand All @@ -109,9 +112,10 @@ public static CommandLineArguments Parse(string[] args)
.Add("h|H|help", "Get some help", h => showHelp = h != null)
.Add("g=|G=|geometry", "Geometry, Instruct Dynamo to output geometry from all evaluations to a json file at this path", g => geometryFilePath = g)
.Add("i=|I=|import", "Import, Instruct Dynamo to import an assembly as a node library. This argument should be a filepath to a single .dll" +
" - if you wish to import multiple dlls - use this flag multiple times: -i 'assembly1.dll' -i 'assembly2.dll' ", i => importPaths.Add(i)).
Add("gp=|GP=|geometrypath=|GeometryPath=", "relative or absolute path to a directory containing ASM. When supplied, instead of searching the hard disk for ASM, it will be loaded directly from this path.", gp => asmPath = gp);

" - if you wish to import multiple dlls - use this flag multiple times: -i 'assembly1.dll' -i 'assembly2.dll' ", i => importPaths.Add(i))
.Add("gp=|GP=|geometrypath=|GeometryPath=", "relative or absolute path to a directory containing ASM. When supplied, instead of searching the hard disk for ASM, it will be loaded directly from this path.", gp => asmPath = gp)
.Add("k|K|keepalive", "Keepalive mode, leave the Dynamo process running until a loaded extension shuts it down.", k => keepAlive = k != null)
;
optionsSet.Parse(args);

if (showHelp)
Expand All @@ -133,7 +137,8 @@ public static CommandLineArguments Parse(string[] args)
ConvertFile = convertFile,
GeometryFilePath = geometryFilePath,
ImportedPaths = importPaths,
ASMPath = asmPath
ASMPath = asmPath,
KeepAlive = keepAlive
};
}

Expand All @@ -151,6 +156,7 @@ private static void ShowHelp(OptionSet opSet)
public string GeometryFilePath { get; set; }
public IEnumerable<String> ImportedPaths { get; set; }
public string ASMPath { get; set; }
public bool KeepAlive { get; set; }
}

public static void PreloadShapeManager(ref string geometryFactoryPath, ref string preloaderLocation)
Expand Down
24 changes: 22 additions & 2 deletions src/DynamoCLI/CommandLineRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public CommandLineRunner(DynamoModel model)
private static XmlDocument RunCommandLineArgs(DynamoModel model, StartupUtils.CommandLineArguments cmdLineArgs)
{
var evalComplete = false;
if (string.IsNullOrEmpty(cmdLineArgs.OpenFilePath))

if (!cmdLineArgs.KeepAlive && string.IsNullOrEmpty(cmdLineArgs.OpenFilePath))
{
return null;
}
Expand All @@ -47,9 +48,28 @@ private static XmlDocument RunCommandLineArgs(DynamoModel model, StartupUtils.Co
cmdLineArgs.ImportedPaths.ToList().ForEach(path =>
{
ImportAssembly(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;

model.ShutdownCompleted += (m) =>
{
running = false;
};

while (running)
{
Thread.Sleep(3000);
}

return null;
}


model.OpenFileFromPath(cmdLineArgs.OpenFilePath, true);
Console.WriteLine("loaded file");
model.EvaluationCompleted += (o, args) => { evalComplete = true; };
Expand Down

0 comments on commit 78ec538

Please sign in to comment.