Exemple #1
0
 private RemotePipeline(RemoteRunspace runspace, bool addToHistory, bool isNested) : base(runspace)
 {
     this._syncRoot            = new object();
     this._pipelineStateInfo   = new System.Management.Automation.Runspaces.PipelineStateInfo(PipelineState.NotStarted);
     this._commands            = new CommandCollection();
     this._executionEventQueue = new Queue <ExecutionEventQueueItem>();
     this._performNestedCheck  = true;
     this._addToHistory        = addToHistory;
     this._isNested            = isNested;
     this._isSteppable         = false;
     this._runspace            = runspace;
     this._computerName        = ((RemoteRunspace)this._runspace).ConnectionInfo.ComputerName;
     this._runspaceId          = this._runspace.InstanceId;
     this._inputCollection     = new PSDataCollection <object>();
     this._inputCollection.ReleaseOnEnumeration = true;
     this._inputStream                   = new PSDataCollectionStream <object>(Guid.Empty, this._inputCollection);
     this._outputCollection              = new PSDataCollection <PSObject>();
     this._outputStream                  = new PSDataCollectionStream <PSObject>(Guid.Empty, this._outputCollection);
     this._errorCollection               = new PSDataCollection <ErrorRecord>();
     this._errorStream                   = new PSDataCollectionStream <ErrorRecord>(Guid.Empty, this._errorCollection);
     this._methodExecutorStream          = new ObjectStream();
     this._isMethodExecutorStreamEnabled = false;
     base.SetCommandCollection(this._commands);
     this._pipelineFinishedEvent = new ManualResetEvent(false);
 }
Exemple #2
0
        /// <summary>
        /// Copy constructor to support cloning.
        /// </summary>
        /// <param name="pipelineStateInfo">Source information.</param>
        /// <throws>
        /// ArgumentNullException when <paramref name="pipelineStateInfo"/> is null.
        /// </throws>
        internal PipelineStateInfo(PipelineStateInfo pipelineStateInfo)
        {
            Dbg.Assert(pipelineStateInfo != null, "caller should validate the parameter");

            State  = pipelineStateInfo.State;
            Reason = pipelineStateInfo.Reason;
        }
Exemple #3
0
 private RemotePipeline(RemoteRunspace runspace, bool addToHistory, bool isNested) : base(runspace)
 {
     this._syncRoot = new object();
     this._pipelineStateInfo = new System.Management.Automation.Runspaces.PipelineStateInfo(PipelineState.NotStarted);
     this._commands = new CommandCollection();
     this._executionEventQueue = new Queue<ExecutionEventQueueItem>();
     this._performNestedCheck = true;
     this._addToHistory = addToHistory;
     this._isNested = isNested;
     this._isSteppable = false;
     this._runspace = runspace;
     this._computerName = ((RemoteRunspace) this._runspace).ConnectionInfo.ComputerName;
     this._runspaceId = this._runspace.InstanceId;
     this._inputCollection = new PSDataCollection<object>();
     this._inputCollection.ReleaseOnEnumeration = true;
     this._inputStream = new PSDataCollectionStream<object>(Guid.Empty, this._inputCollection);
     this._outputCollection = new PSDataCollection<PSObject>();
     this._outputStream = new PSDataCollectionStream<PSObject>(Guid.Empty, this._outputCollection);
     this._errorCollection = new PSDataCollection<ErrorRecord>();
     this._errorStream = new PSDataCollectionStream<ErrorRecord>(Guid.Empty, this._errorCollection);
     this._methodExecutorStream = new ObjectStream();
     this._isMethodExecutorStreamEnabled = false;
     base.SetCommandCollection(this._commands);
     this._pipelineFinishedEvent = new ManualResetEvent(false);
 }
