當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。