public void StartClient(string id, string url, string script_file) { Console.WriteLine("# StartClient:"); string clientID = id; //c1 ProcessSupport ProcessClient = new ProcessSupport(clientID, url); if (ClientProcess.ContainsKey(ProcessClient)) { if (ClientProcess[ProcessClient].HasExited) { ClientProcess.Remove(ProcessClient); } } if (ClientProcess.ContainsKey(ProcessClient) == false) { try { Process p = new Process(); p.StartInfo.FileName = clientPath; p.StartInfo.Arguments = clientID + " " + url + " " + script_file; p.Start(); ClientProcess.Add(ProcessClient, p); } catch (InvalidOperationException) { Console.WriteLine("FileName specified is not valid"); } catch (Win32Exception) { Console.WriteLine("Couldn't Initialize the Client"); } } else { Console.WriteLine("\nThe pid specified already exists : {0}", clientID); } }
public void StartServer(string id, string url, string min_delay, string max_delay) { Console.WriteLine("# StartServer:"); string serverID = id; //s1 ProcessSupport ProcessServer = new ProcessSupport(serverID, url); if (ServerProcess.ContainsKey(ProcessServer)) { if (ServerProcess[ProcessServer].HasExited) //If process is terminated { ServerProcess.Remove(ProcessServer); } } if (!ServerProcess.ContainsKey(ProcessServer)) { try { Process p = new Process(); p.StartInfo.FileName = serverPath; p.StartInfo.Arguments = serverID + " " + url + " " + min_delay + " " + max_delay; p.Start(); ServerProcess.Add(ProcessServer, p); Console.WriteLine("Starting the server"); } catch (InvalidOperationException) { Console.WriteLine("FileName specified is not valid"); } catch (Win32Exception e) { Console.WriteLine("Couldn't Initialize the Server"); Console.WriteLine(e); } } else { Console.WriteLine("\nThe pid specified already exists : {0}", serverID); } }
public override bool Equals(object obj) { if (obj == null) { return(false); } ProcessSupport t = obj as ProcessSupport; if (t == null) { return(false); } return(Processname.Equals(t.GetProcessname())); }
public void Crash(string processname) { Process p; ProcessSupport ProcessInUse = new ProcessSupport(processname, "tcp:\\localhost:9000"); //dummyaddress try { if (processname[0] == 's') //is server? { p = ServerProcess[ProcessInUse]; ServerProcess.Remove(ProcessInUse); } else { if ((processname[0] == 'c')) //is client? { p = ClientProcess[ProcessInUse]; ClientProcess.Remove(ProcessInUse); } else { return; } } if (p.HasExited == false) { p.Kill(); //crash the process } } catch (Exception e) { return; } Console.WriteLine("Process " + processname + "Sucessfully crashed"); }