Exemple #4
0
        /// <summary>
        /// Sets the new execution state.
        /// </summary>
        /// <param name="state">The new state.</param>
        /// <param name="reason">
        /// An exception indicating that state change is the result of an error,
        /// otherwise; null.
        /// </param>
        /// <remarks>
        /// Sets the internal execution state information member variable. It
        /// also adds PipelineStateInfo to a queue. RaisePipelineStateEvents
        /// raises event for each item in this queue.
        /// </remarks>
        protected void SetPipelineState(PipelineState state, Exception reason)
        {
            lock (SyncRoot)
            {
                if (state != PipelineState)
                {
                    _pipelineStateInfo = new PipelineStateInfo(state, reason);

                    // Add _pipelineStateInfo to _executionEventQueue.
                    // RaisePipelineStateEvents will raise event for each item
                    // in this queue.
                    // Note:We are doing clone here instead of passing the member
                    // _pipelineStateInfo because we donot want outside
                    // to change pipeline state.
                    RunspaceAvailability previousAvailability = _runspace.RunspaceAvailability;

                    _runspace.UpdateRunspaceAvailability(_pipelineStateInfo.State, false);

                    _executionEventQueue.Enqueue(
                        new ExecutionEventQueueItem(
                            _pipelineStateInfo.Clone(),
                            previousAvailability,
                            _runspace.RunspaceAvailability));
                }
            }
        }
Exemple #5
0
 public ExecutionEventQueueItem(
     PipelineStateInfo pipelineStateInfo,
     RunspaceAvailability currentAvailability,
     RunspaceAvailability newAvailability)
 {
     this.PipelineStateInfo           = pipelineStateInfo;
     this.CurrentRunspaceAvailability = currentAvailability;
     this.NewRunspaceAvailability     = newAvailability;
 }
Exemple #6
0
        public LocalPipeline(LocalRunspace runspace, string command)
            : base()
        {
            _runspace = runspace;
            _inputStream = new ObjectStream();
            _outputStream = new ObjectStream();
            _errorStream = new ObjectStream();
            _inputPipelineWriter = new ObjectStreamWriter(_inputStream);
            _outputPipelineReader = new PSObjectPipelineReader(_outputStream);
            _errorPipelineReader = new ObjectPipelineReader(_errorStream);
            _pipelineStateInfo = new PipelineStateInfo(PipelineState.NotStarted);

            if (!string.IsNullOrEmpty(command))
                Commands.Add(command);
        }
Exemple #7
0
 protected void SetPipelineState(PipelineState state, Exception reason)
 {
     using (PipelineBase._trace.TraceMethod("{0} to {1} {2}", (object)this.PipelineState, (object)state, reason != null ? (object)reason.Message : (object)""))
     {
         lock (this.SyncRoot)
         {
             if (state == this.PipelineState)
             {
                 return;
             }
             this._pipelineStateInfo = new PipelineStateInfo(state, reason);
             RunspaceAvailability runspaceAvailability = this._runspace.RunspaceAvailability;
             this._runspace.UpdateRunspaceAvailability(this._pipelineStateInfo.State, false);
             this._executionEventQueue.Enqueue(new PipelineBase.ExecutionEventQueueItem(this._pipelineStateInfo.Clone(), runspaceAvailability, this._runspace.RunspaceAvailability));
         }
     }
 }
Exemple #8
0
        private void SetPipelineState(PipelineState state, Exception reason)
        {
            PipelineState stopped = state;

            System.Management.Automation.Runspaces.PipelineStateInfo info = null;
            lock (this._syncRoot)
            {
                switch (this._pipelineStateInfo.State)
                {
                case PipelineState.Running:
                    if (state != PipelineState.Running)
                    {
                        goto Label_005F;
                    }
                    return;

                case PipelineState.Stopping:
                    if ((state != PipelineState.Running) && (state != PipelineState.Stopping))
                    {
                        break;
                    }
                    return;

                case PipelineState.Stopped:
                case PipelineState.Completed:
                case PipelineState.Failed:
                    return;

                default:
                    goto Label_005F;
                }
                stopped = PipelineState.Stopped;
Label_005F:
                this._pipelineStateInfo = new System.Management.Automation.Runspaces.PipelineStateInfo(stopped, reason);
                info = this._pipelineStateInfo;
                RunspaceAvailability runspaceAvailability = this._runspace.RunspaceAvailability;
                this._runspace.UpdateRunspaceAvailability(this._pipelineStateInfo.State, false);
                this._executionEventQueue.Enqueue(new ExecutionEventQueueItem(this._pipelineStateInfo.Clone(), runspaceAvailability, this._runspace.RunspaceAvailability));
            }
            if (((info.State == PipelineState.Completed) || (info.State == PipelineState.Failed)) || (info.State == PipelineState.Stopped))
            {
                this.Cleanup();
            }
        }
