本文整理汇总了C#中System.Management.Automation.ErrorRecord类的典型用法代码示例。如果您正苦于以下问题:C# ErrorRecord类的具体用法?C# ErrorRecord怎么用?C# ErrorRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ErrorRecord类属于System.Management.Automation命名空间,在下文中一共展示了ErrorRecord类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: WriteException
public static ErrorRecord WriteException(this Cmdlet cmdlet, Exception ex, bool isTerminating = false)
{
var errorCode = "Unknown";
var errorCategory = ErrorCategory.NotSpecified;
object targetObj = null;
if (ex.Data.Contains(ERROR_CODE))
{
errorCode = ex.Data[ERROR_CODE].ToString();
}
if (ex.Data.Contains(ERROR_CATEGORY))
{
errorCategory = (ex.Data[ERROR_CATEGORY] as ErrorCategory?).GetValueOrDefault();
}
if (ex.Data.Contains(ERROR_TARGET))
{
targetObj = ex.Data[ERROR_TARGET];
}
var err = new ErrorRecord(ex, errorCode, errorCategory, targetObj);
if (isTerminating)
{
cmdlet.ThrowTerminatingError(err);
}
else
{
cmdlet.WriteError(err);
}
return err;
}
开发者ID:CenturionFox,项目名称:attribute-common,代码行数:34,代码来源:ExceptionHelper.cs
示例17: BeginProcessing
protected override void BeginProcessing()
{
try
{
string str = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "eventvwr.exe");
Process.Start(str, this._computerName);
}
catch (Win32Exception win32Exception1)
{
Win32Exception win32Exception = win32Exception1;
int nativeErrorCode = win32Exception.NativeErrorCode;
if (!nativeErrorCode.Equals(2))
{
ErrorRecord errorRecord = new ErrorRecord(win32Exception, "Win32Exception", ErrorCategory.InvalidArgument, null);
base.WriteError(errorRecord);
}
else
{
string str1 = StringUtil.Format(EventlogResources.NotSupported, new object[0]);
InvalidOperationException invalidOperationException = new InvalidOperationException(str1);
ErrorRecord errorRecord1 = new ErrorRecord(invalidOperationException, "Win32Exception", ErrorCategory.InvalidOperation, null);
base.WriteError(errorRecord1);
}
}
catch (SystemException systemException1)
{
SystemException systemException = systemException1;
ErrorRecord errorRecord2 = new ErrorRecord(systemException, "InvalidComputerName", ErrorCategory.InvalidArgument, this._computerName);
base.WriteError(errorRecord2);
}
}
开发者ID:nickchal,项目名称:pash,代码行数:31,代码来源:ShowEventLogCommand.cs
示例18: WriteErrorObject
private Task WriteErrorObject(object obj)
{
ErrorRecord er = obj as ErrorRecord;
if (er == null)
{
IContainsErrorRecord cer = obj as IContainsErrorRecord;
if (cer != null)
{
er = cer.ErrorRecord;
}
else
{
Exception ex = obj as Exception;
if (ex != null)
{
er = new ErrorRecord(ex, "Error.Unknown", ErrorCategory.InvalidOperation, null);
}
else
{
er = new ErrorRecord(new Exception(obj.ToString()), "Error.Unknown", ErrorCategory.InvalidOperation, null);
}
}
}
Host.WriteLine(new FormattedText(TextClassifications.Error, er.ToString()));
return TaskEx.FromCompleted();
}
开发者ID:anurse,项目名称:Coco,代码行数:26,代码来源:PowerShellConsoleModel.cs
示例19: ReportHelpFileError
internal void ReportHelpFileError(Exception exception, string target, string helpFile)
{
ErrorRecord item = new ErrorRecord(exception, "LoadHelpFileForTargetFailed", ErrorCategory.OpenError, null) {
ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "LoadHelpFileForTargetFailed", new object[] { target, helpFile, exception.Message })
};
this.HelpSystem.LastErrors.Add(item);
}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:HelpProvider.cs
示例20: ProcessRecord
protected override void ProcessRecord()
{
const string particular = @"Software\ParticularSoftware";
ProviderInfo provider;
PSDriveInfo drive;
var psPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(LicenseFile, out provider, out drive);
if (provider.ImplementingType != typeof(FileSystemProvider))
{
var ex = new ArgumentException(string.Format("{0} does not resolve to a path on the FileSystem provider.", psPath));
var error = new ErrorRecord(ex, "InvalidProvider", ErrorCategory.InvalidArgument, psPath);
WriteError(error);
return;
}
var content = File.ReadAllText(psPath);
if (!CheckFileContentIsALicenseFile(content))
{
var ex = new InvalidDataException(string.Format("{0} is not not a valid license file", psPath));
var error = new ErrorRecord(ex, "InvalidLicense", ErrorCategory.InvalidData, psPath);
WriteError(error);
return;
}
if (EnvironmentHelper.Is64BitOperatingSystem)
{
RegistryHelper.LocalMachine(RegistryView.Registry64).WriteValue(particular, "License", content, RegistryValueKind.String);
}
RegistryHelper.LocalMachine(RegistryView.Registry32).WriteValue(particular, "License", content, RegistryValueKind.String);
}
开发者ID:james-wu,项目名称:NServiceBus.PowerShell,代码行数:32,代码来源:InstallPlatformLicense.cs
注:本文中的System.Management.Automation.ErrorRecord类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论