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

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

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

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

                mshCommandRuntime.WriteDebug(record);
            }
            else
            {
                WriteDebug(Message);
            }
        }//processrecord
Пример #2
0
 internal void AddDebug(DebugRecord item)
 {
     if (this.debug != null)
     {
         this.debug.InternalAdd(this.psInstanceId, item);
     }
 }
Пример #3
0
 protected override void ProcessRecord()
 {
     MshCommandRuntime commandRuntime = base.CommandRuntime as MshCommandRuntime;
     if (commandRuntime != null)
     {
         DebugRecord record = new DebugRecord(this.Message);
         InvocationInfo variableValue = base.GetVariableValue("MyInvocation") as InvocationInfo;
         if (variableValue != null)
         {
             record.SetInvocationInfo(variableValue);
         }
         commandRuntime.WriteDebug(record, false);
     }
     else
     {
         base.WriteDebug(this.Message);
     }
 }
 internal void SendDebugRecordToClient(DebugRecord record)
 {
     record.SerializeExtendedInfo = (this.streamSerializationOptions & RemoteStreamOptions.AddInvocationInfoToDebugRecord) != 0;
     this.SendDataAsync(RemotingEncoder.GeneratePowerShellInformational(record, this.clientRunspacePoolId, this.clientPowerShellId, RemotingDataType.PowerShellDebug));
 }
        void Debug_DataAdded(object sender, DataAddedEventArgs e)
        {
            PSDataCollection<DebugRecord> collection = sender as PSDataCollection<DebugRecord>;
            lastDebug = collection[e.Index];
            PSObject psObj = new PSObject(lastDebug);
            PSPropertyInfo propInfo = new PSNoteProperty("TimeStamp", DateTime.Now);
            psObj.Properties.Add(new PSNoteProperty("Stream", "Debug"));
            psObj.Properties.Add(propInfo);
            timeStampedOutput.Add(psObj);

            if (Dispatcher != null)
            {
                RunOnUIThread(
                        new DispatcherOperationCallback(
                        delegate
                        {
                            NotifyDebugChanged();
                            return null;
                        }),
                        true);
            }
            else
            {
                NotifyDebugChanged();
            }

        }
Пример #6
0
 internal void WriteDebug(DebugRecord record, bool overrideInquire = false)
 {
     ActionPreference debugPreference = this.DebugPreference;
     if (overrideInquire && (debugPreference == ActionPreference.Inquire))
     {
         debugPreference = ActionPreference.Continue;
     }
     if (this.WriteHelper_ShouldWrite(debugPreference, this.lastDebugContinueStatus))
     {
         if (record.InvocationInfo == null)
         {
             record.SetInvocationInfo(this.MyInvocation);
         }
         if (this.DebugOutputPipe != null)
         {
             if (((this.CBhost != null) && (this.CBhost.InternalUI != null)) && this.DebugOutputPipe.NullPipe)
             {
                 this.CBhost.InternalUI.WriteDebugInfoBuffers(record);
             }
             PSObject obj2 = PSObject.AsPSObject(record);
             if (obj2.Members["WriteDebugStream"] == null)
             {
                 obj2.Properties.Add(new PSNoteProperty("WriteDebugStream", true));
             }
             this.DebugOutputPipe.Add(obj2);
         }
         else
         {
             if ((this.Host == null) || (this.Host.UI == null))
             {
                 throw PSTraceSource.NewInvalidOperationException();
             }
             this.CBhost.InternalUI.WriteDebugRecord(record);
         }
     }
     this.lastDebugContinueStatus = this.WriteHelper(null, null, debugPreference, this.lastDebugContinueStatus, "DebugPreference", record.Message);
 }
Пример #7
0
 internal void WriteDebugRecord(DebugRecord record)
 {
     this.WriteDebugInfoBuffers(record);
     if (this.externalUI != null)
     {
         this.externalUI.WriteDebugLine(record.Message);
     }
 }
Пример #8
0
 internal void WriteDebugInfoBuffers(DebugRecord record)
 {
     if (this.informationalBuffers != null)
     {
         this.informationalBuffers.AddDebug(record);
     }
 }
Пример #9
0
        /// <summary>
        /// Display debug information
        /// </summary>
        internal void WriteDebug(DebugRecord record, bool overrideInquire = false)
        {
            ActionPreference preference = DebugPreference;
            if (overrideInquire && preference == ActionPreference.Inquire)
                preference = ActionPreference.Continue;

            if (WriteHelper_ShouldWrite(preference, lastDebugContinueStatus))
            {
                if (record.InvocationInfo == null)
                {
                    record.SetInvocationInfo(MyInvocation);
                }

                if (DebugOutputPipe != null)
                {
                    if (CBhost != null && CBhost.InternalUI != null &&
                        DebugOutputPipe.NullPipe)
                    {
                        // If redirecting to a null pipe, still write to
                        // information buffers.
                        CBhost.InternalUI.WriteDebugInfoBuffers(record);
                    }

                    // Add note property so that the debug output is formatted correctly.
                    PSObject debugWrap = PSObject.AsPSObject(record);
                    if (debugWrap.Members["WriteDebugStream"] == null)
                    {
                        debugWrap.Properties.Add(new PSNoteProperty("WriteDebugStream", true));
                    }

                    DebugOutputPipe.Add(debugWrap);
                }
                else
                {
                    //
                    // If no pipe, write directly to host.
                    //
                    if (null == Host || null == Host.UI)
                    {
                        Diagnostics.Assert(false, "No host in CommandBase.WriteDebug()");
                        throw PSTraceSource.NewInvalidOperationException();
                    }

                    CBhost.InternalUI.TranscribeResult(StringUtil.Format(InternalHostUserInterfaceStrings.DebugFormatString, record.Message));
                    CBhost.InternalUI.WriteDebugRecord(record);
                }
            }

            lastDebugContinueStatus = WriteHelper(
                null,
                null,
                preference,
                lastDebugContinueStatus,
                "DebugPreference",
                record.Message);
        }
 /// <summary>
 /// Write debug information to the console.
 /// </summary>
 /// <param name="message">The debug message to display</param>
 public override void WriteDebugLine(string message)
 {
     DebugRecord r = new DebugRecord(message);
     Console.WriteLine(r);
 }