コード例 #1
0
 private void ShowError(PSHostUserInterface hostUI)
 {
     if (_error != null)
     {
         hostUI.WriteErrorLine(_error);
     }
 }
コード例 #2
0
        public override void Log(string message, Exception ex, TraceLevel traceLevel, params object[] formatArgs)
        {
            switch (traceLevel)
            {
            case TraceLevel.Error:
                _psHostUserInterface.WriteErrorLine(string.Format(message, formatArgs));
                break;

            case TraceLevel.Info:
                _psHostUserInterface.WriteLine(string.Format(message, formatArgs));
                break;

            case TraceLevel.Verbose:
                _psHostUserInterface.WriteVerboseLine(string.Format(message, formatArgs));
                break;

            case TraceLevel.Warning:
                _psHostUserInterface.WriteWarningLine(string.Format(message, formatArgs));
                break;

            default:
                _psHostUserInterface.WriteLine(string.Format(message, formatArgs));
                break;
            }
        }
コード例 #3
0
 internal void ReportEngineStartupError(string resourceString, params object[] arguments)
 {
     try
     {
         Cmdlet cmdlet;
         string str;
         if (this.IsModuleCommandCurrentlyRunning(out cmdlet, out str))
         {
             RuntimeException replaceParentContainsErrorRecordException = InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, str, resourceString, arguments);
             cmdlet.WriteError(new ErrorRecord(replaceParentContainsErrorRecordException.ErrorRecord, replaceParentContainsErrorRecordException));
         }
         else
         {
             PSHost engineHostInterface = this.EngineHostInterface;
             if (engineHostInterface != null)
             {
                 PSHostUserInterface uI = engineHostInterface.UI;
                 if (uI != null)
                 {
                     uI.WriteErrorLine(StringUtil.Format(resourceString, arguments));
                 }
             }
         }
     }
     catch (Exception exception2)
     {
         CommandProcessorBase.CheckForSevereException(exception2);
     }
 }
コード例 #4
0
 internal void ReportEngineStartupError(ErrorRecord errorRecord)
 {
     try
     {
         Cmdlet cmdlet;
         string str;
         if (this.IsModuleCommandCurrentlyRunning(out cmdlet, out str))
         {
             cmdlet.WriteError(errorRecord);
         }
         else
         {
             PSHost engineHostInterface = this.EngineHostInterface;
             if (engineHostInterface != null)
             {
                 PSHostUserInterface uI = engineHostInterface.UI;
                 if (uI != null)
                 {
                     uI.WriteErrorLine(errorRecord.ToString());
                 }
             }
         }
     }
     catch (Exception exception)
     {
         CommandProcessorBase.CheckForSevereException(exception);
     }
 }
コード例 #5
0
 internal void ReportEngineStartupError(Exception e)
 {
     try
     {
         Cmdlet cmdlet;
         string str;
         if (this.IsModuleCommandCurrentlyRunning(out cmdlet, out str))
         {
             ErrorRecord      errorRecord = null;
             RuntimeException replaceParentContainsErrorRecordException = e as RuntimeException;
             errorRecord = (replaceParentContainsErrorRecordException != null) ? new ErrorRecord(replaceParentContainsErrorRecordException.ErrorRecord, replaceParentContainsErrorRecordException) : new ErrorRecord(e, str, ErrorCategory.OperationStopped, null);
             cmdlet.WriteError(errorRecord);
         }
         else
         {
             PSHost engineHostInterface = this.EngineHostInterface;
             if (engineHostInterface != null)
             {
                 PSHostUserInterface uI = engineHostInterface.UI;
                 if (uI != null)
                 {
                     uI.WriteErrorLine(e.Message);
                 }
             }
         }
     }
     catch (Exception exception2)
     {
         CommandProcessorBase.CheckForSevereException(exception2);
     }
 }
コード例 #6
0
        public override void WriteErrorLine(string message)
        {
            string[] lines = message.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
            foreach (string line in lines)
            {
                string temp = line;
                SendToSubscribers(s => s.WriteError(temp.TrimEnd() + "\r\n"));
            }

            if (externalUI != null)
            {
                externalUI.WriteErrorLine(message);
            }
        }
コード例 #7
0
        public static PowerShell WithStreamsOutput(this PowerShell ps, PSHostUserInterface psui)
        {
            ps.Streams.Information.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <InformationRecord>)sender)[args.Index];
                psui.WriteInformation(data);
            };
            ps.Streams.Progress.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <ProgressRecord>)sender)[args.Index];
                psui.WriteProgress(data.ActivityId, data);
            };
            ps.Streams.Debug.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <DebugRecord>)sender)[args.Index];
                psui.WriteDebugLine(data.Message);
            };
            ps.Streams.Verbose.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <VerboseRecord>)sender)[args.Index];
                psui.WriteVerboseLine(data.Message);
            };
            ps.Streams.Warning.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <WarningRecord>)sender)[args.Index];
                psui.WriteWarningLine(data.Message);
            };
            ps.Streams.Error.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <ErrorRecord>)sender)[args.Index];
                psui.WriteErrorLine(data.ErrorDetails?.Message ?? "Error Occured:");
                psui.WriteErrorLine("    Id: " + data.FullyQualifiedErrorId);
                psui.WriteErrorLine("    Category: " + data.CategoryInfo.Category);
                psui.WriteErrorLine("    Exception:");
                psui.WriteErrorLine(data.Exception.Print(2));

                if (!string.IsNullOrWhiteSpace(data.ErrorDetails?.RecommendedAction))
                {
                    psui.WriteErrorLine("    Recommendation" + data.ErrorDetails?.RecommendedAction);
                }
            };
            return(ps);
        }
コード例 #8
0
ファイル: Tracer.cs プロジェクト: svetek/Profiler
 public override void WriteErrorLine(string value)
 {
     _ui.WriteErrorLine(value);
 }