/// <summary> /// Create a new ClientMethodExecutor object and then dispatch it. /// </summary> internal static void Dispatch( BaseClientTransportManager transportManager, PSHost clientHost, PSDataCollectionStream <ErrorRecord> errorStream, ObjectStream methodExecutorStream, bool isMethodExecutorStreamEnabled, RemoteRunspacePoolInternal runspacePool, Guid clientPowerShellId, RemoteHostCall remoteHostCall) { ClientMethodExecutor methodExecutor = new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId, clientPowerShellId, remoteHostCall); // If the powershell id is not specified, this message is for the runspace pool, execute // it immediately and return if (clientPowerShellId == Guid.Empty) { methodExecutor.Execute(errorStream); return; } // Check client host to see if SetShouldExit should be allowed bool hostAllowSetShouldExit = false; if (clientHost != null) { PSObject hostPrivateData = clientHost.PrivateData as PSObject; if (hostPrivateData != null) { PSNoteProperty allowSetShouldExit = hostPrivateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty; hostAllowSetShouldExit = allowSetShouldExit != null && allowSetShouldExit.Value is bool && (bool)allowSetShouldExit.Value; } } // Should we kill remote runspace? Check if "SetShouldExit" and if we are in the // cmdlet case. In the API case (when we are invoked from an API not a cmdlet) we // should not interpret "SetShouldExit" but should pass it on to the host. The // variable IsMethodExecutorStreamEnabled is only true in the cmdlet case. In the // API case it is false. if (remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled && !hostAllowSetShouldExit) { runspacePool.Close(); return; } // Cmdlet case: queue up the executor in the pipeline stream. if (isMethodExecutorStreamEnabled) { Dbg.Assert(methodExecutorStream != null, "method executor stream can't be null when enabled"); methodExecutorStream.Write(methodExecutor); } // API case: execute it immediately. else { methodExecutor.Execute(errorStream); } }
/// <summary> /// Execute. /// </summary> internal void Execute(PSDataCollectionStream <ErrorRecord> errorStream) { Action <ErrorRecord> writeErrorAction = null; // If error-stream is null or we are in pushed-runspace - then write error directly to console. if (errorStream == null || IsRunspacePushed(_clientHost)) { writeErrorAction = delegate(ErrorRecord errorRecord) { try { if (_clientHost.UI != null) { _clientHost.UI.WriteErrorLine(errorRecord.ToString()); } } catch (Exception) { // Catch-all OK, 3rd party callout. } }; } // Otherwise write it to error-stream. else { writeErrorAction = delegate(ErrorRecord errorRecord) { errorStream.Write(errorRecord); }; } this.Execute(writeErrorAction); }
internal void Execute(PSDataCollectionStream<ErrorRecord> errorStream) { Action<ErrorRecord> action2 = null; Action<ErrorRecord> action3 = null; Action<ErrorRecord> writeErrorAction = null; if ((errorStream == null) || this.IsRunspacePushed(this._clientHost)) { if (action2 == null) { action2 = delegate (ErrorRecord errorRecord) { try { if (this._clientHost.UI != null) { this._clientHost.UI.WriteErrorLine(errorRecord.ToString()); } } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); } }; } writeErrorAction = action2; } else { if (action3 == null) { action3 = errorRecord => errorStream.Write(errorRecord); } writeErrorAction = action3; } this.Execute(writeErrorAction); }
/// <summary> /// Private constructor that does most of the work constructing a remote pipeline object. /// </summary> /// <param name="runspace">RemoteRunspace object.</param> /// <param name="addToHistory">AddToHistory.</param> /// <param name="isNested">IsNested.</param> private RemotePipeline(RemoteRunspace runspace, bool addToHistory, bool isNested) : base(runspace) { _addToHistory = addToHistory; _isNested = isNested; _isSteppable = false; _runspace = runspace; _computerName = ((RemoteRunspace)_runspace).ConnectionInfo.ComputerName; _runspaceId = _runspace.InstanceId; // Initialize streams _inputCollection = new PSDataCollection <object>(); _inputCollection.ReleaseOnEnumeration = true; _inputStream = new PSDataCollectionStream <object>(Guid.Empty, _inputCollection); _outputCollection = new PSDataCollection <PSObject>(); _outputStream = new PSDataCollectionStream <PSObject>(Guid.Empty, _outputCollection); _errorCollection = new PSDataCollection <ErrorRecord>(); _errorStream = new PSDataCollectionStream <ErrorRecord>(Guid.Empty, _errorCollection); // Create object stream for method executor objects. MethodExecutorStream = new ObjectStream(); IsMethodExecutorStreamEnabled = false; SetCommandCollection(_commands); // Create event which will be signalled when pipeline execution // is completed/failed/stoped. // Note:Runspace.Close waits for all the running pipeline // to finish. This Event must be created before pipeline is // added to list of running pipelines. This avoids the race condition // where Close is called after pipeline is added to list of // running pipeline but before event is created. PipelineFinishedEvent = new ManualResetEvent(false); }
/// <summary> /// Private constructor that does most of the work constructing a remote pipeline object. /// </summary> /// <param name="runspace">RemoteRunspace object</param> /// <param name="addToHistory">AddToHistory</param> /// <param name="isNested">IsNested</param> private RemotePipeline(RemoteRunspace runspace, bool addToHistory, bool isNested) : base(runspace) { _addToHistory = addToHistory; _isNested = isNested; _isSteppable = false; _runspace = runspace; _computerName = ((RemoteRunspace)_runspace).ConnectionInfo.ComputerName; _runspaceId = _runspace.InstanceId; //Initialize streams _inputCollection = new PSDataCollection<object>(); _inputCollection.ReleaseOnEnumeration = true; _inputStream = new PSDataCollectionStream<object>(Guid.Empty, _inputCollection); _outputCollection = new PSDataCollection<PSObject>(); _outputStream = new PSDataCollectionStream<PSObject>(Guid.Empty, _outputCollection); _errorCollection = new PSDataCollection<ErrorRecord>(); _errorStream = new PSDataCollectionStream<ErrorRecord>(Guid.Empty, _errorCollection); // Create object stream for method executor objects. MethodExecutorStream = new ObjectStream(); IsMethodExecutorStreamEnabled = false; SetCommandCollection(_commands); //Create event which will be signalled when pipeline execution //is completed/failed/stoped. //Note:Runspace.Close waits for all the running pipeline //to finish. This Event must be created before pipeline is //added to list of running pipelines. This avoids the race condition //where Close is called after pipeline is added to list of //running pipeline but before event is created. PipelineFinishedEvent = new ManualResetEvent(false); }
internal static void Dispatch(BaseClientTransportManager transportManager, PSHost clientHost, PSDataCollectionStream<ErrorRecord> errorStream, ObjectStream methodExecutorStream, bool isMethodExecutorStreamEnabled, RemoteRunspacePoolInternal runspacePool, Guid clientPowerShellId, System.Management.Automation.Remoting.RemoteHostCall remoteHostCall) { ClientMethodExecutor executor = new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId, clientPowerShellId, remoteHostCall); if (clientPowerShellId == Guid.Empty) { executor.Execute(errorStream); } else { bool flag = false; if (clientHost != null) { PSObject privateData = clientHost.PrivateData; if (privateData != null) { PSNoteProperty property = privateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty; flag = ((property != null) && (property.Value is bool)) ? ((bool) property.Value) : false; } } if ((remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled) && !flag) { runspacePool.Close(); } else if (isMethodExecutorStreamEnabled) { methodExecutorStream.Write(executor); } else { executor.Execute(errorStream); } } }
private RemotePipeline(RemoteRunspace runspace, bool addToHistory, bool isNested) : base(runspace) { this._syncRoot = new object(); this._pipelineStateInfo = new System.Management.Automation.Runspaces.PipelineStateInfo(PipelineState.NotStarted); this._commands = new CommandCollection(); this._executionEventQueue = new Queue <ExecutionEventQueueItem>(); this._performNestedCheck = true; this._addToHistory = addToHistory; this._isNested = isNested; this._isSteppable = false; this._runspace = runspace; this._computerName = ((RemoteRunspace)this._runspace).ConnectionInfo.ComputerName; this._runspaceId = this._runspace.InstanceId; this._inputCollection = new PSDataCollection <object>(); this._inputCollection.ReleaseOnEnumeration = true; this._inputStream = new PSDataCollectionStream <object>(Guid.Empty, this._inputCollection); this._outputCollection = new PSDataCollection <PSObject>(); this._outputStream = new PSDataCollectionStream <PSObject>(Guid.Empty, this._outputCollection); this._errorCollection = new PSDataCollection <ErrorRecord>(); this._errorStream = new PSDataCollectionStream <ErrorRecord>(Guid.Empty, this._errorCollection); this._methodExecutorStream = new ObjectStream(); this._isMethodExecutorStreamEnabled = false; base.SetCommandCollection(this._commands); this._pipelineFinishedEvent = new ManualResetEvent(false); }
internal void Execute(PSDataCollectionStream <ErrorRecord> errorStream) { Action <ErrorRecord> action2 = null; Action <ErrorRecord> action3 = null; Action <ErrorRecord> writeErrorAction = null; if ((errorStream == null) || this.IsRunspacePushed(this._clientHost)) { if (action2 == null) { action2 = delegate(ErrorRecord errorRecord) { try { if (this._clientHost.UI != null) { this._clientHost.UI.WriteErrorLine(errorRecord.ToString()); } } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); } }; } writeErrorAction = action2; } else { if (action3 == null) { action3 = errorRecord => errorStream.Write(errorRecord); } writeErrorAction = action3; } this.Execute(writeErrorAction); }
internal static void Dispatch(BaseClientTransportManager transportManager, PSHost clientHost, PSDataCollectionStream <ErrorRecord> errorStream, ObjectStream methodExecutorStream, bool isMethodExecutorStreamEnabled, RemoteRunspacePoolInternal runspacePool, Guid clientPowerShellId, System.Management.Automation.Remoting.RemoteHostCall remoteHostCall) { ClientMethodExecutor executor = new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId, clientPowerShellId, remoteHostCall); if (clientPowerShellId == Guid.Empty) { executor.Execute(errorStream); } else { bool flag = false; if (clientHost != null) { PSObject privateData = clientHost.PrivateData; if (privateData != null) { PSNoteProperty property = privateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty; flag = ((property != null) && (property.Value is bool)) ? ((bool)property.Value) : false; } } if ((remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled) && !flag) { runspacePool.Close(); } else if (isMethodExecutorStreamEnabled) { methodExecutorStream.Write(executor); } else { executor.Execute(errorStream); } } }
/// <summary> /// Create a new ClientMethodExecutor object and then dispatch it. /// </summary> internal static void Dispatch( BaseClientTransportManager transportManager, PSHost clientHost, PSDataCollectionStream<ErrorRecord> errorStream, ObjectStream methodExecutorStream, bool isMethodExecutorStreamEnabled, RemoteRunspacePoolInternal runspacePool, Guid clientPowerShellId, RemoteHostCall remoteHostCall) { ClientMethodExecutor methodExecutor = new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId, clientPowerShellId, remoteHostCall); // If the powershell id is not specified, this message is for the runspace pool, execute // it immediately and return if (clientPowerShellId == Guid.Empty) { methodExecutor.Execute(errorStream); return; } // Check client host to see if SetShouldExit should be allowed bool hostAllowSetShouldExit = false; if (clientHost != null) { PSObject hostPrivateData = clientHost.PrivateData as PSObject; if (hostPrivateData != null) { PSNoteProperty allowSetShouldExit = hostPrivateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty; hostAllowSetShouldExit = (allowSetShouldExit != null && allowSetShouldExit.Value is bool) ? (bool)allowSetShouldExit.Value : false; } } // Should we kill remote runspace? Check if "SetShouldExit" and if we are in the // cmdlet case. In the API case (when we are invoked from an API not a cmdlet) we // should not interpret "SetShouldExit" but should pass it on to the host. The // variable IsMethodExecutorStreamEnabled is only true in the cmdlet case. In the // API case it is false. if (remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled && !hostAllowSetShouldExit) { runspacePool.Close(); return; } // Cmdlet case: queue up the executor in the pipeline stream. if (isMethodExecutorStreamEnabled) { Dbg.Assert(!isMethodExecutorStreamEnabled || (isMethodExecutorStreamEnabled && methodExecutorStream != null), "method executor stream can't be null when enabled"); methodExecutorStream.Write(methodExecutor); } // API case: execute it immediately. else { methodExecutor.Execute(errorStream); } }
/// <summary> /// Execute. /// </summary> internal void Execute(PSDataCollectionStream<ErrorRecord> errorStream) { Action<ErrorRecord> writeErrorAction = null; // If error-stream is null or we are in pushed-runspace - then write error directly to console. if (errorStream == null || IsRunspacePushed(_clientHost)) { writeErrorAction = delegate (ErrorRecord errorRecord) { try { if (_clientHost.UI != null) { _clientHost.UI.WriteErrorLine(errorRecord.ToString()); } } catch (Exception e) { // Catch-all OK, 3rd party callout. CommandProcessorBase.CheckForSevereException(e); } }; } // Otherwise write it to error-stream. else { writeErrorAction = delegate (ErrorRecord errorRecord) { errorStream.Write(errorRecord); }; } this.Execute(writeErrorAction); }
private RemotePipeline(RemoteRunspace runspace, bool addToHistory, bool isNested) : base(runspace) { this._syncRoot = new object(); this._pipelineStateInfo = new System.Management.Automation.Runspaces.PipelineStateInfo(PipelineState.NotStarted); this._commands = new CommandCollection(); this._executionEventQueue = new Queue<ExecutionEventQueueItem>(); this._performNestedCheck = true; this._addToHistory = addToHistory; this._isNested = isNested; this._isSteppable = false; this._runspace = runspace; this._computerName = ((RemoteRunspace) this._runspace).ConnectionInfo.ComputerName; this._runspaceId = this._runspace.InstanceId; this._inputCollection = new PSDataCollection<object>(); this._inputCollection.ReleaseOnEnumeration = true; this._inputStream = new PSDataCollectionStream<object>(Guid.Empty, this._inputCollection); this._outputCollection = new PSDataCollection<PSObject>(); this._outputStream = new PSDataCollectionStream<PSObject>(Guid.Empty, this._outputCollection); this._errorCollection = new PSDataCollection<ErrorRecord>(); this._errorStream = new PSDataCollectionStream<ErrorRecord>(Guid.Empty, this._errorCollection); this._methodExecutorStream = new ObjectStream(); this._isMethodExecutorStreamEnabled = false; base.SetCommandCollection(this._commands); this._pipelineFinishedEvent = new ManualResetEvent(false); }
public PSDataCollectionWriter(PSDataCollectionStream <T> stream) : base((ObjectStreamBase)stream) { using (ObjectWriter._trace.TraceConstructor((object)this)) ; }