private static XmlDocument RunCommandLineArgs(DynamoModel model, StartupUtils.CommandLineArguments cmdLineArgs) { var evalComplete = false; if (string.IsNullOrEmpty(cmdLineArgs.OpenFilePath)) { return(null); } if (!(string.IsNullOrEmpty(cmdLineArgs.CommandFilePath))) { Console.WriteLine("commandFilePath option is only available when running DynamoSandbox, not DynamoCLI"); } if (!(string.IsNullOrEmpty(cmdLineArgs.GeometryFilePath))) { Console.WriteLine("geometryFilePath option is only available when running DynamoWPFCLI, not DynamoCLI"); } cmdLineArgs.ImportedPaths.ToList().ForEach(path => { ImportAssembly(model, path); }); model.OpenFileFromPath(cmdLineArgs.OpenFilePath, true); Console.WriteLine("loaded file"); model.EvaluationCompleted += (o, args) => { evalComplete = true; }; // Build a list of states, by default there is only a single state `default` // If the desire is to have additional states you can add logic here to build // up a list and iterate through each state in the list using the loop below. // This must be done after potentially loading states from an external file. var stateNames = new List <String>(); stateNames.Add("default"); XmlDocument doc = null; foreach (var stateName in stateNames) { // Graph execution model.ExecuteCommand(new DynamoModel.RunCancelCommand(false, false)); while (evalComplete == false) { Thread.Sleep(250); } //if verbose was true, then print all nodes to the console if (!String.IsNullOrEmpty(cmdLineArgs.Verbose)) { doc = CreateXMLDoc(model); } evalComplete = false; } return(doc); }
public void Run(StartupUtils.CommandLineArguments args) { var doc = RunCommandLineArgs(this.model, args); if (doc != null && Directory.Exists(new FileInfo(args.Verbose).Directory.FullName)) { //if it exists and the path is valid, save the output file doc.Save(args.Verbose); } }
/// <summary> /// Run the CLI with the command line arguments in "args" <see cref="StartupUtils.CommandLineArguments"/> /// </summary> /// <param name="args">Command line arguments</param> public void Run(StartupUtils.CommandLineArguments args) { if (args.ConvertFile) { OpenWorkspaceAndConvert(model, args.OpenFilePath); return; } var doc = RunCommandLineArgs(this.model, args); if (doc != null && Directory.Exists(new FileInfo(args.Verbose).Directory.FullName)) { //if it exists and the path is valid, save the output file doc.Save(args.Verbose); } }
private static XmlDocument RunCommandLineArgs(DynamoModel model, StartupUtils.CommandLineArguments cmdLineArgs) { var evalComplete = false; if (string.IsNullOrEmpty(cmdLineArgs.OpenFilePath)) { return(null); } if (!(string.IsNullOrEmpty(cmdLineArgs.CommandFilePath))) { Console.WriteLine("commandFilePath option is only available when running DynamoSandbox, not DynamoCLI"); } model.OpenFileFromPath(cmdLineArgs.OpenFilePath, true); Console.WriteLine("loaded file"); model.EvaluationCompleted += (o, args) => { evalComplete = true; }; // Build a list of states, by default there is only a single state `default` // If the desire is to have additional states you can add logic here to build // up a list and iterate through each state in the list using the loop below. // This must be done after potentially loading states from an external file. var stateNames = new List <String>(); stateNames.Add("default"); var outputresults = new List <Dictionary <Guid, List <object> > >(); XmlDocument doc = null; foreach (var stateName in stateNames) { // Graph execution model.ExecuteCommand(new DynamoModel.RunCancelCommand(false, false)); while (evalComplete == false) { Thread.Sleep(250); } //if verbose was true, then print all nodes to the console if (!String.IsNullOrEmpty(cmdLineArgs.Verbose)) { doc = new XmlDocument(); var resultsdict = new Dictionary <Guid, List <object> >(); foreach (var node in model.CurrentWorkspace.Nodes) { var portvalues = new List <object>(); foreach (var port in node.OutPorts) { var value = node.GetValue(port.Index, model.EngineController); if (value.IsCollection) { portvalues.Add(GetStringRepOfCollection(value)); } else { portvalues.Add(value.StringData); } } resultsdict.Add(node.GUID, portvalues); } outputresults.Add(resultsdict); populateXmlDocWithResults(doc, outputresults); } evalComplete = false; } return(doc); }
private static XmlDocument RunCommandLineArgs(DynamoModel model, StartupUtils.CommandLineArguments cmdLineArgs) { var evalComplete = false; if (string.IsNullOrEmpty(cmdLineArgs.OpenFilePath)) { return(null); } if (!(string.IsNullOrEmpty(cmdLineArgs.CommandFilePath))) { Console.WriteLine("commandFilePath option is only available when running DynamoSandbox, not DynamoCLI"); } model.OpenFileFromPath(cmdLineArgs.OpenFilePath, true); Console.WriteLine("loaded file"); model.EvaluationCompleted += (o, args) => { evalComplete = true; }; if (!string.IsNullOrEmpty(cmdLineArgs.PresetFilePath)) { //first load the openfile nodegraph var originalGraphdoc = XmlHelper.CreateDocument("tempworkspace"); originalGraphdoc.Load(cmdLineArgs.OpenFilePath); var graph = NodeGraph.LoadGraphFromXml(originalGraphdoc, model.NodeFactory); //then load the presetsfile nodegraph (this should only contain presets), var presetsDoc = XmlHelper.CreateDocument("presetstempworkspace"); presetsDoc.Load(cmdLineArgs.PresetFilePath); //when we load the presets we need to pass in the nodeModels from the original graph var presets = NodeGraph.LoadPresetsFromXml(presetsDoc, graph.Nodes); //load the presets contained in the presetsfile into the workspace, model.CurrentWorkspace.ImportPresets(presets); } //build a list of states, for now, none, a single state, or all of them //this must be done after potentially loading states from external file var stateNames = new List <String>(); if (!string.IsNullOrEmpty(cmdLineArgs.PresetStateID)) { if (cmdLineArgs.PresetStateID == "all") { foreach (var state in model.CurrentWorkspace.Presets) { stateNames.Add(state.Name); } } else { stateNames.Add(cmdLineArgs.PresetStateID); } } else { stateNames.Add("default"); } var outputresults = new List <Dictionary <Guid, List <object> > >(); XmlDocument doc = null; foreach (var stateName in stateNames) { Guid stateGuid = Guid.Empty; var state = model.CurrentWorkspace.Presets.Where(x => x.Name == stateName).FirstOrDefault(); if (state != null) { stateGuid = state.GUID; } model.ExecuteCommand(new DynamoModel.ApplyPresetCommand(model.CurrentWorkspace.Guid, stateGuid)); model.ExecuteCommand(new DynamoModel.RunCancelCommand(false, false)); while (evalComplete == false) { Thread.Sleep(250); } //if verbose was true, then print all nodes to the console if (!String.IsNullOrEmpty(cmdLineArgs.Verbose)) { doc = new XmlDocument(); var resultsdict = new Dictionary <Guid, List <object> >(); foreach (var node in model.CurrentWorkspace.Nodes) { var portvalues = new List <object>(); foreach (var port in node.OutPorts) { var value = node.GetValue(port.Index, model.EngineController); if (value.IsCollection) { portvalues.Add(GetStringRepOfCollection(value)); } else { portvalues.Add(value.StringData); } } resultsdict.Add(node.GUID, portvalues); } outputresults.Add(resultsdict); populateXmlDocWithResults(doc, outputresults); } evalComplete = false; } return(doc); }