本文整理汇总了C#中AggregateException.Flatten方法的典型用法代码示例。如果您正苦于以下问题:C# AggregateException.Flatten方法的具体用法?C# AggregateException.Flatten怎么用?C# AggregateException.Flatten使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AggregateException
的用法示例。
在下文中一共展示了AggregateException.Flatten方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleAggregateException
Tuple<string, bool> HandleAggregateException(AggregateException aggregrateException,
ReportExceptionEventArgs et) {
Tuple<string, bool> handled = null;
foreach (var error in aggregrateException.Flatten().InnerExceptions) {
if (handled == null || handled.Item1 == null)
handled = InternalHandler(error, et); // Does not set the loader to true
}
return handled;
}
示例2: RunAggregateException_Flatten
// Validates that flattening (incl recursive) works.
private static bool RunAggregateException_Flatten()
{
TestHarness.TestLog("* RunAggregateException_Flatten()");
Exception exceptionA = new Exception("A");
Exception exceptionB = new Exception("B");
Exception exceptionC = new Exception("C");
AggregateException aggExceptionBase = new AggregateException(exceptionA, exceptionB, exceptionC);
// Verify flattening one with another.
TestHarness.TestLog(" > Flattening (no recursion)...");
AggregateException flattened1 = aggExceptionBase.Flatten();
Exception[] expected1 = new Exception[] {
exceptionA, exceptionB, exceptionC
};
if (expected1.Length != flattened1.InnerExceptions.Count)
{
TestHarness.TestLog(" > error: expected count {0} differs from actual {1}",
expected1.Length, flattened1.InnerExceptions.Count);
return false;
}
for (int i = 0; i < flattened1.InnerExceptions.Count; i++)
{
if (expected1[i] != flattened1.InnerExceptions[i])
{
TestHarness.TestLog(" > error: inner exception #{0} isn't right:", i);
TestHarness.TestLog(" expected: {0}", expected1[i]);
TestHarness.TestLog(" found : {0}", flattened1.InnerExceptions[i]);
return false;
}
}
// Verify flattening one with another, accounting for recursion.
TestHarness.TestLog(" > Flattening (with recursion)...");
AggregateException aggExceptionRecurse = new AggregateException(aggExceptionBase, aggExceptionBase);
AggregateException flattened2 = aggExceptionRecurse.Flatten();
Exception[] expected2 = new Exception[] {
exceptionA, exceptionB, exceptionC, exceptionA, exceptionB, exceptionC,
};
if (expected2.Length != flattened2.InnerExceptions.Count)
{
TestHarness.TestLog(" > error: expected count {0} differs from actual {1}",
expected2.Length, flattened2.InnerExceptions.Count);
return false;
}
for (int i = 0; i < flattened2.InnerExceptions.Count; i++)
{
if (expected2[i] != flattened2.InnerExceptions[i])
{
TestHarness.TestLog(" > error: inner exception #{0} isn't right:", i);
TestHarness.TestLog(" expected: {0}", expected2[i]);
TestHarness.TestLog(" found : {0}", flattened2.InnerExceptions[i]);
return false;
}
}
return true;
}
示例3: CheckExpectedAggregateException
/// <summary>
/// Method that checks to ensure that the AggregateException contains TPLException (the one throw by the workload)
/// </summary>
/// <param name="ae"></param>
/// <returns></returns>
private void CheckExpectedAggregateException(AggregateException ae)
{
if (_workloadType == WorkloadType.ThrowException)
ae.Flatten().Handle((e) => e is TPLTestException);
else
Assert.True(false, string.Format("Caught un-expected exception - {0]. Fail to re-progogate the test exception via Wait", ae));
}
示例4: HandleExceptionsWritingBlocks
private bool HandleExceptionsWritingBlocks(AggregateException aggregateException)
{
var flattenedException = aggregateException.Flatten();
// deal with "hard" storage exceptions
// only log one error per ErrorCode
var representativeHardStorageExceptions =
flattenedException
.InnerExceptions
.OfType<StorageException>()
.Where(e => IsHardStorageException(e))
.GroupBy(se => se.RequestInformation.ExtendedErrorInformation.ErrorCode)
.Select(g => g.First());
foreach (var storageException in representativeHardStorageExceptions)
{
ColdStorageEventSource.Log.HardStorageExceptionCaughtWritingToBlob(storageException, _blobClient, _containerName);
}
// deal with "soft" storage exceptions
var softStorageExceptions =
flattenedException
.InnerExceptions
.OfType<StorageException>()
.Where(e => !IsHardStorageException(e));
foreach (var storageException in softStorageExceptions)
{
if (storageException.RequestInformation.HttpStatusCode == (int)HttpStatusCode.PreconditionFailed)
{
ColdStorageEventSource.Log.BlobEtagMissMatchOccured(_currentBlob.Name);
ResetCurrentWriterState();
}
else
{
ColdStorageEventSource.Log.StorageExceptionCaughtWritingToBlob(storageException, _blobClient, _containerName);
}
}
// return true if all exceptions are StorageExceptions, which were already handled; otherwise, false.
return flattenedException.InnerExceptions.All(ex => ex is StorageException);
}
示例5: LogExceptions
private void LogExceptions(AggregateException exception)
{
Log (string.Format ("Exception: {0}", exception.Message));
foreach (var ex in exception.Flatten ().InnerExceptions)
Log (string.Format ("Inner Exception: {0}", ex.Message));
}
示例6: GetAggrateException
internal static string GetAggrateException(LogLevel level, string message, AggregateException ex, string exMsg)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Join(blank, DateTime.Now.ToString(TimeFormat), Thread.CurrentThread.ManagedThreadId.ToString("D4"), Task.CurrentId.HasValue ? Task.CurrentId.Value.ToString("D4") : "0000",
LogLevelHelper.GetLevelString(level),
message.RemoveRN(),
ex.Message.RemoveRN(),
ex.HResult.ToString("X8"),
ex.StackTrace.RemoveRN(), ex.GetType().FullName));
foreach (var innerEx in ex.Flatten().InnerExceptions)
{
sb.AppendLine(GetExceptionString(level, message, ex, exMsg));
}
return sb.ToString();
}
示例7: GetLibrariesFailureMethod
void GetLibrariesFailureMethod(AggregateException ae)
{
ReturnedToCallback = true;
ae = ae.Flatten();
foreach (Exception ex in ae.InnerExceptions)
Assert.That(ex.Message == string.Format("Cannot contact site at the specified URL {0}.", Wrong_Url));
}
示例8: GetFilesFailureMethod
void GetFilesFailureMethod(AggregateException ae)
{
ReturnedToCallback = true;
ae = ae.Flatten();
foreach (Exception ex in ae.InnerExceptions)
Assert.That(ex.Message == string.Format("List '{0}' does not exist at site with URL '{1}'.", Wrong_Title, webUrl));
}
示例9: GetAggrateException
internal static string GetAggrateException(string message, AggregateException ex, string exMsg)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Join(blank, DateTime.Now.ToString("yyyyMMddHHmmss"),
message,
ex.Message,
ex.StackTrace));
foreach (var innerEx in ex.Flatten().InnerExceptions)
{
sb.AppendLine(GetExceptionString(message, ex, exMsg));
}
return sb.ToString();
}
示例10: ExtractWebException
private static WebException ExtractWebException(AggregateException aex)
{
if (aex == null || aex.InnerExceptions == null || aex.InnerExceptions.Count == 0)
{
return null;
}
AggregateException flattenedException = aex.Flatten();
foreach (Exception innerException in flattenedException.InnerExceptions)
{
WebException wex = innerException as WebException;
if (wex != null)
{
return wex;
}
}
return null;
}
示例11: LogExceptions
private void LogExceptions (AggregateException exception)
{
Log ($"Exception: {exception.Message}");
foreach (var ex in exception.Flatten ().InnerExceptions)
Log ($"Inner Exception: {ex.Message}");
}