static void ExecFile(PuppetMasterServices pcs, string input) { string line; try { System.IO.StreamReader file = new System.IO.StreamReader(input); while ((line = file.ReadLine()) != null) { //System.Console.WriteLine(line); string[] words = line.Split(' '); ReadCommand(pcs, words); Console.ReadLine(); } Console.WriteLine("File Reading Finished"); } catch (FileNotFoundException) { Console.WriteLine("File doesn't exists"); } catch (DirectoryNotFoundException) { Console.WriteLine("File doesn't exists"); } catch (ArgumentException) { Console.WriteLine("Invalid Command"); } }
static void Exec(PuppetMasterServices pcs) { string line; while ((line = Console.ReadLine()) != null) { //System.Console.WriteLine(line); string[] words = line.Split(' '); ReadCommand(pcs, words); } }
static void ReadCommand(PuppetMasterServices pcs, string[] words) { switch (words[0]) { case "Server": Console.WriteLine("Starting Server..."); Task.Run(() => pcs.StartServer(words[1], words[2], System.Convert.ToInt32(words[3]), System.Convert.ToInt32(words[4]))); break; case "Client": Console.WriteLine("Starting Client..."); Task.Run(() => pcs.StartClient(words[1], words[2], words[3])); break; case "Status": Console.WriteLine("Printing Status..."); Task.Run(() => pcs.PrintStatus()); break; case "Wait": Console.WriteLine("Waiting {0}...", System.Convert.ToInt32(words[1]) / 1000); Thread.Sleep(System.Convert.ToInt32(words[1])); break; case "Crash": Console.WriteLine("Crash Process..."); Task.Run(() => pcs.Crash(words[1])); break; case "Freeze": Console.WriteLine("Freezing Process..."); Task.Run(() => pcs.Freeze(words[1])); break; case "Unfreeze": Console.WriteLine("Unfreezing Process..."); Task.Run(() => pcs.Unfreeze(words[1])); break; default: ExecFile(pcs, "../../../" + words[0]); break; } }
public void InitPuppetMasterServer() { try { Server server = new Server { Services = { PuppetMasterServices.BindService(new PuppetMasterServiceImpl()) }, Ports = { new ServerPort("localhost", Utilities.puppetMasterPort, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine(">>> Puppet Master Server started on port: " + Utilities.puppetMasterPort); } catch { Console.WriteLine(">>> Error. Something went wrong"); } }
static void Main(string[] args) { //port 10001 reserved string file; if (args.Length == 0) { Console.WriteLine("Configuration File"); file = Console.ReadLine(); } else { file = args[0]; } PuppetMasterServices puppetMaster = new PuppetMasterServices(file); Exec(puppetMaster); }