Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 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 + "'");
     }
 }
Exemplo n.º 7
0
        /// <see cref="ITestExecutor.RunTests(IEnumerable{string},IRunContext,IFrameworkHandle)"/>
        public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            if (runContext.KeepAlive)
            {
                frameworkHandle.EnableShutdownAfterTestRun = true;
            }

            Channels.UnregisterAll();

            var logger     = new VSLogger(frameworkHandle);
            var discoverer = _discovererFactory(logger);
            var scripts    = discoverer.Discover(sources.Select(s => new FileInfo(s)));

            RunTestsCore(scripts, _ => true, logger, runContext, frameworkHandle);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
        /// <see cref="ITestExecutor.RunTests(IEnumerable{TestCase},IRunContext,IFrameworkHandle)"/>
        /// <remarks>This method is executed when test cases have already been discovered or when a selected subset of tests are run.</remarks>
        public void RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            if (runContext.KeepAlive)
            {
                frameworkHandle.EnableShutdownAfterTestRun = true;
            }

            Channels.UnregisterAll();

            var selectedTests = new HashSet <string>(tests.Select(test => test.FullyQualifiedName));

            var logger      = new VSLogger(frameworkHandle);
            var discoverer  = _discovererFactory(logger);
            var scriptFiles = tests.Select(test => test.Source).Distinct().Select(source => new FileInfo(source));
            var scripts     = discoverer.Discover(scriptFiles);

            RunTestsCore(scripts, test => selectedTests.Contains(test.UniqueName), logger, runContext, frameworkHandle);
        }
Exemplo n.º 11
0
        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);
        }