private void HandleRobustConnectionNotification(object sender, ConnectionStatusEventArgs e) { RemoteSessionStateMachineEventArgs eventArgument = null; switch (e.Notification) { case ConnectionStatus.AutoDisconnectStarting: eventArgument = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.RCDisconnectStarted); break; case ConnectionStatus.AutoDisconnectSucceeded: eventArgument = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.DisconnectCompleted, new RuntimeException( StringUtil.Format(RemotingErrorIdStrings.RCAutoDisconnectingError, _session.RemoteRunspacePoolInternal.ConnectionInfo.ComputerName))); break; case ConnectionStatus.InternalErrorAbort: eventArgument = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError); break; } if (eventArgument != null) { StateMachine.RaiseEvent(eventArgument); } }
private void HandleRobustConnectionNotification(object sender, ConnectionStatusEventArgs e) { RemoteSessionStateMachineEventArgs arg = null; switch (e.Notification) { case ConnectionStatus.AutoDisconnectStarting: arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.RCDisconnectStarted); break; case ConnectionStatus.AutoDisconnectSucceeded: arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.DisconnectCompleted, new RuntimeException(StringUtil.Format(RemotingErrorIdStrings.RCAutoDisconnectingError, this._session.RemoteRunspacePoolInternal.ConnectionInfo.ComputerName))); break; case ConnectionStatus.InternalErrorAbort: arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError); break; } if (arg != null) { this.StateMachine.RaiseEvent(arg, false); } }
/// <summary> /// Handles a robust connection layer notification from the transport /// manager. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HandleRobustConnectionNotification( object sender, ConnectionStatusEventArgs e) { // Create event arguments and warnings/errors for this robust connection notification. PSConnectionRetryStatusEventArgs connectionRetryStatusArgs = null; WarningRecord warningRecord = null; ErrorRecord errorRecord = null; int maxRetryConnectionTimeMSecs = this.runspacePool.MaxRetryConnectionTime; int maxRetryConnectionTimeMinutes = maxRetryConnectionTimeMSecs / 60000; switch (e.Notification) { case ConnectionStatus.NetworkFailureDetected: warningRecord = new WarningRecord( PSConnectionRetryStatusEventArgs.FQIDNetworkFailureDetected, StringUtil.Format(RemotingErrorIdStrings.RCNetworkFailureDetected, this.computerName, maxRetryConnectionTimeMinutes)); connectionRetryStatusArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.NetworkFailureDetected, this.computerName, maxRetryConnectionTimeMSecs, warningRecord); break; case ConnectionStatus.ConnectionRetryAttempt: warningRecord = new WarningRecord( PSConnectionRetryStatusEventArgs.FQIDConnectionRetryAttempt, StringUtil.Format(RemotingErrorIdStrings.RCConnectionRetryAttempt, this.computerName)); connectionRetryStatusArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.ConnectionRetryAttempt, this.computerName, maxRetryConnectionTimeMSecs, warningRecord); break; case ConnectionStatus.ConnectionRetrySucceeded: warningRecord = new WarningRecord( PSConnectionRetryStatusEventArgs.FQIDConnectionRetrySucceeded, StringUtil.Format(RemotingErrorIdStrings.RCReconnectSucceeded, this.computerName)); connectionRetryStatusArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.ConnectionRetrySucceeded, this.computerName, maxRetryConnectionTimeMinutes, warningRecord); break; case ConnectionStatus.AutoDisconnectStarting: { warningRecord = new WarningRecord( PSConnectionRetryStatusEventArgs.FQIDAutoDisconnectStarting, StringUtil.Format(RemotingErrorIdStrings.RCAutoDisconnectingWarning, this.computerName)); connectionRetryStatusArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.AutoDisconnectStarting, this.computerName, maxRetryConnectionTimeMinutes, warningRecord); } break; case ConnectionStatus.AutoDisconnectSucceeded: warningRecord = new WarningRecord( PSConnectionRetryStatusEventArgs.FQIDAutoDisconnectSucceeded, StringUtil.Format(RemotingErrorIdStrings.RCAutoDisconnected, this.computerName)); connectionRetryStatusArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.AutoDisconnectSucceeded, this.computerName, maxRetryConnectionTimeMinutes, warningRecord); break; case ConnectionStatus.InternalErrorAbort: { string msg = StringUtil.Format(RemotingErrorIdStrings.RCInternalError, this.computerName); RuntimeException reason = new RuntimeException(msg); errorRecord = new ErrorRecord(reason, PSConnectionRetryStatusEventArgs.FQIDNetworkOrDisconnectFailed, ErrorCategory.InvalidOperation, this); connectionRetryStatusArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.InternalErrorAbort, this.computerName, maxRetryConnectionTimeMinutes, errorRecord); } break; } if (connectionRetryStatusArgs == null) { return; } // Update connection status. _connectionRetryStatus = connectionRetryStatusArgs.Notification; if (warningRecord != null) { RemotingWarningRecord remotingWarningRecord = new RemotingWarningRecord( warningRecord, new OriginInfo(this.computerName, this.InstanceId)); // Add warning record to information channel. HandleInformationalMessageReceived(this, new RemoteDataEventArgs<InformationalMessage>( new InformationalMessage(remotingWarningRecord, RemotingDataType.PowerShellWarning))); // Write warning to host. RemoteHostCall writeWarning = new RemoteHostCall( -100, RemoteHostMethodId.WriteWarningLine, new object[] { warningRecord.Message }); try { HandleHostCallReceived(this, new RemoteDataEventArgs<RemoteHostCall>(writeWarning)); } catch (PSNotImplementedException) { } } if (errorRecord != null) { RemotingErrorRecord remotingErrorRecord = new RemotingErrorRecord( errorRecord, new OriginInfo(this.computerName, this.InstanceId)); // Add error record to error channel, will also be written to host. HandleErrorReceived(this, new RemoteDataEventArgs<ErrorRecord>(remotingErrorRecord)); } // Raise event. RCConnectionNotification.SafeInvoke(this, connectionRetryStatusArgs); }
internal void RaiseRobustConnectionNotification(ConnectionStatusEventArgs args) { this.RobustConnectionNotification.SafeInvoke<ConnectionStatusEventArgs>(this, args); }
internal void QueueRobustConnectionNotification(int flags) { ConnectionStatusEventArgs privateData = null; switch (flags) { case 0x400: privateData = new ConnectionStatusEventArgs(ConnectionStatus.ConnectionRetrySucceeded); break; case 0x800: privateData = new ConnectionStatusEventArgs(ConnectionStatus.AutoDisconnectStarting); break; case 0x1000: privateData = new ConnectionStatusEventArgs(ConnectionStatus.InternalErrorAbort); break; case 0x40: privateData = new ConnectionStatusEventArgs(ConnectionStatus.AutoDisconnectSucceeded); break; case 0x100: privateData = new ConnectionStatusEventArgs(ConnectionStatus.NetworkFailureDetected); break; case 0x200: privateData = new ConnectionStatusEventArgs(ConnectionStatus.ConnectionRetryAttempt); break; } this.EnqueueAndStartProcessingThread(null, null, privateData); }
internal void ProcessRobustConnectionNotification(ConnectionStatusEventArgs e) { this.RobustConnectionNotification.SafeInvoke<ConnectionStatusEventArgs>(this, e); }
private void HandleRobustConnectionNotification(object sender, ConnectionStatusEventArgs e) { PSConnectionRetryStatusEventArgs eventArgs = null; WarningRecord infoRecord = null; ErrorRecord record2 = null; int maxRetryConnectionTime = this.runspacePool.MaxRetryConnectionTime; int num2 = maxRetryConnectionTime / 0xea60; switch (e.Notification) { case ConnectionStatus.NetworkFailureDetected: infoRecord = new WarningRecord("PowerShellNetworkFailureDetected", StringUtil.Format(RemotingErrorIdStrings.RCNetworkFailureDetected, this.computerName, num2)); eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.NetworkFailureDetected, this.computerName, maxRetryConnectionTime, infoRecord); break; case ConnectionStatus.ConnectionRetryAttempt: infoRecord = new WarningRecord("PowerShellConnectionRetryAttempt", StringUtil.Format(RemotingErrorIdStrings.RCConnectionRetryAttempt, this.computerName)); eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.ConnectionRetryAttempt, this.computerName, maxRetryConnectionTime, infoRecord); break; case ConnectionStatus.ConnectionRetrySucceeded: infoRecord = new WarningRecord("PowerShellConnectionRetrySucceeded", StringUtil.Format(RemotingErrorIdStrings.RCReconnectSucceeded, this.computerName)); eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.ConnectionRetrySucceeded, this.computerName, num2, infoRecord); break; case ConnectionStatus.AutoDisconnectStarting: infoRecord = new WarningRecord("PowerShellNetworkFailedStartDisconnect", StringUtil.Format(RemotingErrorIdStrings.RCAutoDisconnectingWarning, this.computerName)); eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.AutoDisconnectStarting, this.computerName, num2, infoRecord); break; case ConnectionStatus.AutoDisconnectSucceeded: infoRecord = new WarningRecord("PowerShellAutoDisconnectSucceeded", StringUtil.Format(RemotingErrorIdStrings.RCAutoDisconnected, this.computerName)); eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.AutoDisconnectSucceeded, this.computerName, num2, infoRecord); break; case ConnectionStatus.InternalErrorAbort: { RuntimeException exception = new RuntimeException(StringUtil.Format(RemotingErrorIdStrings.RCInternalError, this.computerName)); record2 = new ErrorRecord(exception, "PowerShellNetworkOrDisconnectFailed", ErrorCategory.InvalidOperation, this); eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.InternalErrorAbort, this.computerName, num2, record2); break; } } if (eventArgs != null) { this.connectionRetryStatus = eventArgs.Notification; if (infoRecord != null) { RemotingWarningRecord message = new RemotingWarningRecord(infoRecord, new OriginInfo(this.computerName, this.InstanceId)); this.HandleInformationalMessageReceived(this, new RemoteDataEventArgs<InformationalMessage>(new InformationalMessage(message, RemotingDataType.PowerShellWarning))); RemoteHostCall data = new RemoteHostCall(-100L, RemoteHostMethodId.WriteWarningLine, new object[] { infoRecord.Message }); try { this.HandleHostCallReceived(this, new RemoteDataEventArgs<RemoteHostCall>(data)); } catch (PSNotImplementedException) { } } if (record2 != null) { RemotingErrorRecord record4 = new RemotingErrorRecord(record2, new OriginInfo(this.computerName, this.InstanceId)); this.HandleErrorReceived(this, new RemoteDataEventArgs<ErrorRecord>(record4)); } this.RCConnectionNotification.SafeInvoke<PSConnectionRetryStatusEventArgs>(this, eventArgs); } }