internal static ErrorRecord InitializeErrorRecordCore(InvocationContext context, Exception exception, string errorId, ErrorCategory errorCategory, CimResultContext cimResultContext) { object errorSource = null; if (cimResultContext != null) { errorSource = cimResultContext.ErrorSource; } if (errorSource == null && context != null && context.TargetCimInstance != null) { errorSource = context.TargetCimInstance; } ErrorRecord errorRecord = new ErrorRecord(exception, errorId, errorCategory, errorSource); if (context != null) { OriginInfo originInfo = new OriginInfo(context.ComputerName, Guid.Empty); ErrorRecord remotingErrorRecord = new RemotingErrorRecord(errorRecord, originInfo); DebugHelper.WriteLogEx("Created RemotingErrorRecord.", 0); return(remotingErrorRecord); } else { return(errorRecord); } }
private void HandleErrorReady(object sender, EventArgs eventArgs) { PSDataCollectionPipelineReader <ErrorRecord, object> reader = sender as PSDataCollectionPipelineReader <ErrorRecord, object>; foreach (object obj2 in reader.NonBlockingRead()) { ErrorRecord errorRecord = obj2 as ErrorRecord; if (errorRecord != null) { OriginInfo originInfo = new OriginInfo(reader.ComputerName, reader.RunspaceId); RemotingErrorRecord record2 = new RemotingErrorRecord(errorRecord, originInfo) { PreserveInvocationInfoOnce = true }; this.WriteError(record2); } } }
/// <summary> /// Handle the object obtained from an ObjectStream's reader /// based on its type. /// </summary> /// <param name="cmdlet">Cmdlet to use for outputting the object.</param> /// <param name="instanceId"></param> /// <param name="overrideInquire">Suppresses prompt on messages with Inquire preference. /// Needed for Receive-Job</param> internal void WriteStreamObject(Cmdlet cmdlet, Guid instanceId, bool overrideInquire = false) { switch (ObjectType) { case PSStreamObjectType.Output: { if (instanceId != Guid.Empty) { PSObject o = Value as PSObject; if (o != null) { AddSourceJobNoteProperty(o, instanceId); } } cmdlet.WriteObject(Value); } break; case PSStreamObjectType.Error: { ErrorRecord errorRecord = (ErrorRecord)this.Value; RemotingErrorRecord remoteErrorRecord = errorRecord as RemotingErrorRecord; if (remoteErrorRecord == null) { // if we get a base ErrorRecord object, check if the computerName is // populated in the RecommendedAction field if (errorRecord.ErrorDetails != null && !string.IsNullOrEmpty(errorRecord.ErrorDetails.RecommendedAction)) { string computerName; Guid jobInstanceId; GetIdentifierInfo(errorRecord.ErrorDetails.RecommendedAction, out jobInstanceId, out computerName); errorRecord = new RemotingErrorRecord(errorRecord, new OriginInfo(computerName, Guid.Empty, jobInstanceId)); } } else { errorRecord = remoteErrorRecord; } errorRecord.PreserveInvocationInfoOnce = true; MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteError(errorRecord, overrideInquire); } } break; case PSStreamObjectType.Warning: { string warning = (string)Value; WarningRecord warningRecord = new WarningRecord(warning); MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteWarning(warningRecord, overrideInquire); } } break; case PSStreamObjectType.Verbose: { string verbose = (string)Value; VerboseRecord verboseRecord = new VerboseRecord(verbose); MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteVerbose(verboseRecord, overrideInquire); } } break; case PSStreamObjectType.Progress: { ProgressRecord progressRecord = (ProgressRecord)Value; RemotingProgressRecord remotingProgressRecord = progressRecord as RemotingProgressRecord; if (remotingProgressRecord == null) { Guid jobInstanceId; string computerName; GetIdentifierInfo(progressRecord.CurrentOperation, out jobInstanceId, out computerName); OriginInfo info = new OriginInfo(computerName, Guid.Empty, jobInstanceId); progressRecord = new RemotingProgressRecord(progressRecord, info); } else { progressRecord = remotingProgressRecord; } MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteProgress(progressRecord, overrideInquire); } } break; case PSStreamObjectType.Debug: { string debug = (string)Value; DebugRecord debugRecord = new DebugRecord(debug); MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteDebug(debugRecord, overrideInquire); } } break; case PSStreamObjectType.Information: { InformationRecord informationRecord = (InformationRecord)this.Value; RemotingInformationRecord remoteInformationRecord = informationRecord as RemotingInformationRecord; if (remoteInformationRecord == null) { // if we get a base InformationRecord object, check if the computerName is // populated in the Source field if (!string.IsNullOrEmpty(informationRecord.Source)) { string computerName; Guid jobInstanceId; GetIdentifierInfo(informationRecord.Source, out jobInstanceId, out computerName); informationRecord = new RemotingInformationRecord(informationRecord, new OriginInfo(computerName, Guid.Empty, jobInstanceId)); } } else { informationRecord = remoteInformationRecord; } MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteInformation(informationRecord, overrideInquire); } } break; case PSStreamObjectType.WarningRecord: case PSStreamObjectType.MethodExecutor: case PSStreamObjectType.BlockingError: case PSStreamObjectType.ShouldMethod: { WriteStreamObject(cmdlet, overrideInquire); } break; } }
/// <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 WriteStreamObject(Cmdlet cmdlet, Guid instanceId, bool overrideInquire = false) { switch (this.ObjectType) { case PSStreamObjectType.Output: if (instanceId != Guid.Empty) { PSObject psObj = this.Value as PSObject; if (psObj != null) { AddSourceJobNoteProperty(psObj, instanceId); } } cmdlet.WriteObject(this.Value); return; case PSStreamObjectType.Error: { ErrorRecord errorRecord = (ErrorRecord)this.Value; if ((!(errorRecord is RemotingErrorRecord) && (errorRecord.ErrorDetails != null)) && !string.IsNullOrEmpty(errorRecord.ErrorDetails.RecommendedAction)) { string str; Guid guid; GetIdentifierInfo(errorRecord.ErrorDetails.RecommendedAction, out guid, out str); errorRecord = new RemotingErrorRecord(errorRecord, new OriginInfo(str, Guid.Empty, guid)); } errorRecord.PreserveInvocationInfoOnce = true; MshCommandRuntime commandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (commandRuntime == null) { break; } commandRuntime.WriteError(errorRecord, overrideInquire); return; } case PSStreamObjectType.MethodExecutor: case PSStreamObjectType.BlockingError: case PSStreamObjectType.ShouldMethod: case PSStreamObjectType.WarningRecord: this.WriteStreamObject(cmdlet, overrideInquire); break; case PSStreamObjectType.Warning: { string message = (string)this.Value; WarningRecord record = new WarningRecord(message); MshCommandRuntime runtime2 = cmdlet.CommandRuntime as MshCommandRuntime; if (runtime2 == null) { break; } runtime2.WriteWarning(record, overrideInquire); return; } case PSStreamObjectType.Debug: { string str5 = (string)this.Value; DebugRecord record7 = new DebugRecord(str5); MshCommandRuntime runtime5 = cmdlet.CommandRuntime as MshCommandRuntime; if (runtime5 == null) { break; } runtime5.WriteDebug(record7, overrideInquire); return; } case PSStreamObjectType.Progress: { ProgressRecord progressRecord = (ProgressRecord)this.Value; if (!(progressRecord is RemotingProgressRecord)) { Guid guid2; string str4; GetIdentifierInfo(progressRecord.CurrentOperation, out guid2, out str4); OriginInfo originInfo = new OriginInfo(str4, Guid.Empty, guid2); progressRecord = new RemotingProgressRecord(progressRecord, originInfo); } MshCommandRuntime runtime4 = cmdlet.CommandRuntime as MshCommandRuntime; if (runtime4 == null) { break; } runtime4.WriteProgress(progressRecord, overrideInquire); return; } case PSStreamObjectType.Verbose: { string str3 = (string)this.Value; VerboseRecord record4 = new VerboseRecord(str3); MshCommandRuntime runtime3 = cmdlet.CommandRuntime as MshCommandRuntime; if (runtime3 == null) { break; } runtime3.WriteVerbose(record4, overrideInquire); return; } default: return; } }
/// <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); }
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); } }