Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 public void Dispose()
 {
     if (this.pp != null)
     {
         this.pp.Dispose();
         this.pp = null;
     }
 }
Exemplo n.º 3
0
 internal Array ShutDown()
 {
     if (this.pp == null)
     {
         return new object[0];
     }
     PipelineProcessor pp = this.pp;
     this.pp = null;
     return pp.Execute();
 }
Exemplo n.º 4
0
 private void DelayedInternalInitialize()
 {
     this.pp = new PipelineProcessor();
     CmdletInfo cmdletInfo = new CmdletInfo(this.commandName, this.commandType, null, null, this.context);
     CommandProcessor commandProcessor = new CommandProcessor(cmdletInfo, this.context);
     foreach (CommandParameterInternal internal2 in this.commandParameterList)
     {
         commandProcessor.AddParameter(internal2);
     }
     this.pp.Add(commandProcessor);
 }
Exemplo n.º 5
0
 internal SteppablePipeline(ExecutionContext context, PipelineProcessor pipeline)
 {
     if (pipeline == null)
     {
         throw new ArgumentNullException("pipeline");
     }
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     this._pipeline = pipeline;
     this._context = context;
 }
Exemplo n.º 6
0
 internal void Push(PipelineProcessor item)
 {
     if (item == null)
     {
         throw PSTraceSource.NewArgumentNullException("item");
     }
     lock (this._syncRoot)
     {
         if (this._stopping)
         {
             PipelineStoppedException exception = new PipelineStoppedException();
             throw exception;
         }
         this._stack.Push(item);
     }
     item.LocalPipeline = this._localPipeline;
 }
Exemplo n.º 7
0
        internal override void Bind(System.Management.Automation.Internal.PipelineProcessor pipelineProcessor, CommandProcessorBase commandProcessor, ExecutionContext context)
        {
            Pipe redirectionPipe = this.GetRedirectionPipe(context, pipelineProcessor);

            switch (base.FromStream)
            {
            case RedirectionStream.All:
                commandProcessor.CommandRuntime.OutputPipe        = redirectionPipe;
                commandProcessor.CommandRuntime.ErrorOutputPipe   = redirectionPipe;
                commandProcessor.CommandRuntime.WarningOutputPipe = redirectionPipe;
                commandProcessor.CommandRuntime.VerboseOutputPipe = redirectionPipe;
                commandProcessor.CommandRuntime.DebugOutputPipe   = redirectionPipe;
                return;

            case RedirectionStream.Output:
                commandProcessor.CommandRuntime.OutputPipe = redirectionPipe;
                return;

            case RedirectionStream.Error:
                commandProcessor.CommandRuntime.ErrorOutputPipe = redirectionPipe;
                return;

            case RedirectionStream.Warning:
                commandProcessor.CommandRuntime.WarningOutputPipe = redirectionPipe;
                return;

            case RedirectionStream.Verbose:
                commandProcessor.CommandRuntime.VerboseOutputPipe = redirectionPipe;
                return;

            case RedirectionStream.Debug:
                commandProcessor.CommandRuntime.DebugOutputPipe = redirectionPipe;
                break;

            case RedirectionStream.Host:
                break;

            default:
                return;
            }
        }
Exemplo n.º 8
0
 protected override void BeginProcessing()
 {
     Collection<PSTraceSource> preconfiguredSources = null;
     this.matchingSources = base.ConfigureTraceSource(base.NameInternal, false, out preconfiguredSources);
     base.TurnOnTracing(this.matchingSources, false);
     base.TurnOnTracing(preconfiguredSources, true);
     foreach (PSTraceSource source in preconfiguredSources)
     {
         this.matchingSources.Add(source);
     }
     if (base.ParameterSetName == "commandSet")
     {
         CommandProcessorBase commandProcessor = base.Context.CommandDiscovery.LookupCommandProcessor(this.command, CommandOrigin.Runspace, false);
         ParameterBinderController.AddArgumentsToCommandProcessor(commandProcessor, this.ArgumentList);
         this.pipeline = new PipelineProcessor();
         this.pipeline.Add(commandProcessor);
         this.pipeline.ExternalErrorOutput = new TracePipelineWriter(this, true, this.matchingSources);
         this.pipeline.ExternalSuccessOutput = new TracePipelineWriter(this, false, this.matchingSources);
     }
     base.ResetTracing(this.matchingSources);
 }
