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


C# Automation.ErrorRecord类代码示例

本文整理汇总了C#中System.Management.Automation.ErrorRecord的典型用法代码示例。如果您正苦于以下问题:C# ErrorRecord类的具体用法?C# ErrorRecord怎么用?C# ErrorRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ErrorRecord类属于System.Management.Automation命名空间,在下文中一共展示了ErrorRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddNameSpaceTable

 private XmlNamespaceManager AddNameSpaceTable(string parametersetname, XmlDocument xDoc, Hashtable namespacetable)
 {
     XmlNamespaceManager manager;
     if (parametersetname.Equals("Xml"))
     {
         XmlNameTable nameTable = new NameTable();
         manager = new XmlNamespaceManager(nameTable);
     }
     else
     {
         manager = new XmlNamespaceManager(xDoc.NameTable);
     }
     foreach (DictionaryEntry entry in namespacetable)
     {
         try
         {
             string prefix = entry.Key.ToString();
             manager.AddNamespace(prefix, entry.Value.ToString());
         }
         catch (NullReferenceException)
         {
             InvalidOperationException exception = new InvalidOperationException(StringUtil.Format(UtilityCommonStrings.SearchXMLPrefixNullError, new object[0]));
             ErrorRecord errorRecord = new ErrorRecord(exception, "PrefixError", ErrorCategory.InvalidOperation, namespacetable);
             base.WriteError(errorRecord);
         }
         catch (ArgumentNullException)
         {
             InvalidOperationException exception2 = new InvalidOperationException(StringUtil.Format(UtilityCommonStrings.SearchXMLPrefixNullError, new object[0]));
             ErrorRecord record2 = new ErrorRecord(exception2, "PrefixError", ErrorCategory.InvalidOperation, namespacetable);
             base.WriteError(record2);
         }
     }
     return manager;
 }
开发者ID:nickchal,项目名称:pash,代码行数:34,代码来源:SelectXmlCommand.cs

示例2: ExtractErrorFromErrorRecord

        public static string ExtractErrorFromErrorRecord(this Runspace runspace, ErrorRecord record)
        {
            Pipeline pipeline = runspace.CreatePipeline("$input", false);
            pipeline.Commands.Add("out-string");

            Collection<PSObject> result;
            using (PSDataCollection<object> inputCollection = new PSDataCollection<object>())
            {
                inputCollection.Add(record);
                inputCollection.Complete();
                result = pipeline.Invoke(inputCollection);
            }

            if (result.Count > 0)
            {
                string str = result[0].BaseObject as string;
                if (!string.IsNullOrEmpty(str))
                {
                    // Remove \r\n, which is added by the Out-String cmdlet.
                    return str.Substring(0, str.Length - 2);
                }
            }

            return String.Empty;
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:25,代码来源:RunspaceExtensions.cs

示例3: WriteError

 public void WriteError(ErrorRecord errorRecord)
 {
     if (_errors != null)
     {
         _errors.Add(errorRecord);
     }
 }
开发者ID:rikoe,项目名称:nuget,代码行数:7,代码来源:MockCommandRuntime.cs

示例4: ProcessRecord

 protected override void ProcessRecord()
 {
     // TODO: Extract as resource
     this.WriteVerbose("Calculating NT hash.");
     try
     {
         byte[] hashBytes = NTHash.ComputeHash(Password);
         string hashHex = hashBytes.ToHex();
         this.WriteObject(hashHex);
     }
     catch (ArgumentException ex)
     {
         ErrorRecord error = new ErrorRecord(ex, "Error1", ErrorCategory.InvalidArgument, this.Password);
         this.WriteError(error);
     }
     catch (Win32Exception ex)
     {
         ErrorCategory category = ((Win32ErrorCode)ex.NativeErrorCode).ToPSCategory();
         ErrorRecord error = new ErrorRecord(ex, "Error2", category, this.Password);
         // Allow the processing to continue on this error:
         this.WriteError(error);
     }
     catch (Exception ex)
     {
         ErrorRecord error = new ErrorRecord(ex, "Error3", ErrorCategory.NotSpecified, this.Password);
         this.WriteError(error);
     }
 }
开发者ID:deimx42,项目名称:DSInternals,代码行数:28,代码来源:ConvertToNTHashCommand.cs

示例5: CreateFileNotFoundErrorRecord

		internal static ErrorRecord CreateFileNotFoundErrorRecord(string resourceStr, string errorId, object[] args)
		{
			string str = StringUtil.Format(resourceStr, args);
			FileNotFoundException fileNotFoundException = new FileNotFoundException(str);
			ErrorRecord errorRecord = new ErrorRecord(fileNotFoundException, errorId, ErrorCategory.ObjectNotFound, null);
			return errorRecord;
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:SecurityUtils.cs

示例6: ProcessRecord

 protected override void ProcessRecord()
 {
     bool flag = false;
     lock (base.Events.ReceivedEvents.SyncRoot)
     {
         PSEventArgsCollection receivedEvents = base.Events.ReceivedEvents;
         for (int i = receivedEvents.Count; i > 0; i--)
         {
             PSEventArgs args = receivedEvents[i - 1];
             if (((this.sourceIdentifier == null) || this.matchPattern.IsMatch(args.SourceIdentifier)) && ((this.eventIdentifier < 0) || (args.EventIdentifier == this.eventIdentifier)))
             {
                 flag = true;
                 if (base.ShouldProcess(string.Format(Thread.CurrentThread.CurrentCulture, EventingStrings.EventResource, new object[] { args.SourceIdentifier }), EventingStrings.Remove))
                 {
                     receivedEvents.RemoveAt(i - 1);
                 }
             }
         }
     }
     if (((this.sourceIdentifier != null) && !WildcardPattern.ContainsWildcardCharacters(this.sourceIdentifier)) && !flag)
     {
         ErrorRecord errorRecord = new ErrorRecord(new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, EventingStrings.SourceIdentifierNotFound, new object[] { this.sourceIdentifier })), "INVALID_SOURCE_IDENTIFIER", ErrorCategory.InvalidArgument, null);
         base.WriteError(errorRecord);
     }
     else if ((this.eventIdentifier >= 0) && !flag)
     {
         ErrorRecord record2 = new ErrorRecord(new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, EventingStrings.EventIdentifierNotFound, new object[] { this.eventIdentifier })), "INVALID_EVENT_IDENTIFIER", ErrorCategory.InvalidArgument, null);
         base.WriteError(record2);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:30,代码来源:RemoveEventCommand.cs

