本文整理汇总了C#中Cmdlet.WriteError方法的典型用法代码示例。如果您正苦于以下问题:C# Cmdlet.WriteError方法的具体用法?C# Cmdlet.WriteError怎么用?C# Cmdlet.WriteError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cmdlet
的用法示例。
在下文中一共展示了Cmdlet.WriteError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteErrorDetails
/// <summary>
/// Process the exception that was thrown and write the error details.
/// </summary>
/// <param name="cmdlet">The cmdlet for which to write the error output.</param>
/// <param name="clientRequestId">The unique id for this request.</param>
/// <param name="exception">The exception that was thrown.</param>
public static void WriteErrorDetails(
Cmdlet cmdlet,
string clientRequestId,
Exception exception)
{
string requestId;
ErrorRecord errorRecord = RetrieveExceptionDetails(exception, out requestId);
// Write the request Id as a warning
if (requestId != null)
{
// requestId was availiable from the server response, write that as warning to the
// console.
cmdlet.WriteWarning(string.Format(
CultureInfo.InvariantCulture,
Resources.ExceptionRequestId,
requestId));
}
else
{
// requestId was not availiable from the server response, write the client Ids that
// was sent.
cmdlet.WriteWarning(string.Format(
CultureInfo.InvariantCulture,
Resources.ExceptionClientSessionId,
SqlDatabaseCmdletBase.clientSessionId));
cmdlet.WriteWarning(string.Format(
CultureInfo.InvariantCulture,
Resources.ExceptionClientRequestId,
clientRequestId));
}
// Write the actual errorRecord containing the exception details
cmdlet.WriteError(errorRecord);
}
示例2: WriteLoadError
private static bool WriteLoadError(Cmdlet cmdlet, ArrayList loadError, string errorId)
{
bool flag;
IEnumerator enumerator = loadError.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
DataFileLoadError current = (DataFileLoadError)enumerator.Current;
if (current.status != DataFileLoadError.ErrorStatus.Warning)
{
if (current.status != DataFileLoadError.ErrorStatus.Error)
{
continue;
}
cmdlet.WriteError(new ErrorRecord(current.exception, errorId, ErrorCategory.InvalidOperation, null));
flag = false;
return flag;
}
else
{
cmdlet.WriteWarning(string.Concat(current.message, "\n\n"));
}
}
return true;
}
finally
{
IDisposable disposable = enumerator as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
return flag;
}
示例3: LoadFromFile
internal static SortedList<int, PswaAuthorizationRule> LoadFromFile(Cmdlet cmdlet, string operationName)
{
SortedList<int, PswaAuthorizationRule> nums;
bool flag;
SortedList<int, PswaAuthorizationRule> nums1;
try
{
ArrayList arrayLists = new ArrayList();
SortedList<int, PswaAuthorizationRule> nums2 = PswaAuthorizationRuleManager.Instance.LoadFromFile(arrayLists);
if (!PswaAuthorizationRuleCommandHelper.WriteLoadError(cmdlet, arrayLists, string.Concat(operationName, "RuleError")))
{
flag = false;
}
else
{
flag = nums2 != null;
}
bool flag1 = flag;
if (flag1)
{
nums1 = nums2;
}
else
{
nums1 = null;
}
nums = nums1;
}
catch (Exception exception1)
{
Exception exception = exception1;
cmdlet.WriteError(new ErrorRecord(exception, string.Concat(operationName, "RuleError"), ErrorCategory.InvalidOperation, null));
nums = null;
}
return nums;
}
示例4: WriteInvalidPathError
/// <summary>
/// Helper routine to say that the path was invalid.
/// </summary>
/// <param name="cmdlet"></param>
/// <param name="path"></param>
public static void WriteInvalidPathError(Cmdlet cmdlet, string path)
{
cmdlet.WriteError(new ErrorRecord(new ArgumentException("Path not valid"),
"InvalidArgument",
ErrorCategory.InvalidArgument,
path));
}
示例5: WriteGenomeHostError
internal static void WriteGenomeHostError(Cmdlet self, string message)
{
self.WriteError(
new ErrorRecord(new Exception(message), "Genome", ErrorCategory.WriteError, null));
}
示例6: AdaptCardObject
public PSObject AdaptCardObject(Cmdlet myCmdlet, card cardObject)
{
var promotedObject = new PSObject(cardObject);
promotedObject.TypeNames.Insert(1, cardObject.GetType().FullName);
promotedObject.TypeNames[0] = String.Format(CultureInfo.CurrentCulture, "CardObject#{0}",cardObject.className);
// loop through the properties and promote them into the PSObject we're going to return
foreach ( var p in cardObject.attributeList)
{
try
{
promotedObject.Members.Add(new PSNoteProperty(p.name, p.value));
}
catch (ExtendedTypeSystemException ets)
{
myCmdlet.WriteWarning(String.Format("The property '{0}' already exists, skipping.\nException: {1}", p.name, ets.Message));
}
catch (Exception e)
{
myCmdlet.WriteError(new ErrorRecord(e, "Property", ErrorCategory.NotSpecified, p.name));
}
}
return promotedObject;
}