Ejemplo n.º 1
0
        private void ConvertToString()
        {
            PipelineProcessor pipelineProcessor = new PipelineProcessor();

            pipelineProcessor.Add(this.command.Context.CreateCommand("out-string"));
            this.inputList = new ArrayList((ICollection)pipelineProcessor.Execute((Array)this.inputList.ToArray()));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        internal Array ShutDown()
        {
            if (this.pp == null)
            {
                return(new object[0]);
            }
            PipelineProcessor pp = this.pp;

            this.pp = null;
            return(pp.Execute());
        }
Ejemplo n.º 4
0
        private void InvokeHelper()
        {
            PipelineProcessor pipelineProcessor = (PipelineProcessor)null;

            try
            {
                this.RaisePipelineStateEvents();
                this.RecordPipelineStartTime();
                try
                {
                    pipelineProcessor = this.CreatePipelineProcessor();
                }
                catch (Exception ex)
                {
                    if (this.SetPipelineSessionState)
                    {
                        this.Runspace.ExecutionContext.AppendDollarError((object)ex);
                    }
                    throw;
                }
                if (this.useExternalInput)
                {
                    pipelineProcessor.ExternalInput = this.InputStream.ObjectReader;
                }
                pipelineProcessor.ExternalSuccessOutput = this.OutputStream.ObjectWriter;
                pipelineProcessor.ExternalErrorOutput   = this.ErrorStream.ObjectWriter;
                this.LocalRunspace.ExecutionContext.InternalHost.InternalUI.SetInformationalMessageBuffers(this.InformationalBuffers);
                bool flag = true;
                bool enclosingStatementBlock = this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock;
                this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock = false;
                try
                {
                    this._stopper.Push(pipelineProcessor);
                    if (!this.AddToHistory)
                    {
                        flag = this.LocalRunspace.ExecutionContext.QuestionMarkVariableValue;
                        this.LocalRunspace.ExecutionContext.IgnoreScriptDebug = true;
                    }
                    else
                    {
                        this.LocalRunspace.ExecutionContext.IgnoreScriptDebug = false;
                    }
                    if (!this.IsNested)
                    {
                        this.LocalRunspace.ExecutionContext.ResetScopeDepth();
                    }
                    this.LocalRunspace.ExecutionContext.ResetRedirection();
                    try
                    {
                        pipelineProcessor.Execute();
                    }
                    catch (ExitException ex1)
                    {
                        int exitCode = 1;
                        if (this.IsNested)
                        {
                            try
                            {
                                this.LocalRunspace.ExecutionContext.SetVariable("global:LASTEXITCODE", (object)(int)ex1.Argument);
                            }
                            finally
                            {
                                try
                                {
                                    LocalPipeline._trace.WriteLine("exiting nested prompt at top level from exit statement", new object[0]);
                                    this.LocalRunspace.ExecutionContext.EngineHostInterface.ExitNestedPrompt();
                                }
                                catch (ExitNestedPromptException ex2)
                                {
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                exitCode = (int)ex1.Argument;
                            }
                            finally
                            {
                                this.LocalRunspace.ExecutionContext.EngineHostInterface.SetShouldExit(exitCode);
                            }
                        }
                    }
                    catch (ExitNestedPromptException ex)
                    {
                        LocalPipeline._trace.WriteLine("exiting nested prompt at top level from direct method call", new object[0]);
                    }
                    catch (FlowControlException ex)
                    {
                    }
                }
                finally
                {
                    if (this.LocalRunspace.Events is PSLocalEventManager events)
                    {
                        events.ProcessPendingActions();
                    }
                    this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock = enclosingStatementBlock;
                    this.LocalRunspace.ExecutionContext.InternalHost.InternalUI.SetInformationalMessageBuffers((PSInformationalBuffers)null);
                    if (!this.AddToHistory)
                    {
                        this.LocalRunspace.ExecutionContext.QuestionMarkVariableValue = flag;
                    }
                    this._stopper.Pop();
                }
            }
            finally
            {
                pipelineProcessor?.Dispose();
            }
        }
Ejemplo n.º 5
0
        private void InvokeHelper()
        {
            PipelineProcessor item = null;

            try
            {
                base.RaisePipelineStateEvents();
                this.RecordPipelineStartTime();
                try
                {
                    item = this.CreatePipelineProcessor();
                }
                catch (Exception exception)
                {
                    if (base.SetPipelineSessionState)
                    {
                        base.SetHadErrors(true);
                        this.Runspace.ExecutionContext.AppendDollarError(exception);
                    }
                    throw;
                }
                if (this.useExternalInput)
                {
                    item.ExternalInput = base.InputStream.ObjectReader;
                }
                item.ExternalSuccessOutput = base.OutputStream.ObjectWriter;
                item.ExternalErrorOutput   = base.ErrorStream.ObjectWriter;
                if (!this.IsChild)
                {
                    this.LocalRunspace.ExecutionContext.InternalHost.InternalUI.SetInformationalMessageBuffers(base.InformationalBuffers);
                }
                bool questionMarkVariableValue = true;
                bool exceptionHandlerInEnclosingStatementBlock = this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock;
                this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock = false;
                try
                {
                    this._stopper.Push(item);
                    if (!base.AddToHistory)
                    {
                        questionMarkVariableValue = this.LocalRunspace.ExecutionContext.QuestionMarkVariableValue;
                        this.LocalRunspace.ExecutionContext.IgnoreScriptDebug = true;
                    }
                    else
                    {
                        this.LocalRunspace.ExecutionContext.IgnoreScriptDebug = false;
                    }
                    if (!this.IsNested && !base.IsPulsePipeline)
                    {
                        this.LocalRunspace.ExecutionContext.ResetRedirection();
                    }
                    try
                    {
                        item.Execute();
                        base.SetHadErrors(item.ExecutionFailed);
                    }
                    catch (ExitException exception2)
                    {
                        base.SetHadErrors(item.ExecutionFailed);
                        int newValue = 1;
                        if (this.IsNested)
                        {
                            try
                            {
                                newValue = (int)exception2.Argument;
                                this.LocalRunspace.ExecutionContext.SetVariable(SpecialVariables.LastExitCodeVarPath, newValue);
                                return;
                            }
                            finally
                            {
                                try
                                {
                                    this.LocalRunspace.ExecutionContext.EngineHostInterface.ExitNestedPrompt();
                                }
                                catch (ExitNestedPromptException)
                                {
                                }
                            }
                        }
                        try
                        {
                            newValue = (int)exception2.Argument;
                        }
                        finally
                        {
                            this.LocalRunspace.ExecutionContext.EngineHostInterface.SetShouldExit(newValue);
                        }
                    }
                    catch (ExitNestedPromptException)
                    {
                    }
                    catch (FlowControlException)
                    {
                    }
                    catch (Exception)
                    {
                        base.SetHadErrors(true);
                        throw;
                    }
                }
                finally
                {
                    if ((item != null) && (item.Commands != null))
                    {
                        for (int i = 0; i < item.Commands.Count; i++)
                        {
                            CommandProcessorBase base2 = item.Commands[i];
                            EtwActivity.SetActivityId(base2.PipelineActivityId);
                            MshLog.LogCommandLifecycleEvent(base2.Context, CommandState.Terminated, base2.Command.MyInvocation);
                        }
                    }
                    PSLocalEventManager events = this.LocalRunspace.Events as PSLocalEventManager;
                    if (events != null)
                    {
                        events.ProcessPendingActions();
                    }
                    this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock = exceptionHandlerInEnclosingStatementBlock;
                    if (!this.IsChild)
                    {
                        this.LocalRunspace.ExecutionContext.InternalHost.InternalUI.SetInformationalMessageBuffers(null);
                    }
                    this._stopper.Pop(false);
                    if (!base.AddToHistory)
                    {
                        this.LocalRunspace.ExecutionContext.QuestionMarkVariableValue = questionMarkVariableValue;
                    }
                }
            }
            catch (FlowControlException)
            {
            }
            finally
            {
                if (item != null)
                {
                    item.Dispose();
                    item = null;
                }
            }
        }