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 bool Import() { try { string raw_json = File.ReadAllText(name + extention); JsonObject json = new JsonObject(raw_json); name = json.Get <string>("name"); id = json.Get <int>("id"); lang = json.Get <string>("lang"); module_dep = json.GetList <int>("module_dep"); file_dep = json.GetList <string>("file_dep"); nodes = json.GetList <string>("nodes"); return(true); } catch (DirectoryNotFoundException) { VSLogger.LogError("Unable to import '" + name + extention + "'"); return(false); } catch (FileNotFoundException) { VSLogger.LogError("Unable to import '" + name + extention + "'"); return(false); } }
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 bool Import() { try { string raw_json = File.ReadAllText(name + extention); JsonObject json = new JsonObject(raw_json); name = json.Get <string>("name"); id = json.Get <int>("id"); source = json.Get <string>("source"); meta_value_key = json.Get <string>("meta_value_key"); colour_r = json.Get <float>("colour_r", json.Get <int>("colour_r")); colour_g = json.Get <float>("colour_g", json.Get <int>("colour_g")); colour_b = json.Get <float>("colour_b", json.Get <int>("colour_b")); foreach (JsonObject input_json in json.GetObjectList("inputs")) { NodeIO input = new NodeIO(); input.name = input_json.Get <string>("name"); input.display_name = input_json.Get <string>("display_name", input.name); input.is_execution = input_json.Get <bool>("is_execution"); input.colour_r = input_json.Get <float>("colour_r", input_json.Get <int>("colour_r")); input.colour_g = input_json.Get <float>("colour_g", input_json.Get <int>("colour_g")); input.colour_b = input_json.Get <float>("colour_b", input_json.Get <int>("colour_b")); inputs.Add(input); } foreach (JsonObject output_json in json.GetObjectList("outputs")) { NodeIO output = new NodeIO(); output.name = output_json.Get <string>("name"); output.display_name = output_json.Get <string>("display_name", output.name); output.is_execution = output_json.Get <bool>("is_execution"); output.colour_r = output_json.Get <float>("colour_r", output_json.Get <int>("colour_r")); output.colour_g = output_json.Get <float>("colour_g", output_json.Get <int>("colour_g")); output.colour_b = output_json.Get <float>("colour_b", output_json.Get <int>("colour_b")); outputs.Add(output); } return(true); } catch (DirectoryNotFoundException) { VSLogger.LogError("Unable to import '" + name + extention + "'"); return(false); } catch (FileNotFoundException) { VSLogger.LogError("Unable to import '" + name + extention + "'"); return(false); } }
public void RemoveConnection(GraphNode out_node, string out_key, GraphNode in_node, string in_key) { if (out_node.outputs.ContainsKey(out_key) && in_node.inputs.ContainsKey(in_key) && out_node.outputs[out_key] == in_node.guid && in_node.inputs[in_key] == out_node.guid ) { out_node.outputs.Remove(out_key); in_node.inputs.Remove(in_key); } else { VSLogger.LogError("Attempting to remove invalid connection between '" + out_node.module_id + ":" + out_node.node_id + "' and '" + in_node.module_id + ":" + in_node.node_id + "'"); } }
public static bool AbortCurrentProcess() { if (Aborting) { return(true); } if (!Running) { VSLogger.LogError("Cannot abort process, as none is active"); return(false); } Aborting = true; return(true); }
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); }