Esempio n. 1
0
        /// <summary>
        /// Stop the pipeline synchronously
        /// </summary>
        public override void Stop()
        {
            bool isAlreadyStopping = false;

            if (CanStopPipeline(out isAlreadyStopping))
            {
                // A pipeline can be stopped before it is started.so protecting against that
                if (_powershell != null)
                {
                    IAsyncResult asyncresult = null;
                    try
                    {
                        asyncresult = _powershell.BeginStop(null, null);
                    }
                    catch (ObjectDisposedException)
                    {
                        throw PSTraceSource.NewObjectDisposedException("Pipeline");
                    };

                    asyncresult.AsyncWaitHandle.WaitOne();
                }
            }

            // Waits until pipeline completes stop as this is a sync call.
            PipelineFinishedEvent.WaitOne();
        }
Esempio n. 2
0
 internal void AssertNotDisposed()
 {
     if (this.isDisposed)
     {
         throw PSTraceSource.NewObjectDisposedException("PSJob");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Creates a cloned pipeline from the specified one
        /// </summary>
        /// <param name="pipeline">pipeline to clone from</param>
        /// <remarks>This constructor is private because this will
        /// only be called from the copy method</remarks>
        private RemotePipeline(RemotePipeline pipeline) :
            this((RemoteRunspace)pipeline.Runspace, null, false, pipeline.IsNested)
        {
            _isSteppable = pipeline._isSteppable;

            // NTRAID#Windows Out Of Band Releases-915851-2005/09/13
            // the above comment copied from RemotePipelineBase which
            // originally copied it from PipelineBase
            if (null == pipeline)
            {
                throw PSTraceSource.NewArgumentNullException("pipeline");
            }
            if (pipeline._disposed)
            {
                throw PSTraceSource.NewObjectDisposedException("pipeline");
            }

            _addToHistory  = pipeline._addToHistory;
            _historyString = pipeline._historyString;
            foreach (Command command in pipeline.Commands)
            {
                Command clone = command.Clone();

                // Attach the cloned Command to this pipeline.
                Commands.Add(clone);
            }
        }
Esempio n. 4
0
 public override Pipeline Copy()
 {
     if (this._disposed)
     {
         throw PSTraceSource.NewObjectDisposedException("pipeline");
     }
     return(new RemotePipeline(this));
 }
Esempio n. 5
0
 public Collection <PSObject> Invoke(string script, IEnumerable input)
 {
     if (this._disposed)
     {
         throw PSTraceSource.NewObjectDisposedException("runspace");
     }
     if (script == null)
     {
         throw PSTraceSource.NewArgumentNullException("script");
     }
     return(this._runspace.CreatePipeline(script).Invoke(input));
 }
Esempio n. 6
0
        /// <summary>
        /// Stop the pipeline asynchronously.
        /// This method calls the BeginStop on the underlying
        /// powershell and so any exception will be
        /// thrown on the same thread.
        /// </summary>
        public override void StopAsync()
        {
            bool isAlreadyStopping;

            if (CanStopPipeline(out isAlreadyStopping))
            {
                try
                {
                    _powershell.BeginStop(null, null);
                }
                catch (ObjectDisposedException)
                {
                    throw PSTraceSource.NewObjectDisposedException("Pipeline");
                }
            }
        }
Esempio n. 7
0
        public Collection <PSObject> Invoke(string script, IEnumerable input, out IList errors)
        {
            if (this._disposed)
            {
                throw PSTraceSource.NewObjectDisposedException("runspace");
            }
            if (script == null)
            {
                throw PSTraceSource.NewArgumentNullException("script");
            }
            Pipeline pipeline = this._runspace.CreatePipeline(script);
            Collection <PSObject> collection = pipeline.Invoke(input);

            errors = pipeline.Error.NonBlockingRead();
            return(collection);
        }
Esempio n. 8
0
        public override void StopAsync()
        {
            bool flag;

            if (this.CanStopPipeline(out flag))
            {
                try
                {
                    this._powershell.BeginStop(null, null);
                }
                catch (ObjectDisposedException)
                {
                    throw PSTraceSource.NewObjectDisposedException("Pipeline");
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Invoke the specified script and passes specified input to the script.
        /// </summary>
        /// <param name="script">msh script to invoke</param>
        /// <param name="input">input to script</param>
        /// <param name="errors">this gets errors from script</param>
        /// <returns>output of invocation</returns>
        /// <remarks>
        /// <paramref name="errors"/> is the non-terminating error stream
        /// from the command.
        /// In this release, the objects read from this PipelineReader
        /// are PSObjects wrapping ErrorRecords.
        /// </remarks>
        public Collection <PSObject> Invoke(string script, IEnumerable input, out IList errors)
        {
            if (_disposed == true)
            {
                throw PSTraceSource.NewObjectDisposedException("runspace");
            }

            if (script == null)
            {
                throw PSTraceSource.NewArgumentNullException("script");
            }
            Pipeline p = _runspace.CreatePipeline(script);
            Collection <PSObject> output = p.Invoke(input);

            // 2004/06/30-JonN was ReadAll() which was non-blocking
            errors = p.Error.NonBlockingRead();
            return(output);
        }
Esempio n. 10
0
        public override void Stop()
        {
            bool isAlreadyStopping = false;

            if (this.CanStopPipeline(out isAlreadyStopping) && (this._powershell != null))
            {
                IAsyncResult result = null;
                try
                {
                    result = this._powershell.BeginStop(null, null);
                }
                catch (ObjectDisposedException)
                {
                    throw PSTraceSource.NewObjectDisposedException("Pipeline");
                }
                result.AsyncWaitHandle.WaitOne();
            }
            this.PipelineFinishedEvent.WaitOne();
        }
Esempio n. 11
0
 private RemotePipeline(RemotePipeline pipeline) : this((RemoteRunspace)pipeline.Runspace, null, false, pipeline.IsNested)
 {
     this._isSteppable = pipeline._isSteppable;
     if (pipeline == null)
     {
         throw PSTraceSource.NewArgumentNullException("pipeline");
     }
     if (pipeline._disposed)
     {
         throw PSTraceSource.NewObjectDisposedException("pipeline");
     }
     this._addToHistory  = pipeline._addToHistory;
     this._historyString = pipeline._historyString;
     foreach (Command command in pipeline.Commands)
     {
         Command item = command.Clone();
         base.Commands.Add(item);
     }
 }