Пример #1
0
 protected override void ProcessRecord()
 {
     MshCommandRuntime commandRuntime = base.CommandRuntime as MshCommandRuntime;
     if (commandRuntime != null)
     {
         WarningRecord record = new WarningRecord(this.Message);
         InvocationInfo variableValue = base.GetVariableValue("MyInvocation") as InvocationInfo;
         if (variableValue != null)
         {
             record.SetInvocationInfo(variableValue);
         }
         commandRuntime.WriteWarning(record, false);
     }
     else
     {
         base.WriteWarning(this.Message);
     }
 }
Пример #2
0
 internal void WriteWarning(WarningRecord record, bool overrideInquire = false)
 {
     ActionPreference warningPreference = this.WarningPreference;
     if (overrideInquire && (warningPreference == ActionPreference.Inquire))
     {
         warningPreference = ActionPreference.Continue;
     }
     if (this.WriteHelper_ShouldWrite(warningPreference, this.lastWarningContinueStatus))
     {
         if (record.InvocationInfo == null)
         {
             record.SetInvocationInfo(this.MyInvocation);
         }
         if (this.WarningOutputPipe != null)
         {
             if (((this.CBhost != null) && (this.CBhost.InternalUI != null)) && this.WarningOutputPipe.NullPipe)
             {
                 this.CBhost.InternalUI.WriteWarningInfoBuffers(record);
             }
             PSObject obj2 = PSObject.AsPSObject(record);
             if (obj2.Members["WriteWarningStream"] == null)
             {
                 obj2.Properties.Add(new PSNoteProperty("WriteWarningStream", true));
             }
             this.WarningOutputPipe.AddWithoutAppendingOutVarList(obj2);
         }
         else
         {
             if ((this.Host == null) || (this.Host.UI == null))
             {
                 throw PSTraceSource.NewInvalidOperationException();
             }
             this.CBhost.InternalUI.WriteWarningRecord(record);
         }
     }
     this.AppendWarningVarList(record);
     this.lastWarningContinueStatus = this.WriteHelper(null, null, warningPreference, this.lastWarningContinueStatus, "WarningPreference", record.Message);
 }
Пример #3
0
        /// <summary>
        /// Display warning information
        /// </summary>
        internal void WriteWarning(WarningRecord record, bool overrideInquire = false)
        {
            ActionPreference preference = WarningPreference;
            if (overrideInquire && preference == ActionPreference.Inquire)
                preference = ActionPreference.Continue;

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

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

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

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

                    CBhost.InternalUI.TranscribeResult(StringUtil.Format(InternalHostUserInterfaceStrings.WarningFormatString, record.Message));
                    CBhost.InternalUI.WriteWarningRecord(record);
                }
            }

            AppendWarningVarList(record);

            lastWarningContinueStatus = WriteHelper(
                null,
                null,
                preference,
                lastWarningContinueStatus,
                "WarningPreference",
                record.Message);
        }
Пример #4
0
        /// <summary>
        /// This method implements the ProcessRecord method for Write-Warning command
        /// </summary>
        protected override void ProcessRecord()
        {
            //
            // The write-warning command must use the script's InvocationInfo rather than its own,
            // so we create the WarningRecord here and fill it up with the appropriate InvocationInfo;
            // then, we call the command runtime directly and pass this record to WriteWarning().
            //
            MshCommandRuntime mshCommandRuntime = this.CommandRuntime as MshCommandRuntime;

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

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

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

                mshCommandRuntime.WriteWarning(record);
            }
            else
            {
                WriteWarning(Message);
            }
        }//processrecord