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