Esempio n. 1
0
 public void RestartProcess()
 {
     KillProcess();
     if (!CheckTargetExeOrSetError())
     {
         return;
     }
     if (string.IsNullOrEmpty(Xaml))
     {
         return;
     }
     _host.Start(TargetExe, Xaml);
 }
        public void process_is_killed_when_process_host_is_disposed()
        {
            uint processId;

            using (var subject = new ProcessHost("./ExampleInteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                subject.Start();
                processId = subject.ProcessId();
            }
            Thread.Sleep(500);
            try
            {
                // system.diagnostics.process throws in debug mode, returns null in release mode!
                var prc = Process.GetProcessById((int)processId);
                Assert.That(prc, Is.Null);
            }
            catch (ArgumentException)
            {
                Assert.Pass();
            }
            catch (InvalidOperationException)
            {
                Assert.Pass();
            }
            Assert.Fail();
        }
Esempio n. 3
0
 private void RegisterProcesses()
 {
     stages[Process_RunScriptsFromQueue]           = true;
     stages[Process_UnsuccessfullyFinishedScripts] = true;
     stages[Process_WaitScriptsForFinish]          = true;
     stages[Process_CheckIfAllFinished]            = true;
     stages.Start();
 }
 public void RestartProcess()
 {
     KillProcess();
     if (!CheckTargetExeOrSetError())
     {
         return;
     }
     if (string.IsNullOrEmpty(Xaml))
     {
         return;
     }
     if (Xaml != null)
     {
         _host.UpdateXaml(Xaml, SourceAssembly);
     }
     _host.Start(TargetExe, Xaml, SourceAssembly);
 }
Esempio n. 5
0
        public EvidenceBase(string id, string description)
        {
            Id          = id;
            Description = description;

            RegisterStages();
            ProcHost.Start();
        }
        public void can_pass_arguments_to_process()
        {
            using (var subject = new ProcessHost("./ExampleNoninteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                subject.Start("print hello world");
                Thread.Sleep(250);

                var output = subject.StdOut.ReadAllText(Encoding.Default);
                Assert.That(output, Is.StringStarting("hello world"));
            }
        }
        public void can_get_exit_code_from_process()
        {
            using (var subject = new ProcessHost("./ExampleNoninteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                subject.Start("return 1729");

                Assert.That(subject.WaitForExit(one_second), "process did not exit");
                var code = subject.ExitCode();

                Assert.That(code, Is.EqualTo(1729));
            }
        }
 public void Dispatch(float speed = 20f, VehicleDrivingFlags flags = VehicleDrivingFlags.Emergency)
 {
     DetectiveBlip = new Blip(DetectivePed);
     DetectiveBlip.SetStandardColor(CalloutStandardization.BlipTypes.Officers);
     DetectiveBlip.SetBlipScalePed();
     DetectivePed.Tasks.DriveToPosition(TargetPosition, speed, flags, 5f);
     IsRunning = true;
     "Detective Dispatched".DisplayNotification("A ~b~detective~w~ has been ~g~dispatched~w~ to your location");
     Game.DisplayHelp("Wait where you are until the ~b~detective~w~ arrives.");
     _processHost.Start();
     _processHost.ActivateProcess(DriveFiber);
 }
        public void stress_test()
        {
            for (int i = 0; i < 10000; i++)
            {
                using (var subject = new ProcessHost("./ExampleNoninteractiveProcess.exe", Directory.GetCurrentDirectory()))
                {
                    subject.Start();
                }
            }

            Assert.Pass();
        }
Esempio n. 10
0
    public ProcessHostExample()
    {
        //turn on a function you like to be called in ticks
        procHost.ActivateProcess(CheckIfPlayerIsClose);
        //OR
        procHost[CheckIfPlayerIsClose] = true;

        //start processing your functions
        procHost.Start();
        //you can also call procHost.Process() inside Process() of your callout
        // in such case you _don't_ call procHost.Start()
    }
        public void can_write_strings_from_a_processes_pipes()
        {
            using (var subject = new ProcessHost("./ExampleInteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                subject.Start();

                subject.StdIn.WriteAllText(Encoding.Default, "bye\r\n");

                int exitCode;
                var ok = subject.WaitForExit(one_second, out exitCode);

                Assert.That(ok, Is.True);
                Assert.That(exitCode, Is.EqualTo(0));
            }
        }
        public void Start()
        {
            IsRunning = true;
            if (!DetectivePed)
            {
                Game.DisplayNotification("Detective error, see log");
                Game.LogTrivial("Detective not found");
                return;
            }
            DetectivePed.IsInvincible         = true;
            DetectivePed.IsPersistent         = true;
            DetectivePed.BlockPermanentEvents = true;

            _procHost.Start();
            _procHost.ActivateProcess(QuestionDisplay);
        }
        public void can_run_and_read_from_a_non_interactive_process()
        {
            using (var subject = new ProcessHost("./ExampleNoninteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                subject.Start();
                Thread.Sleep(250);

                Assert.That(subject.IsAlive(), Is.False);

                var output = subject.StdOut.ReadAllText(Encoding.Default);
                Assert.That(output, Is.StringStarting(ExampleNoninteractiveProcess.Program.StdOutMsg), "Standard Out");

                var err = subject.StdErr.ReadAllText(Encoding.Default);
                Assert.That(err, Is.StringStarting(ExampleNoninteractiveProcess.Program.StdErrMsg), "Standard Error");
            }
        }
        public void can_call_environment_executables()
        {
            using (var subject = new ProcessHost("net", null))
            {
                subject.Start();
                Thread.Sleep(250);

                Assert.That(subject.IsAlive(), Is.False);

                var output = subject.StdOut.ReadAllText(Encoding.Default);
                Assert.That(output, Is.EqualTo(""), "Standard Out");

                var err = subject.StdErr.ReadAllText(Encoding.Default);
                Assert.That(err, Is.StringStarting("The syntax of this command is:"), "Standard Error");
            }
        }
Esempio n. 15
0
        public void can_pass_environment_variables_to_process()
        {
            using (var subject = new ProcessHost("./ExampleNoninteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                var envars = new Dictionary <string, string> {
                    { "one", "two" },
                    { "three", "four" }
                };
                subject.Start("envarg", envars);
                Thread.Sleep(500);

                var output = subject.StdOut.ReadAllWithTimeout(Encoding.Default, TimeSpan.FromSeconds(10));
                Assert.That(output, Is.StringContaining("one = two"));
                Assert.That(output, Is.StringContaining("three = four"));
            }
        }
        public void Writing_to_an_OUT_pipe_throws_an_exception()
        {
            using (var subject = new ProcessHost("./ExampleNoninteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                subject.Start();

                var dummy = new byte[2];

                Assert.Throws <Exception>(() => subject.StdOut.Write(dummy, 0, 1));

                int exitCode;
                var exited = subject.WaitForExit(one_second, out exitCode);

                Assert.That(exited, Is.True);
                Assert.That(exitCode, Is.EqualTo(0));
            }
        }
        public void can_read_and_write_single_lines_on_a_processes_pipes()
        {
            using (var subject = new ProcessHost("./ExampleInteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                subject.Start();

                var read = subject.StdOut.ReadLine(Encoding.Default, one_second);
                Assert.That(read, Is.EqualTo(ExampleProcess.Program.Intro));

                subject.StdIn.WriteLine(Encoding.Default, "bye");

                int exitCode;
                var ok = subject.WaitForExit(one_second, out exitCode);

                Assert.That(ok, Is.True);
                Assert.That(exitCode, Is.EqualTo(0));
            }
        }
        public void can_wait_for_process_and_kill_if_required()
        {
            using (var subject = new ProcessHost("./ExampleNoninteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                subject.Start("wait");

                var ended = subject.WaitForExit(one_second);

                Assert.That(ended, Is.False, "Ended");
                Assert.That(subject.IsAlive(), Is.True, "Alive");

                subject.Kill();
                var endedAfterKill = subject.WaitForExit(one_second);

                Assert.That(endedAfterKill, Is.True, "ended after kill");
                Assert.That(subject.IsAlive(), Is.False, "Alive after kill");
                Assert.That(subject.ExitCode(), Is.EqualTo(127), "standard killed code");
            }
        }
        public void can_get_process_id_and_use_with_existing_dotnet_libraries()
        {
            using (var subject = new ProcessHost("./ExampleInteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                subject.Start();

                uint id = subject.ProcessId();

                var process = Process.GetProcessById((int)id);
                Assert.That(process.HasExited, Is.False, "Exited");

                process.Kill();

                int exitCode;
                var exited = subject.WaitForExit(one_second, out exitCode);

                Assert.That(exited, Is.True, "Exited after kill");
                Assert.That(exitCode, Is.EqualTo(0), "Exit code");
            }
        }
Esempio n. 20
0
        public void child_process_can_be_killed_when_parent_is_killed()
        {
            Process p;
            int     pid;

            using (var subject = new ProcessHost("./ExampleNoninteractiveProcess.exe", Directory.GetCurrentDirectory()))
            {
                // start a process, which calls `StartAsChild`. Then kill that process and check the child died
                subject.Start("spawn");
                var output = subject.StdOut.ReadToTimeout(Encoding.Default, TimeSpan.FromSeconds(1));
                var ok     = int.TryParse(output, out pid);
                Assert.That(ok, Is.True, "PID was {" + output + "}");

                p = Process.GetProcessById(pid);
                Assert.That(p.HasExited, Is.False, "Child process not running");
            }
            Thread.Sleep(500);

            Assert.That(p.HasExited, Is.True, "Child process is still running (pid = " + pid + ")");
        }
Esempio n. 21
0
        ProcessHost CallAsChildUser(string exePath, string args)
        {
            var fullExePath = Path.GetFullPath(exePath);
            var runningDirectory = InitialWorkingDirectory(fullExePath);

            var proc = new ProcessHost(fullExePath, runningDirectory);

            proc.Start(args);

            return proc;
        }
 public EvidenceController()
 {
     proc.ActivateProcess(Process);
     proc.Start();
 }