/// <summary> /// Execute void method. /// </summary> internal void ExecuteVoidMethod(PSHost clientHost) { // The clientHost can be null if the user creates a runspace object without providing // a host parameter. if (clientHost == null) { return; } RemoteRunspace remoteRunspaceToClose = null; if (this.IsSetShouldExitOrPopRunspace) { remoteRunspaceToClose = GetRemoteRunspaceToClose(clientHost); } try { object targetObject = this.SelectTargetObject(clientHost); MyMethodBase.Invoke(targetObject, Parameters); } finally { if (remoteRunspaceToClose != null) { remoteRunspaceToClose.Close(); } } }
internal void ExecuteVoidMethod(PSHost clientHost) { RemoteRunspace remoteRunspace = (RemoteRunspace)null; if (this.IsSetShouldExitOrPopRunspace) { remoteRunspace = this.GetRemoteRunspaceToClose(clientHost); } try { this.MyMethodBase.Invoke(this.SelectTargetObject(clientHost), this._parameters); } finally { remoteRunspace?.Close(); } }
/// <summary> /// Pop runspace /// </summary> public override void PopRunspace() { if (_pushedRunspace != null) { if (_debugger != null) { _debugger.PopDebugger(); } if (_hostSupportsPSEdit) { RemovePSEditFromRunspace(_pushedRunspace); } if (_pushedRunspace.ShouldCloseOnPop) { _pushedRunspace.Close(); } _pushedRunspace = null; } }
internal void ExecuteVoidMethod(PSHost clientHost) { if (clientHost != null) { RemoteRunspace remoteRunspaceToClose = null; if (this.IsSetShouldExitOrPopRunspace) { remoteRunspaceToClose = this.GetRemoteRunspaceToClose(clientHost); } try { object obj2 = this.SelectTargetObject(clientHost); this.MyMethodBase.Invoke(obj2, this._parameters); } finally { if (remoteRunspaceToClose != null) { remoteRunspaceToClose.Close(); } } } }
protected override void ProcessRecord() { IHostSupportsInteractiveSession session = base.Host as IHostSupportsInteractiveSession; if (session == null) { base.WriteError(new ErrorRecord(new ArgumentException(base.GetMessage(RemotingErrorIdStrings.HostDoesNotSupportPushRunspace)), PSRemotingErrorId.HostDoesNotSupportPushRunspace.ToString(), ErrorCategory.InvalidArgument, null)); } /* * else if (((base.Context != null) && (base.Context.EngineHostInterface != null)) && ((base.Context.EngineHostInterface.ExternalHost != null) && (base.Context.EngineHostInterface.ExternalHost is ServerRemoteHost))) * { * base.WriteError(new ErrorRecord(new ArgumentException(base.GetMessage(RemotingErrorIdStrings.RemoteHostDoesNotSupportPushRunspace)), PSRemotingErrorId.RemoteHostDoesNotSupportPushRunspace.ToString(), ErrorCategory.InvalidArgument, null)); * } */ else { InternalHost targetObject = base.Host as InternalHost; if ((targetObject != null) && targetObject.HostInNestedPrompt()) { base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.HostInNestedPrompt, new object[0])), "HostInNestedPrompt", ErrorCategory.InvalidOperation, targetObject)); } RemoteRunspace runspaceMatchingRunspaceId = null; string parameterSetName = base.ParameterSetName; if (parameterSetName != null) { if (!(parameterSetName == "ComputerName")) { if (parameterSetName == "Uri") { runspaceMatchingRunspaceId = this.CreateRunspaceWhenUriParameterSpecified(); } else if (parameterSetName == "Session") { runspaceMatchingRunspaceId = (RemoteRunspace)this.remoteRunspaceInfo.Runspace; } else if (parameterSetName == "InstanceId") { runspaceMatchingRunspaceId = this.GetRunspaceMatchingRunspaceId(this.InstanceId); } else if (parameterSetName == "Id") { runspaceMatchingRunspaceId = this.GetRunspaceMatchingSessionId(this.Id); } else if (parameterSetName == "Name") { runspaceMatchingRunspaceId = this.GetRunspaceMatchingName(this.Name); } } else { runspaceMatchingRunspaceId = this.CreateRunspaceWhenComputerNameParameterSpecified(); } } if (runspaceMatchingRunspaceId != null) { if (runspaceMatchingRunspaceId.RunspaceStateInfo.State == RunspaceState.Disconnected) { if (!runspaceMatchingRunspaceId.CanConnect) { string message = StringUtil.Format(RemotingErrorIdStrings.SessionNotAvailableForConnection, new object[0]); base.WriteError(new ErrorRecord(new RuntimeException(message), "EnterPSSessionCannotConnectDisconnectedSession", ErrorCategory.InvalidOperation, runspaceMatchingRunspaceId)); return; } Exception innerException = null; try { runspaceMatchingRunspaceId.Connect(); } catch (PSRemotingTransportException exception2) { innerException = exception2; } catch (PSInvalidOperationException exception3) { innerException = exception3; } catch (InvalidRunspacePoolStateException exception4) { innerException = exception4; } if (innerException != null) { string str2 = StringUtil.Format(RemotingErrorIdStrings.SessionConnectFailed, new object[0]); base.WriteError(new ErrorRecord(new RuntimeException(str2, innerException), "EnterPSSessionConnectSessionFailed", ErrorCategory.InvalidOperation, runspaceMatchingRunspaceId)); return; } if (runspaceMatchingRunspaceId.RunspaceAvailability == RunspaceAvailability.Busy) { string str3 = StringUtil.Format(RemotingErrorIdStrings.EnterPSSessionDisconnected, runspaceMatchingRunspaceId.Name); base.WriteError(new ErrorRecord(new RuntimeException(str3, innerException), "EnterPSSessionConnectSessionNotAvailable", ErrorCategory.InvalidOperation, this.remoteRunspaceInfo)); runspaceMatchingRunspaceId.DisconnectAsync(); return; } } if (runspaceMatchingRunspaceId.RunspaceStateInfo.State != RunspaceState.Opened) { if (base.ParameterSetName == "Session") { string str4 = (this.remoteRunspaceInfo != null) ? this.remoteRunspaceInfo.Name : string.Empty; base.WriteError(new ErrorRecord(new ArgumentException(base.GetMessage(RemotingErrorIdStrings.EnterPSSessionBrokenSession, new object[] { str4, runspaceMatchingRunspaceId.ConnectionInfo.ComputerName, runspaceMatchingRunspaceId.InstanceId })), PSRemotingErrorId.PushedRunspaceMustBeOpen.ToString(), ErrorCategory.InvalidArgument, null)); } else { base.WriteError(new ErrorRecord(new ArgumentException(base.GetMessage(RemotingErrorIdStrings.PushedRunspaceMustBeOpen)), PSRemotingErrorId.PushedRunspaceMustBeOpen.ToString(), ErrorCategory.InvalidArgument, null)); } } else { if (runspaceMatchingRunspaceId.RunspaceAvailability != RunspaceAvailability.Available) { base.WriteWarning(base.GetMessage(RunspaceStrings.RunspaceNotReady)); } try { session.PushRunspace(runspaceMatchingRunspaceId); } catch (Exception) { if ((runspaceMatchingRunspaceId != null) && runspaceMatchingRunspaceId.ShouldCloseOnPop) { runspaceMatchingRunspaceId.Close(); } throw; } } } } }