/// <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; } }
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; } }