当前位置: 首页>>代码示例>>C#>>正文


C# ErrorRecord.ToString方法代码示例

本文整理汇总了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());
 }
开发者ID:40a,项目名称:PowerShell,代码行数:13,代码来源:DefaultCommandRuntime.cs

示例2: ThrowTerminatingError

 public void ThrowTerminatingError(ErrorRecord errorRecord)
 {
     if (errorRecord.Exception != null)
     {
         throw errorRecord.Exception;
     }
     throw new InvalidOperationException(errorRecord.ToString());
 }
开发者ID:rikoe,项目名称:nuget,代码行数:8,代码来源:MockCommandRuntime.cs

示例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());
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:RemotingCommandUtil.cs

示例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();
 }
开发者ID:hugodahl,项目名称:powershell-for-developers,代码行数:8,代码来源:PS.cs

示例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());
        }
开发者ID:Pash-Project,项目名称:Pash,代码行数:18,代码来源:ErrorRecordTests.cs

示例6: GetErrorMessage

 private static string GetErrorMessage(ErrorRecord errorRecord)
 {
     var sb = new StringBuilder(errorRecord.ToString());
     sb.Append(errorRecord.InvocationInfo.PositionMessage);
     return sb.ToString();
 }
开发者ID:sos-berlin,项目名称:scheduler-engine,代码行数:6,代码来源:PowershellAdapter.cs

示例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);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:PipelineProcessor.cs

示例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);
             }
         }
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:60,代码来源:MshCommandRuntime.cs

示例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.

//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:MshCommandRuntime.cs

示例10: PowershellError

 public PowershellError(ErrorRecord error)
 {
     InnerError = error;
     Message = error.ToString();
 }
开发者ID:neutmute,项目名称:exchange-client,代码行数:5,代码来源:PowershellError.cs

示例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);
        }
开发者ID:rafd123,项目名称:PowerBridge,代码行数:22,代码来源:LogEntryInfo.cs

示例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());
     }
 }
开发者ID:40a,项目名称:PowerShell,代码行数:23,代码来源:remotingcommandutil.cs

示例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();
 }
开发者ID:nazik,项目名称:inst4wa,代码行数:12,代码来源:ExecuteCommands.cs

示例14: WriteErrorRecord

 private void WriteErrorRecord(RemoteComputer powershellComputer, ErrorRecord record) {
     powershellComputer.AddLogEntry(new LogEntry(powershellComputer.Name, record.ToString(), LogEntryType.Error));
 }
开发者ID:nickguletskii,项目名称:SchoolCommander,代码行数:3,代码来源:RunPowershellWindow.xaml.cs


注:本文中的System.Management.Automation.ErrorRecord.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。