本文整理汇总了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;
}
示例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;
}
示例3: WriteError
public void WriteError(ErrorRecord errorRecord)
{
if (_errors != null)
{
_errors.Add(errorRecord);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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) {
}
示例9: TraceError
internal void TraceError(ErrorRecord errorRecord)
{
if (this._traceFrames.Count > 0)
{
((TraceFrame) this._traceFrames[this._traceFrames.Count - 1]).TraceError(errorRecord);
}
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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());
}
}
示例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( );
}
}
示例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);
}
}
}