Exemplo n.º 1
0
        public void AddCommand(string commandName, Dictionary <object, string> commandArgs)
        {
            var command = new PipelineCommand
            {
                CommandName = commandName,
                CommandArgs = commandArgs
            };

            commands.Add(command);
        }
Exemplo n.º 2
0
        public ExecutionLog(PipelineCommand command, IDictionary <string, PipelineVariable> variables) : this()
        {
            CommandName          = command.FullyQualifiedCommandName;
            CommandText          = command.OriginalText;
            CommandFactorySource = command.CommandFactorySource;

            Variables = new Dictionary <string, string>();
            Arguments = new List <DictionaryEntry>();
            Messages  = new List <string>();

            foreach (var argument in command.CommandArgs)
            {
                Arguments.Add(new DictionaryEntry(argument.Key.ToString(), argument.Value));
            }

            foreach (var variable in variables.Where(v => v.Key != Pipeline.GLOBAL_VARIABLE_NAME))
            {
                Variables.Add(variable.Key, variable.Value?.Value?.ToString());
            }
        }
        public static IEnumerable <PipelineCommand> ParseCommandString(string commandString)
        {
            var commands = new List <PipelineCommand>();

            // If we have nothing, return an empty list of commands
            if (String.IsNullOrWhiteSpace(commandString))
            {
                return(commands);
            }

            var lines = Regex.Split(commandString, @"\n(?!-| )")
                        .Select(s => s.Replace(Environment.NewLine, " "))
                        .Where(s => !String.IsNullOrWhiteSpace(s))
                        .ToList();

            foreach (var line in lines)
            {
                // Is this a comment, or is it empty?
                if (String.IsNullOrWhiteSpace(line) || line.Trim().StartsWith(COMMENT_PREFIX))
                {
                    // Skip it...
                    continue;
                }

                var tokens = new TokenList(line);

                var command = new PipelineCommand()
                {
                    OriginalText = line
                };

                // +
                if (tokens.First == "+")
                {
                    command.AppendToLast = true;
                    tokens.RemoveFromStart(1);
                }

                // $myVar =>
                if (tokens.Last == PIPE_TOKEN && tokens.Count == 2)
                {
                    command.CommandName    = Pipeline.READ_FROM_VARIABLE_COMMAND;
                    command.OutputVariable = NormalizeVariableName(tokens.First);
                    commands.Add(command);
                    continue;
                }

                // => $myVar
                if (tokens.First == PIPE_TOKEN && tokens.Count == 2)
                {
                    command.CommandName    = Pipeline.WRITE_TO_VARIABLE_COMMAND;
                    command.OutputVariable = NormalizeVariableName(tokens.Last);
                    commands.Add(command);
                    continue;
                }

                // WriteTo $myVar
                if (PipelineCommand.EnsureCategoryName(tokens.First.ToLower()) == Pipeline.WRITE_TO_VARIABLE_COMMAND)
                {
                    command.CommandName    = Pipeline.WRITE_TO_VARIABLE_COMMAND;
                    command.OutputVariable = NormalizeVariableName(tokens.Second);
                    commands.Add(command);
                    continue;
                }

                // ReadFrom $myVar
                if (PipelineCommand.EnsureCategoryName(tokens.First.ToLower()) == Pipeline.READ_FROM_VARIABLE_COMMAND)
                {
                    command.CommandName   = Pipeline.READ_FROM_VARIABLE_COMMAND;
                    command.InputVariable = NormalizeVariableName(tokens.Second);
                    commands.Add(command);
                    continue;
                }

                // DoSomething SomeArgument => $myVar
                if (tokens.Count > 2 && tokens.SecondToLast == PIPE_TOKEN && IsVariableName(tokens.Last))
                {
                    command.OutputVariable = NormalizeVariableName(tokens.Last());

                    // Now, remove the last two items from the tokens and continue like normal...
                    tokens.RemoveFromEnd(2);
                }

                // $myVar => DoSomething
                if (tokens.Count > 2 && tokens.Second == PIPE_TOKEN && IsVariableName(tokens.First))
                {
                    command.InputVariable = NormalizeVariableName(tokens.First());

                    // Now, remove the last two items from the tokens and continue like normal...
                    tokens.RemoveFromStart(2);
                }

                // $myVar => DoSomething SomeArgument => $myVar
                // This situation will be handled by this point and the related tokens removed so that all that remains is (1) DoSomething, and (2) SomeArgument. From here, the command is parsed normally.

                // The first token is the command name...
                command.CommandName = tokens.First();

                //... the remaining tokens are the arguments.
                var counter = 0;
                foreach (var token in tokens.Skip(1))
                {
                    var value = token;
                    var key   = counter.ToString();

                    if (Regex.IsMatch(token, "-[^:]+:.*"))
                    {
                        key   = value.Substring(0, token.IndexOf(':')).Trim('-');
                        value = value.Substring(token.IndexOf(':') + 1);
                    }

                    if (command.CommandArgs.ContainsKey(key))
                    {
                        var multiVariableCounter = 1;
                        while (true)
                        {
                            var tempKey = String.Concat(key, ".", multiVariableCounter);
                            if (command.CommandArgs.ContainsKey(tempKey))
                            {
                                multiVariableCounter++;
                                continue;
                            }
                            key = tempKey;
                            break;
                        }
                    }

                    command.CommandArgs.Add(key, value.Trim('"'));
                    counter++;
                }

                commands.Add(command);
            }

            return(commands);
        }
Exemplo n.º 4
0
 public void AddCommand(PipelineCommand command)
 {
     commands.Add(command);
 }
Exemplo n.º 5
0
 public FilterEventArgs(PipelineCommand command, string input, string output)
 {
     Command = command;
     Input   = input;
     Output  = output;
 }