private void StopAgent() { if (process_agent != null) { try { ProcessHandling.StopProcess((uint)process_agent.Id); } catch { } process_agent.Close(); process_agent.Dispose(); process_agent = null; } }
private void StopGateway() { if (process_gateway != null) { try { ProcessHandling.StopProcess((uint)process_gateway.Id); } catch { } process_gateway.Close(); process_gateway.Dispose(); process_gateway = null; } }
private void StartGateway() { Task.Factory.StartNew(() => { process_gateway = new Process(); process_gateway.StartInfo.FileName = "java"; process_gateway.StartInfo.Arguments = @"-jar target/ogwapi-jar-with-dependencies.jar"; process_gateway.StartInfo.WorkingDirectory = @"C:\VICINITY\Gateway"; process_gateway.StartInfo.RedirectStandardOutput = true; process_gateway.StartInfo.RedirectStandardError = true; process_gateway.StartInfo.UseShellExecute = false; process_gateway.StartInfo.CreateNoWindow = true; process_gateway.EnableRaisingEvents = true; process_gateway.OutputDataReceived += Process_Gateway_OutputDataReceived; process_gateway.ErrorDataReceived += Process_Gateway_ErrorDataReceived; process_gateway.Start(); try { process_gateway.BeginErrorReadLine(); process_gateway.BeginOutputReadLine(); } catch { if (process_gateway != null) { try { ProcessHandling.StopProcess((uint)process_gateway.Id); } catch { } process_gateway.Close(); process_gateway.Dispose(); } } }); }
public override void Specify() { given("a psake script which writes the current process id to output", delegate { string scriptPath = GetVerifiedPathOfTestScript("task_writes_process_id.ps1"); when("that script is invoked interactively", delegate { ConsoleApplicationResult invocation = arrange(() => { string moduleLocation = GetModuleLocation(); return(ProcessHandling.RunNoninteractiveConsoleProcess(PsakeUtil.GetPowershellCommand(moduleLocation, scriptPath, "default"))); }); then("the script succeeds", delegate { expect(() => invocation.ExitCode == 0); }); then("the output file has a different process id than the current", delegate { var allLines = invocation.ConsoleOutput; int?processId = allLines.Select(l => Regex.Match(l, @"Process ID: (\d*)")).Where(m => m.Success).Select( m => int.Parse(m.Groups[1].Value)).Single(); expect(() => processId.Value > 0); expect(() => processId.Value != Process.GetCurrentProcess().Id); }); }); }); given("a psake script that fails", delegate { var scriptPath = GetVerifiedPathOfTestScript("task_fails_assert.ps1"); when("that script is invoked interactively", delegate { ConsoleApplicationResult invocation = arrange(() => { string moduleLocation = GetModuleLocation(); return(ProcessHandling.RunNoninteractiveConsoleProcess(PsakeUtil.GetPowershellCommand(moduleLocation, scriptPath, "Fails"))); }); then("the exit code indicates failure", delegate { expect(() => invocation.ExitCode == 1); }); }); }); given("a non-default psake script", delegate { var scriptPath = GetVerifiedPathOfTestScript("task_writes_process_id.ps1"); when("that script is invoked interactively", delegate { ConsoleApplicationResult invocation = arrange(() => { string moduleLocation = GetModuleLocation(); return(ProcessHandling.RunNoninteractiveConsoleProcess(PsakeUtil.GetPowershellCommand(moduleLocation, scriptPath, "Other"))); }); then("the other tasks output is seen", delegate { expect(() => invocation.ConsoleOutput.Any(l => l.Equals("Another task"))); }); }); }); given("a different user account", delegate { given("a script that prints the accounts username", delegate { when("that script is invoked interactively", delegate { then("the script output is the user account's username"); then("the script can interact with a desktop"); }); }); }); given("a vhd image (64bit? 32bit?)", delegate { given("a psake script that writes its IP address and process id", delegate { when("the script is invoked remotely", delegate { then("the reported ip address and process id are different"); }); }); }); }