private void ConvertToString() { PipelineProcessor processor = new PipelineProcessor(); processor.Add(this.command.Context.CreateCommand("out-string", false)); object[] c = (object[]) processor.Execute(this.inputList.ToArray()); this.inputList = new ArrayList(c); }
/// <summary> /// Formats the input objects using out-string. Output of out-string /// is given as input to native command processor. /// This method is to be called from the pipeline thread and not from the /// thread which writes input in to process. /// </summary> private void ConvertToString() { Dbg.Assert(_inputFormat == NativeCommandIOFormat.Text, "InputFormat should be Text"); PipelineProcessor p = new PipelineProcessor(); p.Add(_command.Context.CreateCommand("out-string", false)); object[] result = (object[])p.SynchronousExecuteEnumerate(_inputList.ToArray()); _inputList = new ArrayList(result); }
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; }
private static void AddNoopCommandProcessor(PipelineProcessor pipelineProcessor, System.Management.Automation.ExecutionContext context) { CmdletInfo commandInfo = new CmdletInfo("Out-Null", typeof(OutNullCommand)); CommandProcessorBase commandProcessor = context.CommandDiscovery.LookupCommandProcessor(commandInfo, context.EngineSessionState.CurrentScope.ScopeOrigin, false, null); pipelineProcessor.Add(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; }
/// <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(); } } }
/// <summary> /// Gets the PSTraceSource instances that match the names specified. /// </summary> protected override void BeginProcessing() { Collection<PSTraceSource> preconfiguredSources = null; _matchingSources = ConfigureTraceSource(base.NameInternal, false, out preconfiguredSources); TurnOnTracing(_matchingSources, false); TurnOnTracing(preconfiguredSources, true); // Now that tracing has been configured, move all the sources into a // single collection foreach (PSTraceSource preconfiguredSource in preconfiguredSources) { _matchingSources.Add(preconfiguredSource); } if (ParameterSetName == "commandSet") { // Create the CommandProcessor and add it to a pipeline CommandProcessorBase commandProcessor = this.Context.CommandDiscovery.LookupCommandProcessor(Command, CommandOrigin.Runspace, false); // Add the parameters that were specified ParameterBinderController.AddArgumentsToCommandProcessor(commandProcessor, ArgumentList); _pipeline = new PipelineProcessor(); _pipeline.Add(commandProcessor); // Hook up the success and error pipelines to this cmdlet's WriteObject and // WriteError methods _pipeline.ExternalErrorOutput = new TracePipelineWriter(this, true, _matchingSources); _pipeline.ExternalSuccessOutput = new TracePipelineWriter(this, false, _matchingSources); } ResetTracing(_matchingSources); }
private void DelayedInternalInitialize() { _pp = new PipelineProcessor(); CmdletInfo cmdletInfo = new CmdletInfo(_commandName, _commandType, null, null, _context); CommandProcessor cp = new CommandProcessor(cmdletInfo, _context); foreach (CommandParameterInternal par in _commandParameterList) { cp.AddParameter(par); } _pp.Add(cp); }