private void ShowError(PSHostUserInterface hostUI) { if (_error != null) { hostUI.WriteErrorLine(_error); } }
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; } }
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); } }
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); } }
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); } }
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); } }
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); }
public override void WriteErrorLine(string value) { _ui.WriteErrorLine(value); }