Пример #1
0
        internal static void InvokePipeline(object input, bool ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
        {
            PipelineProcessor pipelineProcessor = new PipelineProcessor();

            System.Management.Automation.ExecutionContext context = funcContext._executionContext;
            Pipe pipe = funcContext._outputPipe;

            try {
                if (context.Events != null)
                {
                    context.Events.ProcessPendingActions();
                }
                if ((input == AutomationNull.Value) && !ignoreInput)
                {
                    AddNoopCommandProcessor(pipelineProcessor, context);
                }
                CommandProcessorBase commandProcessor = null;
                CommandRedirection[] redirections     = null;
                for (int i = 0; i < pipeElements.Length; i++)
                {
                    redirections     = (commandRedirections != null) ? commandRedirections [i] : null;
                    commandProcessor = AddCommand(pipelineProcessor, pipeElements [i], pipeElementAsts [i], redirections, context);
                }
                if ((commandProcessor != null) && !commandProcessor.CommandRuntime.OutputPipe.IsRedirected)
                {
                    pipelineProcessor.LinkPipelineSuccessOutput(pipe ?? new Pipe(new ArrayList()));
                    if (redirections != null)
                    {
                        foreach (CommandRedirection redirection in redirections)
                        {
                            if (redirection is MergingRedirection)
                            {
                                redirection.Bind(pipelineProcessor, commandProcessor, context);
                            }
                        }
                    }
                }
                context.PushPipelineProcessor(pipelineProcessor);
                try {
                    pipelineProcessor.SynchronousExecuteEnumerate(input, null, true);
                } finally {
                    context.PopPipelineProcessor(false);
                }
            }
            finally
            {
                context.QuestionMarkVariableValue = !pipelineProcessor.ExecutionFailed;
                pipelineProcessor.Dispose();
            }
        }