示例#1
0
            public static ScriptEventQueue ReadCommand( string command )
            {
                ScriptEventQueue queue = new ScriptEventQueue();

                ScriptCommandDescription description = new ScriptCommandDescription();
                description.type = CommandType.Invalid;
                description.fullInput = command;

                if ( command.StartsWith( "Subscriber" ) ) {
                    Regex pattern = new Regex( @"Subscriber (?<pname>\w+) (?<type>Subscribe|Unsubscribe) (?<topic>[\w/-]+\*?)" );
                    Match match = pattern.Match( command );
                    if ( match.Success ) {
                        if ( match.Groups[ "type" ].Value == "Subscribe" ) {
                            description.type = CommandType.Subscribe;
                        }
                        else {
                            description.type = CommandType.Unsubscribe;
                        }

                        description.properties = new string[ 2 ];
                        description.properties[ 0 ] = match.Groups[ "pname" ].Value;
                        description.properties[ 1 ] = match.Groups[ "topic" ].Value;

                        queue.AddCommand( description );
                    }
                }
                else if ( command.StartsWith( "Publisher" ) ) {
                    Regex pattern = new Regex( @"Publisher (?<pname>\w+) Publish (?<numevents>\d+) Ontopic (?<topic>[\w/-]+) Interval (?<interval>\d+)" );
                    Match match = pattern.Match( command );
                    if ( match.Success ) {
                        description.type = CommandType.Publish;

                        description.properties = new string[ 4 ];
                        description.properties[ 0 ] = match.Groups[ "pname" ].Value;
                        description.properties[ 1 ] = match.Groups[ "numevents" ].Value;
                        description.properties[ 2 ] = match.Groups[ "topic" ].Value;
                        description.properties[ 3 ] = match.Groups[ "interval" ].Value;

                        queue.AddCommand( description );
                    }
                }
                else if ( command.StartsWith( "Status" ) ) {
                    /*Status for all nodes - no parameters*/
                    description.type = CommandType.Status;
                    description.properties = null;
                    queue.AddCommand( description );
                }
                else if ( command.StartsWith( "Crash" ) ) {
                    Regex pattern = new Regex( @"Crash (?<pname>.*)" );
                    Match match = pattern.Match( command );
                    if ( match.Success ) {
                        description.type = CommandType.Crash;

                        description.properties = new string[ 1 ];
                        description.properties[0 ] = match.Groups[ "pname" ].Value;
                        queue.AddCommand( description );
                    }
                }
                else if ( command.StartsWith( "Freeze" ) ) {
                    Regex pattern = new Regex( @"Freeze (?<pname>.*)" );
                    Match match = pattern.Match( command );
                    if ( match.Success ) {
                        description.type = CommandType.Freeze;

                        description.properties = new string[ 1 ];
                        description.properties[ 0 ] = match.Groups[ "pname" ].Value;
                        queue.AddCommand( description );
                    }
                }
                else if ( command.StartsWith( "Unfreeze" ) ) {
                    Regex pattern = new Regex( @"Unfreeze (?<pname>.*)" );
                    Match match = pattern.Match( command );
                    if ( match.Success ) {
                        description.type = CommandType.Unfreeze;

                        description.properties = new string[ 1 ];
                        description.properties[ 0 ] = match.Groups[ "pname" ].Value;
                        queue.AddCommand( description );
                    }
                }
                else if ( command.StartsWith( "Wait" ) ) {
                    Regex pattern = new Regex( @"Wait (?<time>\d+)" );
                    Match match = pattern.Match( command );
                    if ( match.Success ) {
                        description.type = CommandType.Wait;

                        description.properties = new string[ 1 ];
                        description.properties[ 0 ] = match.Groups[ "time" ].Value;
                        queue.AddCommand( description );
                    }
                }
                else if ( command.StartsWith( "Script" ) ) {
                    Regex pattern = new Regex( @"Script (?<filename>.*)" );
                    Match match = pattern.Match( command );
                    if ( match.Success ) {
                        /*description.type = CommandType.Script;

                        description.properties = new string[ 1 ];
                        description.properties[ 0 ] = match.Groups[ "filename" ].Value;*/
                        ScriptEventQueue fileEvents = null;
                        try {
                            fileEvents = ReadScriptFile( match.Groups[ "filename" ].Value );
                        }
                        catch ( Exception e ) {
                            /* Do nothing */
                        }

                        if ( fileEvents != null ) {
                            queue.Concatenate( fileEvents );
                        }
                    }
                }

                return queue;
            }
