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(); } }
private PipelineProcessor CreatePipelineProcessor() { PipelineProcessor processor2; CommandCollection commands = base.Commands; if ((commands == null) || (commands.Count == 0)) { throw PSTraceSource.NewInvalidOperationException("RunspaceStrings", "NoCommandInPipeline", new object[0]); } PipelineProcessor processor = new PipelineProcessor { TopLevel = true }; bool flag = false; try { foreach (Command command in commands) { CommandProcessorBase base2; if (command.CommandInfo == null) { base2 = command.CreateCommandProcessor(this.LocalRunspace.ExecutionContext, this.LocalRunspace.CommandFactory, base.AddToHistory, this.IsNested ? CommandOrigin.Internal : CommandOrigin.Runspace); } else { CmdletInfo commandInfo = (CmdletInfo) command.CommandInfo; base2 = new CommandProcessor(commandInfo, this.LocalRunspace.ExecutionContext); PSSQMAPI.IncrementData(commandInfo.CommandType); base2.Command.CommandOriginInternal = CommandOrigin.Internal; base2.Command.MyInvocation.InvocationName = commandInfo.Name; if (command.Parameters != null) { foreach (CommandParameter parameter in command.Parameters) { CommandParameterInternal internal2 = CommandParameter.ToCommandParameterInternal(parameter, false); base2.AddParameter(internal2); } } } base2.RedirectShellErrorOutputPipe = base.RedirectShellErrorOutputPipe; processor.Add(base2); } processor2 = processor; } catch (RuntimeException) { flag = true; throw; } catch (Exception exception) { flag = true; CommandProcessorBase.CheckForSevereException(exception); throw new RuntimeException(PipelineStrings.CannotCreatePipeline, exception); } finally { if (flag) { base.SetHadErrors(true); processor.Dispose(); } } return processor2; }
/// <summary> /// Creates a PipelineProcessor object from LocalPipeline object. /// </summary> /// <returns>Created PipelineProcessor object</returns> private PipelineProcessor CreatePipelineProcessor() { CommandCollection commands = Commands; if (commands == null || commands.Count == 0) { throw PSTraceSource.NewInvalidOperationException(RunspaceStrings.NoCommandInPipeline); } PipelineProcessor pipelineProcessor = new PipelineProcessor(); pipelineProcessor.TopLevel = true; bool failed = false; try { foreach (Command command in commands) { CommandProcessorBase commandProcessorBase; // If CommandInfo is null, proceed with CommandDiscovery to resolve the command name if (command.CommandInfo == null) { try { CommandOrigin commandOrigin = command.CommandOrigin; if (IsNested) { commandOrigin = CommandOrigin.Internal; } commandProcessorBase = command.CreateCommandProcessor ( LocalRunspace.ExecutionContext, LocalRunspace.CommandFactory, AddToHistory, commandOrigin ); } catch { // If we had an error creating a command processor and we are logging, then // log the attempted command invocation anyways. if (this.Runspace.GetExecutionContext.EngineHostInterface.UI.IsTranscribing) { // Don't need to log script commands, as they were already logged during pipeline // setup if (!command.IsScript) { this.Runspace.ExecutionContext.InternalHost.UI.TranscribeCommand(command.CommandText, null); } } throw; } } else { commandProcessorBase = CreateCommandProcessBase(command); // Set the internal command origin member on the command object at this point... commandProcessorBase.Command.CommandOriginInternal = CommandOrigin.Internal; commandProcessorBase.Command.MyInvocation.InvocationName = command.CommandInfo.Name; if (command.Parameters != null) { foreach (CommandParameter publicParameter in command.Parameters) { CommandParameterInternal internalParameter = CommandParameter.ToCommandParameterInternal(publicParameter, false); commandProcessorBase.AddParameter(internalParameter); } } } commandProcessorBase.RedirectShellErrorOutputPipe = this.RedirectShellErrorOutputPipe; pipelineProcessor.Add(commandProcessorBase); } return pipelineProcessor; } catch (RuntimeException) { failed = true; throw; } catch (Exception e) { failed = true; CommandProcessorBase.CheckForSevereException(e); throw new RuntimeException(PipelineStrings.CannotCreatePipeline, e); } finally { if (failed) { this.SetHadErrors(true); // 2004/02/26-JonN added IDisposable to PipelineProcessor pipelineProcessor.Dispose(); } } }