/// <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(); }
internal void AssertNotDisposed() { if (this.isDisposed) { throw PSTraceSource.NewObjectDisposedException("PSJob"); } }
/// <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); } }
public override Pipeline Copy() { if (this._disposed) { throw PSTraceSource.NewObjectDisposedException("pipeline"); } return(new RemotePipeline(this)); }
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)); }
/// <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"); } } }
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); }
public override void StopAsync() { bool flag; if (this.CanStopPipeline(out flag)) { try { this._powershell.BeginStop(null, null); } catch (ObjectDisposedException) { throw PSTraceSource.NewObjectDisposedException("Pipeline"); } } }
/// <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); }
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(); }
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); } }