Exemple #1
0
        /// <summary>
        /// This method implements the ProcessRecord method for Write-verbose command.
        /// </summary>
        protected override void ProcessRecord()
        {
            //
            // The write-verbose command must use the script's InvocationInfo rather than its own,
            // so we create the VerboseRecord here and fill it up with the appropriate InvocationInfo;
            // then, we call the command runtime directly and pass this record to WriteVerbose().
            //
            MshCommandRuntime mshCommandRuntime = this.CommandRuntime as MshCommandRuntime;

            if (mshCommandRuntime != null)
            {
                VerboseRecord record = new VerboseRecord(Message);

                InvocationInfo invocationInfo = GetVariableValue(SpecialVariables.MyInvocation) as InvocationInfo;

                if (invocationInfo != null)
                {
                    record.SetInvocationInfo(invocationInfo);
                }

                mshCommandRuntime.WriteVerbose(record);
            }
            else
            {
                WriteVerbose(Message);
            }
        }
Exemple #2
0
 /// <summary>
 /// Writes the VerboseRecord to informational buffers.
 /// </summary>
 /// <param name="record">VerboseRecord.</param>
 internal void WriteVerboseInfoBuffers(VerboseRecord record)
 {
     if (_informationalBuffers != null)
     {
         _informationalBuffers.AddVerbose(record);
     }
 }
Exemple #3
0
        private void OnVerbose(object sender, DataAddedEventArgs e)
        {
            var           data   = (PSDataCollection <VerboseRecord>)sender;
            VerboseRecord record = data[e.Index];

            Write(record.ToString());
        }
Exemple #4
0
        void jackInformationEventHandler(object sender, DataAddedEventArgs e)
        {
            VerboseRecord newRecord = ((PSDataCollection <VerboseRecord>)sender)[e.Index];

            AppendOutputText(newRecord.ToString() + "\n");
            Console.WriteLine(newRecord.ToString());
        }
 internal void WriteVerboseRecord(VerboseRecord record)
 {
     this.WriteVerboseInfoBuffers(record);
     if (this.externalUI != null)
     {
         this.externalUI.WriteVerboseLine(record.Message);
     }
 }
        /// <summary>
        /// </summary>
        internal void WriteVerboseRecord(VerboseRecord record)
        {
            WriteVerboseInfoBuffers(record);

            if (_externalUI == null)
            {
                return;
            }

            _externalUI.WriteVerboseLine(record.Message);
        }
 public static PsStreamEventHandlers GetUIHandlers(WorkerContext ctx) => new PsStreamEventHandlers()
 {
     Debug = (o, e) =>
     {
         DebugRecord newRecord = ((PSDataCollection <DebugRecord>)o)[e.Index];
         if (!string.IsNullOrEmpty(newRecord.Message))
         {
             Program.MainFrmInstance.SetStatus(newRecord.Message);
         }
     },
     Error = (o, ev) =>
     {
         ErrorRecord newRecord = ((PSDataCollection <ErrorRecord>)o)[ev.Index];
         MessageBox.Show(newRecord.ToString(), "Powershell Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     },
     Information = (o, e) =>
     {
         InformationalRecord newRecord = ((PSDataCollection <InformationalRecord>)o)[e.Index];
         if (!string.IsNullOrEmpty(newRecord.Message))
         {
             Program.MainFrmInstance.SetStatus(newRecord.Message);
         }
     },
     Progress = (o, ev) =>
     {
         ProgressRecord r = ((PSDataCollection <ProgressRecord>)o)[ev.Index];
         ctx.d.ReportCaption(r.Activity);
         if (r.PercentComplete >= 0 && r.PercentComplete <= 100)
         {
             ctx.d.ReportProgress(r.PercentComplete);
         }
     },
     Verbose = (o, e) =>
     {
         VerboseRecord newRecord = ((PSDataCollection <VerboseRecord>)o)[e.Index];
         if (!string.IsNullOrEmpty(newRecord.Message))
         {
             Program.MainFrmInstance.SetStatus(newRecord.Message);
         }
     },
     Warning = (o, e) =>
     {
         WarningRecord newRecord = ((PSDataCollection <WarningRecord>)o)[e.Index];
         if (!string.IsNullOrEmpty(newRecord.Message))
         {
             Program.MainFrmInstance.SetStatus(newRecord.Message);
         }
     }
 };
Exemple #8
0
 internal void WriteVerboseRecord(VerboseRecord record)
 {
     using (InternalHostUserInterface.tracer.TraceMethod(record.Message, new object[0]))
     {
         if (this.informationalBuffers != null)
         {
             this.informationalBuffers.AddVerbose(record);
         }
         if (this.externalUI == null)
         {
             InternalHostUserInterface.tracer.WriteLine("no external user interface implemented; doing nothing", new object[0]);
         }
         else
         {
             this.externalUI.WriteVerboseLine(record.Message);
         }
     }
 }
        protected override void ProcessRecord()
        {
            MshCommandRuntime commandRuntime = base.CommandRuntime as MshCommandRuntime;

            if (commandRuntime != null)
            {
                VerboseRecord  record        = new VerboseRecord(this.Message);
                InvocationInfo variableValue = base.GetVariableValue("MyInvocation") as InvocationInfo;
                if (variableValue != null)
                {
                    record.SetInvocationInfo(variableValue);
                }
                commandRuntime.WriteVerbose(record, false);
            }
            else
            {
                base.WriteVerbose(this.Message);
            }
        }
        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;
            }
        }