Exemple #9
0
 public PipelineStateEventArgs(PipelineStateInfo state)
 {
     PipelineStateInfo = state;
 }
Exemple #10
0
 internal PipelineStateInfo(PipelineStateInfo pipelineStateInfo)
 {
     Reason = pipelineStateInfo.Reason;
     State = pipelineStateInfo.State;
 }
Exemple #11
0
        /// <summary>
        /// Copy constructor to support cloning
        /// </summary>
        /// <param name="pipelineStateInfo">source information</param>
        /// <throws>
        /// ArgumentNullException when <paramref name="pipelineStateInfo"/> is null.
        /// </throws>
        internal PipelineStateInfo(PipelineStateInfo pipelineStateInfo)
        {
            Dbg.Assert(pipelineStateInfo != null, "caller should validate the parameter");

            State = pipelineStateInfo.State;
            Reason = pipelineStateInfo.Reason;
        }
Exemple #12
0
 /// <summary>
 /// Constructor PipelineStateEventArgs from PipelineStateInfo
 /// </summary>
 /// <param name="pipelineStateInfo">The current state of the 
 /// pipeline.</param>
 /// <throws>
 /// ArgumentNullException when <paramref name="pipelineStateInfo"/> is null.
 /// </throws>
 internal PipelineStateEventArgs(PipelineStateInfo pipelineStateInfo)
 {
     Dbg.Assert(pipelineStateInfo != null, "caller should validate the parameter");
     PipelineStateInfo = pipelineStateInfo;
 }
Exemple #13
0
 public ExecutionEventQueueItem(PipelineStateInfo pipelineStateInfo, RunspaceAvailability currentAvailability, RunspaceAvailability newAvailability)
 {
     this.PipelineStateInfo = pipelineStateInfo;
     this.CurrentRunspaceAvailability = currentAvailability;
     this.NewRunspaceAvailability = newAvailability;
 }
Exemple #14
0
        /// <summary>
        /// Sets the new execution state.
        /// </summary>
        /// <param name="state">the new state</param>
        /// <param name="reason">
        /// An exception indicating that state change is the result of an error, 
        /// otherwise; null.
        /// </param>
        /// <remarks>
        /// Sets the internal execution state information member variable. It
        /// also adds PipelineStateInfo to a queue. RaisePipelineStateEvents
        /// raises event for each item in this queue.  
        /// </remarks>
        private void SetPipelineState(PipelineState state, Exception reason)
        {
            PipelineState copyState = state;
            PipelineStateInfo copyStateInfo = null;

            lock (_syncRoot)
            {
                switch (_pipelineStateInfo.State)
                {
                    case PipelineState.Completed:
                    case PipelineState.Failed:
                    case PipelineState.Stopped:
                        return;

                    case PipelineState.Running:
                        {
                            if (state == PipelineState.Running)
                            {
                                return;
                            }
                        }
                        break;
                    case PipelineState.Stopping:
                        {
                            if (state == PipelineState.Running || state == PipelineState.Stopping)
                            {
                                return;
                            }
                            else
                            {
                                copyState = PipelineState.Stopped;
                            }
                        }
                        break;
                }
                _pipelineStateInfo = new PipelineStateInfo(copyState, reason);
                copyStateInfo = _pipelineStateInfo;

                //Add _pipelineStateInfo to _executionEventQueue. 
                //RaisePipelineStateEvents will raise event for each item
                //in this queue.
                //Note:We are doing clone here instead of passing the member 
                //_pipelineStateInfo because we donot want outside
                //to change pipeline state.
                RunspaceAvailability previousAvailability = _runspace.RunspaceAvailability;

                Guid? cmdInstanceId = (_powershell != null) ? _powershell.InstanceId : (Guid?)null;
                _runspace.UpdateRunspaceAvailability(_pipelineStateInfo.State, false, cmdInstanceId);

                _executionEventQueue.Enqueue(
                    new ExecutionEventQueueItem(
                        _pipelineStateInfo.Clone(),
                        previousAvailability,
                        _runspace.RunspaceAvailability));
            } // lock...

            // using the copyStateInfo here as this piece of code is 
            // outside of lock and _pipelineStateInfo might get changed
            // by two threads running concurrently..so its value is 
            // not guaranteed to be the same for this entire method call.
            // copyStateInfo is a local variable.
            if (copyStateInfo.State == PipelineState.Completed ||
                copyStateInfo.State == PipelineState.Failed ||
                copyStateInfo.State == PipelineState.Stopped)
            {
                Cleanup();
            }
        }