示例#2
0
            public static ScriptEventQueue ReadCommand(string command)
            {
                ScriptEventQueue queue = new ScriptEventQueue();

                ScriptCommandDescription description = new ScriptCommandDescription();

                description.type      = CommandType.Invalid;
                description.fullInput = command;

                if (command.StartsWith("Subscriber"))
                {
                    Regex pattern = new Regex(@"Subscriber (?<pname>\w+) (?<type>Subscribe|Unsubscribe) (?<topic>[\w/-]+\*?)");
                    Match match   = pattern.Match(command);
                    if (match.Success)
                    {
                        if (match.Groups["type"].Value == "Subscribe")
                        {
                            description.type = CommandType.Subscribe;
                        }
                        else
                        {
                            description.type = CommandType.Unsubscribe;
                        }

                        description.properties    = new string[2];
                        description.properties[0] = match.Groups["pname"].Value;
                        description.properties[1] = match.Groups["topic"].Value;

                        queue.AddCommand(description);
                    }
                }
                else if (command.StartsWith("Publisher"))
                {
                    Regex pattern = new Regex(@"Publisher (?<pname>\w+) Publish (?<numevents>\d+) Ontopic (?<topic>[\w/-]+) Interval (?<interval>\d+)");
                    Match match   = pattern.Match(command);
                    if (match.Success)
                    {
                        description.type = CommandType.Publish;

                        description.properties    = new string[4];
                        description.properties[0] = match.Groups["pname"].Value;
                        description.properties[1] = match.Groups["numevents"].Value;
                        description.properties[2] = match.Groups["topic"].Value;
                        description.properties[3] = match.Groups["interval"].Value;

                        queue.AddCommand(description);
                    }
                }
                else if (command.StartsWith("Status"))
                {
                    /*Status for all nodes - no parameters*/
                    description.type       = CommandType.Status;
                    description.properties = null;
                    queue.AddCommand(description);
                }
                else if (command.StartsWith("Crash"))
                {
                    Regex pattern = new Regex(@"Crash (?<pname>.*)");
                    Match match   = pattern.Match(command);
                    if (match.Success)
                    {
                        description.type = CommandType.Crash;

                        description.properties    = new string[1];
                        description.properties[0] = match.Groups["pname"].Value;
                        queue.AddCommand(description);
                    }
                }
                else if (command.StartsWith("Freeze"))
                {
                    Regex pattern = new Regex(@"Freeze (?<pname>.*)");
                    Match match   = pattern.Match(command);
                    if (match.Success)
                    {
                        description.type = CommandType.Freeze;

                        description.properties    = new string[1];
                        description.properties[0] = match.Groups["pname"].Value;
                        queue.AddCommand(description);
                    }
                }
                else if (command.StartsWith("Unfreeze"))
                {
                    Regex pattern = new Regex(@"Unfreeze (?<pname>.*)");
                    Match match   = pattern.Match(command);
                    if (match.Success)
                    {
                        description.type = CommandType.Unfreeze;

                        description.properties    = new string[1];
                        description.properties[0] = match.Groups["pname"].Value;
                        queue.AddCommand(description);
                    }
                }
                else if (command.StartsWith("Wait"))
                {
                    Regex pattern = new Regex(@"Wait (?<time>\d+)");
                    Match match   = pattern.Match(command);
                    if (match.Success)
                    {
                        description.type = CommandType.Wait;

                        description.properties    = new string[1];
                        description.properties[0] = match.Groups["time"].Value;
                        queue.AddCommand(description);
                    }
                }
                else if (command.StartsWith("Script"))
                {
                    Regex pattern = new Regex(@"Script (?<filename>.*)");
                    Match match   = pattern.Match(command);
                    if (match.Success)
                    {
                        /*description.type = CommandType.Script;
                         *
                         * description.properties = new string[ 1 ];
                         * description.properties[ 0 ] = match.Groups[ "filename" ].Value;*/
                        ScriptEventQueue fileEvents = null;
                        try {
                            fileEvents = ReadScriptFile(match.Groups["filename"].Value);
                        }
                        catch (Exception e) {
                            /* Do nothing */
                        }

                        if (fileEvents != null)
                        {
                            queue.Concatenate(fileEvents);
                        }
                    }
                }

                return(queue);
            }
示例#3
0
 public void AddCommand( ScriptCommandDescription scd )
 {
     commands.Enqueue( scd );
 }
示例#4
0
 public void AddCommand(ScriptCommandDescription scd)
 {
     commands.Enqueue(scd);
 }