/// <summary> /// Initializes the underlying PowerShell object after verifying /// if the pipeline is in a state where it can be invoked. /// If invokeAndDisconnect is true then the remote PowerShell /// command will be immediately disconnected after it begins /// running. /// </summary> /// <param name="syncCall">true if called from a sync call</param> /// <param name="invokeAndDisconnect">Invoke and Disconnect</param> private void InitPowerShell(bool syncCall, bool invokeAndDisconnect = false) { if (_commands == null || _commands.Count == 0) { throw PSTraceSource.NewInvalidOperationException( RunspaceStrings.NoCommandInPipeline); } if (_pipelineStateInfo.State != PipelineState.NotStarted) { InvalidPipelineStateException e = new InvalidPipelineStateException ( StringUtil.Format(RunspaceStrings.PipelineReInvokeNotAllowed), _pipelineStateInfo.State, PipelineState.NotStarted ); throw e; } ((RemoteRunspace)_runspace).DoConcurrentCheckAndAddToRunningPipelines(this, syncCall); PSInvocationSettings settings = new PSInvocationSettings(); settings.AddToHistory = _addToHistory; settings.InvokeAndDisconnect = invokeAndDisconnect; _powershell.InitForRemotePipeline(_commands, _inputStream, _outputStream, _errorStream, settings, RedirectShellErrorOutputPipe); _powershell.RemotePowerShell.HostCallReceived += new EventHandler <RemoteDataEventArgs <RemoteHostCall> >(HandleHostCallReceived); }
private void InitPowerShell(bool syncCall) { if (this._commands == null || this._commands.Count == 0) { throw RemotePipeline._trace.NewInvalidOperationException("Runspace", "NoCommandInPipeline"); } if (this._pipelineStateInfo.State != PipelineState.NotStarted) { InvalidPipelineStateException pipelineStateException = new InvalidPipelineStateException(ResourceManagerCache.FormatResourceString("Runspace", "PipelineReInvokeNotAllowed"), this._pipelineStateInfo.State, PipelineState.NotStarted); RemotePipeline._trace.TraceException((Exception)pipelineStateException); throw pipelineStateException; } ((RemoteRunspace)this._runspace).DoConcurrentCheckAndAddToRunningPipelines(this, syncCall); this._powershell.InitForRemotePipeline(this._commands, (ObjectStreamBase)this._inputStream, (ObjectStreamBase)this._outputStream, (ObjectStreamBase)this._errorStream, new PSInvocationSettings() { AddToHistory = this._addToHistory }, this.RedirectShellErrorOutputPipe); this._powershell.RemotePowerShell.HostCallReceived += new EventHandler <RemoteDataEventArgs <RemoteHostCall> >(this.HandleHostCallReceived); }
private void InitPowerShell(bool syncCall, bool invokeAndDisconnect = false) { if ((this._commands == null) || (this._commands.Count == 0)) { throw PSTraceSource.NewInvalidOperationException("RunspaceStrings", "NoCommandInPipeline", new object[0]); } if (this._pipelineStateInfo.State != PipelineState.NotStarted) { InvalidPipelineStateException exception = new InvalidPipelineStateException(StringUtil.Format(RunspaceStrings.PipelineReInvokeNotAllowed, new object[0]), this._pipelineStateInfo.State, PipelineState.NotStarted); throw exception; } ((RemoteRunspace)this._runspace).DoConcurrentCheckAndAddToRunningPipelines(this, syncCall); PSInvocationSettings settings = new PSInvocationSettings { AddToHistory = this._addToHistory, InvokeAndDisconnect = invokeAndDisconnect }; this._powershell.InitForRemotePipeline(this._commands, this._inputStream, this._outputStream, this._errorStream, settings, base.RedirectShellErrorOutputPipe); this._powershell.RemotePowerShell.HostCallReceived += new EventHandler <RemoteDataEventArgs <RemoteHostCall> >(this.HandleHostCallReceived); }