Ejemplo n.º 1
0
 private void DoCompleteCore(CommandProcessorBase commandRequestingUpstreamCommandsToStop)
 {
     for (int i = 0; i < this._commands.Count; i++)
     {
         CommandProcessorBase objB = this._commands[i];
         if (objB == null)
         {
             throw PSTraceSource.NewInvalidOperationException();
         }
         if (object.ReferenceEquals(commandRequestingUpstreamCommandsToStop, objB))
         {
             commandRequestingUpstreamCommandsToStop = null;
         }
         else if (commandRequestingUpstreamCommandsToStop == null)
         {
             try
             {
                 objB.DoComplete();
             }
             catch (PipelineStoppedException)
             {
                 StopUpstreamCommandsException firstTerminatingError = this.firstTerminatingError as StopUpstreamCommandsException;
                 if (firstTerminatingError == null)
                 {
                     throw;
                 }
                 this.firstTerminatingError = null;
                 commandRequestingUpstreamCommandsToStop = firstTerminatingError.RequestingCommandProcessor;
             }
             EtwActivity.SetActivityId(objB.PipelineActivityId);
             MshLog.LogCommandLifecycleEvent(objB.Command.Context, CommandState.Stopped, objB.Command.MyInvocation);
         }
     }
     if (this.firstTerminatingError != null)
     {
         this.LogExecutionException(this.firstTerminatingError);
         throw this.firstTerminatingError;
     }
 }
Ejemplo n.º 2
0
 private void Start(bool incomingStream)
 {
     if (this.disposed)
     {
         throw PSTraceSource.NewObjectDisposedException("PipelineProcessor");
     }
     if (this.Stopping)
     {
         throw new PipelineStoppedException();
     }
     if (!this.executionStarted)
     {
         if ((this._commands == null) || (this._commands.Count == 0))
         {
             throw PSTraceSource.NewInvalidOperationException("PipelineStrings", "PipelineExecuteRequiresAtLeastOneCommand", new object[0]);
         }
         CommandProcessorBase base2 = this._commands[0];
         if ((base2 == null) || (base2.CommandRuntime == null))
         {
             throw PSTraceSource.NewInvalidOperationException("PipelineStrings", "PipelineExecuteRequiresAtLeastOneCommand", new object[0]);
         }
         if (this.executionScope == null)
         {
             this.executionScope = base2.Context.EngineSessionState.CurrentScope;
         }
         CommandProcessorBase base3 = this._commands[this._commands.Count - 1];
         if ((base3 == null) || (base3.CommandRuntime == null))
         {
             throw PSTraceSource.NewInvalidOperationException();
         }
         if (this.ExternalSuccessOutput != null)
         {
             base3.CommandRuntime.OutputPipe.ExternalWriter = this.ExternalSuccessOutput;
         }
         this.SetExternalErrorOutput();
         if ((this.ExternalInput == null) && !incomingStream)
         {
             base2.CommandRuntime.IsClosed = true;
         }
         IDictionary variableValue = base2.Context.GetVariableValue(SpecialVariables.PSDefaultParameterValuesVarPath, false) as IDictionary;
         this.executionStarted = true;
         int[] numArray = new int[this._commands.Count + 1];
         for (int i = 0; i < this._commands.Count; i++)
         {
             CommandProcessorBase base4 = this._commands[i];
             if (base4 == null)
             {
                 throw PSTraceSource.NewInvalidOperationException();
             }
             Guid engineActivityId = base4.Context.CurrentRunspace.EngineActivityId;
             Guid activityId       = EtwActivity.CreateActivityId();
             EtwActivity.SetActivityId(activityId);
             base4.PipelineActivityId = activityId;
             MshLog.LogCommandLifecycleEvent(base4.Context, CommandState.Started, base4.Command.MyInvocation);
             InvocationInfo myInvocation = base4.Command.MyInvocation;
             myInvocation.PipelinePosition      = i + 1;
             myInvocation.PipelineLength        = this._commands.Count;
             myInvocation.PipelineIterationInfo = numArray;
             base4.DoPrepare(variableValue);
             myInvocation.ExpectingInput = base4.IsPipelineInputExpected();
         }
         this.SetupOutErrorVariable();
         for (int j = 0; j < this._commands.Count; j++)
         {
             this._commands[j].DoBegin();
         }
     }
 }
Ejemplo n.º 3
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;
                }
            }
        }