Exemple #15
0
 public PipelineStateEventArgs(PipelineStateInfo state)
 {
     PipelineStateInfo = state;
 }
Exemple #16
0
        private void SetPipelineState(PipelineState state, Exception reason)
        {
            PipelineState stopped = state;
            System.Management.Automation.Runspaces.PipelineStateInfo info = null;
            lock (this._syncRoot)
            {
                switch (this._pipelineStateInfo.State)
                {
                    case PipelineState.Running:
                        if (state != PipelineState.Running)
                        {
                            goto Label_005F;
                        }
                        return;

                    case PipelineState.Stopping:
                        if ((state != PipelineState.Running) && (state != PipelineState.Stopping))
                        {
                            break;
                        }
                        return;

                    case PipelineState.Stopped:
                    case PipelineState.Completed:
                    case PipelineState.Failed:
                        return;

                    default:
                        goto Label_005F;
                }
                stopped = PipelineState.Stopped;
            Label_005F:
                this._pipelineStateInfo = new System.Management.Automation.Runspaces.PipelineStateInfo(stopped, reason);
                info = this._pipelineStateInfo;
                RunspaceAvailability runspaceAvailability = this._runspace.RunspaceAvailability;
                this._runspace.UpdateRunspaceAvailability(this._pipelineStateInfo.State, false);
                this._executionEventQueue.Enqueue(new ExecutionEventQueueItem(this._pipelineStateInfo.Clone(), runspaceAvailability, this._runspace.RunspaceAvailability));
            }
            if (((info.State == PipelineState.Completed) || (info.State == PipelineState.Failed)) || (info.State == PipelineState.Stopped))
            {
                this.Cleanup();
            }
        }
Exemple #17
0
 internal PipelineStateInfo(PipelineStateInfo pipelineStateInfo)
 {
     Reason = pipelineStateInfo.Reason;
     State  = pipelineStateInfo.State;
 }
 internal PSInvocationStateInfo(PipelineStateInfo pipelineStateInfo)
 {
     this.executionState = (PSInvocationState) pipelineStateInfo.State;
     this.exceptionReason = pipelineStateInfo.Reason;
 }
Exemple #19
0
        private void SetPipelineState(PipelineState state, Exception reason)
        {
            _pipelineStateInfo = new PipelineStateInfo(state, reason);

            if (StateChanged != null)
                StateChanged(this, new PipelineStateEventArgs(_pipelineStateInfo));
        }
Exemple #20
0
 public ExecutionEventQueueItem(System.Management.Automation.Runspaces.PipelineStateInfo pipelineStateInfo, RunspaceAvailability currentAvailability, RunspaceAvailability newAvailability)
 {
     this.PipelineStateInfo = pipelineStateInfo;
     this.CurrentRunspaceAvailability = currentAvailability;
     this.NewRunspaceAvailability = newAvailability;
 }