Exemple #11
0
        internal void WriteStreamObject(Cmdlet cmdlet, bool overrideInquire = false)
        {
            switch (this.ObjectType)
            {
            case PSStreamObjectType.Output:
                cmdlet.WriteObject(this.Value);
                return;

            case PSStreamObjectType.Error:
            {
                ErrorRecord errorRecord = (ErrorRecord)this.Value;
                errorRecord.PreserveInvocationInfoOnce = true;
                MshCommandRuntime commandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (commandRuntime == null)
                {
                    break;
                }
                commandRuntime.WriteError(errorRecord, overrideInquire);
                return;
            }

            case PSStreamObjectType.MethodExecutor:
                ((ClientMethodExecutor)this.Value).Execute(cmdlet);
                return;

            case PSStreamObjectType.Warning:
            {
                string            message  = (string)this.Value;
                WarningRecord     record   = new WarningRecord(message);
                MshCommandRuntime runtime3 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime3 == null)
                {
                    break;
                }
                runtime3.WriteWarning(record, overrideInquire);
                return;
            }

            case PSStreamObjectType.BlockingError:
            {
                CmdletMethodInvoker <object> cmdletMethodInvoker = (CmdletMethodInvoker <object>) this.Value;
                InvokeCmdletMethodAndWaitForResults <object>(cmdletMethodInvoker, cmdlet);
                return;
            }

            case PSStreamObjectType.ShouldMethod:
            {
                CmdletMethodInvoker <bool> invoker2 = (CmdletMethodInvoker <bool>) this.Value;
                InvokeCmdletMethodAndWaitForResults <bool>(invoker2, cmdlet);
                return;
            }

            case PSStreamObjectType.WarningRecord:
            {
                WarningRecord     record5  = (WarningRecord)this.Value;
                MshCommandRuntime runtime6 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime6 == null)
                {
                    break;
                }
                runtime6.AppendWarningVarList(record5);
                return;
            }

            case PSStreamObjectType.Debug:
            {
                string            str      = (string)this.Value;
                DebugRecord       record2  = new DebugRecord(str);
                MshCommandRuntime runtime2 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime2 == null)
                {
                    break;
                }
                runtime2.WriteDebug(record2, overrideInquire);
                return;
            }

            case PSStreamObjectType.Progress:
            {
                MshCommandRuntime runtime5 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime5 == null)
                {
                    break;
                }
                runtime5.WriteProgress((ProgressRecord)this.Value, overrideInquire);
                return;
            }

            case PSStreamObjectType.Verbose:
            {
                string            str3     = (string)this.Value;
                VerboseRecord     record4  = new VerboseRecord(str3);
                MshCommandRuntime runtime4 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime4 == null)
                {
                    break;
                }
                runtime4.WriteVerbose(record4, overrideInquire);
                return;
            }

            case PSStreamObjectType.Exception:
            {
                Exception exception = (Exception)this.Value;
                throw exception;
            }

            default:
                return;
            }
        }
Exemple #12
0
        /// <summary>
        /// Sets up the PowerShell shell stream event handlers.
        /// </summary>
        /// <param name="shell">The PowerShell shell.</param>
        private static void SetupStreamEventHandlers(PowerShell shell)
        {
            Logger.Instance.WriteMethodEntry(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlers);

            try
            {
                shell.Streams.ClearStreams();
                shell.Streams.Error.DataAdded += delegate(object sender, DataAddedEventArgs e)
                {
                    PSDataCollection <ErrorRecord> errorStream = (PSDataCollection <ErrorRecord>)sender;
                    ErrorRecord record = errorStream[e.Index];
                    if (record == null)
                    {
                        return;
                    }

                    StringBuilder builder = new StringBuilder();
                    builder.AppendLine(record.ToString());

                    if (record.InvocationInfo != null)
                    {
                        builder.AppendLine();
                        builder.AppendLine(record.InvocationInfo.PositionMessage);
                    }

                    Logger.Instance.WriteError(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersErrorEvents, builder.ToString());
                };
                shell.Streams.Warning.DataAdded += delegate(object sender, DataAddedEventArgs e)
                {
                    PSDataCollection <WarningRecord> warningStream = (PSDataCollection <WarningRecord>)sender;
                    WarningRecord record = warningStream[e.Index];
                    if (record != null)
                    {
                        Logger.Instance.WriteWarning(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersWarningEvents, record.ToString());
                    }
                };
                shell.Streams.Debug.DataAdded += delegate(object sender, DataAddedEventArgs e)
                {
                    PSDataCollection <DebugRecord> debugStream = (PSDataCollection <DebugRecord>)sender;
                    DebugRecord record = debugStream[e.Index];
                    if (record != null)
                    {
                        Logger.Instance.WriteInfo(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersDebugEvents, record.ToString());
                    }
                };
                shell.Streams.Verbose.DataAdded += delegate(object sender, DataAddedEventArgs e)
                {
                    PSDataCollection <VerboseRecord> versboseStream = (PSDataCollection <VerboseRecord>)sender;
                    VerboseRecord record = versboseStream[e.Index];
                    if (record != null)
                    {
                        Logger.Instance.WriteVerbose(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersEvents, record.ToString());
                    }
                };
                shell.Streams.Progress.DataAdded += delegate(object sender, DataAddedEventArgs e)
                {
                    PSDataCollection <ProgressRecord> progressStream = (PSDataCollection <ProgressRecord>)sender;
                    ProgressRecord record = progressStream[e.Index];
                    if (record != null)
                    {
                        Logger.Instance.WriteInfo(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersProgressEvents, record.ToString());
                    }
                };
            }
            finally
            {
                Logger.Instance.WriteMethodExit(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlers);
            }
        }
 private void WriteVerboseRecord(RemoteComputer powershellComputer, VerboseRecord record)
 {
     powershellComputer.AddLogEntry(new LogEntry(powershellComputer.Name, record.Message, LogEntryType.Verbose));
 }
