private static IEnumerable <PSObject> InvokeTopLevelPowerShell( PowerShell powerShell, CancellationToken cancellationToken, PSCmdlet cmdlet, PSInvocationSettings invocationSettings, string errorMessageTemplate) { using (var mergedOutput = new BlockingCollection <Func <PSCmdlet, IEnumerable <PSObject> > >(s_blockingCollectionCapacity)) { var asyncOutput = new PSDataCollection <PSObject>(); EventHandler <DataAddedEventArgs> outputHandler = GetStreamForwarder <PSObject>( output => mergedOutput.Add(_ => new[] { output }), swallowInvalidOperationExceptions: true); EventHandler <DataAddedEventArgs> errorHandler = GetStreamForwarder <ErrorRecord>( errorRecord => mergedOutput.Add( delegate(PSCmdlet c) { errorRecord = GetErrorRecordForRemotePipelineInvocation(errorRecord, errorMessageTemplate); HandleErrorFromPipeline(c, errorRecord, powerShell); return(Enumerable.Empty <PSObject>()); }), swallowInvalidOperationExceptions: true); EventHandler <DataAddedEventArgs> warningHandler = GetStreamForwarder <WarningRecord>( warningRecord => mergedOutput.Add( delegate(PSCmdlet c) { c.WriteWarning(warningRecord.Message); return(Enumerable.Empty <PSObject>()); }), swallowInvalidOperationExceptions: true); EventHandler <DataAddedEventArgs> verboseHandler = GetStreamForwarder <VerboseRecord>( verboseRecord => mergedOutput.Add( delegate(PSCmdlet c) { c.WriteVerbose(verboseRecord.Message); return(Enumerable.Empty <PSObject>()); }), swallowInvalidOperationExceptions: true); EventHandler <DataAddedEventArgs> debugHandler = GetStreamForwarder <DebugRecord>( debugRecord => mergedOutput.Add( delegate(PSCmdlet c) { c.WriteDebug(debugRecord.Message); return(Enumerable.Empty <PSObject>()); }), swallowInvalidOperationExceptions: true); EventHandler <DataAddedEventArgs> informationHandler = GetStreamForwarder <InformationRecord>( informationRecord => mergedOutput.Add( delegate(PSCmdlet c) { c.WriteInformation(informationRecord); return(Enumerable.Empty <PSObject>()); }), swallowInvalidOperationExceptions: true); asyncOutput.DataAdded += outputHandler; powerShell.Streams.Error.DataAdded += errorHandler; powerShell.Streams.Warning.DataAdded += warningHandler; powerShell.Streams.Verbose.DataAdded += verboseHandler; powerShell.Streams.Debug.DataAdded += debugHandler; powerShell.Streams.Information.DataAdded += informationHandler; try { // TODO/FIXME: ETW event for PowerShell invocation var asyncResult = powerShell.BeginInvoke <PSObject, PSObject>( input: null, output: asyncOutput, settings: invocationSettings, callback: delegate { try { mergedOutput.CompleteAdding(); } catch (InvalidOperationException) // ignore exceptions thrown because mergedOutput.CompleteAdding was called { } }, state: null); using (cancellationToken.Register(powerShell.Stop)) { try { foreach (Func <PSCmdlet, IEnumerable <PSObject> > mergedOutputItem in mergedOutput.GetConsumingEnumerable()) { foreach (PSObject outputObject in mergedOutputItem(cmdlet)) { yield return(outputObject); } } } finally { mergedOutput.CompleteAdding(); powerShell.EndInvoke(asyncResult); } } } finally { asyncOutput.DataAdded -= outputHandler; powerShell.Streams.Error.DataAdded -= errorHandler; powerShell.Streams.Warning.DataAdded -= warningHandler; powerShell.Streams.Verbose.DataAdded -= verboseHandler; powerShell.Streams.Debug.DataAdded -= debugHandler; powerShell.Streams.Information.DataAdded -= informationHandler; } } }
private static IEnumerable <PSObject> InvokeTopLevelPowerShell(PowerShell powerShell, CancellationToken cancellationToken, PSCmdlet cmdlet, PSInvocationSettings invocationSettings, string errorMessageTemplate) { Action <PSObject> action = null; Action <ErrorRecord> action1 = null; Action <WarningRecord> action2 = null; Action <VerboseRecord> action3 = null; Action <DebugRecord> action4 = null; AsyncCallback asyncCallback = null; using (BlockingCollection <Func <PSCmdlet, IEnumerable <PSObject> > > funcs = new BlockingCollection <Func <PSCmdlet, IEnumerable <PSObject> > >(RemoteDiscoveryHelper.BlockingCollectionCapacity)) { PSDataCollection <PSObject> pSObjects = new PSDataCollection <PSObject>(); if (action == null) { action = (PSObject output) => funcs.Add((PSCmdlet argument0) => { PSObject[] pSObjectArray = new PSObject[1]; pSObjectArray[0] = output; return(pSObjectArray); } ); } EventHandler <DataAddedEventArgs> streamForwarder = RemoteDiscoveryHelper.GetStreamForwarder <PSObject>(action, true); if (action1 == null) { action1 = (ErrorRecord errorRecord) => funcs.Add((PSCmdlet c) => { errorRecord = RemoteDiscoveryHelper.GetErrorRecordForRemotePipelineInvocation(errorRecord, errorMessageTemplate); RemoteDiscoveryHelper.HandleErrorFromPipeline(c, errorRecord, powerShell); return(Enumerable.Empty <PSObject>()); } ); } EventHandler <DataAddedEventArgs> eventHandler = RemoteDiscoveryHelper.GetStreamForwarder <ErrorRecord>(action1, true); if (action2 == null) { action2 = (WarningRecord warningRecord) => funcs.Add((PSCmdlet c) => { c.WriteWarning(warningRecord.Message); return(Enumerable.Empty <PSObject>()); } ); } EventHandler <DataAddedEventArgs> streamForwarder1 = RemoteDiscoveryHelper.GetStreamForwarder <WarningRecord>(action2, true); if (action3 == null) { action3 = (VerboseRecord verboseRecord) => funcs.Add((PSCmdlet c) => { c.WriteVerbose(verboseRecord.Message); return(Enumerable.Empty <PSObject>()); } ); } EventHandler <DataAddedEventArgs> eventHandler1 = RemoteDiscoveryHelper.GetStreamForwarder <VerboseRecord>(action3, true); if (action4 == null) { action4 = (DebugRecord debugRecord) => funcs.Add((PSCmdlet c) => { c.WriteDebug(debugRecord.Message); return(Enumerable.Empty <PSObject>()); } ); } EventHandler <DataAddedEventArgs> streamForwarder2 = RemoteDiscoveryHelper.GetStreamForwarder <DebugRecord>(action4, true); pSObjects.DataAdded += streamForwarder; powerShell.Streams.Error.DataAdded += eventHandler; powerShell.Streams.Warning.DataAdded += streamForwarder1; powerShell.Streams.Verbose.DataAdded += eventHandler1; powerShell.Streams.Debug.DataAdded += streamForwarder2; try { PowerShell powerShell1 = powerShell; object obj = null; PSDataCollection <PSObject> pSObjects1 = pSObjects; PSInvocationSettings pSInvocationSetting = invocationSettings; if (asyncCallback == null) { asyncCallback = (IAsyncResult param0) => { try { funcs.CompleteAdding(); } catch (InvalidOperationException invalidOperationException) { } } ; } IAsyncResult asyncResult = powerShell1.BeginInvoke <PSObject, PSObject>((PSDataCollection <PSObject>)obj, pSObjects1, pSInvocationSetting, asyncCallback, null); CancellationTokenRegistration cancellationTokenRegistration = cancellationToken.Register(new Action(powerShell.Stop)); try { try { foreach (Func <PSCmdlet, IEnumerable <PSObject> > func in funcs) { IEnumerator <PSObject> enumerator = func(cmdlet).GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { yield return(enumerator.Current); } } } } finally { funcs.CompleteAdding(); powerShell.EndInvoke(asyncResult); } } finally { cancellationTokenRegistration.Dispose(); } } finally { pSObjects.DataAdded -= streamForwarder; powerShell.Streams.Error.DataAdded -= eventHandler; powerShell.Streams.Warning.DataAdded -= streamForwarder1; powerShell.Streams.Verbose.DataAdded -= eventHandler1; powerShell.Streams.Debug.DataAdded -= streamForwarder2; } } }
internal BatchInvocationContext(PSCommand command, PSDataCollection <PSObject> output) { this.command = command; this.output = output; this.completionEvent = new AutoResetEvent(false); }
/// <summary> /// Default constructor for creating ServerPowerShellDrivers /// </summary> /// <param name="powershell">decoded powershell object</param> /// <param name="extraPowerShell">extra pipeline to be run after <paramref name="powershell"/> completes</param> /// <param name="noInput">whether there is input for this powershell</param> /// <param name="clientPowerShellId">the client powershell id</param> /// <param name="clientRunspacePoolId">the client runspacepool id</param> /// <param name="runspacePoolDriver">runspace pool driver /// which is creating this powershell driver</param> /// <param name="hostInfo">host info using which the host for /// this powershell will be constructed</param> /// <param name="streamOptions">serialization options for the streams in this powershell</param> /// <param name="addToHistory"> /// true if the command is to be added to history list of the runspace. false, otherwise. /// </param> /// <param name="rsToUse"> /// If not null, this Runspace will be used to invoke Powershell. /// If null, the RunspacePool pointed by <paramref name="runspacePoolDriver"/> will be used. /// </param> /// <param name="output"> /// If not null, this is used as another source of output sent to the client. /// </param> internal ServerPowerShellDriver(PowerShell powershell, PowerShell extraPowerShell, bool noInput, Guid clientPowerShellId, Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, HostInfo hostInfo, RemoteStreamOptions streamOptions, bool addToHistory, Runspace rsToUse, PSDataCollection <PSObject> output)
internal PowerShellAsyncResult(Guid ownerId, AsyncCallback callback, object state, PSDataCollection <PSObject> output, bool isCalledFromBeginInvoke) : base(ownerId, callback, state) { this.isAssociatedWithAsyncInvoke = isCalledFromBeginInvoke; this.output = output; }
void IList.Remove(object value) { PSDataCollection <T> .VerifyValueType(value); this.Remove((T)value); }
bool IList.Contains(object value) { PSDataCollection <T> .VerifyValueType(value); return(this.Contains((T)value)); }
/// <summary> /// Default constructor for creating ServerPowerShellDrivers. /// </summary> /// <param name="powershell">Decoded powershell object.</param> /// <param name="extraPowerShell">Extra pipeline to be run after <paramref name="powershell"/> completes.</param> /// <param name="noInput">Whether there is input for this powershell.</param> /// <param name="clientPowerShellId">The client powershell id.</param> /// <param name="clientRunspacePoolId">The client runspacepool id.</param> /// <param name="runspacePoolDriver">runspace pool driver /// which is creating this powershell driver</param> /// <param name="apartmentState">Apartment state for this powershell.</param> /// <param name="hostInfo">host info using which the host for /// this powershell will be constructed</param> /// <param name="streamOptions">Serialization options for the streams in this powershell.</param> /// <param name="addToHistory"> /// true if the command is to be added to history list of the runspace. false, otherwise. /// </param> /// <param name="rsToUse"> /// If not null, this Runspace will be used to invoke Powershell. /// If null, the RunspacePool pointed by <paramref name="runspacePoolDriver"/> will be used. /// </param> /// <param name="output"> /// If not null, this is used as another source of output sent to the client. /// </param> internal ServerPowerShellDriver(PowerShell powershell, PowerShell extraPowerShell, bool noInput, Guid clientPowerShellId, Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, ApartmentState apartmentState, HostInfo hostInfo, RemoteStreamOptions streamOptions, bool addToHistory, Runspace rsToUse, PSDataCollection <PSObject> output) { InstanceId = clientPowerShellId; RunspacePoolId = clientRunspacePoolId; RemoteStreamOptions = streamOptions; this.apartmentState = apartmentState; LocalPowerShell = powershell; _extraPowerShell = extraPowerShell; _localPowerShellOutput = new PSDataCollection <PSObject>(); _noInput = noInput; _addToHistory = addToHistory; _psDriverInvoker = runspacePoolDriver; DataStructureHandler = runspacePoolDriver.DataStructureHandler.CreatePowerShellDataStructureHandler(clientPowerShellId, clientRunspacePoolId, RemoteStreamOptions, LocalPowerShell); _remoteHost = DataStructureHandler.GetHostAssociatedWithPowerShell(hostInfo, runspacePoolDriver.ServerRemoteHost); if (!noInput) { InputCollection = new PSDataCollection <object>(); InputCollection.ReleaseOnEnumeration = true; InputCollection.IdleEvent += new EventHandler <EventArgs>(HandleIdleEvent); } RegisterPipelineOutputEventHandlers(_localPowerShellOutput); if (LocalPowerShell != null) { RegisterPowerShellEventHandlers(LocalPowerShell); _datasent[0] = false; } if (extraPowerShell != null) { RegisterPowerShellEventHandlers(extraPowerShell); _datasent[1] = false; } RegisterDataStructureHandlerEventHandlers(DataStructureHandler); // set the runspace pool and invoke this powershell if (rsToUse != null) { LocalPowerShell.Runspace = rsToUse; if (extraPowerShell != null) { extraPowerShell.Runspace = rsToUse; } } else { LocalPowerShell.RunspacePool = runspacePoolDriver.RunspacePool; if (extraPowerShell != null) { extraPowerShell.RunspacePool = runspacePoolDriver.RunspacePool; } } if (output != null) { output.DataAdded += (sender, args) => { if (_localPowerShellOutput.IsOpen) { var items = output.ReadAll(); foreach (var item in items) { _localPowerShellOutput.Add(item); } } }; } }
private void UnregisterPipelineOutputEventHandlers(PSDataCollection <PSObject> pipelineOutput) { pipelineOutput.DataAdded -= new EventHandler <DataAddedEventArgs>(this.HandleOutputDataAdded); }
internal ServerSteppablePipelineDriver(PowerShell powershell, bool noInput, Guid clientPowerShellId, Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, ApartmentState apartmentState, HostInfo hostInfo, System.Management.Automation.RemoteStreamOptions streamOptions, bool addToHistory, Runspace rsToUse, ServerSteppablePipelineSubscriber eventSubscriber, PSDataCollection <object> powershellInput) { this.localPowerShell = powershell; this.clientPowerShellId = clientPowerShellId; this.clientRunspacePoolId = clientRunspacePoolId; this.remoteStreamOptions = streamOptions; this.apartmentState = apartmentState; this.noInput = noInput; this.addToHistory = addToHistory; this.eventSubscriber = eventSubscriber; this.powershellInput = powershellInput; this.input = new PSDataCollection <object>(); this.inputEnumerator = this.input.GetEnumerator(); this.input.ReleaseOnEnumeration = true; this.dsHandler = runspacePoolDriver.DataStructureHandler.CreatePowerShellDataStructureHandler(clientPowerShellId, clientRunspacePoolId, this.remoteStreamOptions, null); this.remoteHost = this.dsHandler.GetHostAssociatedWithPowerShell(hostInfo, runspacePoolDriver.ServerRemoteHost); this.dsHandler.InputEndReceived += new EventHandler(this.HandleInputEndReceived); this.dsHandler.InputReceived += new EventHandler <RemoteDataEventArgs <object> >(this.HandleInputReceived); this.dsHandler.StopPowerShellReceived += new EventHandler(this.HandleStopReceived); this.dsHandler.HostResponseReceived += new EventHandler <RemoteDataEventArgs <RemoteHostResponse> >(this.HandleHostResponseReceived); this.dsHandler.OnSessionConnected += new EventHandler(this.HandleSessionConnected); if (rsToUse == null) { throw PSTraceSource.NewInvalidOperationException("RemotingErrorIdStrings", "NestedPipelineMissingRunspace", new object[0]); } this.localPowerShell.Runspace = rsToUse; eventSubscriber.SubscribeEvents(this); this.stateOfSteppablePipeline = PSInvocationState.NotStarted; }
public IAsyncResult BeginInvoke<TInput, TOutput>(PSDataCollection<TInput> input, PSDataCollection<TOutput> output, PSInvocationSettings settings, AsyncCallback callback, object state) { throw new NotImplementedException(); }
public IAsyncResult BeginInvoke<TInput, TOutput>(PSDataCollection<TInput> input, PSDataCollection<TOutput> output) { throw new NotImplementedException(); }
public IAsyncResult BeginInvoke<T>(PSDataCollection<T> input) { throw new NotImplementedException(); }
private PSDataCollection <object> _powershellInput; // input collection of the PowerShell pipeline #endregion #if CORECLR // No ApartmentState In CoreCLR /// <summary> /// Default constructor for creating ServerSteppablePipelineDriver...Used by server to concurrently /// run 2 pipelines. /// </summary> /// <param name="powershell">decoded powershell object.</param> /// <param name="noInput">whether there is input for this powershell.</param> /// <param name="clientPowerShellId">the client powershell id.</param> /// <param name="clientRunspacePoolId">the client runspacepool id.</param> /// <param name="runspacePoolDriver">runspace pool driver /// which is creating this powershell driver</param> /// <param name="hostInfo">host info using which the host for /// this powershell will be constructed</param> /// <param name="streamOptions">serialization options for the streams in this powershell.</param> /// <param name="addToHistory"> /// true if the command is to be added to history list of the runspace. false, otherwise. /// </param> /// <param name="rsToUse"> /// If not null, this Runspace will be used to invoke Powershell. /// If null, the RunspacePool pointed by <paramref name="runspacePoolDriver"/> will be used. /// </param> /// <param name="eventSubscriber"> /// Steppable pipeline event subscriber /// </param> /// <param name="powershellInput">input collection of the PowerShell pipeline.</param> internal ServerSteppablePipelineDriver(PowerShell powershell, bool noInput, Guid clientPowerShellId, Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, HostInfo hostInfo, RemoteStreamOptions streamOptions, bool addToHistory, Runspace rsToUse, ServerSteppablePipelineSubscriber eventSubscriber, PSDataCollection <object> powershellInput)
int IList.IndexOf(object value) { PSDataCollection <T> .VerifyValueType(value); return(this.IndexOf((T)value)); }
/// <summary> /// Default constructor for creating ServerSteppablePipelineDriver...Used by server to concurrently /// run 2 pipelines. /// </summary> /// <param name="powershell">decoded powershell object.</param> /// <param name="noInput">whether there is input for this powershell.</param> /// <param name="clientPowerShellId">the client powershell id.</param> /// <param name="clientRunspacePoolId">the client runspacepool id.</param> /// <param name="runspacePoolDriver">runspace pool driver /// which is creating this powershell driver</param> /// <param name="apartmentState">apartment state for this powershell.</param> /// <param name="hostInfo">host info using which the host for /// this powershell will be constructed</param> /// <param name="streamOptions">serialization options for the streams in this powershell.</param> /// <param name="addToHistory"> /// true if the command is to be added to history list of the runspace. false, otherwise. /// </param> /// <param name="rsToUse"> /// If not null, this Runspace will be used to invoke Powershell. /// If null, the RunspacePool pointed by <paramref name="runspacePoolDriver"/> will be used. /// </param> /// <param name="eventSubscriber"> /// Steppable pipeline event subscriber /// </param> /// <param name="powershellInput">input collection of the PowerShell pipeline.</param> internal ServerSteppablePipelineDriver(PowerShell powershell, bool noInput, Guid clientPowerShellId, Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, ApartmentState apartmentState, HostInfo hostInfo, RemoteStreamOptions streamOptions, bool addToHistory, Runspace rsToUse, ServerSteppablePipelineSubscriber eventSubscriber, PSDataCollection <object> powershellInput) #endif { LocalPowerShell = powershell; InstanceId = clientPowerShellId; RunspacePoolId = clientRunspacePoolId; RemoteStreamOptions = streamOptions; #if !CORECLR // No ApartmentState In CoreCLR this.apartmentState = apartmentState; #endif NoInput = noInput; _addToHistory = addToHistory; _eventSubscriber = eventSubscriber; _powershellInput = powershellInput; Input = new PSDataCollection <object>(); InputEnumerator = Input.GetEnumerator(); Input.ReleaseOnEnumeration = true; DataStructureHandler = runspacePoolDriver.DataStructureHandler.CreatePowerShellDataStructureHandler(clientPowerShellId, clientRunspacePoolId, RemoteStreamOptions, null); RemoteHost = DataStructureHandler.GetHostAssociatedWithPowerShell(hostInfo, runspacePoolDriver.ServerRemoteHost); // subscribe to various data structure handler events DataStructureHandler.InputEndReceived += new EventHandler(HandleInputEndReceived); DataStructureHandler.InputReceived += new EventHandler <RemoteDataEventArgs <object> >(HandleInputReceived); DataStructureHandler.StopPowerShellReceived += new EventHandler(HandleStopReceived); DataStructureHandler.HostResponseReceived += new EventHandler <RemoteDataEventArgs <RemoteHostResponse> >(HandleHostResponseReceived); DataStructureHandler.OnSessionConnected += new EventHandler(HandleSessionConnected); if (rsToUse == null) { throw PSTraceSource.NewInvalidOperationException(RemotingErrorIdStrings.NestedPipelineMissingRunspace); } // else, set the runspace pool and invoke this powershell LocalPowerShell.Runspace = rsToUse; eventSubscriber.SubscribeEvents(this); PipelineState = PSInvocationState.NotStarted; }
void IList.Insert(int index, object value) { PSDataCollection <T> .VerifyValueType(value); this.Insert(index, (T)value); }
private void UnregisterPipelineOutputEventHandlers(PSDataCollection <PSObject> pipelineOutput) { pipelineOutput.DataAdded -= HandleOutputDataAdded; }
internal ServerPowerShellDriver( PowerShell powershell, PowerShell extraPowerShell, bool noInput, Guid clientPowerShellId, Guid clientRunspacePoolId, ServerRunspacePoolDriver runspacePoolDriver, ApartmentState apartmentState, HostInfo hostInfo, RemoteStreamOptions streamOptions, bool addToHistory, Runspace rsToUse) { this.clientPowerShellId = clientPowerShellId; this.clientRunspacePoolId = clientRunspacePoolId; this.remoteStreamOptions = streamOptions; this.apartmentState = apartmentState; this.localPowerShell = powershell; this.extraPowerShell = extraPowerShell; this.localPowerShellOutput = new PSDataCollection <PSObject>(); this.noInput = noInput; this.addToHistory = addToHistory; if (!noInput) { this.input = new PSDataCollection <object>(); this.input.ReleaseOnEnumeration = true; } this.dsHandler = runspacePoolDriver.DataStructureHandler.CreatePowerShellDataStructureHandler(this); this.remoteHost = this.dsHandler.GetHostAssociatedWithPowerShell(hostInfo, runspacePoolDriver.ServerRemoteHost); this.localPowerShellOutput.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleOutputDataAdded); if (this.localPowerShell != null) { this.localPowerShell.InvocationStateChanged += new EventHandler <PSInvocationStateChangedEventArgs>(this.HandlePowerShellInvocationStateChanged); this.localPowerShell.Streams.Error.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleErrorDataAdded); this.localPowerShell.Streams.Debug.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleDebugAdded); this.localPowerShell.Streams.Verbose.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleVerboseAdded); this.localPowerShell.Streams.Warning.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleWarningAdded); this.localPowerShell.Streams.Progress.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleProgressAdded); } if (extraPowerShell != null) { extraPowerShell.InvocationStateChanged += new EventHandler <PSInvocationStateChangedEventArgs>(this.HandlePowerShellInvocationStateChanged); extraPowerShell.Streams.Error.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleErrorDataAdded); extraPowerShell.Streams.Debug.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleDebugAdded); extraPowerShell.Streams.Verbose.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleVerboseAdded); extraPowerShell.Streams.Warning.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleWarningAdded); extraPowerShell.Streams.Progress.DataAdded += new EventHandler <DataAddedEventArgs>(this.HandleProgressAdded); } this.dsHandler.InputEndReceived += new EventHandler(this.HandleInputEndReceived); this.dsHandler.InputReceived += new EventHandler <RemoteDataEventArgs <object> >(this.HandleInputReceived); this.dsHandler.StopPowerShellReceived += new EventHandler(this.HandleStopReceived); this.dsHandler.HostResponseReceived += new EventHandler <RemoteDataEventArgs <RemoteHostResponse> >(this.HandleHostResponseReceived); if (rsToUse != null) { this.localPowerShell.Runspace = rsToUse; if (extraPowerShell == null) { return; } extraPowerShell.Runspace = rsToUse; } else { this.localPowerShell.RunspacePool = runspacePoolDriver.RunspacePool; if (extraPowerShell == null) { return; } extraPowerShell.RunspacePool = runspacePoolDriver.RunspacePool; } }