Exemplo n.º 1
0
        public virtual IList <string> Validate(CommandParameters parameters, ValidationContext context = ValidationContext.Static)
        {
            var messages = new List <string>();

            if (parameters == null)
            {
                parameters = this.Parameters;
            }

            foreach (var parameter in parameters)
            {
                if (parameter.NotNull && !parameter.HasValue)
                {
                    messages.Add(string.Format("The parameter '{0}' must not be empty", parameter.Name));
                }
            }

            return(messages);
        }
Exemplo n.º 2
0
        protected void TransferInParameters(CommandParameters inParameters)
        {
            if (inParameters == null)
            {
                inParameters = new CommandParameters();
            }

            this.InitExecuteParameters();

            foreach (var inParameter in inParameters)
            {
                var parameter = this.ExecuteParameters.FirstOrDefault(x => x.Token == inParameter.Name);
                if (parameter != null && !parameter.HasValue)
                {
                    parameter.Value = inParameter.Value;
                }
                else
                {
                    if (!this.ExecuteParameters.Any(x => x.Name == inParameter.Name))
                    {
                        this.ExecuteParameters.AddOrUpdate(inParameter);
                    }
                }
            }

            var currentInParameters = this.GetCurrentInParameters();

            foreach (var currentInParameter in currentInParameters)
            {
                string newValue = null;
                if (TokenProcessor.ReplaceTokens(currentInParameter.Value.ToStringOrEmpty(), inParameters.ToDictionary(), out newValue))
                {
                    currentInParameter.Value = newValue;
                }

                if (currentInParameter.DataType == DataTypes.String)
                {
                    currentInParameter.Value = TokenProcessor.ExpandEnvironmentVariables(currentInParameter.Value.ToStringOrEmpty());
                }
            }
        }
        protected bool ExecuteCommand(DataCommand currentCmd, int loopCounter, DataCommand previousCmd = null)
        {
            try
            {
                if (this.CurrentPipeline.IsInBlackout)
                {
                    LogManager.Instance.LogNamedDebugFormat(this.CurrentPipeline.Name, this.GetType(), "Blackout detected. Ignoring execution of pipeline '{0}'", this.CurrentPipeline.Name);
                    if (this.OnExecutionCanceled != null)
                    {
                        this.OnExecutionCanceled(this, new EventArgs <string>("Blackout"));
                    }
                    return(false);
                }

                if (currentCmd != null)
                {
                    // Execute the currentCmd command as often as possible and pull the parameters out and push them into the next command
                    int i = 0;
                    CommandParameters lastParameter = null;
                    TokenManager.Instance.SetTokens(currentCmd.ExecuteParameters.ToDictionary(), this.CurrentPipeline.Name);

                    var commandParametersList = new List <CommandParameters> {
                        currentCmd.ExecuteParameters
                    };
                    foreach (CommandParameters outParameters in currentCmd.ExecuteCommand(commandParametersList))
                    {
                        if (this.OnExecuteCommand != null)
                        {
                            this.OnExecuteCommand(currentCmd);
                        }

                        if (currentCmd.HasChildCommands)
                        {
                            // execute the childs
                            var nextChildCmd = currentCmd.GetFirstChild();
                            if (nextChildCmd != null)
                            {
                                if (i == 0)
                                {
                                    if (!nextChildCmd.IsInitialized)
                                    {
                                        nextChildCmd.Initialize();
                                        nextChildCmd.UseStreaming       = this.CurrentPipeline.UseStreaming;
                                        nextChildCmd.StreamingBlockSize = this.CurrentPipeline.StreamingBlockSize;
                                    }
                                }

                                nextChildCmd.SetParameters(outParameters, this.OnSignalExecution, currentCmd);
                                nextChildCmd.LoopCounter = i;
                                nextChildCmd.BeforeExecute();
                            }
                        }

                        lastParameter = outParameters;

                        i++;
                    }

                    currentCmd.AfterExecute();

                    // execute the siblings
                    var nextSiblingCmd = currentCmd.GetNextSibling();
                    if (nextSiblingCmd != null)
                    {
                        if (!nextSiblingCmd.IsInitialized)
                        {
                            nextSiblingCmd.Initialize();
                            nextSiblingCmd.UseStreaming       = this.CurrentPipeline.UseStreaming;
                            nextSiblingCmd.StreamingBlockSize = this.CurrentPipeline.StreamingBlockSize;
                        }

                        if (lastParameter == null)
                        {
                            lastParameter = currentCmd.GetCurrentOutParameters();
                        }
                        nextSiblingCmd.SetParameters(lastParameter, this.OnSignalExecution, currentCmd);
                        nextSiblingCmd.LoopCounter = loopCounter;
                        nextSiblingCmd.BeforeExecute();
                    }
                }
            }
            catch (ThreadAbortException ex)
            {
                // ignore them
            }
            catch (ThreadInterruptedException ex)
            {
                // ignore them
            }
            return(true);
        }
Exemplo n.º 4
0
 public void SetParameters(CommandParameters inParameters, OnSignalNextDelegate onSignalNext, DataCommand prevCmd = null)
 {
     this.OnSignalNext = onSignalNext;
     this.TransferInParameters(inParameters);
 }
Exemplo n.º 5
0
 public bool ExecutePipeline(CommandParameters inParameters = null)
 {
     return(executer.ExecutePipeline(inParameters));
 }
Exemplo n.º 6
0
        public static void Evaluate(IEnumerable <ParameterCondition> parameterConditions, CommandParameters parameters)
        {
            var tokens = parameters.ToDictionary();

            var condition = GetFirstMatchingCondition(parameterConditions, tokens) as ParameterCondition;

            if (condition != null)
            {
                foreach (var action in condition.Actions)
                {
                    ExecuteAction(action, tokens);
                }
            }
        }