/// <summary> /// private ErrorReady handling method that will pass the call on to any event handlers that are /// attached to the OnErrorReady event of this <see cref="AsyncPipelineExecutor"/> instance. /// </summary> /// <param name="sender"></param> /// <param name="data"></param> private void SynchErrorReady(AsyncPipelineExecutor sender, ICollection <object> data) { ErrorReadyDelegate delegateErrorReadyCopy = OnErrorReady; if (delegateErrorReadyCopy != null) { delegateErrorReadyCopy(sender, data); } }
internal ScriptRunner(Runspace runSpace, ISynchronizeInvoke invoker, string script, IDictionary <string, dynamic> parameters = null) { _invoker = invoker; _stopEvent = new ManualResetEvent(false); _waitHandles = new WaitHandle[] { null, _stopEvent }; ScriptFile = script; Parameters = parameters; _powerShell = System.Management.Automation.PowerShell.Create(); _powerShell.Runspace = runSpace; var command = new Command(script); if (parameters != null) { foreach (KeyValuePair <string, dynamic> parameter in parameters) { command.Parameters.Add(new CommandParameter(parameter.Key, parameter.Value)); } } _powerShell.Commands.AddCommand(command); _outputCollection = new PSDataCollection <PSObject>(); _outputCollection.DataAdded += OnObjectOutput; synchComplete = SyncComplete; synchObjectReady = SyncObjectReady; synchProgressReady = SyncProgressReady; synchInformationReady = SyncInformationReady; synchWarningReady = SyncWarningReady; synchErrorReady = SyncErrorReady; synchVerboseReady = SyncVerboseReady; synchDebugReady = SyncDebugReady; _powerShell.InvocationStateChanged += StateChanged; _powerShell.Streams.Progress.DataAdded += OnProgress; _powerShell.Streams.Error.DataAdded += OnError; _powerShell.Streams.Information.DataAdded += OnInformation; _powerShell.Streams.Verbose.DataAdded += OnVerbose; _powerShell.Streams.Debug.DataAdded += OnDebug; _powerShell.Streams.Warning.DataAdded += OnWarning; }
/// <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); }