Exemplo n.º 9
0
        internal Pipe GetRedirectionPipe(ExecutionContext context, System.Management.Automation.Internal.PipelineProcessor parentPipelineProcessor)
        {
            if (string.IsNullOrWhiteSpace(this.File))
            {
                return(new Pipe {
                    NullPipe = true
                });
            }
            CommandProcessorBase     commandProcessor = context.CreateCommand("out-file", false);
            CommandParameterInternal parameter        = CommandParameterInternal.CreateParameterWithArgument(PositionUtilities.EmptyExtent, "Encoding", "-Encoding:", PositionUtilities.EmptyExtent, "Unicode", false);

            commandProcessor.AddParameter(parameter);
            if (this.Appending)
            {
                parameter = CommandParameterInternal.CreateParameterWithArgument(PositionUtilities.EmptyExtent, "Append", "-Append:", PositionUtilities.EmptyExtent, true, false);
                commandProcessor.AddParameter(parameter);
            }
            parameter = CommandParameterInternal.CreateParameterWithArgument(PositionUtilities.EmptyExtent, "Filepath", "-Filepath:", PositionUtilities.EmptyExtent, this.File, false);
            commandProcessor.AddParameter(parameter);
            this.PipelineProcessor = new System.Management.Automation.Internal.PipelineProcessor();
            this.PipelineProcessor.Add(commandProcessor);
            try
            {
                this.PipelineProcessor.StartStepping(true);
            }
            catch (RuntimeException exception)
            {
                if (exception.ErrorRecord.Exception is ArgumentException)
                {
                    throw InterpreterError.NewInterpreterExceptionWithInnerException(null, typeof(RuntimeException), null, "RedirectionFailed", ParserStrings.RedirectionFailed, exception.ErrorRecord.Exception, new object[] { this.File, exception.ErrorRecord.Exception.Message });
                }
                throw;
            }
            if (parentPipelineProcessor != null)
            {
                parentPipelineProcessor.AddRedirectionPipe(this.PipelineProcessor);
            }
            return(new Pipe(context, this.PipelineProcessor));
        }
Exemplo n.º 10
0
 public void Dispose()
 {
     if (!this.disposed)
     {
         this.disposed = true;
         base.ResetTracing(this.matchingSources);
         base.ClearStoredState();
         this.matchingSources = null;
         if (this.pipeline != null)
         {
             this.pipeline.Dispose();
             this.pipeline = null;
         }
         if (base.FileStreams != null)
         {
             foreach (FileStream stream in base.FileStreams)
             {
                 stream.Flush();
                 stream.Close();
             }
         }
         GC.SuppressFinalize(this);
     }
 }
Exemplo n.º 11
0
        internal override void Bind(PipelineProcessor pipelineProcessor, CommandProcessorBase commandProcessor, ExecutionContext context)
        {
            Pipe outputPipe = commandProcessor.CommandRuntime.OutputPipe;
            switch (base.FromStream)
            {
                case RedirectionStream.All:
                    commandProcessor.CommandRuntime.ErrorMergeTo = MshCommandRuntime.MergeDataStream.Output;
                    commandProcessor.CommandRuntime.WarningOutputPipe = outputPipe;
                    commandProcessor.CommandRuntime.VerboseOutputPipe = outputPipe;
                    commandProcessor.CommandRuntime.DebugOutputPipe = outputPipe;
                    return;

                case RedirectionStream.Output:
                case RedirectionStream.Host:
                    break;

                case RedirectionStream.Error:
                    commandProcessor.CommandRuntime.ErrorMergeTo = MshCommandRuntime.MergeDataStream.Output;
                    return;

                case RedirectionStream.Warning:
                    commandProcessor.CommandRuntime.WarningOutputPipe = outputPipe;
                    return;

                case RedirectionStream.Verbose:
                    commandProcessor.CommandRuntime.VerboseOutputPipe = outputPipe;
                    return;

                case RedirectionStream.Debug:
                    commandProcessor.CommandRuntime.DebugOutputPipe = outputPipe;
                    break;

                default:
                    return;
            }
        }
Exemplo n.º 12
0
 internal AllowWrite(InternalCommand permittedToWrite, bool permittedToWriteToPipeline)
 {
     if (permittedToWrite == null)
     {
         throw PSTraceSource.NewArgumentNullException("permittedToWrite");
     }
     MshCommandRuntime commandRuntime = permittedToWrite.commandRuntime as MshCommandRuntime;
     if (commandRuntime == null)
     {
         throw PSTraceSource.NewArgumentNullException("permittedToWrite.CommandRuntime");
     }
     this._pp = commandRuntime.PipelineProcessor;
     if (this._pp == null)
     {
         throw PSTraceSource.NewArgumentNullException("permittedToWrite.CommandRuntime.PipelineProcessor");
     }
     this._wasPermittedToWrite = this._pp._permittedToWrite;
     this._wasPermittedToWriteToPipeline = this._pp._permittedToWriteToPipeline;
     this._wasPermittedToWriteThread = this._pp._permittedToWriteThread;
     this._pp._permittedToWrite = permittedToWrite;
     this._pp._permittedToWriteToPipeline = permittedToWriteToPipeline;
     this._pp._permittedToWriteThread = Thread.CurrentThread;
 }
Exemplo n.º 13
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();
            }
        }
Exemplo n.º 14
0
 internal abstract void Bind(PipelineProcessor pipelineProcessor, CommandProcessorBase commandProcessor, ExecutionContext context);
Exemplo n.º 15
0
 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);
 }
