Пример #1
0
        private void execute(string commandName, string[] parameters)
        {
            switch (commandName)
            {
            case "Configure":
                msecRound  = parameters[0];
                numPlayers = parameters[1];
                break;

            case "CreateServer":
                saveProcessPCS(parameters[0], parameters[1]);
                serverURIs.Add(parameters[0], parameters[2]);
                break;

            case "StartServers":
                foreach (string pid in this.serverURIs.Keys)
                {
                    StartServer(pid, serverURIs[pid], this.serverURIs.Values.ToList(), msecRound, numPlayers);
                }
                break;

            case "StartClient":
                // find the server url to which im going to connect
                if (parameters.Length < 4)     // there is not instructions
                {
                    StartClientNotInstructed(parameters[0], parameters[2], serverURIs.Values.ToList());
                    saveProcessPCS(parameters[0], parameters[1]);
                    return;
                }

                string instructions    = "";
                string uniformFilepath = @"../../scripts/" + parameters[3];
                // check if the file exists
                if (File.Exists(uniformFilepath))
                {
                    Console.WriteLine("*** Reading client moves trace file ***");
                    string[] lines = File.ReadAllLines(uniformFilepath);
                    foreach (string line in lines)
                    {
                        instructions += line + "\n";
                    }
                    Console.WriteLine("*** Finished reading client moves trace file ***");
                }

                if (instructions != "")
                {
                    StartClientInstructed(parameters[0], parameters[2], instructions, serverURIs.Values.ToList());
                    saveProcessPCS(parameters[0], parameters[1]);
                    return;
                }
                else
                {
                    Console.WriteLine("No file or no instructions");
                    return;
                }

                break;

            case "GlobalStatus":
                GlobalStatus gs = new GlobalStatus();
                gs.processesPCS = processesPCS;
                gs.Execute(parameters);
                break;

            case "Crash":
                Crash c = new Crash();
                c.processesPCS = processesPCS;
                c.Execute(parameters);
                break;

            case "Freeze":
                Freeze f = new Freeze();
                f.processesPCS = processesPCS;
                f.Execute(parameters);
                break;

            case "Unfreeze":
                Unfreeze u = new Unfreeze();
                u.processesPCS = processesPCS;
                u.Execute(parameters);
                break;

            case "InjectDelay":
                InjectDelay id = new InjectDelay();
                id.processesPCS = processesPCS;
                id.Execute(parameters);
                break;

            case "LocalState":
                LocalState ls = new LocalState();
                ls.processesPCS = processesPCS;
                ls.Execute(parameters);
                break;

            case "Wait":
                new Wait().Execute(parameters);
                break;

            default:
                throw new ArgumentException("Invalid command!");
            }
        }