Преглед изворни кода

qdr.fnd.core: Date:__24.06.2025__

- Add extension Exception.ToAggregateException to convert exception to AggregateException
- update dependencies packages (System.IO.Abstractions)
---
Dalibor Votruba пре 1 година
родитељ
комит
62e6468f94

+ 58 - 2
qdr.fnd.core/Exceptions/ExceptionExc.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 
 namespace Quadarax.Foundation.Core.Exceptions
 {
@@ -35,6 +36,61 @@ namespace Quadarax.Foundation.Core.Exceptions
                 sb.AppendLine(e.StackTrace);
             }
             return sb.ToString();
-        }
-    }
+        }
+
+
+        /// <summary>
+        /// Converts an Exception and its inner exceptions to an AggregateException.
+        /// Flattens the exception hierarchy into a single AggregateException containing all exceptions.
+        /// </summary>
+        /// <param name="exception">The exception to convert</param>
+        /// <returns>An AggregateException containing the original exception and all inner exceptions</returns>
+        public static AggregateException ToAggregateException(this Exception exception)
+        {
+            if (exception == null)
+                throw new ArgumentNullException(nameof(exception));
+
+            // If it's already an AggregateException, flatten it to avoid nested AggregateExceptions
+            if (exception is AggregateException aggregateException)
+            {
+                return aggregateException.Flatten();
+            }
+
+            var exceptions = new List<Exception>();
+            FlattenExceptions(exception, exceptions);
+
+            return new AggregateException(exceptions);
+        }
+
+        /// <summary>
+        /// Recursively flattens exception hierarchy into a list
+        /// </summary>
+        /// <param name="exception">Current exception to process</param>
+        /// <param name="exceptions">List to accumulate flattened exceptions</param>
+        private static void FlattenExceptions(Exception exception, List<Exception> exceptions)
+        {
+            if (exception == null)
+                return;
+
+            // Handle AggregateException specially to avoid deep nesting
+            if (exception is AggregateException aggEx)
+            {
+                foreach (var innerEx in aggEx.InnerExceptions)
+                {
+                    FlattenExceptions(innerEx, exceptions);
+                }
+            }
+            else
+            {
+                // Add the current exception
+                exceptions.Add(exception);
+
+                // Recursively process inner exception
+                if (exception.InnerException != null)
+                {
+                    FlattenExceptions(exception.InnerException, exceptions);
+                }
+            }
+        }
+    }
 }

+ 5 - 7
qdr.fnd.core/qdr.fnd.core.csproj

@@ -15,13 +15,11 @@
     <Copyright>Copyright © 2023,2024,2025 Quadarax</Copyright>
     <PackageIcon>quadarax_dll.png</PackageIcon>
     <PackageTags>QDR;FND;CORE</PackageTags>
-    <AssemblyVersion>0.0.8.0</AssemblyVersion>
-    <FileVersion>0.0.8.0</FileVersion>
-    <Version>0.0.8.0-alpha</Version>
-    <PackageReleaseNotes>Date:13.3.2025
-		- Add Object.Dynamic.Dyna dynamic object to work with dynamic properties
-		- Add DataTransaction to work with simple transactional data operations
-		- Add TDyna dynamic object that supports DataTransaction
+    <AssemblyVersion>0.0.9.0</AssemblyVersion>
+    <FileVersion>0.0.9.0</FileVersion>
+    <Version>0.0.9.0-alpha</Version>
+    <PackageReleaseNotes>Date:24.6.2025
+		- Add extension Exception.ToAggregateException to convert exception to AggregateException
 		- update dependencies packages (System.IO.Abstractions)
     </PackageReleaseNotes>
     <PackageReadmeFile>releasenotes.md</PackageReadmeFile>

+ 10 - 9
qdr.fnd.core/qdr.fnd.core.csproj.Backup.tmp

@@ -12,16 +12,17 @@
     <Company>Quadarax</Company>
     <Product>Quadarax.Foundation</Product>
     <Description>Core library with general pattern implementations and patterns</Description>
-    <Copyright>Copyright © 2023,2024 Quadarax</Copyright>
+    <Copyright>Copyright © 2023,2024,2025 Quadarax</Copyright>
     <PackageIcon>quadarax_dll.png</PackageIcon>
     <PackageTags>QDR;FND;CORE</PackageTags>
-    <AssemblyVersion>0.0.5.0</AssemblyVersion>
-    <FileVersion>0.0.5.0</FileVersion>
-    <Version>0.0.5.0-alpha</Version>
-    <PackageReleaseNotes>Date:26.9.2024
-      - improve class CsvHelper to support with quoted values, add operation to write DataTable to CSV file.
-	  - extends ParametrizedString to set parametr value.
-      - update dependencies packages (System.IO.Abstractions)
+    <AssemblyVersion>0.0.8.0</AssemblyVersion>
+    <FileVersion>0.0.8.0</FileVersion>
+    <Version>0.0.8.0-alpha</Version>
+    <PackageReleaseNotes>Date:13.3.2025
+		- Add Object.Dynamic.Dyna dynamic object to work with dynamic properties
+		- Add DataTransaction to work with simple transactional data operations
+		- Add TDyna dynamic object that supports DataTransaction
+		- update dependencies packages (System.IO.Abstractions)
     </PackageReleaseNotes>
     <PackageReadmeFile>releasenotes.md</PackageReadmeFile>
     <Nullable>enable</Nullable>
@@ -47,7 +48,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="System.IO.Abstractions" Version="21.2.1" />
+    <PackageReference Include="System.IO.Abstractions" Version="22.0.14" />
   </ItemGroup>
 
   <ItemGroup>

+ 6 - 0
qdr.fnd.core/releasenotes.md

@@ -1,6 +1,12 @@
 # Quadarax.Foundation.Core * Release notes
 Ordered by version descending
 
+## 0.0.9.0
+Date:__24.06.2025__
+- Add extension Exception.ToAggregateException to convert exception to AggregateException
+- update dependencies packages (System.IO.Abstractions)
+---
+
 ## 0.0.8.0
 Date:__13.3.2025__
 - Add Object.Dynamic.Dyna dynamic object to work with dynamic properties