Exemplo n.º 16
0
 internal static SteppablePipeline GetSteppablePipeline(PipelineAst pipelineAst, CommandOrigin commandOrigin)
 {
     PipelineProcessor pipe = new PipelineProcessor();
     System.Management.Automation.ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS();
     foreach (CommandAst ast in pipelineAst.PipelineElements.Cast<CommandAst>())
     {
         List<CommandParameterInternal> list = new List<CommandParameterInternal>();
         foreach (CommandElementAst ast2 in ast.CommandElements)
         {
             CommandParameterAst commandParameterAst = ast2 as CommandParameterAst;
             if (commandParameterAst != null)
             {
                 list.Add(GetCommandParameter(commandParameterAst, executionContextFromTLS));
             }
             else
             {
                 ExpressionAst expressionAst = (ExpressionAst) ast2;
                 object obj2 = Compiler.GetExpressionValue(expressionAst, executionContextFromTLS, (IList)null);
                 bool splatted = (expressionAst is VariableExpressionAst) && ((VariableExpressionAst) expressionAst).Splatted;
                 list.Add(CommandParameterInternal.CreateArgument(expressionAst.Extent, obj2, splatted));
             }
         }
         List<CommandRedirection> list2 = new List<CommandRedirection>();
         foreach (RedirectionAst ast5 in ast.Redirections)
         {
             list2.Add(GetCommandRedirection(ast5, executionContextFromTLS));
         }
         CommandProcessorBase base2 = AddCommand(pipe, list.ToArray(), ast, list2.ToArray(), executionContextFromTLS);
         base2.Command.CommandOriginInternal = commandOrigin;
         base2.CommandScope.ScopeOrigin = commandOrigin;
         base2.Command.MyInvocation.CommandOrigin = commandOrigin;
         CallStackFrame[] frameArray = executionContextFromTLS.Debugger.GetCallStack().ToArray<CallStackFrame>();
         if ((frameArray.Length > 0) && Regex.IsMatch(frameArray[0].Position.Text, "GetSteppablePipeline", RegexOptions.IgnoreCase))
         {
             InvocationInfo myInvocation = base2.Command.MyInvocation;
             myInvocation.InvocationName = frameArray[0].InvocationInfo.InvocationName;
             if (frameArray.Length > 1)
             {
                 IScriptExtent position = frameArray[1].Position;
                 if ((position != null) && (position != PositionUtilities.EmptyExtent))
                 {
                     myInvocation.DisplayScriptPosition = position;
                 }
             }
         }
         if ((executionContextFromTLS.CurrentCommandProcessor != null) && (executionContextFromTLS.CurrentCommandProcessor.CommandRuntime != null))
         {
             base2.CommandRuntime.SetMergeFromRuntime(executionContextFromTLS.CurrentCommandProcessor.CommandRuntime);
         }
     }
     return new SteppablePipeline(executionContextFromTLS, pipe);
 }
Exemplo n.º 17
0
        /// <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();
                }
            }
        }
Exemplo n.º 18
0
        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;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Resets the TraceSource flags back to their original value and restores
        /// the original TraceListeners.
        /// </summary>
        public void Dispose()
        {
            if (!_disposed)
            {
                _disposed = true;

                // Reset the flags for the trace switch back to the original value
                ResetTracing(_matchingSources);
                ClearStoredState();
                _matchingSources = null;

                if (_pipeline != null)
                {
                    _pipeline.Dispose();
                    _pipeline = null;
                }

                // If there are any file streams, close those as well.

                if (this.FileStreams != null)
                {
                    foreach (FileStream fileStream in this.FileStreams)
                    {
                        fileStream.Flush();
                        fileStream.Dispose();
                    }
                }
                GC.SuppressFinalize(this);
            }
        } // Dispose
Exemplo n.º 20
0
        /// <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);
        }
Exemplo n.º 21
0
 /// <summary>
 /// This pipe writes into another pipeline processor allowing
 /// pipelines to be chained together...
 /// </summary>
 /// <param name="context">The execution context object for this engine instance</param>
 /// <param name="outputPipeline">The pipeline to write into...</param>
 internal Pipe(ExecutionContext context, PipelineProcessor outputPipeline)
 {
     Diagnostics.Assert(outputPipeline != null, "outputPipeline cannot be null");
     Diagnostics.Assert(outputPipeline != null, "context cannot be null");
     _isRedirected = true;
     _context = context;
     PipelineProcessor = outputPipeline;
 }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
 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;
 }
Exemplo n.º 24
0
        /// <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);
        }
Exemplo n.º 25
0
 internal void AddRedirectionPipe(PipelineProcessor pipelineProcessor)
 {
     if (pipelineProcessor == null)
     {
         throw PSTraceSource.NewArgumentNullException("pipelineProcessor");
     }
     if (this._redirectionPipes == null)
     {
         this._redirectionPipes = new List<PipelineProcessor>();
     }
     this._redirectionPipes.Add(pipelineProcessor);
 }