public void StartServer(string id, string url, int mindelay, int maxdelay, string serverid2, string algorithm, string mode) { //Initialize a process startinfo with the server.exe file ProcessStartInfo info = new ProcessStartInfo(AuxFunctions.GetProjPath() + "\\Server\\bin\\Debug\\Server.exe"); //info.UseShellExecute = false; info.CreateNoWindow = false; //if we have a server to get state from if (serverid2 != " ") { //add the arguments to the info info.Arguments = url + " " + mindelay + " " + maxdelay + " " + serverid2 + " " + algorithm + " " + mode; } //if we dont have a server to get state from else { info.Arguments = url + " " + mindelay + " " + maxdelay + " " + algorithm + " " + mode; } //Start the process Process P = Process.Start(info); //Add process to the process servers list Servers.Add(id, P); }
//Gets the available PCS from a config file ArrayList getPCS() { StreamReader reader = File.OpenText(AuxFunctions.GetProjPath() + "\\scripts\\PuppetMaster\\config.txt"); //each line is a PCS string line; ArrayList PCS = new ArrayList(); while ((line = reader.ReadLine()) != null) { //add PCS to the list PCS.Add(line); } return(PCS); }
public void StartClient(string script, string id, string serverurl, string algorithm, string mode) { //Initialize a process startinfo with the client.exe file ProcessStartInfo info = new ProcessStartInfo(AuxFunctions.GetProjPath() + "\\Client\\bin\\Debug\\Client.exe"); //info.UseShellExecute = false; info.CreateNoWindow = false; //add the arguments to the info if (serverurl == "none") { info.Arguments = script + " " + id + " " + algorithm + " " + mode; } else { info.Arguments = script + " " + id + " " + algorithm + " " + serverurl + " " + mode; } //Start the process Process P = Process.Start(info); Clients.Add(id, P); }
static void Main(string[] args) { //StreamReader reader = File.OpenText(args[0]); StreamReader reader = null; Console.WriteLine("Choose type of command introduction: s for script w for writing commands"); string inputtype = Console.ReadLine(); //if user choose script mode if (inputtype == "s") { try { //open the script reader = File.OpenText(AuxFunctions.GetProjPath() + "\\scripts\\PuppetMaster\\" + "script.txt"); } catch (FileNotFoundException e) { Console.WriteLine("Introduce a correct script file"); } } Console.WriteLine("Choose the algorithm: x for XL and s for SMR"); //get the type of algorithm string algorithm = Console.ReadLine(); Console.WriteLine("Choose the mode: a for advanced, b for basic"); string mode = Console.ReadLine(); //initiliaze a executer of commands PuppetMasterService MasterofPuppets = new PuppetMasterService(algorithm, mode); //get the commands from cmd input if (reader == null) { while (true) { Console.WriteLine("Write a command:" + "\n\r"); string Command = Console.ReadLine(); Console.WriteLine(Command); //execute the command MasterofPuppets.Execute(Command); } } //choose the typeof execution Console.WriteLine("Choose type of execution: s for step, nothing for complete"); //get the type of execution string command = Console.ReadLine(); //if step by step add a readline to stop the full execution if (command == "s") { Console.WriteLine("Step by Step execution"); Console.ReadLine(); string line; while ((line = reader.ReadLine()) != null) { MasterofPuppets.Execute(line); Console.ReadLine(); } } //if complete just execute the lines else { string line; while ((line = reader.ReadLine()) != null) { MasterofPuppets.Execute(line); } } Console.ReadLine(); }
static void Main(string[] args) { //filename of script string filename = " "; string clientid; //ClientID random or user introduced int clientID = 0; //Type of algorithm string algorithm = "x"; // pre definido ou escolher no inicio? //Type of implementation string mode = "b"; //PuppetMaster initialization if (args.Length == 5) { //if defined in script filename = args[0]; clientid = args[1]; algorithm = args[2]; Servers.Add(args[3]); mode = args[4]; Int32.TryParse(clientid, out clientID); Console.WriteLine(clientID); } if (args.Length == 4) { //if not defined in script Servers.Add("tcp://localhost:50001/S"); filename = args[0]; clientid = args[1]; algorithm = args[2]; mode = args[3]; Int32.TryParse(clientid, out clientID); Console.WriteLine(clientID); } //Command Line initialization with script if (args.Length == 1) { filename = args[0]; Console.WriteLine("Introduza o numero unico do cliente"); clientid = Console.ReadLine(); Int32.TryParse(clientid, out clientID); } //Command Line initialization without a script if (args.Length == 0) { Console.WriteLine("Introduza o nome do script que pretende executar"); filename = Console.ReadLine(); Console.WriteLine("Introduza o numero unico do cliente"); clientid = Console.ReadLine(); Int32.TryParse(clientid, out clientID); } if (algorithm == "x") { if (mode == "a") { ClientType = new AdvXL_Client(Servers, clientID); } if (mode == "b") { ClientType = new XL_Client(Servers, clientID); } } if (algorithm == "s") { if (mode == "a") { ClientType = new AdvSMR_Client(Servers, clientID); } if (mode == "b") { ClientType = new SMR_Client(Servers, clientID); } } try { //Get the script from the script folder string filePath = AuxFunctions.GetProjPath() + "\\scripts\\Client\\" + filename; //Initializes a file executer to execute a script file, passes the client to execute the operations on FileExecuter exec = new FileExecuter(ClientType); //Executes the script file exec.ExecuteFile(filePath); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }