private static void Exec(ClientObj client) { string line; try { while ((line = Console.ReadLine()) != null) { System.Console.WriteLine(line); string[] words = line.Split(' '); switch (words[0]) { case "begin-repeat": BeginRepeat(client, System.Convert.ToInt32(words[1]), null); break; case "exit": case "Exit": break; default: ReadCommand(client, words[0], words[1]); break; } } } catch (FileNotFoundException) { Console.WriteLine("File doesn't exists"); } }
private static void ReadCommand(ClientObj client, string command, string parameters) { switch (command) { case "add": client.Add(parameters); break; case "read": client.Read(parameters); break; case "take": client.Take(parameters); break; case "wait": Thread.Sleep(System.Convert.ToInt32(parameters)); break; default: Console.WriteLine("Command not recognized.\n"); break; } }
static void Main(string[] args) { string[] aux; int comType; if (args.Length == 0) //read from file { aux = ReadConfFile(); } else //arguments { aux = ReadArgs(args); } string serverLoc = aux[0]; if (aux[1].Equals("SMR")) { comType = 1; } else if (aux[1].Equals("XL")) { comType = 2; } else { //error comType = 0; } serverLoc = System.Configuration.ConfigurationManager.AppSettings["server"]; Console.WriteLine(serverLoc); TcpChannel channel = new TcpChannel(); ChannelServices.RegisterChannel(channel, true); IServerService obj = (IServerService)Activator.GetObject( typeof(IServerService), serverLoc); ClientObj client = new ClientObj(obj.GetView(), comType, args[3]); Console.WriteLine("Client\n"); if (args.Length < 3) { Exec(client); } else { ExecPuppet(client, args[2]); } Console.WriteLine("Script finished"); Console.ReadLine(); }
private static void BeginRepeat(ClientObj client, int loop, System.IO.StreamReader file) { string line; bool end = false; List <string[]> commands = new List <string[]>(); if (file != null) { line = file.ReadLine(); } else { line = Console.ReadLine(); } while (line != null && !end) { //System.Console.WriteLine(line); string[] words = line.Split(' '); switch (words[0]) { case "end-repeat": end = true; break; default: commands.Add(words); //ReadCommand(client, words[0], words[1]); break; } if (file != null) { line = file.ReadLine(); } else { line = Console.ReadLine(); } } for (int i = 0; i < loop; i++) { for (int n = 0; n < commands.Count; n++) { ReadCommand(client, commands[n][0], commands[n][1]); } } }