Esempio n. 1
0
        bool PythonGraphGenerate(int graph_seed, bool seed_enable)
        {
            if (seed_enable)
            {
                PythonProxy.ExecutePythonScript(this.GeneratePath + " " + graph_seed);
            }
            else
            {
                PythonProxy.ExecutePythonScript(this.GeneratePath);
            }
            bool exist_flag = false;

            while (!exist_flag)
            {
                var working_path = Properties.Settings.Default.WorkingFolderPath;
                var graph_flag   = Properties.Settings.Default.RawGraphFile;
                exist_flag = File.Exists(working_path + graph_flag);
                System.Threading.Thread.Sleep(100);
                if (PythonProxy.ErrorFlag)
                {
                    System.Threading.Thread.Sleep(100);
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        private static void Context_Spansh_Nearestsystem(dynamic vaProxy)
        {
            int x = vaProxy.GetInt("~x") ?? throw new ArgumentNullException("~x");
            int y = vaProxy.GetInt("~y") ?? throw new ArgumentNullException("~y");
            int z = vaProxy.GetInt("~z") ?? throw new ArgumentNullException("~z");

            string path      = $@"{vaProxy.SessionState["VA_SOUNDS"]}\Scripts\spansh.exe";
            string arguments = $@"nearestsystem --parsable {x} {y} {z}";

            Process p = PythonProxy.SetupPythonScript(path, arguments);

            Dictionary <char, decimal> coords = new Dictionary <char, decimal> {
                { 'x', 0 }, { 'y', 0 }, { 'z', 0 }
            };
            string  system       = "";
            decimal distance     = 0;
            bool    error        = false;
            string  errorMessage = "";

            p.Start();
            string stdout = p.StandardOutput.ReadToEnd();
            string stderr = p.StandardError.ReadToEnd();

            p.WaitForExit();
            switch (p.ExitCode)
            {
            case 0:
                string[] stdoutExploded = stdout.Split('|');
                system   = stdoutExploded[0];
                distance = decimal.Parse(stdoutExploded[2]);
                string[] stdoutCoords = stdoutExploded[1].Split(',');
                coords['x'] = decimal.Parse(stdoutCoords[0]);
                coords['y'] = decimal.Parse(stdoutCoords[1]);
                coords['z'] = decimal.Parse(stdoutCoords[2]);
                Log.Info($"Nearest system to ({x}, {y}, {z}): {system} ({coords['x']}, {coords['y']}, {coords['z']}), distance: {distance} ly");
                break;

            case 1:
                error        = true;
                errorMessage = stdout;
                Log.Error(errorMessage);
                break;

            default:
                error = true;
                Log.Error(stderr);
                errorMessage = "Unrecoverable error in plugin.";
                break;
            }

            vaProxy.SetText("~system", system);
            vaProxy.SetDecimal("~x", coords['x']);
            vaProxy.SetDecimal("~y", coords['y']);
            vaProxy.SetDecimal("~z", coords['z']);
            vaProxy.SetDecimal("~distance", distance);
            vaProxy.SetBoolean("~error", error);
            vaProxy.SetText("~errorMessage", errorMessage);
            vaProxy.SetInt("~exitCode", p.ExitCode);
        }
Esempio n. 3
0
 private void UserInitialize()
 {
     Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
     PythonProxy.StartUpPython();
     this.radioButtonStepCheck.Checked = true;
     this.radioButtonNetworkGUI.Checked = true;
     this.numericUpDownStepsControl.Value = 3000;
     this.numericUpDownSpeedControl.Value = 1;
     this.labelRoundNum.Text = 1.ToString();
     this.PlayStopFlag = true;
 }
Esempio n. 4
0
        private static void Context_Spansh_SytemExists(dynamic vaProxy)
        {
            string system = vaProxy.GetText("~system") ?? throw new ArgumentNullException("~system");

            string path      = $@"{vaProxy.SessionState["VA_SOUNDS"]}\Scripts\spansh.exe";
            string arguments = $@"systemexists ""{system}""";

            Process p = PythonProxy.SetupPythonScript(path, arguments);

            bool   exists       = true;
            bool   error        = false;
            string errorMessage = "";

            p.Start();
            string stdout = p.StandardOutput.ReadToEnd();
            string stderr = p.StandardError.ReadToEnd();

            p.WaitForExit();
            switch (p.ExitCode)
            {
            case 0:
                Log.Info($@"System ""{system}"" found in Spansh’s DB");
                break;

            case 1:
                error        = true;
                errorMessage = stdout;
                Log.Error(errorMessage);
                break;

            case 3:
                exists = false;
                Log.Info($@"System ""{system}"" not found in Spansh’s DB");
                break;

            default:
                error = true;
                Log.Error(stderr);
                errorMessage = "Unrecoverable error in plugin.";
                break;
            }

            vaProxy.SetBoolean("~systemExists", exists);
            vaProxy.SetBoolean("~error", error);
            vaProxy.SetText("~errorMessage", errorMessage);
            vaProxy.SetInt("~exitCode", p.ExitCode);
        }
Esempio n. 5
0
        bool RawGenerate()
        {
            PythonProxy.GeneratePosition(this.GeneratePath);

            bool exist_flag = false;

            while (!exist_flag)
            {
                exist_flag = File.Exists(Properties.Settings.Default.NetworkOutput + "layout_flag");
                System.Threading.Thread.Sleep(100);
                if (PythonProxy.ErrorFlag)
                {
                    System.Threading.Thread.Sleep(100);
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 6
0
        void UserInitialize()
        {
            Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
            PythonProxy.StartUpPython();
            var working_folder_path = Properties.Settings.Default.WorkingFolderPath;

            if (!Directory.Exists(working_folder_path))
            {
                Directory.CreateDirectory(working_folder_path);
            }

            this.radioButtonGraphGUI.Checked     = true;
            this.radioButtonRoundCheck.Checked   = true;
            this.numericUpDownStepsControl.Value = 3000;
            this.numericUpDownSpeedControl.Value = 1;
            this.labelRoundNum.Text   = 0.ToString();
            this.PlayStopFlag         = true;
            this.checkBoxMenu.Checked = true;
        }
Esempio n. 7
0
        protected bool PythonLayoutGenerate(RawGraph graph)
        {
            graph.OutputGraphJSON();
            PythonProxy.ExecutePythonScript(this.GeneratePath);

            bool exist_flag = false;

            while (!exist_flag)
            {
                var working_path = Properties.Settings.Default.WorkingFolderPath;
                var layout_flag  = Properties.Settings.Default.LayoutFlag;
                exist_flag = File.Exists(working_path + layout_flag);
                System.Threading.Thread.Sleep(100);
                if (PythonProxy.ErrorFlag)
                {
                    System.Threading.Thread.Sleep(100);
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 8
0
        bool RawGenerate(int network_seed, bool seed_enable)
        {
            if (seed_enable)
            {
                PythonProxy.GenerateGraph(this.GeneratePath + " " + network_seed);
            }
            else
            {
                PythonProxy.GenerateGraph(this.GeneratePath);
            }
            bool exist_flag = false;

            while (!exist_flag)
            {
                exist_flag = File.Exists(Properties.Settings.Default.NetworkOutput + "flag");
                System.Threading.Thread.Sleep(100);
                if (PythonProxy.ErrorFlag)
                {
                    System.Threading.Thread.Sleep(100);
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 9
0
        public Task Initialize(string workingFolder, CancellationToken ct, double timeout)
        {
            ct.ThrowIfCancellationRequested();

            Trace.TraceInformation($"Initializing Python runtime using version {_version} and path {_path}");

            Stopwatch sw = Stopwatch.StartNew();

            // TODO: expose visible as a property?
            _provider = new Controller <IPythonService>()
            {
                ExeFile = TargetPlatform.x64 == _target ? ServiceExe_x64 : ServiceExe_x86,
                Visible = _visible
            };
            _provider.Create();
            _proxy = new PythonProxy(_provider.Client, timeout, ct);
            _proxy.Initialize(_path, _libraryPath, _version, workingFolder);

            sw.Stop();

            Trace.TraceInformation($"Engine intialization took {sw.ElapsedMilliseconds} ms");

            return(Task.FromResult(true));
        }
Esempio n. 10
0
 public Task Release()
 {
     _proxy?.Shutdown();
     _proxy = null;
     return(Task.FromResult(true));
 }