internal CommandProcessorBase AddToPipeline( PipelineProcessor pipeline, ExecutionContext context) { if (pipeline == null) { throw ParseTreeNode.tracer.NewArgumentNullException(nameof(pipeline)); } int index; CommandProcessorBase commandProcessor = this.CreateCommandProcessor(out index, context); foreach (CommandParameterInternal parametersAndArgument in (IEnumerable <CommandParameterInternal>) this.BindParametersAndArguments(index, context)) { commandProcessor.AddParameter(parametersAndArgument); } string helpTarget; HelpCategory helpCategory; if (commandProcessor.IsHelpRequested(out helpTarget, out helpCategory)) { commandProcessor = CommandProcessorBase.CreateGetHelpCommandProcessor(context, helpTarget, helpCategory); commandProcessor.Command.MyInvocation.ScriptToken = (Token)this._elements[0]; } pipeline.Add(commandProcessor); this.BindRedirectionPipes(commandProcessor, pipeline, context); return(commandProcessor); }
private static CommandProcessorBase AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, System.Management.Automation.ExecutionContext context) { object parameterText; IScriptExtent parameterExtent; CommandProcessorBase base2; InternalCommand command; string str3; HelpCategory category; CommandAst ast = commandBaseAst as CommandAst; TokenKind kind = (ast != null) ? ast.InvocationOperator : TokenKind.Unknown; bool dotSource = kind == TokenKind.Dot; SessionStateInternal sessionState = null; int index = 0; PSModuleInfo info = PSObject.Base(commandElements[0].ArgumentValue) as PSModuleInfo; if (info != null) { if ((info.ModuleType == ModuleType.Binary) && (info.SessionState == null)) { throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "CantInvokeInBinaryModule", ParserStrings.CantInvokeInBinaryModule, new object[] { info.Name }); } if (info.SessionState == null) { throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "CantInvokeInNonImportedModule", ParserStrings.CantInvokeInNonImportedModule, new object[] { info.Name }); } sessionState = info.SessionState.Internal; index++; } CommandParameterInternal internal3 = commandElements[index]; if (internal3.ParameterNameSpecified) { parameterText = internal3.ParameterText; parameterExtent = internal3.ParameterExtent; if (!internal3.ArgumentSpecified) { } } else { parameterText = PSObject.Base(internal3.ArgumentValue); parameterExtent = internal3.ArgumentExtent; } string str = dotSource ? "." : ((kind == TokenKind.Ampersand) ? "&" : null); ScriptBlock scriptblock = parameterText as ScriptBlock; if (scriptblock != null) { base2 = CommandDiscovery.CreateCommandProcessorForScript(scriptblock, context, !dotSource, sessionState); } else { CommandInfo commandInfo = parameterText as CommandInfo; if (commandInfo != null) { base2 = context.CommandDiscovery.LookupCommandProcessor(commandInfo, context.EngineSessionState.CurrentScope.ScopeOrigin, new bool?(!dotSource), sessionState); } else { string str2 = (parameterText as string) ?? PSObject.ToStringParser(context, parameterText); str = str ?? str2; if (string.IsNullOrEmpty(str2)) { throw InterpreterError.NewInterpreterException(parameterText, typeof(RuntimeException), parameterExtent, "BadExpression", ParserStrings.BadExpression, new object[] { dotSource ? "." : "&" }); } try { if (sessionState != null) { SessionStateInternal engineSessionState = context.EngineSessionState; try { context.EngineSessionState = sessionState; base2 = context.CreateCommand(str2, dotSource); goto Label_025D; } finally { context.EngineSessionState = engineSessionState; } } base2 = context.CreateCommand(str2, dotSource); } catch (RuntimeException exception) { if (exception.ErrorRecord.InvocationInfo == null) { InvocationInfo invocationInfo = new InvocationInfo(null, parameterExtent, context) { InvocationName = str }; exception.ErrorRecord.SetInvocationInfo(invocationInfo); } throw; } } } Label_025D: command = base2.Command; base2.UseLocalScope = !dotSource && ((command is ScriptCommand) || (command is PSScriptCmdlet)); bool flag2 = base2 is NativeCommandProcessor; for (int i = index + 1; i < commandElements.Length; i++) { CommandParameterInternal parameter = commandElements[i]; if ((!parameter.ParameterNameSpecified || !parameter.ParameterName.Equals("-", StringComparison.OrdinalIgnoreCase)) || flag2) { if (parameter.ArgumentSplatted) { foreach (CommandParameterInternal internal6 in Splat(parameter.ArgumentValue, parameter.ArgumentExtent)) { base2.AddParameter(internal6); } } else { base2.AddParameter(parameter); } } } if (base2.IsHelpRequested(out str3, out category)) { base2 = CommandProcessorBase.CreateGetHelpCommandProcessor(context, str3, category); } base2.Command.InvocationExtent = commandBaseAst.Extent; base2.Command.MyInvocation.ScriptPosition = commandBaseAst.Extent; base2.Command.MyInvocation.InvocationName = str; pipe.Add(base2); bool flag3 = false; bool flag4 = false; bool flag5 = false; bool flag6 = false; if (redirections != null) { foreach (CommandRedirection redirection in redirections) { redirection.Bind(pipe, base2, context); switch (redirection.FromStream) { case RedirectionStream.All: flag3 = true; flag4 = true; flag5 = true; flag6 = true; break; case RedirectionStream.Error: flag3 = true; break; case RedirectionStream.Warning: flag4 = true; break; case RedirectionStream.Verbose: flag5 = true; break; case RedirectionStream.Debug: flag6 = true; break; } } } if (!flag3) { if (context.ShellFunctionErrorOutputPipe != null) { base2.CommandRuntime.ErrorOutputPipe = context.ShellFunctionErrorOutputPipe; } else { base2.CommandRuntime.ErrorOutputPipe.ExternalWriter = context.ExternalErrorOutput; } } if (!flag4 && (context.ExpressionWarningOutputPipe != null)) { base2.CommandRuntime.WarningOutputPipe = context.ExpressionWarningOutputPipe; flag4 = true; } if (!flag5 && (context.ExpressionVerboseOutputPipe != null)) { base2.CommandRuntime.VerboseOutputPipe = context.ExpressionVerboseOutputPipe; flag5 = true; } if (!flag6 && (context.ExpressionDebugOutputPipe != null)) { base2.CommandRuntime.DebugOutputPipe = context.ExpressionDebugOutputPipe; flag6 = true; } if ((context.CurrentCommandProcessor != null) && (context.CurrentCommandProcessor.CommandRuntime != null)) { if (!flag4 && (context.CurrentCommandProcessor.CommandRuntime.WarningOutputPipe != null)) { base2.CommandRuntime.WarningOutputPipe = context.CurrentCommandProcessor.CommandRuntime.WarningOutputPipe; } if (!flag5 && (context.CurrentCommandProcessor.CommandRuntime.VerboseOutputPipe != null)) { base2.CommandRuntime.VerboseOutputPipe = context.CurrentCommandProcessor.CommandRuntime.VerboseOutputPipe; } if (!flag6 && (context.CurrentCommandProcessor.CommandRuntime.DebugOutputPipe != null)) { base2.CommandRuntime.DebugOutputPipe = context.CurrentCommandProcessor.CommandRuntime.DebugOutputPipe; } } return(base2); }