public void LoadModule(string folder, string name) { Module module = new Module(folder + "/" + name); module.Import(); if (module_nodes.ContainsKey(module.id)) { VSLogger.LogError("Cannot load module '" + name + "':" + module.id + " as module with same id already exists"); return; } Dictionary <int, Node> nodes = new Dictionary <int, Node>(); foreach (string node_name in module.nodes) { Node node = new Node(folder + "/" + node_name); node.Import(); node.module_id = module.id; if (nodes.ContainsKey(node.id)) { VSLogger.LogError("Cannot load node '" + node_name + "':" + node.id + " in module '" + name + "' as node with same id already exists"); continue; } nodes.Add(node.id, node); } module_nodes.Add(module.id, nodes); VSLogger.Log("Loaded module '" + name + "':" + module.id + " with " + nodes.Count + " nodes"); }
public static void RunGraph(string graph_path, ReadInput input_function) { if (CurrentProcess != null && !CurrentProcess.HasExited) { CurrentProcess.Kill(); } CurrentProcess = FetchNewProcess(graph_path); Aborting = false; if (input_function != null) { CurrentProcess.StartInfo.RedirectStandardInput = true; } try { //Start process and asynchronous reading CurrentProcess.Start(); CurrentProcess.BeginOutputReadLine(); CurrentProcess.BeginErrorReadLine(); if (input_function != null) { using (StreamWriter writer = new StreamWriter(CurrentProcess.StandardInput.BaseStream, Encoding.ASCII)) { while (!CurrentProcess.HasExited && !Aborting) { byte[] input = input_function(); if (input != null && input.Length != 0) { writer.WriteLine(Encoding.ASCII.GetString(input)); } else { writer.Flush(); } } } } if (Aborting && !CurrentProcess.HasExited) { CurrentProcess.Kill(); CurrentProcess.WaitForExit(); VSLogger.Log("Aborted current process."); } } catch (Win32Exception exception) { VSLogger.LogError("Output:\n" + exception.ToString()); } CurrentProcess.WaitForExit(); CurrentProcess = null; Aborting = false; }
public string Compile(Graph graph) { string graph_path = build_path + graph.display_name + ".py"; VSLogger.Log("Starting Compile '" + graph_path + "'"); Directory.CreateDirectory(build_path); string source = Expand(graph.start_node); File.WriteAllText(graph_path, source); VSLogger.DebugLog("\n==Source-start==\n" + source + "\n===Source-end==="); VSLogger.Log("Finished Compile!"); return(graph_path); }
static void Main(string[] args) { VSLogger.std_print = Print; VSLogger.debug_print = Print; VSLogger.error_print = Print; VScriptEngine.input_function = delegate() { return(Encoding.ASCII.GetBytes("Test")); }; VScriptEngine.engine_directory = "../../VScript/"; VScriptEngine.Init(); Graph graph = VScriptEngine.NewGraph("Temp"); //Graph graph = VScriptEngine.OpenGraph("Infinite Loop"); /* * graph.Clear(); * graph.AddNode(0, 1); * * GraphNode const_msg = graph.AddNode(0, 2); * const_msg.meta_data.Put("value", "\"Hard coded msg\""); * * GraphNode true_node = graph.AddNode(1, 5); * GraphNode false_node = graph.AddNode(1, 6); * GraphNode print_true = graph.AddNode(1, 3); * GraphNode print_false = graph.AddNode(1, 3); * GraphNode print_msg = graph.AddNode(1, 3); * * graph.AddConnection(true_node, "end", print_true, "message"); * graph.AddConnection(false_node, "end", print_false, "message"); * graph.AddConnection(const_msg, "end", print_msg, "message"); * * * graph.AddConnection(graph.start_node, "end", print_true, "begin"); * graph.AddConnection(print_true, "end", print_false, "begin"); * graph.AddConnection(print_false, "end", print_msg, "begin"); */ //graph.AddConnection(if_then, "true", print_true, "begin"); //graph.AddConnection(if_then, "false", print_false, "begin"); VScriptEngine.CompileAndRun(graph); VSLogger.Log("Done"); Console.ReadLine(); }
private static Process FetchNewProcess(string graph_path, string args = "") { Process process = new Process(); process.StartInfo.FileName = exe_path; process.StartInfo.WorkingDirectory = VScriptEngine.executable_directory; Directory.CreateDirectory(VScriptEngine.executable_directory); process.StartInfo.Arguments = "\"" + Directory.GetCurrentDirectory() + "/" + graph_path + "\" " + args; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; //Register std output process.OutputDataReceived += (sender, arg) => { if (arg != null && arg.Data != null) { VSLogger.Log(arg.Data.ToString()); } }; //Register error output process.ErrorDataReceived += (sender, arg) => { if (arg == null || arg.Data == null) { return; } String error = arg.Data.ToString(); if (error != null && error.Length != 0) { VSLogger.LogError(error); } }; return(process); }