当前位置: 首页>>代码示例>>C#>>正文


C# AggregateException.Flatten方法代码示例

本文整理汇总了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;
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:10,代码来源:KnownExceptions.cs

示例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;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:66,代码来源:CdsTests.cs

示例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));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:TaskRunSyncTests.cs

示例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);
        }
开发者ID:niksacmsft,项目名称:iot-journey,代码行数:40,代码来源:RollingBlobWriter.cs

示例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));
        }
开发者ID:awb99,项目名称:netmq,代码行数:7,代码来源:TitanicBroker.cs

示例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();
        }
开发者ID:haiyangIt,项目名称:Haiyang,代码行数:16,代码来源:DefaultLog.cs

示例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));
 }
开发者ID:beachandbytes,项目名称:GorillaDocs,代码行数:7,代码来源:SPHelperTests.cs

示例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));
 }
开发者ID:beachandbytes,项目名称:GorillaDocs,代码行数:7,代码来源:SPHelperTests.cs

示例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();
        }
开发者ID:haiyangIt,项目名称:Haiyang,代码行数:14,代码来源:CatalogService.cs

示例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;
        }
开发者ID:rodrycode,项目名称:Revalee,代码行数:21,代码来源:WorkManager.cs

示例11: LogExceptions

        private void LogExceptions (AggregateException exception)
        {
            Log ($"Exception: {exception.Message}");

            foreach (var ex in exception.Flatten ().InnerExceptions)
                Log ($"Inner Exception: {ex.Message}");
        }
开发者ID:cjkao,项目名称:netmq,代码行数:7,代码来源:TitanicBroker.cs


注:本文中的AggregateException.Flatten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。