internal static void ExitHandler(object sender, RemoteDataEventArgs <RemoteHostCall> eventArgs) { RemoteHostCall data = eventArgs.Data; if (!data.IsSetShouldExitOrPopRunspace) { ((ClientRemotePowerShell)sender).ExecuteHostCall(data); } }
internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData) { if (receivedData.RunspacePoolId != this.clientRunspacePoolId) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.RunspaceIdsDoNotMatch, new object[] { receivedData.RunspacePoolId, this.clientRunspacePoolId }); } switch (receivedData.DataType) { case RemotingDataType.RunspacePoolOperationResponse: this.SetMaxMinRunspacesResponseRecieved.SafeInvoke <RemoteDataEventArgs <PSObject> >(this, new RemoteDataEventArgs <PSObject>(receivedData.Data)); return; case RemotingDataType.RunspacePoolStateInfo: { RunspacePoolStateInfo runspacePoolStateInfo = RemotingDecoder.GetRunspacePoolStateInfo(receivedData.Data); this.StateInfoReceived.SafeInvoke <RemoteDataEventArgs <RunspacePoolStateInfo> >(this, new RemoteDataEventArgs <RunspacePoolStateInfo>(runspacePoolStateInfo)); this.NotifyAssociatedPowerShells(runspacePoolStateInfo); return; } case RemotingDataType.CreatePowerShell: case RemotingDataType.AvailableRunspaces: case RemotingDataType.GetCommandMetadata: break; case RemotingDataType.PSEventArgs: { PSEventArgs pSEventArgs = RemotingDecoder.GetPSEventArgs(receivedData.Data); this.PSEventArgsReceived.SafeInvoke <RemoteDataEventArgs <PSEventArgs> >(this, new RemoteDataEventArgs <PSEventArgs>(pSEventArgs)); break; } case RemotingDataType.ApplicationPrivateData: { PSPrimitiveDictionary applicationPrivateData = RemotingDecoder.GetApplicationPrivateData(receivedData.Data); this.ApplicationPrivateDataReceived.SafeInvoke <RemoteDataEventArgs <PSPrimitiveDictionary> >(this, new RemoteDataEventArgs <PSPrimitiveDictionary>(applicationPrivateData)); return; } case RemotingDataType.RunspacePoolInitData: { RunspacePoolInitInfo runspacePoolInitInfo = RemotingDecoder.GetRunspacePoolInitInfo(receivedData.Data); this.RSPoolInitInfoReceived.SafeInvoke <RemoteDataEventArgs <RunspacePoolInitInfo> >(this, new RemoteDataEventArgs <RunspacePoolInitInfo>(runspacePoolInitInfo)); return; } case RemotingDataType.RemoteHostCallUsingRunspaceHost: { RemoteHostCall data = RemoteHostCall.Decode(receivedData.Data); this.RemoteHostCallReceived.SafeInvoke <RemoteDataEventArgs <RemoteHostCall> >(this, new RemoteDataEventArgs <RemoteHostCall>(data)); return; } default: return; } }
/// <summary> /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> internal static void ExitHandler(object sender, RemoteDataEventArgs <RemoteHostCall> eventArgs) { RemoteHostCall hostcall = eventArgs.Data; if (hostcall.IsSetShouldExitOrPopRunspace) { return; } // use the method from the RemotePowerShell to indeed execute this call ClientRemotePowerShell remotePowerShell = (ClientRemotePowerShell)sender; remotePowerShell.ExecuteHostCall(hostcall); }
private void ExecuteHostCall(RemoteHostCall hostcall) { if (hostcall.IsVoidMethod) { if (hostcall.IsSetShouldExitOrPopRunspace) { this.shell.ClearRemotePowerShell(); } hostcall.ExecuteVoidMethod(this.hostToUse); } else { RemoteHostResponse hostResponse = hostcall.ExecuteNonVoidMethod(this.hostToUse); this.dataStructureHandler.SendHostResponseToServer(hostResponse); } }
internal void HandleRemoteHostCalls(object sender, RemoteDataEventArgs <RemoteHostCall> eventArgs) { if (this.HostCallReceived != null) { this.HostCallReceived.SafeInvoke <RemoteDataEventArgs <RemoteHostCall> >(sender, eventArgs); } else { RemoteHostCall data = eventArgs.Data; if (data.IsVoidMethod) { data.ExecuteVoidMethod(base.host); } else { RemoteHostResponse hostResponse = data.ExecuteNonVoidMethod(base.host); this.dataStructureHandler.SendHostResponseToServer(hostResponse); } } }
internal void HandleRemoteHostCalls( object sender, RemoteDataEventArgs <RemoteHostCall> eventArgs) { using (RemoteRunspacePoolInternal.tracer.TraceMethod()) { if (this.HostCallReceived != null) { this.HostCallReceived(sender, eventArgs); } else { RemoteHostCall data = eventArgs.Data; if (data.IsVoidMethod) { data.ExecuteVoidMethod(this.host); } else { this.dataStructureHandler.SendHostResponseToServer(data.ExecuteNonVoidMethod(this.host)); } } } }
/// <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 ProcessReceivedData(RemoteDataObject <PSObject> receivedData) { using (ClientPowerShellDataStructureHandler.tracer.TraceMethod()) { if (receivedData.PowerShellId != this.clientPowerShellId) { throw new PSRemotingDataStructureException(PSRemotingErrorId.PipelineIdsDoNotMatch, new object[2] { (object)receivedData.PowerShellId, (object)this.clientPowerShellId }); } switch (receivedData.DataType) { case RemotingDataType.PowerShellOutput: this.OutputReceived((object)this, new RemoteDataEventArgs <object>(RemotingDecoder.GetPowerShellOutput((object)receivedData.Data))); break; case RemotingDataType.PowerShellErrorRecord: this.ErrorReceived((object)this, new RemoteDataEventArgs <ErrorRecord>((object)RemotingDecoder.GetPowerShellError((object)receivedData.Data))); break; case RemotingDataType.PowerShellStateInfo: this.InvocationStateInfoReceived((object)this, new RemoteDataEventArgs <PSInvocationStateInfo>((object)RemotingDecoder.GetPowerShellStateInfo((object)receivedData.Data))); break; case RemotingDataType.PowerShellDebug: this.InformationalMessageReceived((object)this, new RemoteDataEventArgs <InformationalMessage>((object)new InformationalMessage((object)RemotingDecoder.GetPowerShellDebug((object)receivedData.Data), RemotingDataType.PowerShellDebug))); break; case RemotingDataType.PowerShellVerbose: this.InformationalMessageReceived((object)this, new RemoteDataEventArgs <InformationalMessage>((object)new InformationalMessage((object)RemotingDecoder.GetPowerShellVerbose((object)receivedData.Data), RemotingDataType.PowerShellVerbose))); break; case RemotingDataType.PowerShellWarning: this.InformationalMessageReceived((object)this, new RemoteDataEventArgs <InformationalMessage>((object)new InformationalMessage((object)RemotingDecoder.GetPowerShellWarning((object)receivedData.Data), RemotingDataType.PowerShellWarning))); break; case RemotingDataType.PowerShellProgress: this.InformationalMessageReceived((object)this, new RemoteDataEventArgs <InformationalMessage>((object)new InformationalMessage((object)RemotingDecoder.GetPowerShellProgress((object)receivedData.Data), RemotingDataType.PowerShellProgress))); break; case RemotingDataType.RemoteHostCallUsingPowerShellHost: this.HostCallReceived((object)this, new RemoteDataEventArgs <RemoteHostCall>((object)RemoteHostCall.Decode(receivedData.Data))); break; } } }
internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData) { if (receivedData.PowerShellId != this.clientPowerShellId) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.PipelineIdsDoNotMatch, new object[] { receivedData.PowerShellId, this.clientPowerShellId }); } switch (receivedData.DataType) { case RemotingDataType.PowerShellOutput: { object powerShellOutput = RemotingDecoder.GetPowerShellOutput(receivedData.Data); this.OutputReceived.SafeInvoke <RemoteDataEventArgs <object> >(this, new RemoteDataEventArgs <object>(powerShellOutput)); return; } case RemotingDataType.PowerShellErrorRecord: { ErrorRecord powerShellError = RemotingDecoder.GetPowerShellError(receivedData.Data); this.ErrorReceived.SafeInvoke <RemoteDataEventArgs <ErrorRecord> >(this, new RemoteDataEventArgs <ErrorRecord>(powerShellError)); return; } case RemotingDataType.PowerShellStateInfo: { PSInvocationStateInfo powerShellStateInfo = RemotingDecoder.GetPowerShellStateInfo(receivedData.Data); this.InvocationStateInfoReceived.SafeInvoke <RemoteDataEventArgs <PSInvocationStateInfo> >(this, new RemoteDataEventArgs <PSInvocationStateInfo>(powerShellStateInfo)); return; } case RemotingDataType.PowerShellDebug: { DebugRecord powerShellDebug = RemotingDecoder.GetPowerShellDebug(receivedData.Data); this.InformationalMessageReceived.SafeInvoke <RemoteDataEventArgs <InformationalMessage> >(this, new RemoteDataEventArgs <InformationalMessage>(new InformationalMessage(powerShellDebug, RemotingDataType.PowerShellDebug))); return; } case RemotingDataType.PowerShellVerbose: { VerboseRecord powerShellVerbose = RemotingDecoder.GetPowerShellVerbose(receivedData.Data); this.InformationalMessageReceived.SafeInvoke <RemoteDataEventArgs <InformationalMessage> >(this, new RemoteDataEventArgs <InformationalMessage>(new InformationalMessage(powerShellVerbose, RemotingDataType.PowerShellVerbose))); return; } case RemotingDataType.PowerShellWarning: { WarningRecord powerShellWarning = RemotingDecoder.GetPowerShellWarning(receivedData.Data); this.InformationalMessageReceived.SafeInvoke <RemoteDataEventArgs <InformationalMessage> >(this, new RemoteDataEventArgs <InformationalMessage>(new InformationalMessage(powerShellWarning, RemotingDataType.PowerShellWarning))); return; } case ((RemotingDataType)0x4100a): case ((RemotingDataType)0x4100b): case ((RemotingDataType)0x4100c): case ((RemotingDataType)0x4100d): case ((RemotingDataType)0x4100e): case ((RemotingDataType)0x4100f): break; case RemotingDataType.PowerShellProgress: { ProgressRecord powerShellProgress = RemotingDecoder.GetPowerShellProgress(receivedData.Data); this.InformationalMessageReceived.SafeInvoke <RemoteDataEventArgs <InformationalMessage> >(this, new RemoteDataEventArgs <InformationalMessage>(new InformationalMessage(powerShellProgress, RemotingDataType.PowerShellProgress))); return; } case RemotingDataType.RemoteHostCallUsingPowerShellHost: { RemoteHostCall data = RemoteHostCall.Decode(receivedData.Data); this.HostCallReceived.SafeInvoke <RemoteDataEventArgs <RemoteHostCall> >(this, new RemoteDataEventArgs <RemoteHostCall>(data)); break; } default: return; } }
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); } }
internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData) { using (ClientRunspacePoolDataStructureHandler.tracer.TraceMethod()) { if (receivedData.RunspacePoolId != this.clientRunspacePoolId) { throw new PSRemotingDataStructureException(PSRemotingErrorId.RunspaceIdsDoNotMatch, new object[2] { (object)receivedData.RunspacePoolId, (object)this.clientRunspacePoolId }); } switch (receivedData.DataType) { case RemotingDataType.RunspacePoolOperationResponse: this.SetMaxMinRunspacesResponseRecieved((object)this, new RemoteDataEventArgs <PSObject>((object)receivedData.Data)); break; case RemotingDataType.RunspacePoolStateInfo: RunspacePoolStateInfo runspacePoolStateInfo = RemotingDecoder.GetRunspacePoolStateInfo(receivedData.Data); this.StateInfoReceived((object)this, new RemoteDataEventArgs <RunspacePoolStateInfo>((object)runspacePoolStateInfo)); this.NotifyAssociatedPowerShells(runspacePoolStateInfo); break; case RemotingDataType.PSEventArgs: this.PSEventArgsReceived((object)this, new RemoteDataEventArgs <PSEventArgs>((object)RemotingDecoder.GetPSEventArgs(receivedData.Data))); break; case RemotingDataType.ApplicationPrivateData: this.ApplicationPrivateDataReceived((object)this, new RemoteDataEventArgs <PSPrimitiveDictionary>((object)RemotingDecoder.GetApplicationPrivateData(receivedData.Data))); break; case RemotingDataType.RemoteHostCallUsingRunspaceHost: this.RemoteHostCallReceived((object)this, new RemoteDataEventArgs <RemoteHostCall>((object)RemoteHostCall.Decode(receivedData.Data))); break; } } }