本文整理汇总了C#中System.Management.Automation.ErrorRecord.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ErrorRecord.ToString方法的具体用法?C# ErrorRecord.ToString怎么用?C# ErrorRecord.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.ErrorRecord
的用法示例。
在下文中一共展示了ErrorRecord.ToString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteError
/// <summary>
/// Default implementation of WriteError - if the error record contains
/// an exception then that exception will be thrown. If not, then an
/// InvalidOperationException will be constructed and thrown.
/// </summary>
/// <param name="errorRecord">Error record instance to process</param>
public void WriteError(ErrorRecord errorRecord)
{
if (errorRecord.Exception != null)
throw errorRecord.Exception;
else
throw new InvalidOperationException(errorRecord.ToString());
}
示例2: ThrowTerminatingError
public void ThrowTerminatingError(ErrorRecord errorRecord)
{
if (errorRecord.Exception != null)
{
throw errorRecord.Exception;
}
throw new InvalidOperationException(errorRecord.ToString());
}
示例3: CheckHostRemotingPrerequisites
internal static void CheckHostRemotingPrerequisites()
{
if (IsWinPEHost())
{
ErrorRecord record = new ErrorRecord(new InvalidOperationException(StringUtil.Format(RemotingErrorIdStrings.WinPERemotingNotSupported, new object[0])), null, ErrorCategory.InvalidOperation, null);
throw new InvalidOperationException(record.ToString());
}
}
示例4: AddErrorInfo
private static void AddErrorInfo(StringBuilder sb, ErrorRecord err)
{
sb.Append(err.ToString());
sb.AppendFormat("\r\n +{0}", err.InvocationInfo.PositionMessage);
sb.AppendFormat("\r\n + CategoryInfo :{0}", err.CategoryInfo);
sb.AppendFormat("\r\n + FullyQualifiedErrorId :{0}", err.FullyQualifiedErrorId.ToString());
sb.AppendLine();
}
示例5: TargetObjectIsString
public void TargetObjectIsString()
{
var ex = new ApplicationException("Exception error message");
var error = new ErrorRecord(ex, "errorId", ErrorCategory.AuthenticationError, "targetObject");
Assert.AreEqual("Exception error message", error.ToString());
Assert.AreEqual("errorId", error.FullyQualifiedErrorId);
Assert.IsNull(error.ErrorDetails);
Assert.AreEqual(ex, error.Exception);
Assert.AreEqual("targetObject", error.TargetObject);
Assert.AreEqual("", error.CategoryInfo.Activity);
Assert.AreEqual(ErrorCategory.AuthenticationError, error.CategoryInfo.Category);
Assert.AreEqual("ApplicationException", error.CategoryInfo.Reason);
Assert.AreEqual("targetObject", error.CategoryInfo.TargetName);
Assert.AreEqual("String", error.CategoryInfo.TargetType);
Assert.AreEqual("AuthenticationError: (targetObject:String) [], ApplicationException", error.CategoryInfo.ToString());
Assert.AreEqual("AuthenticationError: (targetObject:String) [], ApplicationException", error.CategoryInfo.GetMessage());
}
示例6: GetErrorMessage
private static string GetErrorMessage(ErrorRecord errorRecord)
{
var sb = new StringBuilder(errorRecord.ToString());
sb.Append(errorRecord.InvocationInfo.PositionMessage);
return sb.ToString();
}
示例7: LogExecutionError
internal void LogExecutionError(InvocationInfo invocationInfo, ErrorRecord errorRecord)
{
if (errorRecord != null)
{
string item = StringUtil.Format(PipelineStrings.PipelineExecutionNonTerminatingError, this.GetCommand(invocationInfo), errorRecord.ToString());
this.logBuffer.Add(item);
}
}
示例8: _WriteErrorSkipAllowCheck
internal void _WriteErrorSkipAllowCheck(ErrorRecord errorRecord, ActionPreference? actionPreference = new ActionPreference?())
{
this.ThrowIfStopping();
if ((errorRecord.ErrorDetails != null) && (errorRecord.ErrorDetails.TextLookupError != null))
{
Exception textLookupError = errorRecord.ErrorDetails.TextLookupError;
errorRecord.ErrorDetails.TextLookupError = null;
MshLog.LogCommandHealthEvent(this.context, textLookupError, Severity.Warning);
}
this.pipelineProcessor.ExecutionFailed = true;
if (this.shouldLogPipelineExecutionDetail)
{
this.pipelineProcessor.LogExecutionError(this.thisCommand.MyInvocation, errorRecord);
}
ActionPreference errorAction = this.ErrorAction;
if (actionPreference.HasValue)
{
errorAction = actionPreference.Value;
}
if (ActionPreference.Ignore != errorAction)
{
if (errorAction == ActionPreference.SilentlyContinue)
{
this.AppendErrorToVariables(errorRecord);
}
else
{
if (ContinueStatus.YesToAll == this.lastErrorContinueStatus)
{
errorAction = ActionPreference.Continue;
}
switch (errorAction)
{
case ActionPreference.Stop:
{
ActionPreferenceStopException e = new ActionPreferenceStopException(this.MyInvocation, errorRecord, this.CBResourcesBaseName, "ErrorPreferenceStop", new object[] { "ErrorActionPreference", errorRecord.ToString() });
throw this.ManageException(e);
}
case ActionPreference.Inquire:
this.lastErrorContinueStatus = this.InquireHelper(RuntimeException.RetrieveMessage(errorRecord), null, true, false, true);
break;
}
this.AppendErrorToVariables(errorRecord);
PSObject obj2 = PSObject.AsPSObject(errorRecord);
if (obj2.Members["writeErrorStream"] == null)
{
PSNoteProperty member = new PSNoteProperty("writeErrorStream", true);
obj2.Properties.Add(member);
}
if (this.ErrorMergeTo != MergeDataStream.None)
{
this.OutputPipe.AddWithoutAppendingOutVarList(obj2);
}
else
{
this.ErrorOutputPipe.AddWithoutAppendingOutVarList(obj2);
}
}
}
}
示例9: _WriteErrorSkipAllowCheck
} // DoWriteError
// NOTICE-2004/06/08-JonN 959638
// Use this variant to skip the ThrowIfWriteNotPermitted check
/// <exception cref="System.Management.Automation.PipelineStoppedException">
/// The pipeline has already been terminated, or was terminated
/// during the execution of this method.
/// The Cmdlet should generally just allow PipelineStoppedException
/// to percolate up to the caller of ProcessRecord etc.
/// </exception>
/// <remarks>
/// If the pipeline is terminated due to ActionPreference.Stop
/// or ActionPreference.Inquire, this method will throw
/// <see cref="System.Management.Automation.PipelineStoppedException"/>,
/// but the command failure will ultimately be
/// <see cref="System.Management.Automation.ActionPreferenceStopException"/>,
/// </remarks>
internal void _WriteErrorSkipAllowCheck(ErrorRecord errorRecord, ActionPreference? actionPreference = null, bool isNativeError = false)
{
ThrowIfStopping();
if (null != errorRecord.ErrorDetails
&& null != errorRecord.ErrorDetails.TextLookupError)
{
Exception textLookupError = errorRecord.ErrorDetails.TextLookupError;
errorRecord.ErrorDetails.TextLookupError = null;
MshLog.LogCommandHealthEvent(
Context,
textLookupError,
Severity.Warning);
}
this.PipelineProcessor.ExecutionFailed = true;
if (LogPipelineExecutionDetail)
{
this.PipelineProcessor.LogExecutionError(_thisCommand.MyInvocation, errorRecord);
}
ActionPreference preference = ErrorAction;
if (actionPreference.HasValue)
{
preference = actionPreference.Value;
}
// No trace of the error in the 'Ignore' case
if (ActionPreference.Ignore == preference)
{
return; // do not write or record to output pipe
}
// 2004/05/26-JonN
// The object is not written in the SilentlyContinue case
if (ActionPreference.SilentlyContinue == preference)
{
AppendErrorToVariables(errorRecord);
return; // do not write to output pipe
}
if (ContinueStatus.YesToAll == lastErrorContinueStatus)
{
preference = ActionPreference.Continue;
}
switch (preference)
{
case ActionPreference.Stop:
ActionPreferenceStopException e =
new ActionPreferenceStopException(
MyInvocation,
errorRecord,
StringUtil.Format(CommandBaseStrings.ErrorPreferenceStop,
"ErrorActionPreference",
errorRecord.ToString()));
throw ManageException(e);
case ActionPreference.Inquire:
// ignore return value
// this will throw if the user chooses not to continue
lastErrorContinueStatus = InquireHelper(
RuntimeException.RetrieveMessage(errorRecord),
null,
true, // allowYesToAll
false, // allowNoToAll
true, // replaceNoWithHalt
false // hasSecurityImpact
);
break;
} // switch (preference)
// 2005/01/20 Do not write the object to $error if
// ManageException has already done so
AppendErrorToVariables(errorRecord);
// Add this note property and set its value to true for F&O
// to decide whether to call WriteErrorLine or WriteLine.
// We want errors to print in red in both cases.
PSObject errorWrap = PSObject.AsPSObject(errorRecord);
// It's possible we've already added the member (this method is recursive sometimes
// when tracing), so don't add the member again.
//.........这里部分代码省略.........
示例10: PowershellError
public PowershellError(ErrorRecord error)
{
InnerError = error;
Message = error.ToString();
}
示例11: GetLogEntryInfoFromMessage
private static LogEntryInfo GetLogEntryInfoFromMessage(ErrorRecord errorRecord)
{
string message;
string file;
int lineNumber;
int columnNumber;
if (!TryGetLineInfoFromMessages(errorRecord.ToString(), out message, out file, out lineNumber, out columnNumber))
{
return null;
}
message = message + Environment.NewLine +
string.Format(CultureInfo.CurrentCulture, Resources.CustomFileLineNumberFormat, file, lineNumber) + Environment.NewLine +
errorRecord.ScriptStackTrace;
return new LogEntryInfo(
message: message,
file: file,
lineNumber: lineNumber,
columnNumber: columnNumber);
}
示例12: CheckHostRemotingPrerequisites
/// <summary>
/// Facilitates to check if remoting is supported on the host machine.
/// PowerShell remoting is supported on all Windows SQU's except WinPE.
/// </summary>
/// <exception cref="InvalidOperationException">
/// When PowerShell is hosted on a WinPE machine, the execution
/// of this API would result in an InvalidOperationException being
/// thrown, indicating that remoting is not supported on a WinPE machine.
/// </exception>
internal static void CheckHostRemotingPrerequisites()
{
// A registry key indicates if the SKU is WINPE. If this turns out to be true,
// then an InValidOperation exception is thrown.
bool isWinPEHost = Utils.IsWinPEHost();
if (isWinPEHost)
{
// WSMan is not supported on this platform
//throw new InvalidOperationException(
// "WinPE does not support Windows PowerShell remoting");
ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(StringUtil.Format(RemotingErrorIdStrings.WinPERemotingNotSupported)), null, ErrorCategory.InvalidOperation, null);
throw new InvalidOperationException(errorRecord.ToString());
}
}
示例13: GetMessageFromErrorRecord
private static string GetMessageFromErrorRecord(ErrorRecord record)
{
if(record.Exception != null)
{
return record.Exception.Message;
}
if(record.ErrorDetails != null)
{
return String.Format(CultureInfo.InvariantCulture, "Erro - {0} & Recommended action - {1}", record.ErrorDetails.Message, record.ErrorDetails.RecommendedAction);
}
return record.ToString();
}
示例14: WriteErrorRecord
private void WriteErrorRecord(RemoteComputer powershellComputer, ErrorRecord record) {
powershellComputer.AddLogEntry(new LogEntry(powershellComputer.Name, record.ToString(), LogEntryType.Error));
}