/// <summary> /// private DataReady handling method that will pass the call on to any event handlers that are /// attached to the OnDataReady event of this <see cref="AsyncPipelineExecutor"/> instance. /// </summary> /// <param name="sender"></param> /// <param name="data"></param> private void SynchDataReady(AsyncPipelineExecutor sender, ICollection <PSObject> data) { DataReadyDelegate delegateDataReadyCopy = OnDataReady; if (delegateDataReadyCopy != null) { delegateDataReadyCopy(sender, data); } }
/// <summary> /// Constructor, creates a new PipelineExecutor for the given powershell script. /// </summary> /// <param name="runSpace">Powershell runspace to use for creating and executing the script.</param> /// <param name="invoker">The object to synchronize the DataReady and DataEnd events with. /// Normally you'd pass the form or component here.</param> /// <param name="command">The script to run</param> public PipelineExecutor(Runspace runSpace, ISynchronizeInvoke invoker, string command) { this.invoker = invoker; // initialize delegates synchDataReady = new DataReadyDelegate(SynchDataReady); synchDataEnd = new DataEndDelegate(SynchDataEnd); synchErrorReady = new ErrorReadyDelegate(SynchErrorReady); // initialize event members stopEvent = new ManualResetEvent(false); waitHandles = new WaitHandle[] { null, stopEvent }; // create a pipeline and feed it the script text pipeline = runSpace.CreatePipeline(command); // we'll listen for script output data by way of the DataReady event pipeline.Output.DataReady += new EventHandler(Output_DataReady); pipeline.Error.DataReady += new EventHandler(Error_DataReady); }
public PipelineExecutor(Runspace runSpace,ISynchronizeInvoke invoker,string command) { this.invoker = invoker; // initialize delegates synchDataReady = new DataReadyDelegate(SynchDataReady); synchDataEnd = new DataEndDelegate(SynchDataEnd); synchErrorReady = new ErrorReadyDelegate(SynchErrorReady); // initialize event members stopEvent = new ManualResetEvent(false); waitHandles = new WaitHandle[] { null, stopEvent }; // create a pipeline and feed it the script text pipeline = runSpace.CreatePipeline(command); // we'll listen for script output data by way of the DataReady event pipeline.Output.DataReady += new EventHandler(Output_DataReady); pipeline.Error.DataReady += new EventHandler(Error_DataReady); }
/// <summary> /// Constructor, creates a new AsyncPipelineExecutor for the given powershell script. /// </summary> /// <param name="runSpace">Powershell runspace to use for creating and executing the script.</param> /// <param name="invoker">The object to synchronize the DataReady and DataEnd events with. /// Normally you'd pass the form or component here.</param> /// <param name="command">The script to run</param> public AsyncPipelineExecutor(Runspace runSpace, ISynchronizeInvoke invoker, string command) { this.invoker = invoker; synchDataReady = new DataReadyDelegate(SynchDataReady); synchDataEnd = new DataEndDelegate(SynchDataEnd); synchErrorReady = new ErrorReadyDelegate(SynchErrorReady); stopEvent = new ManualResetEvent(false); waitHandles = new WaitHandle[] { null, stopEvent }; pipeline = runSpace.CreatePipeline(command); pipeline.Output.DataReady += new EventHandler(Output_DataReady); pipeline.Error.DataReady += new EventHandler(Error_DataReady); }