本文整理汇总了C#中Cmdlet.WriteWarning方法的典型用法代码示例。如果您正苦于以下问题:C# Cmdlet.WriteWarning方法的具体用法?C# Cmdlet.WriteWarning怎么用?C# Cmdlet.WriteWarning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cmdlet
的用法示例。
在下文中一共展示了Cmdlet.WriteWarning方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CopyDirectory
//.........这里部分代码省略.........
while (!task.IsCompleted && !task.IsCanceled)
{
// if we somehow made it in here prior to the cancel, I want to issue a throw
cmdletCancellationToken.ThrowIfCancellationRequested();
// only update progress if the percentage has changed.
if ((int) Math.Ceiling((decimal) testFileCountChanged/totalFiles*100)
< (int) Math.Ceiling((decimal) fileCount/totalFiles*100))
{
testFileCountChanged = fileCount;
var percentComplete = (int) Math.Ceiling((decimal) fileCount/totalFiles*100);
if (percentComplete > 100)
{
// in some cases we can get 101 percent complete using ceiling, however we want to be
// able to round up to full percentage values, instead of down.
percentComplete = 100;
}
progress.PercentComplete = percentComplete;
UpdateProgress(progress, cmdletRunningRequest);
}
// sleep for a half of a second.
TestMockSupport.Delay(500);
}
if (task.IsFaulted && !task.IsCanceled)
{
var ae = task.Exception;
if (ae != null)
{
if (cmdletRunningRequest != null)
{
cmdletRunningRequest.WriteWarning(
"The following errors were encountered during the copy:");
}
else
{
Console.WriteLine(@"The following errors were encountered during the copy:");
}
ae.Handle(
ex =>
{
if (ex is AggregateException)
{
var secondLevel = ex as AggregateException;
secondLevel.Handle(
secondEx =>
{
if (cmdletRunningRequest != null)
{
cmdletRunningRequest.WriteWarning(secondEx.ToString());
}
else
{
Console.WriteLine(secondEx);
}
return true;
});
}
else
{
if (cmdletRunningRequest != null)
{
示例4: AutoFillMetricsConfig
private static void AutoFillMetricsConfig(JObject wadCfgObject, string resourceId, Cmdlet cmdlet)
{
if (string.IsNullOrEmpty(resourceId))
{
return;
}
var configObject = wadCfgObject[DiagnosticMonitorConfigurationElemStr] as JObject;
if (configObject == null)
{
throw new ArgumentException(Properties.Resources.DiagnosticsExtensionDiagnosticMonitorConfigurationElementNotDefined);
}
var metricsObject = configObject[MetricsElemStr] as JObject;
if (metricsObject == null)
{
configObject.Add(new JProperty(MetricsElemStr,
new JObject(
new JProperty(MetricsResourceIdAttr, resourceId))));
}
else
{
var resourceIdValue = metricsObject[MetricsResourceIdAttr] as JValue;
if (resourceIdValue != null && !resourceIdValue.Value.Equals(resourceId))
{
cmdlet.WriteWarning(Properties.Resources.DiagnosticsExtensionMetricsResourceIdNotMatch);
}
metricsObject[MetricsResourceIdAttr] = resourceId;
}
}
示例5: WriteGenomeHostWarning
internal static void WriteGenomeHostWarning(Cmdlet self, string message)
{
self.WriteWarning(message);
}
示例6: AssignNewValue
public void AssignNewValue(Cmdlet myCmdlet, attributeSchema prop, card so, object newValue)
{
if (newValue == null) { return; } // Hacky Workaround
var lists = so.attributeList != null ? so.attributeList.ToList() : new List<attribute>();
myCmdlet.WriteVerbose("Want to set " + prop.name + " to " + newValue.ToString());
var dict = lists.ToDictionary(key => key.name, value => value);
var as1 = new attribute{ name = prop.name};
switch (prop.type)
{
case "DATE":
string valtoset = newValue != null ? newValue.ToString() : null;
if (!string.IsNullOrEmpty(valtoset))
{
try
{
myCmdlet.WriteVerbose("DATE: Convert string to DateTimeObject");
DateTime xd = DateTime.Parse(valtoset.ToString(), CultureInfo.CurrentCulture);
as1.value = xd.ToString("yyyy-MM-ddThh:mm:ssZ");
}
catch (Exception e) { myCmdlet.WriteWarning(e.Message); }
}
break;
case "TIMESTAMP":
string datetimetoset = newValue != null ? newValue.ToString() : null;
if (!string.IsNullOrEmpty(datetimetoset))
{
try
{
myCmdlet.WriteVerbose("TIMESTAMP: Convert string to DateTimeObject -> _" + datetimetoset.ToString() +"_");
DateTime xd = DateTime.Parse(datetimetoset.ToString(), CultureInfo.CurrentCulture);
as1.value = xd.ToString("yyyy-MM-ddThh:mm:ssZ");
}
catch (Exception e) { myCmdlet.WriteWarning(e.Message); }
}
break;
case "REFERENCE":
if (prop.referencedIdClassSpecified && newValue.ToString().Length > 0)
{
int codeint = 0;
int.TryParse(newValue.ToString(), out codeint);
if (codeint == 0)
{
myCmdlet.WriteVerbose("Try it with Workaround Parent Class: " + prop.referencedClassName);
int tmpvalue = 0;
var parentclass = _clientconnection.getAttributeList(prop.referencedClassName);
foreach (attributeSchema attributeschema in parentclass)
{
if (attributeschema.name == as1.name)
{
string newclassname = attributeschema.referencedClassName;
myCmdlet.WriteVerbose("Try it with Fulltext search classname: " + newclassname);
tmpvalue = GetCardbyCode(newclassname, newValue.ToString());
if (tmpvalue == 0)
{
myCmdlet.WriteWarning("Reference Card not found: " + newValue.ToString());
dict.Remove(as1.name);
}
else
{
myCmdlet.WriteVerbose("Card found: " + tmpvalue);
newValue = tmpvalue;
}
break;
}
}
if (tmpvalue == 0)
{
myCmdlet.WriteVerbose("Fulltext search ReferenceCard: " + newValue.ToString());
myCmdlet.WriteVerbose("Fulltext search classname: " + prop.referencedClassName);
tmpvalue = GetCardbyCode(prop.referencedClassName, newValue.ToString());
newValue = tmpvalue;
}
else
{
myCmdlet.WriteVerbose("Card found Set to Value: " + tmpvalue);
newValue = tmpvalue;
}
}
else
{
//myCmdlet.WriteVerbose("Check if ReferenceCard exists: " + codeint);
//var check = _clientconnection.getCard(prop.referencedClassName, codeint, null);
//if (check == null)
//{
// myCmdlet.WriteWarning("Reference Card not found: " + codeint);
// dict.Remove(as1.name);
//}
}
as1.value = newValue.ToString();
}
break;
default:
//.........这里部分代码省略.........
示例7: 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;
}