示例7: WarnAboutUnsupportedActionPreferences

        private static void WarnAboutUnsupportedActionPreferences(
            Cmdlet cmdlet,
            ActionPreference effectiveActionPreference,
            string nameOfCommandLineParameter,
            Func<string> inquireMessageGetter,
            Func<string> stopMessageGetter)
        {
            string message;
            switch (effectiveActionPreference)
            {
                case ActionPreference.Stop:
                    message = stopMessageGetter();
                    break;

                case ActionPreference.Inquire:
                    message = inquireMessageGetter();
                    break;

                default:
                    return; // we can handle everything that is not Stop or Inquire
            }

            bool actionPreferenceComesFromCommandLineParameter = cmdlet.MyInvocation.BoundParameters.ContainsKey(nameOfCommandLineParameter);
            if (actionPreferenceComesFromCommandLineParameter)
            {
                Exception exception = new ArgumentException(message);
                ErrorRecord errorRecord = new ErrorRecord(exception, "ActionPreferenceNotSupportedByCimCmdletAdapter", ErrorCategory.NotImplemented, null);
                cmdlet.ThrowTerminatingError(errorRecord);
            }
        }
开发者ID:40a,项目名称:PowerShell,代码行数:30,代码来源:cimCmdletInvocationContext.cs

示例8: ProcessRecord

 /// <summary>
 /// Processes the pipeline.
 /// </summary>
 protected override void ProcessRecord()
 {
     if (InputObject != null && InputObject is Wizard) {
         WizardStep stepToRemove = null;
         foreach (WizardStep step in InputObject.Steps) {
             if (step.Name == Name) {
                 stepToRemove = step;
             }
         }
         InputObject.Steps.Remove(stepToRemove);
         if (PassThru) {
             WriteObject(this, InputObject);
         } else {
             WriteObject(this, true);
         }
     } else {
         ErrorRecord err =
             new ErrorRecord(
                 new Exception("The wizard object you provided is not valid"),
                 "WrongWizardObject",
                 ErrorCategory.InvalidArgument,
                 InputObject);
         err.ErrorDetails =
             new ErrorDetails(
                 "The wizard object you provided is not valid");
         WriteError(this, err, true);
     }
     // WizardStep step = new WizardStep(Name, Order);
     // if (SearchCriteria != null && SearchCriteria.Length > 0) {
 }