Exemple #14
0
 private void SyncVerboseReady(ScriptRunner sender, VerboseRecord data)
 {
     OnVerboseReady(this, data);
 }
Exemple #15
0
 public PSOutput(VerboseRecord verbose)
 {
     Stream  = PowerShellStreamType.Verbose;
     Verbose = verbose ?? throw new ArgumentNullException(nameof(verbose));
 }
Exemple #16
0
 public static UniversalStreamRecord FromVerboseRecord(VerboseRecord record)
 {
     return(FromInformationalRecord(record));
 }
Exemple #17
0
        private void Verbose_DataAdded(object sender, DataAddedEventArgs e)
        {
            VerboseRecord verboseRecord = PS.Streams.Verbose.Last();

            Logger.Log(verboseRecord.Message, LogLevels.Verbose);
        }
Exemple #18
0
        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;
            }
        }
Exemple #19
0
        /// <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;
            }
        }
Exemple #20
0
        /// <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="overrideInquire">Used by Receive-Job to suppress inquire preference.</param>
        public void WriteStreamObject(Cmdlet cmdlet, bool overrideInquire = false)
        {
            if (cmdlet != null)
            {
                switch (this.ObjectType)
                {
                case PSStreamObjectType.Output:
                {
                    cmdlet.WriteObject(this.Value);
                }

                break;

                case PSStreamObjectType.Error:
                {
                    ErrorRecord errorRecord = (ErrorRecord)this.Value;
                    errorRecord.PreserveInvocationInfoOnce = true;
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.WriteError(errorRecord, 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.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:
                {
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.WriteProgress((ProgressRecord)Value, overrideInquire);
                    }
                }

                break;

                case PSStreamObjectType.Information:
                {
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.WriteInformation((InformationRecord)Value, overrideInquire);
                    }
                }

                break;

                case PSStreamObjectType.WarningRecord:
                {
                    WarningRecord     warningRecord     = (WarningRecord)Value;
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.AppendWarningVarList(warningRecord);
                    }
                }

                break;

                case PSStreamObjectType.MethodExecutor:
                {
                    Dbg.Assert(this.Value is ClientMethodExecutor,
                               "Expected psstreamObject.value is ClientMethodExecutor");
                    ClientMethodExecutor methodExecutor = (ClientMethodExecutor)Value;
                    methodExecutor.Execute(cmdlet);
                }

                break;

                case PSStreamObjectType.BlockingError:
                {
                    CmdletMethodInvoker <object> methodInvoker = (CmdletMethodInvoker <object>)Value;
                    InvokeCmdletMethodAndWaitForResults(methodInvoker, cmdlet);
                }

                break;

                case PSStreamObjectType.ShouldMethod:
                {
                    CmdletMethodInvoker <bool> methodInvoker = (CmdletMethodInvoker <bool>)Value;
                    InvokeCmdletMethodAndWaitForResults(methodInvoker, cmdlet);
                }

                break;

                case PSStreamObjectType.Exception:
                {
                    Exception e = (Exception)Value;
                    throw e;
                }
                }
            }
            else if (ObjectType == PSStreamObjectType.Exception)
            {
                Exception e = (Exception)Value;
                throw e;
            }
        }
 /// <summary>
 /// Writes the VerboseRecord to informational buffers.
 /// </summary>
 /// <param name="record">VerboseRecord</param>
 internal void WriteVerboseInfoBuffers(VerboseRecord record)
 {
     if (_informationalBuffers != null)
     {
         _informationalBuffers.AddVerbose(record);
     }
 }
        /// <summary>
        /// 
        /// </summary>
        internal void WriteVerboseRecord(VerboseRecord record)
        {
            WriteVerboseInfoBuffers(record);

            if (_externalUI == null)
            {
                return;
            }

            _externalUI.WriteVerboseLine(record.Message);
        }