Exemple #21
0
        private void Handle_StateChanged(object sender, PipelineStateEventArgs e)
        {
            Pipeline pipeline = sender as Pipeline;
            lock (lockState)
            {
                stateInfo = pipeline.PipelineStateInfo;
            }
            executeAction(stateChangedAction);
            if (pipeline.PipelineStateInfo.State > PipelineState.Stopping)
            {

                 pipeline.Dispose();
            }
        }
Exemple #22
0
 internal PipelineStateInfo(PipelineStateInfo pipelineStateInfo)
 {
     this._state = pipelineStateInfo.State;
     this._reason = pipelineStateInfo.Reason;
 }
Exemple #23
0
 public ExecutionEventQueueItem(System.Management.Automation.Runspaces.PipelineStateInfo pipelineStateInfo, RunspaceAvailability currentAvailability, RunspaceAvailability newAvailability)
 {
     this.PipelineStateInfo           = pipelineStateInfo;
     this.CurrentRunspaceAvailability = currentAvailability;
     this.NewRunspaceAvailability     = newAvailability;
 }
Exemple #24
0
 internal PSInvocationStateInfo(PipelineStateInfo pipelineStateInfo)
 {
     throw new NotImplementedException();
 }
Exemple #25
0
 /// <summary>
 /// Constructor PipelineStateEventArgs from PipelineStateInfo.
 /// </summary>
 /// <param name="pipelineStateInfo">The current state of the
 /// pipeline.</param>
 /// <throws>
 /// ArgumentNullException when <paramref name="pipelineStateInfo"/> is null.
 /// </throws>
 internal PipelineStateEventArgs(PipelineStateInfo pipelineStateInfo)
 {
     Dbg.Assert(pipelineStateInfo != null, "caller should validate the parameter");
     PipelineStateInfo = pipelineStateInfo;
 }
 private void OnScriptStateChanged(object sender, PipelineStateInfo info)
 {
     switch(info.State) {
         case PipelineState.Completed: {
                 exitEvent.Set();
                 break;
             }
         case PipelineState.Failed: {
                 sucessfull = false;
                 ActionErrorReporter.ReportError(_session, _afterWipe, ErrorSeverity.High,
                                                 FailedRunMessage, info.Reason.Message);
                 exitEvent.Set();
                 break;
             }
     }
 }
 private void StateChangedHandler(object sender, PipelineStateInfo state)
 {
     this.Invoke(new EventHandler(StateChangedInvoked), state, null);
 }
Exemple #28
0
 internal PipelineStateInfo(PipelineStateInfo pipelineStateInfo)
 {
     this._state  = pipelineStateInfo.State;
     this._reason = pipelineStateInfo.Reason;
 }
Exemple #29
0
        /// <summary>
        /// Sets the new execution state.
        /// </summary>
        /// <param name="state">the new state</param>
        /// <param name="reason">
        /// An exception indicating that state change is the result of an error, 
        /// otherwise; null.
        /// </param>
        /// <remarks>
        /// Sets the internal execution state information member variable. It
        /// also adds PipelineStateInfo to a queue. RaisePipelineStateEvents
        /// raises event for each item in this queue.  
        /// </remarks>
        protected void SetPipelineState(PipelineState state, Exception reason)
        {
            lock (SyncRoot)
            {
                if (state != PipelineState)
                {
                    _pipelineStateInfo = new PipelineStateInfo(state, reason);

                    //Add _pipelineStateInfo to _executionEventQueue. 
                    //RaisePipelineStateEvents will raise event for each item
                    //in this queue.
                    //Note:We are doing clone here instead of passing the member 
                    //_pipelineStateInfo because we donot want outside
                    //to change pipeline state.
                    RunspaceAvailability previousAvailability = _runspace.RunspaceAvailability;

                    _runspace.UpdateRunspaceAvailability(_pipelineStateInfo.State, false);

                    _executionEventQueue.Enqueue(
                        new ExecutionEventQueueItem(
                            _pipelineStateInfo.Clone(),
                            previousAvailability,
                            _runspace.RunspaceAvailability));
                }
            }
        }