开发者ID:uiatester,项目名称:STUPS,代码行数:33,代码来源:RemoveUIAWizardStepCommand.cs

示例9: TraceError

 internal void TraceError(ErrorRecord errorRecord)
 {
     if (this._traceFrames.Count > 0)
     {
         ((TraceFrame) this._traceFrames[this._traceFrames.Count - 1]).TraceError(errorRecord);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:HelpErrorTracer.cs

示例10: EndProcessing

		protected override void EndProcessing()
		{
			using (base.CurrentPSTransaction)
			{
				try
				{
					this.transactedScript.InvokeUsingCmdlet(this, false, ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, null, new object[0], AutomationNull.Value, new object[0]);
				}
				catch (Exception exception1)
				{
					Exception exception = exception1;
					CommandProcessorBase.CheckForSevereException(exception);
					ErrorRecord errorRecord = new ErrorRecord(exception, "TRANSACTED_SCRIPT_EXCEPTION", ErrorCategory.NotSpecified, null);
					bool flag = false;
					Exception innerException = exception;
					while (innerException != null)
					{
						if (innerException as TimeoutException == null)
						{
							innerException = innerException.InnerException;
						}
						else
						{
							flag = true;
							break;
						}
					}
					if (flag)
					{
						errorRecord = new ErrorRecord(new InvalidOperationException(TransactionResources.TransactionTimedOut), "TRANSACTION_TIMEOUT", ErrorCategory.InvalidOperation, exception);
					}
					base.WriteError(errorRecord);
				}
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:35,代码来源:UseTransactionCommand.cs

示例11: ProcessRecord

 protected override void ProcessRecord()
 {
     System.Management.Automation.ErrorRecord errorRecord = this.ErrorRecord;
     if (errorRecord != null)
     {
         errorRecord = new System.Management.Automation.ErrorRecord(errorRecord, null);
     }
     else
     {
         System.Exception exception = this.Exception;
         string message = this.Message;
         if (exception == null)
         {
             exception = new WriteErrorException(message);
         }
         string errorId = this.ErrorId;
         if (string.IsNullOrEmpty(errorId))
         {
             errorId = exception.GetType().FullName;
         }
         errorRecord = new System.Management.Automation.ErrorRecord(exception, errorId, this.Category, this.TargetObject);
         if ((this.Exception != null) && !string.IsNullOrEmpty(message))
         {
             errorRecord.ErrorDetails = new ErrorDetails(message);
         }
     }
     string recommendedAction = this.RecommendedAction;
     if (!string.IsNullOrEmpty(recommendedAction))
     {
         if (errorRecord.ErrorDetails == null)
         {
             errorRecord.ErrorDetails = new ErrorDetails(errorRecord.ToString());
         }
         errorRecord.ErrorDetails.RecommendedAction = recommendedAction;
     }
     if (!string.IsNullOrEmpty(this.CategoryActivity))
     {
         errorRecord.CategoryInfo.Activity = this.CategoryActivity;
     }
     if (!string.IsNullOrEmpty(this.CategoryReason))
     {
         errorRecord.CategoryInfo.Reason = this.CategoryReason;
     }
     if (!string.IsNullOrEmpty(this.CategoryTargetName))
     {
         errorRecord.CategoryInfo.TargetName = this.CategoryTargetName;
     }
     if (!string.IsNullOrEmpty(this.CategoryTargetType))
     {
         errorRecord.CategoryInfo.TargetType = this.CategoryTargetType;
     }
     InvocationInfo variableValue = base.GetVariableValue("MyInvocation") as InvocationInfo;
     if (variableValue != null)
     {
         errorRecord.SetInvocationInfo(variableValue);
         errorRecord.PreserveInvocationInfoOnce = true;
         errorRecord.CategoryInfo.Activity = "Write-Error";
     }
     base.WriteError(errorRecord);
 }
开发者ID:nickchal,项目名称:pash,代码行数:60,代码来源:WriteOrThrowErrorCommand.cs

示例12: CreateErrorRecord

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fullyQualifiedErrorId"></param>
        /// <param name="errorCategory"></param>
        /// <param name="innerException"></param>
        /// <param name="resourceId"></param>
        /// <param name="resourceParms"></param>
        /// <returns></returns>
        internal static ErrorRecord CreateErrorRecord(
            string fullyQualifiedErrorId,
            ErrorCategory errorCategory,
            Exception innerException,
            string resourceId,
            params object[] resourceParms)
        {
            InvalidOperationException invalidOperationException;

            string errorMessage = string.Format(
                CultureInfo.CurrentCulture,
                resourceId,
                resourceParms);

            if (innerException != null)
            {
                invalidOperationException = new InvalidOperationException(errorMessage, innerException);
            }
            else
            {
                invalidOperationException = new InvalidOperationException(errorMessage);
            }

            ErrorRecord errorRecord = new ErrorRecord(
                invalidOperationException,
                fullyQualifiedErrorId,
                errorCategory,
                null);

            return errorRecord;
        }
开发者ID:PowerShell,项目名称:SmartPackageProvider,代码行数:40,代码来源:DscInvoker.cs

示例13: ExtractTags

 private void ExtractTags(Object obj, string filename)
 {
     try {
         var f = TagLib.File.Create(filename);
         WriteObject(new TagSet(filename,f.Tag));
     }
     catch (TagLib.UnsupportedFormatException e)
     {
         if (!useWildcard)
         {
             var err = new ErrorRecord(e, "The format is unsupported by get-tags", ErrorCategory.InvalidArgument, obj);
             WriteError(err);
         }
     }
     catch (System.IO.FileNotFoundException e)
     {
         var err = new ErrorRecord(e, "File doesn't exist", ErrorCategory.ResourceUnavailable, obj);
         WriteError(err);
     }
     catch (TagLib.CorruptFileException e)
     {
         var err = new ErrorRecord(e, "File is corrupted", ErrorCategory.InvalidData, obj);
         WriteError(err);
     }
     catch (Exception e)
     {
         WriteDebug(e.ToString());
     }
 }
开发者ID:Twinside,项目名称:Tagcmdlet,代码行数:29,代码来源:GetTagCommand.cs

示例14: PopulateFromList

 private static ICollection<object> PopulateFromList( ICollection<object> list, out ErrorRecord error )
 {
     ICollection<object> objs;
     error = null;
     List<object> objs1 = new List<object>( );
     using ( IEnumerator<object> enumerator = list.GetEnumerator( ) ) {
         while ( enumerator.MoveNext( ) ) {
             object current = enumerator.Current;
             if ( current is IDictionary<string, object> ) {
                 PSObject pSObject = JsonObject.PopulateFromDictionary( current as IDictionary<string, object>, out error );
                 if ( error == null ) {
                     objs1.Add( pSObject );
                 }
                 else {
                     objs = null;
                     return objs;
                 }
             }
             else if ( !( current is ICollection<object> ) ) {
                 objs1.Add( current );
             }
             else {
                 ICollection<object> objs2 = JsonObject.PopulateFromList( current as ICollection<object>, out error );
                 if ( error == null ) {
                     objs1.Add( objs2 );
                 }
                 else {
                     objs = null;
                     return objs;
                 }
             }
         }
         return objs1.ToArray( );
     }
 }
开发者ID:josheinstein,项目名称:PowerShell-Einstein,代码行数:35,代码来源:JsonObject.cs

示例15: ProcessRecord

 protected override void ProcessRecord()
 {
     bool flag = false;
     List<PSEventSubscriber> list = new List<PSEventSubscriber>(base.Events.Subscribers);
     foreach (PSEventSubscriber subscriber in list)
     {
         if ((((this.sourceIdentifier == null) || this.matchPattern.IsMatch(subscriber.SourceIdentifier)) && ((this.subscriptionId < 0) || (subscriber.SubscriptionId == this.subscriptionId))) && (!subscriber.SupportEvent || (this.Force != 0)))
         {
             base.WriteObject(subscriber);
             flag = true;
         }
     }
     if (!flag)
     {
         bool flag2 = (this.sourceIdentifier != null) && !WildcardPattern.ContainsWildcardCharacters(this.sourceIdentifier);
         bool flag3 = this.subscriptionId >= 0;
         if (flag2 || flag3)
         {
             object sourceIdentifier = null;
             string format = null;
             if (flag2)
             {
                 sourceIdentifier = this.sourceIdentifier;
                 format = EventingStrings.EventSubscriptionSourceNotFound;
             }
             else if (flag3)
             {
                 sourceIdentifier = this.subscriptionId;
                 format = EventingStrings.EventSubscriptionNotFound;
             }
             ErrorRecord errorRecord = new ErrorRecord(new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, format, new object[] { sourceIdentifier })), "INVALID_SOURCE_IDENTIFIER", ErrorCategory.InvalidArgument, null);
             base.WriteError(errorRecord);
         }
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:35,代码来源:GetEventSubscriberCommand.cs


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