/// <summary> /// Constructor. /// </summary> /// <param name="driverInvoker"></param> /// <param name="runspace"></param> /// <param name="debugger"></param> internal ServerRemoteDebugger( IRSPDriverInvoke driverInvoker, Runspace runspace, Debugger debugger) { if (driverInvoker == null) { throw new PSArgumentNullException("driverInvoker"); } if (runspace == null) { throw new PSArgumentNullException("runspace"); } if (debugger == null) { throw new PSArgumentNullException("debugger"); } _driverInvoker = driverInvoker; _runspace = runspace; _wrappedDebugger = new ObjectRef<Debugger>(debugger); SetDebuggerCallbacks(); _runspace.Name = "RemoteHost"; _runspace.InternalDebugger = this; }
/// <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) #endif { InstanceId = clientPowerShellId; RunspacePoolId = clientRunspacePoolId; RemoteStreamOptions = streamOptions; #if !CORECLR // No ApartmentState In CoreCLR this.apartmentState = apartmentState; #endif 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); } } }; } }
/// <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) #endif { InstanceId = clientPowerShellId; RunspacePoolId = clientRunspacePoolId; RemoteStreamOptions = streamOptions; #if !CORECLR // No ApartmentState In CoreCLR this.apartmentState = apartmentState; #endif 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 (null != rsToUse) { 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); } } }; } }