예제 #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!");
            }
        }
예제 #2
0
        /// <summary>
        /// parses a single line and queues/executes it
        /// </summary>
        /// <param name="line"></param>
        /// <param name="queue">true if the command is to be enqueue. False mean it should be ran immediately</param>
        /// <returns></returns>
        public static LineSyntax executeLine(string line, bool queue)
        {
            //regex init
            Regex rgxComment   = new Regex(RGX_COMMENT, RegexOptions.IgnoreCase);
            Regex rgxStart     = new Regex(RGX_START, RegexOptions.IgnoreCase);
            Regex rgxInterval  = new Regex(RGX_INTERVAL, RegexOptions.IgnoreCase);
            Regex rgxStatus    = new Regex(RGX_STATUS, RegexOptions.IgnoreCase);
            Regex rgxCrash     = new Regex(RGX_CRASH, RegexOptions.IgnoreCase);
            Regex rgxFreeze    = new Regex(RGX_FREEZE, RegexOptions.IgnoreCase);
            Regex rgxUnfreeze  = new Regex(RGX_UNFREEZE, RegexOptions.IgnoreCase);
            Regex rgxWait      = new Regex(RGX_WAIT, RegexOptions.IgnoreCase);
            Regex rgxLog       = new Regex(RGX_LOG, RegexOptions.IgnoreCase);
            Regex rgxSemantics = new Regex(RGX_SEMANTICS, RegexOptions.IgnoreCase);
            Regex rgxConf      = new Regex(RGX_CONF, RegexOptions.IgnoreCase);

            //comment
            if (rgxComment.IsMatch(line))
            {
                Logger.debugWriteLine("Parser: return match COMMENT");
                return(LineSyntax.COMMENT);
            }
            //hack just in case the config file has more spaces than it should, such as the sample one
            line = line.Replace(", ", ",");
            String[] fields  = line.Split(' ');
            ICommand command = null;

            //start
            if (rgxStart.IsMatch(line))
            {
                String opID = fields[1];
                command = new Start(opID);
            } //interval
            else if (rgxInterval.IsMatch(line))
            {
                String opID     = fields[1];
                int    millisec = Int32.Parse(fields[2]);
                command = new Interval(opID, millisec);
            } //status
            else if (rgxStatus.IsMatch(line))
            {
                command = new Status();
            } //crash
            else if (rgxCrash.IsMatch(line))
            {
                String opID = fields[1];
                int    rep  = Int32.Parse(fields[2]);
                command = new Crash(opID, rep);
            } //unfreeze
            else if (rgxUnfreeze.IsMatch(line))
            {
                String opID = fields[1];
                int    rep  = Int32.Parse(fields[2]);
                command = new Unfreeze(opID, rep);
            } //freeze
            else if (rgxFreeze.IsMatch(line))
            {
                String opID = fields[1];
                int    rep  = Int32.Parse(fields[2]);
                command = new Freeze(opID, rep);
            } //wait
            else if (rgxWait.IsMatch(line))
            {
                int millisec = Int32.Parse(fields[1]);
                command = new Wait(millisec);
            }
            else if (rgxLog.IsMatch(line))
            {
                String loggingLevel = fields[1];
                command = new Log(loggingLevel);
            }
            else if (rgxSemantics.IsMatch(line))
            {
                String semantics = fields[1];
                command = new SetSemantics(semantics);
            }
            //TODO MISSING: LOG & SEMANTICS

            //configuration of operator
            else if (rgxConf.IsMatch(line))
            {
                String   opID      = fields[0];
                String[] inputOps  = fields[2].Split(',');
                int      repFact   = Int32.Parse(fields[4]);
                String   routing   = fields[6];
                String[] addresses = fields[8].Split(',');
                String[] opSpec    = fields.Skip(10).ToArray();
                command = new ConfigureOperator(opID, inputOps, repFact, routing, addresses, opSpec);
            } //invalid command
            else
            {
                Logger.debugWriteLine("Parser: return match INVALID");
                return(LineSyntax.INVALID);
            }
            //store commands
            if (command != null)
            {
                if (queue)
                {
                    Logger.debugWriteLine("Parser: Enqueue");
                    PuppetMaster.Commands.Enqueue(command);
                }
                else
                {
                    Logger.debugWriteLine("Parser: execute");
                    command.execute();
                }
            } // FIXME
            else
            {
                Logger.debugWriteLine("Parser: return match INVALID");
                return(LineSyntax.INVALID);
            }
            Logger.debugWriteLine("Parser: return match VALID");
            return(LineSyntax.VALID);
        }