From cdda21b91fd4301712e62fb79e3e4bfd67b45dbe Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sat, 12 Oct 2024 22:33:14 +0200 Subject: [PATCH 01/12] :bug: fixed a bug that mistakenly applied key instead of key-value when converting Failure to JSON --- .../Converters/FailureConverter.cs | 110 ------------------ .../JsonConverterCollectionExtensions.cs | 5 +- .../ApplicationBuilderExtensionsTest.cs | 6 +- 3 files changed, 7 insertions(+), 114 deletions(-) delete mode 100644 src/Cuemon.Extensions.Text.Json/Converters/FailureConverter.cs diff --git a/src/Cuemon.Extensions.Text.Json/Converters/FailureConverter.cs b/src/Cuemon.Extensions.Text.Json/Converters/FailureConverter.cs deleted file mode 100644 index e7b6b83c5..000000000 --- a/src/Cuemon.Extensions.Text.Json/Converters/FailureConverter.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.Json; -using System.Text.Json.Serialization; -using Cuemon.Diagnostics; - -namespace Cuemon.Extensions.Text.Json.Converters -{ - /// - /// Converts a object to JSON. - /// - public class FailureConverter : JsonConverter - { - /// - /// Reads and converts the JSON to type . - /// - /// The reader. - /// The type to convert. - /// An object that specifies serialization options to use. - /// The converted value. - /// - public override Failure Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - throw new NotImplementedException(); - } - - /// - /// Writes a specified value as JSON. - /// - /// The writer to write to. - /// The value to convert to JSON. - /// An object that specifies serialization options to use. - public override void Write(Utf8JsonWriter writer, Failure value, JsonSerializerOptions options) - { - writer.WriteStartObject(); - writer.WriteString(options.PropertyNamingPolicy.DefaultOrConvertName(nameof(value.Type)), value.Type); - - WriteException(writer, value, options); - - writer.WriteEndObject(); - } - - private static void WriteException(Utf8JsonWriter writer, Failure value, JsonSerializerOptions options) - { - if (!string.IsNullOrWhiteSpace(value.Source)) { writer.WriteString(options.SetPropertyName(nameof(value.Source)), value.Source); } - if (!string.IsNullOrWhiteSpace(value.Message)) { writer.WriteString(options.SetPropertyName(nameof(value.Message)), value.Message); } - - if (value.Stack.Any()) - { - writer.WritePropertyName(options.SetPropertyName(nameof(value.Stack))); - writer.WriteStartArray(); - foreach (var line in value.Stack) - { - writer.WriteStringValue(line); - } - writer.WriteEndArray(); - } - - if (value.Data.Count > 0) - { - writer.WritePropertyName(options.SetPropertyName(nameof(value.Data))); - writer.WriteStartObject(); - foreach (var kvp in value.Data) - { - writer.WritePropertyName(options.SetPropertyName(nameof(kvp.Key))); - writer.WriteObject(kvp.Value, options); - } - writer.WriteEndObject(); - } - - foreach (var kvp in value) - { - writer.WritePropertyName(options.SetPropertyName(kvp.Key)); - writer.WriteObject(kvp.Value, options); - } - - WriteInnerExceptions(writer, value, options); - } - - private static void WriteInnerExceptions(Utf8JsonWriter writer, Failure value, JsonSerializerOptions options) - { - var exception = value.GetUnderlyingException(); - var innerExceptions = new List(); - if (exception is AggregateException aggregated) - { - innerExceptions.AddRange(aggregated.Flatten().InnerExceptions); - } - else - { - if (exception.InnerException != null) { innerExceptions.Add(exception.InnerException); } - } - if (innerExceptions.Count > 0) - { - var endElementsToWrite = 0; - foreach (var inner in innerExceptions) - { - var innerValue = new Failure(inner, value.GetUnderlyingSensitivity()); - writer.WritePropertyName(options.SetPropertyName("Inner")); - writer.WriteStartObject(); - writer.WriteString(options.SetPropertyName(nameof(value.Type)), innerValue.Type); - WriteException(writer, innerValue, options); - endElementsToWrite++; - } - - for (var i = 0; i < endElementsToWrite; i++) { writer.WriteEndObject(); } - } - } - } -} diff --git a/src/Cuemon.Extensions.Text.Json/Converters/JsonConverterCollectionExtensions.cs b/src/Cuemon.Extensions.Text.Json/Converters/JsonConverterCollectionExtensions.cs index 4a9206b8a..e384ddb53 100644 --- a/src/Cuemon.Extensions.Text.Json/Converters/JsonConverterCollectionExtensions.cs +++ b/src/Cuemon.Extensions.Text.Json/Converters/JsonConverterCollectionExtensions.cs @@ -181,7 +181,10 @@ public static ICollection AddExceptionConverter(this ICollection< /// A reference to after the operation has completed. public static ICollection AddFailureConverter(this ICollection converters) { - converters.Add(new FailureConverter()); + converters.Add(DynamicJsonConverter.Create((writer, failure, options) => + { + new ExceptionConverter(failure.GetUnderlyingSensitivity().HasFlag(FaultSensitivityDetails.StackTrace), failure.GetUnderlyingSensitivity().HasFlag(FaultSensitivityDetails.Data)).Write(writer, failure.GetUnderlyingException(), options); + })); return converters; } diff --git a/test/Cuemon.AspNetCore.FunctionalTests/Diagnostics/ApplicationBuilderExtensionsTest.cs b/test/Cuemon.AspNetCore.FunctionalTests/Diagnostics/ApplicationBuilderExtensionsTest.cs index 8e214c7d0..ed1514087 100644 --- a/test/Cuemon.AspNetCore.FunctionalTests/Diagnostics/ApplicationBuilderExtensionsTest.cs +++ b/test/Cuemon.AspNetCore.FunctionalTests/Diagnostics/ApplicationBuilderExtensionsTest.cs @@ -379,7 +379,7 @@ public async Task UseFaultDescriptorExceptionHandler_ShouldCaptureException_Rend "at Cuemon.AspNetCore.Diagnostics.ApplicationBuilderExtensionsTest.<>c.<c.< Date: Mon, 14 Oct 2024 21:43:32 +0200 Subject: [PATCH 02/12] :sparkles: extended with new method; RawEnclose --- src/Cuemon.Core/Decorator.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Cuemon.Core/Decorator.cs b/src/Cuemon.Core/Decorator.cs index e4a9295b6..e7d9864f2 100644 --- a/src/Cuemon.Core/Decorator.cs +++ b/src/Cuemon.Core/Decorator.cs @@ -29,6 +29,18 @@ public static Decorator Enclose(T inner, bool throwIfNull = true) return new Decorator(inner, throwIfNull); } + /// + /// Encloses the specified so that it can be extended by non-common extension methods. + /// + /// The type of the to wrap for non-common extension methods. + /// The object to extend for non-common extension methods. + /// An instance of . + /// Unlike , this method does not perform a null-check when wrapping the value. + public static Decorator RawEnclose(T inner) + { + return Enclose(inner, false); + } + /// /// Encloses the specified so that it can be extended by both common and non-common extension methods. /// From ecc8a3e444f40c1959e59a68059b2dc4fafde573 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 14 Oct 2024 21:46:50 +0200 Subject: [PATCH 03/12] :recycle: moved internal ResolveDelegateInfo to public extension method hidden by IDecorator, incl. consequence changes --- src/Cuemon.Core/ActionFactory.cs | 2 +- .../Extensions/DelegateDecoratorExtensions.cs | 27 +++++++++++++++++++ src/Cuemon.Core/FuncFactory.cs | 2 +- src/Cuemon.Core/Infrastructure.cs | 12 ++------- src/Cuemon.Core/TesterFuncFactory.cs | 2 +- 5 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 src/Cuemon.Core/Extensions/DelegateDecoratorExtensions.cs diff --git a/src/Cuemon.Core/ActionFactory.cs b/src/Cuemon.Core/ActionFactory.cs index 11f1c0254..ecca65a15 100644 --- a/src/Cuemon.Core/ActionFactory.cs +++ b/src/Cuemon.Core/ActionFactory.cs @@ -486,7 +486,7 @@ public ActionFactory(Action method, TTuple tuple) : this(method, tuple, internal ActionFactory(Action method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; - DelegateInfo = Infrastructure.ResolveDelegateInfo(method, originalDelegate); + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); } /// diff --git a/src/Cuemon.Core/Extensions/DelegateDecoratorExtensions.cs b/src/Cuemon.Core/Extensions/DelegateDecoratorExtensions.cs new file mode 100644 index 000000000..abe2e4fcb --- /dev/null +++ b/src/Cuemon.Core/Extensions/DelegateDecoratorExtensions.cs @@ -0,0 +1,27 @@ +using System; +using System.Reflection; + +namespace Cuemon +{ + /// + /// Extension methods for the hidden behind the interface. + /// + /// + /// + public static class DelegateDecoratorExtensions + { + /// + /// Resolves the of the specified delegate or the enclosed of the . + /// + /// The to extend. + /// The original delegate to resolve the method information from. + /// The of the specified delegate or the enclosed of the ; otherwise, null if both are null. + public static MethodInfo ResolveDelegateInfo(this IDecorator decorator, Delegate original) + { + var wrapper = decorator?.Inner; + if (original != null) { return original.GetMethodInfo(); } + if (wrapper != null) { return wrapper.GetMethodInfo(); } + return null; + } + } +} diff --git a/src/Cuemon.Core/FuncFactory.cs b/src/Cuemon.Core/FuncFactory.cs index afb0d6b59..d89be450d 100644 --- a/src/Cuemon.Core/FuncFactory.cs +++ b/src/Cuemon.Core/FuncFactory.cs @@ -506,7 +506,7 @@ public FuncFactory(Func method, TTuple tuple) : this(method, tu internal FuncFactory(Func method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; - DelegateInfo = Infrastructure.ResolveDelegateInfo(method, originalDelegate); + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); } /// diff --git a/src/Cuemon.Core/Infrastructure.cs b/src/Cuemon.Core/Infrastructure.cs index 7dbeeb0e2..0bee963ba 100644 --- a/src/Cuemon.Core/Infrastructure.cs +++ b/src/Cuemon.Core/Infrastructure.cs @@ -1,20 +1,12 @@ -using System; -using System.Reflection; +using System.Reflection; namespace Cuemon { internal static class Infrastructure { - internal static MethodInfo ResolveDelegateInfo(Delegate wrapper, Delegate original) - { - if (original != null) { return original.GetMethodInfo(); } - if (wrapper != null) { return wrapper.GetMethodInfo(); } - return null; - } - internal static object DefaultPropertyValueResolver(object source, PropertyInfo pi) { return source == null ? null : pi.GetValue(source, null); } } -} \ No newline at end of file +} diff --git a/src/Cuemon.Core/TesterFuncFactory.cs b/src/Cuemon.Core/TesterFuncFactory.cs index 68cb80c84..f43b51d40 100644 --- a/src/Cuemon.Core/TesterFuncFactory.cs +++ b/src/Cuemon.Core/TesterFuncFactory.cs @@ -527,7 +527,7 @@ public TesterFuncFactory(TesterFunc method, TTuple tu internal TesterFuncFactory(TesterFunc method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; - DelegateInfo = Infrastructure.ResolveDelegateInfo(method, originalDelegate); + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); } /// From 2aed276bc3e21bd758b21d27d4997569aff908cb Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 14 Oct 2024 22:00:43 +0200 Subject: [PATCH 04/12] :building_construction: move SafeInvokeAsync to specialized assembly and new static class; AsyncPatterns --- src/Cuemon.Core/Patterns.cs | 184 +------------------------ src/Cuemon.Threading/AsyncPatterns.cs | 190 ++++++++++++++++++++++++++ 2 files changed, 196 insertions(+), 178 deletions(-) create mode 100644 src/Cuemon.Threading/AsyncPatterns.cs diff --git a/src/Cuemon.Core/Patterns.cs b/src/Cuemon.Core/Patterns.cs index 480fcc031..83b81e792 100644 --- a/src/Cuemon.Core/Patterns.cs +++ b/src/Cuemon.Core/Patterns.cs @@ -1,8 +1,6 @@ using System; using System.Linq; using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; using Cuemon.Configuration; namespace Cuemon @@ -210,7 +208,7 @@ public static Action ConfigureRevertExchange(TSource /// The type of the return value of the function delegate . /// The function delegate that initializes an object implementing the interface. /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, Action catcher = null) where TResult : class, IDisposable { @@ -229,7 +227,7 @@ public static TResult SafeInvoke(Func initializer, FuncThe function delegate that initializes an object implementing the interface. /// The function delegate that is used to ensure that operations performed on abides CA2000. /// The parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T arg, Action catcher = null) where TResult : class, IDisposable { @@ -250,7 +248,7 @@ public static TResult SafeInvoke(Func initializer, FuncThe function delegate that is used to ensure that operations performed on abides CA2000. /// The first parameter of the function delegate and delegate . /// The second parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T1 arg1, T2 arg2, Action catcher = null) where TResult : class, IDisposable { @@ -273,7 +271,7 @@ public static TResult SafeInvoke(Func initializer, Fun /// The first parameter of the function delegate and delegate . /// The second parameter of the function delegate and delegate . /// The third parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T1 arg1, T2 arg2, T3 arg3, Action catcher = null) where TResult : class, IDisposable { @@ -298,7 +296,7 @@ public static TResult SafeInvoke(Func initializer, /// The second parameter of the function delegate and delegate . /// The third parameter of the function delegate and delegate . /// The fourth parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action catcher = null) where TResult : class, IDisposable { @@ -325,7 +323,7 @@ public static TResult SafeInvoke(Func initiali /// The third parameter of the function delegate and delegate . /// The fourth parameter of the function delegate and delegate . /// The fifth parameter of the function delegate and delegate . - /// The delegate that will handle any exceptions might thrown by . + /// The delegate that will handle any exceptions that might have been thrown by . /// The return value of the function delegate if the operations succeeded; otherwise null if the operation failed. public static TResult SafeInvoke(Func initializer, Func tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action catcher = null) where TResult : class, IDisposable { @@ -336,144 +334,6 @@ public static TResult SafeInvoke(Func init return SafeInvokeCore(f1, initializer, f2); } - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default); - var f2 = TaskActionFactory.Create(catcher, default); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T arg, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg); - var f2 = TaskActionFactory.Create(catcher, default, arg); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the first parameter of the function delegate and delegate . - /// The type of the second parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The first parameter of the function delegate and delegate . - /// The second parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2); - var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the first parameter of the function delegate and delegate . - /// The type of the second parameter of the function delegate and delegate . - /// The type of the third parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The first parameter of the function delegate and delegate . - /// The second parameter of the function delegate and delegate . - /// The third parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, T3 arg3, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2, arg3); - var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2, arg3); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the first parameter of the function delegate and delegate . - /// The type of the second parameter of the function delegate and delegate . - /// The type of the third parameter of the function delegate and delegate . - /// The type of the fourth parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The first parameter of the function delegate and delegate . - /// The second parameter of the function delegate and delegate . - /// The third parameter of the function delegate and delegate . - /// The fourth parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2, arg3, arg4); - var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2, arg3, arg4); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - - /// - /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). - /// - /// The type of the first parameter of the function delegate and delegate . - /// The type of the second parameter of the function delegate and delegate . - /// The type of the third parameter of the function delegate and delegate . - /// The type of the fourth parameter of the function delegate and delegate . - /// The type of the fifth parameter of the function delegate and delegate . - /// The type of the return value of the function delegate . - /// The function delegate that initializes an object implementing the interface. - /// The function delegate that is used to ensure that operations performed on abides CA2000. - /// The first parameter of the function delegate and delegate . - /// The second parameter of the function delegate and delegate . - /// The third parameter of the function delegate and delegate . - /// The fourth parameter of the function delegate and delegate . - /// The fifth parameter of the function delegate and delegate . - /// The token to monitor for cancellation requests. The default value is . - /// The function delegate that will handle any exceptions might thrown by . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. - public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, CancellationToken ct = default, Func catcher = null) where TResult : class, IDisposable - { - Validator.ThrowIfNull(initializer); - Validator.ThrowIfNull(tester); - var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2, arg3, arg4, arg5); - var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2, arg3, arg4, arg5); - return SafeInvokeAsyncCore(f1, initializer, f2, ct); - } - private static TResult SafeInvokeCore(FuncFactory testerFactory, Func initializer, ActionFactory catcherFactory) where TResult : class, IDisposable where TTester : Template @@ -505,37 +365,5 @@ private static TResult SafeInvokeCore(FuncFactory SafeInvokeAsyncCore(TaskFuncFactory testerFactory, Func initializer, TaskActionFactory catcherFactory, CancellationToken ct) - where TResult : class, IDisposable - where TTester : Template - where TCatcher : Template - { - TResult result = null; - try - { - testerFactory.GenericArguments.Arg1 = initializer(); - testerFactory.GenericArguments.Arg1 = await testerFactory.ExecuteMethodAsync(ct).ConfigureAwait(false); - result = testerFactory.GenericArguments.Arg1; - testerFactory.GenericArguments.Arg1 = null; - } - catch (Exception e) - { - if (!catcherFactory.HasDelegate) - { - throw; - } - else - { - catcherFactory.GenericArguments.Arg1 = e; - await catcherFactory.ExecuteMethodAsync(ct).ConfigureAwait(false); - } - } - finally - { - testerFactory.GenericArguments.Arg1?.Dispose(); - } - return result; - } } } diff --git a/src/Cuemon.Threading/AsyncPatterns.cs b/src/Cuemon.Threading/AsyncPatterns.cs new file mode 100644 index 000000000..837b641b4 --- /dev/null +++ b/src/Cuemon.Threading/AsyncPatterns.cs @@ -0,0 +1,190 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Cuemon.Threading +{ + /// + /// Provides a generic way to support different types of design patterns and practices with small utility methods scoped to . + /// + public sealed class AsyncPatterns + { + private static readonly AsyncPatterns ExtendedPatterns = new(); + + /// + /// Gets the singleton instance of the AsyncPatterns functionality allowing for extensions methods like: AsyncPatterns.Use.SomeIngeniousMethod(). + /// + /// The singleton instance of the AsyncPatterns functionality. + public static AsyncPatterns Use { get; } = ExtendedPatterns; + + /// + /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). + /// + /// The type of the return value of the function delegate . + /// The function delegate that initializes an object implementing the interface. + /// The function delegate that is used to ensure that operations performed on abides CA2000. + /// The function delegate that will handle any exceptions that might have been thrown by . + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. + public static Task SafeInvokeAsync(Func initializer, Func> tester, Func catcher = null, CancellationToken ct = default) where TResult : class, IDisposable + { + Validator.ThrowIfNull(initializer); + Validator.ThrowIfNull(tester); + var f1 = TaskFuncFactory.Create(tester, default); + var f2 = TaskActionFactory.Create(catcher, default); + return SafeInvokeAsyncCore(f1, initializer, f2, ct); + } + + /// + /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). + /// + /// The type of the parameter of the function delegate and delegate . + /// The type of the return value of the function delegate . + /// The function delegate that initializes an object implementing the interface. + /// The function delegate that is used to ensure that operations performed on abides CA2000. + /// The parameter of the function delegate and delegate . + /// The function delegate that will handle any exceptions that might have been thrown by . + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. + public static Task SafeInvokeAsync(Func initializer, Func> tester, T arg, Func catcher = null, CancellationToken ct = default) where TResult : class, IDisposable + { + Validator.ThrowIfNull(initializer); + Validator.ThrowIfNull(tester); + var f1 = TaskFuncFactory.Create(tester, default, arg); + var f2 = TaskActionFactory.Create(catcher, default, arg); + return SafeInvokeAsyncCore(f1, initializer, f2, ct); + } + + /// + /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). + /// + /// The type of the first parameter of the function delegate and delegate . + /// The type of the second parameter of the function delegate and delegate . + /// The type of the return value of the function delegate . + /// The function delegate that initializes an object implementing the interface. + /// The function delegate that is used to ensure that operations performed on abides CA2000. + /// The first parameter of the function delegate and delegate . + /// The second parameter of the function delegate and delegate . + /// The function delegate that will handle any exceptions that might have been thrown by . + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. + public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, Func catcher = null, CancellationToken ct = default) where TResult : class, IDisposable + { + Validator.ThrowIfNull(initializer); + Validator.ThrowIfNull(tester); + var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2); + var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2); + return SafeInvokeAsyncCore(f1, initializer, f2, ct); + } + + /// + /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). + /// + /// The type of the first parameter of the function delegate and delegate . + /// The type of the second parameter of the function delegate and delegate . + /// The type of the third parameter of the function delegate and delegate . + /// The type of the return value of the function delegate . + /// The function delegate that initializes an object implementing the interface. + /// The function delegate that is used to ensure that operations performed on abides CA2000. + /// The first parameter of the function delegate and delegate . + /// The second parameter of the function delegate and delegate . + /// The third parameter of the function delegate and delegate . + /// The function delegate that will handle any exceptions that might have been thrown by . + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. + public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, T3 arg3, Func catcher = null, CancellationToken ct = default) where TResult : class, IDisposable + { + Validator.ThrowIfNull(initializer); + Validator.ThrowIfNull(tester); + var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2, arg3); + var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2, arg3); + return SafeInvokeAsyncCore(f1, initializer, f2, ct); + } + + /// + /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). + /// + /// The type of the first parameter of the function delegate and delegate . + /// The type of the second parameter of the function delegate and delegate . + /// The type of the third parameter of the function delegate and delegate . + /// The type of the fourth parameter of the function delegate and delegate . + /// The type of the return value of the function delegate . + /// The function delegate that initializes an object implementing the interface. + /// The function delegate that is used to ensure that operations performed on abides CA2000. + /// The first parameter of the function delegate and delegate . + /// The second parameter of the function delegate and delegate . + /// The third parameter of the function delegate and delegate . + /// The fourth parameter of the function delegate and delegate . + /// The function delegate that will handle any exceptions that might have been thrown by . + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. + public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Func catcher = null, CancellationToken ct = default) where TResult : class, IDisposable + { + Validator.ThrowIfNull(initializer); + Validator.ThrowIfNull(tester); + var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2, arg3, arg4); + var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2, arg3, arg4); + return SafeInvokeAsyncCore(f1, initializer, f2, ct); + } + + /// + /// Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope). + /// + /// The type of the first parameter of the function delegate and delegate . + /// The type of the second parameter of the function delegate and delegate . + /// The type of the third parameter of the function delegate and delegate . + /// The type of the fourth parameter of the function delegate and delegate . + /// The type of the fifth parameter of the function delegate and delegate . + /// The type of the return value of the function delegate . + /// The function delegate that initializes an object implementing the interface. + /// The function delegate that is used to ensure that operations performed on abides CA2000. + /// The first parameter of the function delegate and delegate . + /// The second parameter of the function delegate and delegate . + /// The third parameter of the function delegate and delegate . + /// The fourth parameter of the function delegate and delegate . + /// The fifth parameter of the function delegate and delegate . + /// The function delegate that will handle any exceptions that might have been thrown by . + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate if the operations succeeded; otherwise null if the operation failed. + public static Task SafeInvokeAsync(Func initializer, Func> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Func catcher = null, CancellationToken ct = default) where TResult : class, IDisposable + { + Validator.ThrowIfNull(initializer); + Validator.ThrowIfNull(tester); + var f1 = TaskFuncFactory.Create(tester, default, arg1, arg2, arg3, arg4, arg5); + var f2 = TaskActionFactory.Create(catcher, default, arg1, arg2, arg3, arg4, arg5); + return SafeInvokeAsyncCore(f1, initializer, f2, ct); + } + + private static async Task SafeInvokeAsyncCore(TaskFuncFactory testerFactory, Func initializer, TaskActionFactory catcherFactory, CancellationToken ct) + where TResult : class, IDisposable + where TTester : Template + where TCatcher : Template + { + TResult result = null; + try + { + testerFactory.GenericArguments.Arg1 = initializer(); + testerFactory.GenericArguments.Arg1 = await testerFactory.ExecuteMethodAsync(ct).ConfigureAwait(false); + result = testerFactory.GenericArguments.Arg1; + testerFactory.GenericArguments.Arg1 = null; + } + catch (Exception e) + { + if (!catcherFactory.HasDelegate) + { + throw; + } + else + { + catcherFactory.GenericArguments.Arg1 = e; + await catcherFactory.ExecuteMethodAsync(ct).ConfigureAwait(false); + } + } + finally + { + testerFactory.GenericArguments.Arg1?.Dispose(); + } + return result; + } + } +} From bca8c62b21363cb9ec435049ab4a57aff0d03bf3 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 14 Oct 2024 22:03:42 +0200 Subject: [PATCH 05/12] :building_construction: move Task-based Action and Func factories to specialized assembly (reduce footprint of core) --- src/Cuemon.Core/GlobalSuppressions.cs | 56 ------------------- .../GlobalSuppressions.cs | 1 - src/Cuemon.Threading/GlobalSuppressions.cs | 50 ++++++++++++++++- .../TaskActionFactory.cs | 4 +- .../TaskFuncFactory.cs | 4 +- 5 files changed, 53 insertions(+), 62 deletions(-) rename src/{Cuemon.Core => Cuemon.Threading}/TaskActionFactory.cs (99%) rename src/{Cuemon.Core => Cuemon.Threading}/TaskFuncFactory.cs (99%) diff --git a/src/Cuemon.Core/GlobalSuppressions.cs b/src/Cuemon.Core/GlobalSuppressions.cs index 70def55c9..8444fea6f 100644 --- a/src/Cuemon.Core/GlobalSuppressions.cs +++ b/src/Cuemon.Core/GlobalSuppressions.cs @@ -118,49 +118,6 @@ [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Func delegates.", Scope = "member", Target = "~M:Cuemon.FuncFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,``7},``0,``1,``2,``3,``4,``5,``6)~Cuemon.FuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7}")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Func delegates.", Scope = "member", Target = "~M:Cuemon.FuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.FuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Func delegates.", Scope = "member", Target = "~M:Cuemon.FuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.FuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``4(System.Func{``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``5(System.Func{``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``6(System.Func{``0,``1,``2,``3,``4,``5,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``7(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``7(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8}}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskActionFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8}}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task{``9}},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8},``9}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task{``10}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9},``10}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task{``11}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10},``11}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task{``12}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11},``12}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task{``13}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12},``13}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task{``14}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13},``14}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``16(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task{``15}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14},``15}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task{``7}},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task{``8}},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task{``9}},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8},``9}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task{``10}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9},``10}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task{``11}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10},``11}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task{``12}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11},``12}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task{``13}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12},``13}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task{``14}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13},``14}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``16(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task{``15}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14},``15}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``4(System.Func{``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task{``3}},``0,``1,``2)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2},``3}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``5(System.Func{``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3},``4}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``6(System.Func{``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4},``5}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``7(System.Func{``0,``1,``2,``3,``4,``5,System.Threading.CancellationToken,System.Threading.Tasks.Task{``6}},``0,``1,``2,``3,``4,``5)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5},``6}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task{``7}},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.TaskFuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task{``8}},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "A Func designed for the Tester pattern. Microsoft allows 17 arguments in there Func impl; so do i here.", Scope = "type", Target = "~T:Cuemon.TesterFunc`10")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "A Func designed for the Tester pattern. Microsoft allows 17 arguments in there Func impl; so do i here.", Scope = "type", Target = "~T:Cuemon.TesterFunc`11")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "A Func designed for the Tester pattern. Microsoft allows 17 arguments in there Func impl; so do i here.", Scope = "type", Target = "~T:Cuemon.TesterFunc`12")] @@ -198,14 +155,9 @@ [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for TesterFunc delegates.", Scope = "member", Target = "~M:Cuemon.TesterFuncFactory.Create``9(Cuemon.TesterFunc{``0,``1,``2,``3,``4,``5,``6,``7,``8},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TesterFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7,``8}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for TesterFunc delegates.", Scope = "type", Target = "~T:Cuemon.TesterFuncFactory`3")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvoke``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,``5},``0,``1,``2,``3,``4,System.Action{System.Exception,``0,``1,``2,``3,``4})~``5")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``4}")] -[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``5}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvoke``4(System.Func{``3},System.Func{``3,``0,``1,``2,``3},``0,``1,``2,System.Action{System.Exception,``0,``1,``2})~``3")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvoke``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,``4},``0,``1,``2,``3,System.Action{System.Exception,``0,``1,``2,``3})~``4")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvoke``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,``5},``0,``1,``2,``3,``4,System.Action{System.Exception,``0,``1,``2,``3,``4})~``5")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``4(System.Func{``3},System.Func{``3,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task{``3}},``0,``1,``2,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``3}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``4}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions)..", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``5}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Condition.FlipFlop``4(System.Boolean,System.Action{``0,``1,``2,``3},System.Action{``0,``1,``2,``3},``0,``1,``2,``3)")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Condition.FlipFlop``5(System.Boolean,System.Action{``0,``1,``2,``3,``4},System.Action{``0,``1,``2,``3,``4},``0,``1,``2,``3,``4)")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Condition.FlipFlop``5(System.Boolean,System.Action{``0,``1,``2,``3,``4},System.Action{``0,``1,``2,``3,``4},``0,``1,``2,``3,``4)")] @@ -217,15 +169,7 @@ [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Reflection.ActivatorFactory.CreateInstance``5(``0,``1,``2,``3,System.Action{Cuemon.Reflection.ActivatorOptions})~``4")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Reflection.ActivatorFactory.CreateInstance``6(``0,``1,``2,``3,``4,System.Action{Cuemon.Reflection.ActivatorOptions})~``5")] [assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "By design; although a good rule, this is the exception to the rule.", Scope = "member", Target = "~M:Cuemon.Calculator.CalculateCore``1(``0,``0,Cuemon.AssignmentOperator)~``0")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``1(System.Func{``0},System.Func{``0,System.Threading.CancellationToken,System.Threading.Tasks.Task{``0}},System.Threading.CancellationToken,System.Func{System.Exception,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``0}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``2(System.Func{``1},System.Func{``1,``0,System.Threading.CancellationToken,System.Threading.Tasks.Task{``1}},``0,System.Threading.CancellationToken,System.Func{System.Exception,``0,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``1}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``3(System.Func{``2},System.Func{``2,``0,``1,System.Threading.CancellationToken,System.Threading.Tasks.Task{``2}},``0,``1,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``2}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``4(System.Func{``3},System.Func{``3,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task{``3}},``0,``1,``2,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``3}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``4}")] -[assembly: SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "CancellationToken (ct) is more likely to be used than function delegate catcher, hence optimized for flow and consistency.", Scope = "member", Target = "~M:Cuemon.Patterns.SafeInvokeAsync``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Func{System.Exception,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task})~System.Threading.Tasks.Task{``5}")] [assembly: SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "Out of scope.", Scope = "type", Target = "~T:Cuemon.Collections.DataPairDictionary")] -[assembly: SuppressMessage("Performance", "CA1835:Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'", Justification = "Already fixed for .NET 5, but SonarCloud cannot figure out multiple framework support, eg. NETStandard 2.", Scope = "member", Target = "~M:Cuemon.ByteArrayDecoratorExtensions.ToStreamAsync(Cuemon.IDecorator{System.Byte[]},System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.IO.Stream}")] -[assembly: SuppressMessage("Performance", "CA1835:Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'", Justification = "Already fixed for .NET 5, but SonarCloud cannot figure out multiple framework support, eg. NETStandard 2.", Scope = "member", Target = "~M:Cuemon.StringDecoratorExtensions.ToStreamAsync(Cuemon.IDecorator{System.String},System.Action{Cuemon.Text.AsyncEncodingOptions})~System.Threading.Tasks.Task{System.IO.Stream}")] [assembly: SuppressMessage("Major Code Smell", "S3011:Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design.", Scope = "member", Target = "~F:Cuemon.Reflection.MemberReflection.Everything")] [assembly: SuppressMessage("Major Code Smell", "S3011:Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design.", Scope = "member", Target = "~M:Cuemon.Reflection.MemberReflection.#ctor(System.Action{Cuemon.Reflection.MemberReflectionOptions})")] [assembly: SuppressMessage("Major Code Smell", "S3011:Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design.", Scope = "member", Target = "~M:Cuemon.Globalization.ResourceAttribute.GetString(System.String)~System.String")] diff --git a/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs b/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs index 5369adb23..cbabe6827 100644 --- a/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs +++ b/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs @@ -8,4 +8,3 @@ [assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "Transitioned legacy code ;-)", Scope = "member", Target = "~M:Cuemon.Extensions.Text.Json.JsonReaderExtensions.ToHierarchy(System.Text.Json.Utf8JsonReader)~Cuemon.IHierarchy{Cuemon.DataPair}")] [assembly: SuppressMessage("Major Code Smell", "S907:\"goto\" statement should not be used", Justification = "Transitioned legacy code ;-)", Scope = "member", Target = "~M:Cuemon.Extensions.Text.Json.JsonReaderExtensions.ToHierarchy(System.Text.Json.Utf8JsonReader)~Cuemon.IHierarchy{Cuemon.DataPair}")] [assembly: SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "False-positive; .NET 7 reads this value.", Scope = "member", Target = "~P:Cuemon.Extensions.Text.Json.Converters.FlagsEnumConverter.TypeToConvert")] -[assembly: SuppressMessage("Major Code Smell", "S1172:Unused method parameters should be removed", Justification = "False-positive; value is conditionally used.", Scope = "member", Target = "~M:Cuemon.Extensions.Text.Json.Converters.ExceptionConverter.ParseJsonReader(System.Text.Json.Utf8JsonReader@,System.Type)~System.Collections.Generic.Stack{System.Collections.Generic.IList{Cuemon.Reflection.MemberArgument}}")] diff --git a/src/Cuemon.Threading/GlobalSuppressions.cs b/src/Cuemon.Threading/GlobalSuppressions.cs index 813a627fc..01a924588 100644 --- a/src/Cuemon.Threading/GlobalSuppressions.cs +++ b/src/Cuemon.Threading/GlobalSuppressions.cs @@ -54,7 +54,6 @@ [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.AdvancedParallelFactory.WhileResultAsync``8(``0,System.Func{System.Threading.Tasks.Task{System.Boolean}},System.Func{``0,``1},System.Func{``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task{``7}},``2,``3,``4,``5,``6,System.Action{Cuemon.Threading.AsyncWorkloadOptions})~System.Threading.Tasks.Task{System.Collections.Generic.IReadOnlyCollection{``7}}")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.AdvancedParallelFactory.WhileResultAsync``8(``0,System.Func{System.Threading.Tasks.Task{System.Boolean}},System.Func{``0,``1},System.Func{``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task{``7}},``2,``3,``4,``5,``6,System.Action{Cuemon.Threading.AsyncWorkloadOptions})~System.Threading.Tasks.Task{System.Collections.Generic.IReadOnlyCollection{``7}}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.AdvancedParallelFactory.WhileResultCore``4(Cuemon.Threading.ForwardIterator{``0,``1},Cuemon.FuncFactory{``2,``3},System.Action{Cuemon.Threading.AsyncTaskFactoryOptions})~System.Collections.Generic.IReadOnlyCollection{``3}")] -[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.AdvancedParallelFactory.WhileResultCoreAsync``4(Cuemon.Threading.AsyncForwardIterator{``0,``1},Cuemon.TaskFuncFactory{``2,``3},System.Action{Cuemon.Threading.AsyncWorkloadOptions})~System.Threading.Tasks.Task{System.Collections.Generic.IReadOnlyCollection{``3}}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.ParallelFactory.For``4(System.Int32,System.Int32,System.Action{System.Int32,``0,``1,``2,``3},``0,``1,``2,``3,System.Action{Cuemon.Threading.AsyncTaskFactoryOptions})")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.ParallelFactory.For``4(System.Int32,System.Int32,System.Action{System.Int32,``0,``1,``2,``3},``0,``1,``2,``3,System.Action{Cuemon.Threading.AsyncTaskFactoryOptions})")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.ParallelFactory.For``4(System.Int64,System.Int64,System.Action{System.Int64,``0,``1,``2,``3},``0,``1,``2,``3,System.Action{Cuemon.Threading.AsyncTaskFactoryOptions})")] @@ -110,3 +109,52 @@ [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.ParallelFactory.ForResultAsync``6(System.Int64,System.Int64,System.Func{System.Int64,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Action{Cuemon.Threading.AsyncWorkloadOptions})~System.Threading.Tasks.Task{System.Collections.Generic.IReadOnlyCollection{``5}}")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.ParallelFactory.ForResultAsync``6(System.Int64,System.Int64,System.Func{System.Int64,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Action{Cuemon.Threading.AsyncWorkloadOptions})~System.Threading.Tasks.Task{System.Collections.Generic.IReadOnlyCollection{``5}}")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "type", Target = "~T:Cuemon.Threading.FuncWhileSynchronousLoop`3")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``4(System.Func{``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``5(System.Func{``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``6(System.Func{``0,``1,``2,``3,``4,``5,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``7(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7}}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``7(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskActionFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.Threading.TaskActionFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8}}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task{``9}},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8},``9}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task{``10}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9},``10}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task{``11}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10},``11}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task{``12}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11},``12}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task{``13}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12},``13}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task{``14}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13},``14}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``16(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task{``15}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14},``15}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task{``7}},``0,``1,``2,``3,``4,``5,``6)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task{``8}},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``10(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,System.Threading.CancellationToken,System.Threading.Tasks.Task{``9}},``0,``1,``2,``3,``4,``5,``6,``7,``8)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8},``9}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``11(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,System.Threading.CancellationToken,System.Threading.Tasks.Task{``10}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9},``10}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``12(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,System.Threading.CancellationToken,System.Threading.Tasks.Task{``11}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10},``11}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``13(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,System.Threading.CancellationToken,System.Threading.Tasks.Task{``12}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11},``12}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``14(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,System.Threading.CancellationToken,System.Threading.Tasks.Task{``13}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12},``13}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``15(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,System.Threading.CancellationToken,System.Threading.Tasks.Task{``14}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13},``14}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``16(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,System.Threading.CancellationToken,System.Threading.Tasks.Task{``15}},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14},``15}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``4(System.Func{``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task{``3}},``0,``1,``2)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2},``3}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``5(System.Func{``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3},``4}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``6(System.Func{``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4},``5}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``7(System.Func{``0,``1,``2,``3,``4,``5,System.Threading.CancellationToken,System.Threading.Tasks.Task{``6}},``0,``1,``2,``3,``4,``5)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5},``6}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``8(System.Func{``0,``1,``2,``3,``4,``5,``6,System.Threading.CancellationToken,System.Threading.Tasks.Task{``7}},``0,``1,``2,``3,``4,``5,``6)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6},``7}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; think about it as a Tuple/Variadic - but for Task based Func delegates.", Scope = "member", Target = "~M:Cuemon.Threading.TaskFuncFactory.Create``9(System.Func{``0,``1,``2,``3,``4,``5,``6,``7,System.Threading.CancellationToken,System.Threading.Tasks.Task{``8}},``0,``1,``2,``3,``4,``5,``6,``7)~Cuemon.Threading.TaskFuncFactory{Cuemon.Template{``0,``1,``2,``3,``4,``5,``6,``7},``8}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.AsyncPatterns.SafeInvokeAsync``4(System.Func{``3},System.Func{``3,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task{``3}},``0,``1,``2,System.Func{System.Exception,``0,``1,``2,System.Threading.CancellationToken,System.Threading.Tasks.Task},System.Threading.CancellationToken)~System.Threading.Tasks.Task{``3}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.AsyncPatterns.SafeInvokeAsync``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3,System.Func{System.Exception,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task},System.Threading.CancellationToken)~System.Threading.Tasks.Task{``4}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.AsyncPatterns.SafeInvokeAsync``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Func{System.Exception,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task},System.Threading.CancellationToken)~System.Threading.Tasks.Task{``5}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.AsyncPatterns.SafeInvokeAsync``6(System.Func{``5},System.Func{``5,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task{``5}},``0,``1,``2,``3,``4,System.Func{System.Exception,``0,``1,``2,``3,``4,System.Threading.CancellationToken,System.Threading.Tasks.Task},System.Threading.CancellationToken)~System.Threading.Tasks.Task{``5}")] +[assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow up till 5 generic arguments.", Scope = "member", Target = "~M:Cuemon.Threading.AsyncPatterns.SafeInvokeAsync``5(System.Func{``4},System.Func{``4,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task{``4}},``0,``1,``2,``3,System.Func{System.Exception,``0,``1,``2,``3,System.Threading.CancellationToken,System.Threading.Tasks.Task},System.Threading.CancellationToken)~System.Threading.Tasks.Task{``4}")] +[assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design - AND private method.", Scope = "member", Target = "~M:Cuemon.Threading.AdvancedParallelFactory.WhileResultCoreAsync``4(Cuemon.Threading.AsyncForwardIterator{``0,``1},Cuemon.Threading.TaskFuncFactory{``2,``3},System.Action{Cuemon.Threading.AsyncWorkloadOptions})~System.Threading.Tasks.Task{System.Collections.Generic.IReadOnlyCollection{``3}}")] diff --git a/src/Cuemon.Core/TaskActionFactory.cs b/src/Cuemon.Threading/TaskActionFactory.cs similarity index 99% rename from src/Cuemon.Core/TaskActionFactory.cs rename to src/Cuemon.Threading/TaskActionFactory.cs index feb950340..ef3f77ebd 100644 --- a/src/Cuemon.Core/TaskActionFactory.cs +++ b/src/Cuemon.Threading/TaskActionFactory.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Cuemon +namespace Cuemon.Threading { /// /// Provides access to factory methods for creating instances that encapsulate a based function delegate with a variable amount of generic arguments. @@ -434,7 +434,7 @@ public TaskActionFactory(Func method, TTuple tu internal TaskActionFactory(Func method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; - DelegateInfo = Infrastructure.ResolveDelegateInfo(method, originalDelegate); + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); } /// diff --git a/src/Cuemon.Core/TaskFuncFactory.cs b/src/Cuemon.Threading/TaskFuncFactory.cs similarity index 99% rename from src/Cuemon.Core/TaskFuncFactory.cs rename to src/Cuemon.Threading/TaskFuncFactory.cs index f55959350..0f23dd52e 100644 --- a/src/Cuemon.Core/TaskFuncFactory.cs +++ b/src/Cuemon.Threading/TaskFuncFactory.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Cuemon +namespace Cuemon.Threading { /// /// Provides access to factory methods for creating instances that encapsulate a based function delegate with a variable amount of generic arguments. @@ -451,7 +451,7 @@ public TaskFuncFactory(Func> method, TT internal TaskFuncFactory(Func> method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; - DelegateInfo = Infrastructure.ResolveDelegateInfo(method, originalDelegate); + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); } /// From a2e4fbc3aba23401fc8923aea267ac0858de7fa2 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 14 Oct 2024 22:04:28 +0200 Subject: [PATCH 06/12] :building_construction: related to 2aed276 --- src/Cuemon.IO/Extensions/StreamDecoratorExtensions.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Cuemon.IO/Extensions/StreamDecoratorExtensions.cs b/src/Cuemon.IO/Extensions/StreamDecoratorExtensions.cs index cfe2aa658..02d2411ec 100644 --- a/src/Cuemon.IO/Extensions/StreamDecoratorExtensions.cs +++ b/src/Cuemon.IO/Extensions/StreamDecoratorExtensions.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Cuemon.Text; +using Cuemon.Threading; namespace Cuemon.IO { @@ -458,7 +459,7 @@ private static Stream Compress(IDecorator decorator, StreamCompressio private static Task CompressAsync(IDecorator decorator, AsyncStreamCompressionOptions options, Func decompressor) where T : Stream { - return Patterns.SafeInvokeAsync(() => new MemoryStream(), async (target, ct) => + return AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), async (target, ct) => { #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER await using (var compressed = decompressor(target, options.Level, true)) @@ -474,7 +475,7 @@ private static Task CompressAsync(IDecorator decorator, Async await target.FlushAsync(ct).ConfigureAwait(false); target.Position = 0; return target; - }, options.CancellationToken); + }, ct: options.CancellationToken); } private static Stream Decompress(IDecorator decorator, StreamCopyOptions options, Func compressor) where T : Stream @@ -494,7 +495,7 @@ private static Stream Decompress(IDecorator decorator, StreamCopyOpti private static Task DecompressAsync(IDecorator decorator, AsyncStreamCopyOptions options, Func compressor) where T : Stream { - return Patterns.SafeInvokeAsync(() => new MemoryStream(), async (target, ct) => + return AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), async (target, ct) => { #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER await using (var uncompressed = compressor(decorator.Inner, CompressionMode.Decompress, true)) @@ -510,7 +511,7 @@ private static Task DecompressAsync(IDecorator decorator, Asy await target.FlushAsync(ct).ConfigureAwait(false); target.Position = 0; return target; - }, options.CancellationToken); + }, ct:options.CancellationToken); } /// From ed49cef0ac28a25593f8d125b7accc97349ab056 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 14 Oct 2024 22:05:03 +0200 Subject: [PATCH 07/12] :recycle: reduced footprint in core assembly --- .../ByteArrayDecoratorExtensions.cs | 26 ---------------- .../Extensions/StringDecoratorExtensions.cs | 31 ------------------- .../ByteArrayExtensions.cs | 20 +++++++++--- src/Cuemon.Extensions.IO/StringExtensions.cs | 14 ++++++++- 4 files changed, 29 insertions(+), 62 deletions(-) diff --git a/src/Cuemon.Core/Extensions/ByteArrayDecoratorExtensions.cs b/src/Cuemon.Core/Extensions/ByteArrayDecoratorExtensions.cs index 4488b8ac9..2051e97bb 100644 --- a/src/Cuemon.Core/Extensions/ByteArrayDecoratorExtensions.cs +++ b/src/Cuemon.Core/Extensions/ByteArrayDecoratorExtensions.cs @@ -1,7 +1,5 @@ using System; using System.IO; -using System.Threading; -using System.Threading.Tasks; using Cuemon.Text; namespace Cuemon @@ -44,29 +42,5 @@ public static Stream ToStream(this IDecorator decorator) return ms; }); } - - /// - /// Converts the enclosed of the specified to its equivalent representation. - /// - /// The to extend. - /// The token to monitor for cancellation requests. The default value is . - /// A task that represents the asynchronous operation. The task result contains a that is equivalent to the enclosed of the specified . - /// - /// cannot be null. - /// - public static Task ToStreamAsync(this IDecorator decorator, CancellationToken ct = default) - { - Validator.ThrowIfNull(decorator); - return Patterns.SafeInvokeAsync(() => new MemoryStream(decorator.Inner.Length), async (ms, cti) => - { -#if NETSTANDARD - await ms.WriteAsync(decorator.Inner, 0, decorator.Inner.Length, cti).ConfigureAwait(false); -#else - await ms.WriteAsync(decorator.Inner.AsMemory(0, decorator.Inner.Length), cti).ConfigureAwait(false); -#endif - ms.Position = 0; - return ms; - }, ct); - } } } diff --git a/src/Cuemon.Core/Extensions/StringDecoratorExtensions.cs b/src/Cuemon.Core/Extensions/StringDecoratorExtensions.cs index 1b3120777..0e5bab3b5 100644 --- a/src/Cuemon.Core/Extensions/StringDecoratorExtensions.cs +++ b/src/Cuemon.Core/Extensions/StringDecoratorExtensions.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Text; -using System.Threading.Tasks; using Cuemon.Text; namespace Cuemon @@ -149,36 +148,6 @@ public static Stream ToStream(this IDecorator decorator, Action - /// Converts the enclosed of the specified to a . - /// - /// The to extend. - /// The which may be configured. - /// A task that represents the asynchronous operation. The task result contains a containing the result of the enclosed of the specified . - /// will be initialized with and . - /// - /// cannot be null. - /// - /// - /// was initialized with an invalid . - /// - public static Task ToStreamAsync(this IDecorator decorator, Action setup = null) - { - Validator.ThrowIfNull(decorator); - var options = Patterns.Configure(setup); - return Patterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, token) => - { - var bytes = Convertible.GetBytes(decorator.Inner, Patterns.ConfigureExchange(setup)); -#if NETSTANDARD - await ms.WriteAsync(bytes, 0, bytes.Length, token).ConfigureAwait(false); -#else - await ms.WriteAsync(bytes.AsMemory(0, bytes.Length), token).ConfigureAwait(false); -#endif - ms.Position = 0; - return ms; - }, options.CancellationToken); - } - /// /// Converts the enclosed of the specified to its equivalent representation. /// diff --git a/src/Cuemon.Extensions.IO/ByteArrayExtensions.cs b/src/Cuemon.Extensions.IO/ByteArrayExtensions.cs index d5f2e5b07..4fb8ddf15 100644 --- a/src/Cuemon.Extensions.IO/ByteArrayExtensions.cs +++ b/src/Cuemon.Extensions.IO/ByteArrayExtensions.cs @@ -1,6 +1,8 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; +using Cuemon.Threading; namespace Cuemon.Extensions.IO { @@ -24,17 +26,27 @@ public static Stream ToStream(this byte[] bytes) } /// - /// Converts the the specified to its equivalent representation. + /// Converts the specified to its equivalent representation. /// /// The to extend. + /// The token to monitor for cancellation requests. The default value is . /// A task that represents the asynchronous operation. The task result contains a that is equivalent to . /// /// cannot be null. /// - public static Task ToStreamAsync(this byte[] bytes) + public static Task ToStreamAsync(this byte[] bytes, CancellationToken cancellationToken = default) { Validator.ThrowIfNull(bytes); - return Decorator.Enclose(bytes).ToStreamAsync(); + return AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(bytes.Length), async (ms, cti) => + { +#if NETSTANDARD + await ms.WriteAsync(bytes, 0, bytes.Length, cti).ConfigureAwait(false); +#else + await ms.WriteAsync(bytes.AsMemory(0, bytes.Length), cti).ConfigureAwait(false); +#endif + ms.Position = 0; + return ms; + }, ct: cancellationToken); } } -} \ No newline at end of file +} diff --git a/src/Cuemon.Extensions.IO/StringExtensions.cs b/src/Cuemon.Extensions.IO/StringExtensions.cs index b1674108b..e6c585c45 100644 --- a/src/Cuemon.Extensions.IO/StringExtensions.cs +++ b/src/Cuemon.Extensions.IO/StringExtensions.cs @@ -3,6 +3,7 @@ using System.IO; using System.Threading.Tasks; using Cuemon.Text; +using Cuemon.Threading; namespace Cuemon.Extensions.IO { @@ -44,7 +45,18 @@ public static Stream ToStream(this string value, Action setup = /// public static Task ToStreamAsync(this string value, Action setup = null) { - return Decorator.Enclose(value).ToStreamAsync(setup); + Validator.ThrowIfInvalidConfigurator(setup, out var options); + return AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, token) => + { + var bytes = Convertible.GetBytes(value, Patterns.ConfigureExchange(setup)); +#if NETSTANDARD + await ms.WriteAsync(bytes, 0, bytes.Length, token).ConfigureAwait(false); +#else + await ms.WriteAsync(bytes.AsMemory(0, bytes.Length), token).ConfigureAwait(false); +#endif + ms.Position = 0; + return ms; + }, ct: options.CancellationToken); } /// From 85b2456315172ee8dbf5b38d398d819874ddf4ae Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 14 Oct 2024 22:05:42 +0200 Subject: [PATCH 08/12] :heavy_plus_sign: added reference to Cuemon.Diagnostics --- src/Cuemon.Diagnostics/Cuemon.Diagnostics.csproj | 3 ++- src/Cuemon.Diagnostics/TimeMeasure.Async.cs | 1 + src/Cuemon.Resilience/Cuemon.Resilience.csproj | 1 + src/Cuemon.Resilience/TransientOperation.Async.cs | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Cuemon.Diagnostics/Cuemon.Diagnostics.csproj b/src/Cuemon.Diagnostics/Cuemon.Diagnostics.csproj index 7ac56f284..919d59dd5 100644 --- a/src/Cuemon.Diagnostics/Cuemon.Diagnostics.csproj +++ b/src/Cuemon.Diagnostics/Cuemon.Diagnostics.csproj @@ -11,6 +11,7 @@ + - \ No newline at end of file + diff --git a/src/Cuemon.Diagnostics/TimeMeasure.Async.cs b/src/Cuemon.Diagnostics/TimeMeasure.Async.cs index 322001e3a..ab1b660aa 100644 --- a/src/Cuemon.Diagnostics/TimeMeasure.Async.cs +++ b/src/Cuemon.Diagnostics/TimeMeasure.Async.cs @@ -3,6 +3,7 @@ using System.Threading; using System.Threading.Tasks; using Cuemon.Reflection; +using Cuemon.Threading; namespace Cuemon.Diagnostics { diff --git a/src/Cuemon.Resilience/Cuemon.Resilience.csproj b/src/Cuemon.Resilience/Cuemon.Resilience.csproj index 07208406e..4258390d0 100644 --- a/src/Cuemon.Resilience/Cuemon.Resilience.csproj +++ b/src/Cuemon.Resilience/Cuemon.Resilience.csproj @@ -11,6 +11,7 @@ + \ No newline at end of file diff --git a/src/Cuemon.Resilience/TransientOperation.Async.cs b/src/Cuemon.Resilience/TransientOperation.Async.cs index fd9641c17..362d5a58a 100644 --- a/src/Cuemon.Resilience/TransientOperation.Async.cs +++ b/src/Cuemon.Resilience/TransientOperation.Async.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Cuemon.Threading; namespace Cuemon.Resilience { From e0beb79ec548a00047e17108f8f628d5e40f2187 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 14 Oct 2024 22:06:18 +0200 Subject: [PATCH 09/12] :white_check_mark: updated to reflect refactoring/restructuring --- .../Diagnostics/FaultDescriptorFilterTest.cs | 6 ++-- .../ByteArrayDecoratorExtensionsTest.cs | 17 +-------- test/Cuemon.Core.Tests/DisposableTest.cs | 17 ++++----- .../AssemblyDecoratorExtensionsTest.cs | 2 +- .../StringDecoratorExtensionsTest.cs | 16 +-------- .../StreamExtensionsTest.cs | 35 +++++++++++++++++-- test/Cuemon.IO.Tests/Cuemon.IO.Tests.csproj | 1 + .../StreamDecoratorExtensionsTest.cs | 17 ++++----- 8 files changed, 57 insertions(+), 54 deletions(-) diff --git a/test/Cuemon.AspNetCore.Mvc.FunctionalTests/Filters/Diagnostics/FaultDescriptorFilterTest.cs b/test/Cuemon.AspNetCore.Mvc.FunctionalTests/Filters/Diagnostics/FaultDescriptorFilterTest.cs index 068481cac..443d47740 100644 --- a/test/Cuemon.AspNetCore.Mvc.FunctionalTests/Filters/Diagnostics/FaultDescriptorFilterTest.cs +++ b/test/Cuemon.AspNetCore.Mvc.FunctionalTests/Filters/Diagnostics/FaultDescriptorFilterTest.cs @@ -93,7 +93,7 @@ public async Task OnException_ShouldCaptureException_RenderAsProblemDetails_Usin "at Cuemon.AspNetCore.Mvc.Assets.StatusCodesController.Get_XXX(String app)*" ], "data": { - "key": "serverError" + "app": "serverError" }, "paramName": "app" } @@ -170,7 +170,7 @@ public async Task OnException_ShouldCaptureException_RenderAsProblemDetails_Usin "at Cuemon.AspNetCore.Mvc.Assets.StatusCodesController.Get_XXX(String app)*" ], "data": { - "key": "serverError" + "app": "serverError" }, "paramName": "app" } @@ -196,7 +196,7 @@ public async Task OnException_ShouldCaptureException_RenderAsProblemDetails_Usin "source": "Cuemon.AspNetCore.Mvc.FunctionalTests", "message": "This is an inner exception message ... (Parameter 'app')", "data": { - "key": "serverError" + "app": "serverError" }, "paramName": "app" } diff --git a/test/Cuemon.Core.Tests/ByteArrayDecoratorExtensionsTest.cs b/test/Cuemon.Core.Tests/ByteArrayDecoratorExtensionsTest.cs index 6cdac72eb..88bb09bd2 100644 --- a/test/Cuemon.Core.Tests/ByteArrayDecoratorExtensionsTest.cs +++ b/test/Cuemon.Core.Tests/ByteArrayDecoratorExtensionsTest.cs @@ -26,20 +26,5 @@ public void ToStream_ShouldConvertByteArrayToStream() Assert.All(result, c => Assert.Equal('*', c)); } } - - [Fact] - public async Task ToStreamAsync_ShouldConvertByteArrayToStream() - { - var size = 1024 * 1024; - var fs = Generate.FixedString('*', size); - var fsBytes = Convertible.GetBytes(fs); - var s = await Decorator.Enclose(fsBytes).ToStreamAsync(); - using (var sr = new StreamReader(s)) - { - var result = await sr.ReadToEndAsync(); - Assert.Equal(size, s.Length); - Assert.All(result, c => Assert.Equal('*', c)); - } - } } -} \ No newline at end of file +} diff --git a/test/Cuemon.Core.Tests/DisposableTest.cs b/test/Cuemon.Core.Tests/DisposableTest.cs index ab93a3e44..43a1cdf2b 100644 --- a/test/Cuemon.Core.Tests/DisposableTest.cs +++ b/test/Cuemon.Core.Tests/DisposableTest.cs @@ -6,6 +6,7 @@ using Cuemon.Extensions.IO; using Codebelt.Extensions.Xunit; using Cuemon.IO; +using Cuemon.Threading; using Xunit; using Xunit.Abstractions; @@ -68,7 +69,7 @@ public async Task SafeInvokeAsync_ShouldAbideRuleCA2000() { var guid = Guid.NewGuid(); var called = 0; - var stream = await Patterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, ct) => + var stream = await AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, ct) => { called++; await ms.WriteAllAsync(new byte[] { 1 }, ct); @@ -81,17 +82,17 @@ public async Task SafeInvokeAsync_ShouldAbideRuleCA2000() MemoryStream msRef = null; called = 0; - stream = await Patterns.SafeInvokeAsync(() => new MemoryStream(), (ms, g, ct) => + stream = await AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), (ms, g, ct) => { msRef = ms; Assert.Equal(guid, g); throw new InvalidOperationException(); - }, guid, default, (exception, g, ct) => + }, guid, (exception, g, ct) => { Assert.Equal(guid, g); Assert.True(exception is InvalidOperationException); return Task.CompletedTask; - }); + }, default); Assert.Equal(0, called); Assert.Null(stream); Assert.Throws(() => msRef.Length); @@ -101,7 +102,7 @@ await Assert.ThrowsAsync(async () => var ctsShouldFail = new CancellationTokenSource(TimeSpan.FromMilliseconds(5)); msRef = null; called = 0; - stream = await Patterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, g, ct) => + stream = await AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, g, ct) => { msRef = ms; Assert.Equal(guid, g); @@ -109,18 +110,18 @@ await Assert.ThrowsAsync(async () => await ms.WriteAllAsync(new byte[] { 1 }, ct); ms.Position = 0; return ms; - }, guid, ctsShouldFail.Token, (exception, g, ct) => + }, guid, (exception, g, ct) => { Assert.Equal(guid, g); Assert.True(exception is TaskCanceledException); return Task.CompletedTask; - }); + }, ctsShouldFail.Token); Assert.Equal(0, called); Assert.Null(stream); Assert.Throws(() => msRef.Length); }); - stream = await Patterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, n1, n2, n3, n4, n5, ct) => + stream = await AsyncPatterns.SafeInvokeAsync(() => new MemoryStream(), async (ms, n1, n2, n3, n4, n5, ct) => { called++; var bytes = Decorator.Enclose($"{n1}{n2}{n3}{n4}{n5}").ToByteArray(); diff --git a/test/Cuemon.Core.Tests/Reflection/AssemblyDecoratorExtensionsTest.cs b/test/Cuemon.Core.Tests/Reflection/AssemblyDecoratorExtensionsTest.cs index cff1e548b..970c3f68b 100644 --- a/test/Cuemon.Core.Tests/Reflection/AssemblyDecoratorExtensionsTest.cs +++ b/test/Cuemon.Core.Tests/Reflection/AssemblyDecoratorExtensionsTest.cs @@ -41,7 +41,7 @@ public void GetTypes_ShouldReturnAllTypesFromCuemonCore() TestOutput.WriteLine(disposableTypes.ToDelimitedString()); - Assert.InRange(allTypesCount, 475, 575); // range because of tooling on CI adding dynamic types and high range of refactoring + Assert.InRange(allTypesCount, 425, 525); // range because of tooling on CI adding dynamic types and high range of refactoring Assert.Equal(5, disposableTypesCount); Assert.Equal(4, configurationTypesCount); } diff --git a/test/Cuemon.Core.Tests/StringDecoratorExtensionsTest.cs b/test/Cuemon.Core.Tests/StringDecoratorExtensionsTest.cs index 5968ba937..ccf3e692c 100644 --- a/test/Cuemon.Core.Tests/StringDecoratorExtensionsTest.cs +++ b/test/Cuemon.Core.Tests/StringDecoratorExtensionsTest.cs @@ -68,19 +68,5 @@ public void ToStream_ShouldConvertStringToStream() Assert.Equal(rs, result); } } - - [Fact] - public async Task ToStreamAsync_ShouldConvertStringToStream() - { - var size = 2048; - var rs = Generate.RandomString(size); - var s = await Decorator.Enclose(rs).ToStreamAsync(); - using (var sr = new StreamReader(s)) - { - var result = await sr.ReadToEndAsync(); - Assert.Equal(size, s.Length); - Assert.Equal(rs, result); - } - } } -} \ No newline at end of file +} diff --git a/test/Cuemon.Extensions.IO.Tests/StreamExtensionsTest.cs b/test/Cuemon.Extensions.IO.Tests/StreamExtensionsTest.cs index 541ca3b89..e871b8066 100644 --- a/test/Cuemon.Extensions.IO.Tests/StreamExtensionsTest.cs +++ b/test/Cuemon.Extensions.IO.Tests/StreamExtensionsTest.cs @@ -275,7 +275,7 @@ public async Task CompressBrotliAsync_ShouldThrowTaskCanceledException() var sut1 = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)); var size = 1024 * 1024; var sut2 = Generate.RandomString(size); - var sut3 = await Decorator.Enclose(sut2).ToStreamAsync(); + var sut3 = await sut2.ToStreamAsync(); await Assert.ThrowsAsync(async () => { await Task.Delay(TimeSpan.FromMilliseconds(100), sut1.Token); @@ -339,7 +339,7 @@ public async Task CompressGZipAsync_ShouldThrowTaskCanceledException() var sut1 = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)); var size = 1024 * 1024; var sut2 = Generate.RandomString(size); - var sut3 = await Decorator.Enclose(sut2).ToStreamAsync(); + var sut3 = await sut2.ToStreamAsync(); await Assert.ThrowsAsync(async () => { await Task.Delay(TimeSpan.FromMilliseconds(100), sut1.Token); @@ -401,12 +401,41 @@ public async Task CompressDeflateAsync_ShouldThrowTaskCanceledException() var sut1 = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)); var size = 1024 * 1024; var sut2 = Generate.RandomString(size); - var sut3 = await Decorator.Enclose(sut2).ToStreamAsync(); + var sut3 = await sut2.ToStreamAsync(); await Assert.ThrowsAsync(async () => { await Task.Delay(TimeSpan.FromMilliseconds(100), sut1.Token); await sut3.CompressDeflateAsync(o => o.CancellationToken = sut1.Token); }); } + + [Fact] + public async Task ToStreamAsync_ShouldConvertStringToStream() + { + var size = 2048; + var rs = Generate.RandomString(size); + var s = await rs.ToStreamAsync(); + using (var sr = new StreamReader(s)) + { + var result = await sr.ReadToEndAsync(); + Assert.Equal(size, s.Length); + Assert.Equal(rs, result); + } + } + + [Fact] + public async Task ToStreamAsync_ShouldConvertByteArrayToStream() + { + var size = 1024 * 1024; + var fs = Generate.FixedString('*', size); + var fsBytes = Convertible.GetBytes(fs); + var s = await fsBytes.ToStreamAsync(); + using (var sr = new StreamReader(s)) + { + var result = await sr.ReadToEndAsync(); + Assert.Equal(size, s.Length); + Assert.All(result, c => Assert.Equal('*', c)); + } + } } } diff --git a/test/Cuemon.IO.Tests/Cuemon.IO.Tests.csproj b/test/Cuemon.IO.Tests/Cuemon.IO.Tests.csproj index cbbf40002..f4119be8e 100644 --- a/test/Cuemon.IO.Tests/Cuemon.IO.Tests.csproj +++ b/test/Cuemon.IO.Tests/Cuemon.IO.Tests.csproj @@ -5,6 +5,7 @@ + diff --git a/test/Cuemon.IO.Tests/StreamDecoratorExtensionsTest.cs b/test/Cuemon.IO.Tests/StreamDecoratorExtensionsTest.cs index 2213bca6b..89f63c981 100644 --- a/test/Cuemon.IO.Tests/StreamDecoratorExtensionsTest.cs +++ b/test/Cuemon.IO.Tests/StreamDecoratorExtensionsTest.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Codebelt.Extensions.Xunit; +using Cuemon.Extensions.IO; using Xunit; using Xunit.Abstractions; @@ -47,7 +48,7 @@ public async Task CompressBrotliAsync_ShouldCompressAndDecompress() { var size = 1024 * 1024; var fs = Generate.RandomString(size); - var os = await Decorator.Enclose(fs).ToStreamAsync(); + var os = await fs.ToStreamAsync(); var cos = await Decorator.Enclose(os).CompressBrotliAsync(); var dos = await Decorator.Enclose(cos).DecompressBrotliAsync(); var osResult = await Decorator.Enclose(os).ToEncodedStringAsync(o => o.LeaveOpen = true); @@ -72,7 +73,7 @@ public async Task CompressBrotliAsync_ShouldThrowTaskCanceledException() var ctsShouldFail = new CancellationTokenSource(TimeSpan.FromMilliseconds(5)); var size = 1024 * 1024; var fs = Generate.RandomString(size); - var os = await Decorator.Enclose(fs).ToStreamAsync(); + var os = await fs.ToStreamAsync(); await Assert.ThrowsAsync(async () => { await Task.Delay(TimeSpan.FromMilliseconds(100), ctsShouldFail.Token); @@ -111,7 +112,7 @@ public async Task CompressGZipAsync_ShouldCompressAndDecompress() { var size = 1024 * 1024; var fs = Generate.RandomString(size); - var os = await Decorator.Enclose(fs).ToStreamAsync(); + var os = await fs.ToStreamAsync(); var cos = await Decorator.Enclose(os).CompressGZipAsync(); var dos = await Decorator.Enclose(cos).DecompressGZipAsync(); var osResult = await Decorator.Enclose(os).ToEncodedStringAsync(o => o.LeaveOpen = true); @@ -136,7 +137,7 @@ public async Task CompressGZipAsync_ShouldThrowTaskCanceledException() var ctsShouldFail = new CancellationTokenSource(TimeSpan.FromMilliseconds(5)); var size = 1024 * 1024; var fs = Generate.RandomString(size); - var os = await Decorator.Enclose(fs).ToStreamAsync(); + var os = await fs.ToStreamAsync(); await Assert.ThrowsAsync(async () => { await Task.Delay(TimeSpan.FromMilliseconds(100), ctsShouldFail.Token); @@ -173,7 +174,7 @@ public async Task CompressDeflateAsync_ShouldCompressAndDecompress() { var size = 1024 * 1024; var fs = Generate.RandomString(size); - var os = await Decorator.Enclose(fs).ToStreamAsync(); + var os = await fs.ToStreamAsync(); var cos = await Decorator.Enclose(os).CompressDeflateAsync(); var dos = await Decorator.Enclose(cos).DecompressDeflateAsync(); var osResult = await Decorator.Enclose(os).ToEncodedStringAsync(o => o.LeaveOpen = true); @@ -198,7 +199,7 @@ public async Task CompressDeflateAsync_ShouldThrowTaskCanceledException() var ctsShouldFail = new CancellationTokenSource(TimeSpan.FromMilliseconds(5)); var size = 1024 * 1024; var fs = Generate.RandomString(size); - var os = await Decorator.Enclose(fs).ToStreamAsync(); + var os = await fs.ToStreamAsync(); await Assert.ThrowsAsync(async () => { await Task.Delay(TimeSpan.FromMilliseconds(100), ctsShouldFail.Token); @@ -277,9 +278,9 @@ public async Task ToEncodedStringAsync_ShouldConvertStreamToString() var fs = Generate.RandomString(size, "æøåÆØÅ"); var fsBytesUnicode = Convertible.GetBytes(fs); var fsBytesIso88591 = Convertible.GetBytes(fs, o => o.Encoding = enc); - var sUnicode = await Decorator.Enclose(fsBytesUnicode).ToStreamAsync(); + var sUnicode = await fsBytesUnicode.ToStreamAsync(); var sUnicodeLength = sUnicode.Length; - var sIso88591 = await Decorator.Enclose(fsBytesIso88591).ToStreamAsync(); + var sIso88591 = await fsBytesIso88591.ToStreamAsync(); var sIso88591Length = sIso88591.Length; var resultUnicode = await Decorator.Enclose(sUnicode).ToEncodedStringAsync(o => o.LeaveOpen = true); var resultIso88591 = await Decorator.Enclose(sIso88591).ToEncodedStringAsync(o => From 40ac494f46e71591533bdb0c19cf678455de8b01 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 14 Oct 2024 22:07:49 +0200 Subject: [PATCH 10/12] :arrow_up: bumbed dependency --- .../Cuemon.Extensions.Globalization.csproj | 2 +- tooling/gse/gse.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cuemon.Extensions.Globalization/Cuemon.Extensions.Globalization.csproj b/src/Cuemon.Extensions.Globalization/Cuemon.Extensions.Globalization.csproj index 8f4c3bf71..088e67c75 100644 --- a/src/Cuemon.Extensions.Globalization/Cuemon.Extensions.Globalization.csproj +++ b/src/Cuemon.Extensions.Globalization/Cuemon.Extensions.Globalization.csproj @@ -1200,7 +1200,7 @@ - + diff --git a/tooling/gse/gse.csproj b/tooling/gse/gse.csproj index 0f5630575..9f7dd76e5 100644 --- a/tooling/gse/gse.csproj +++ b/tooling/gse/gse.csproj @@ -19,7 +19,7 @@ - + From f1799f82fa9f690db0066f79ad5680bb39da0975 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 14 Oct 2024 22:24:00 +0200 Subject: [PATCH 11/12] :recycle: organic split that is true to vision --- .../Threading/TaskActionFactory.cs | 68 ++++++++++++++++++ src/Cuemon.Core/Threading/TaskFuncFactory.cs | 69 +++++++++++++++++++ src/Cuemon.Threading/TaskActionFactory.cs | 64 +---------------- src/Cuemon.Threading/TaskFuncFactory.cs | 67 +----------------- 4 files changed, 140 insertions(+), 128 deletions(-) create mode 100644 src/Cuemon.Core/Threading/TaskActionFactory.cs create mode 100644 src/Cuemon.Core/Threading/TaskFuncFactory.cs diff --git a/src/Cuemon.Core/Threading/TaskActionFactory.cs b/src/Cuemon.Core/Threading/TaskActionFactory.cs new file mode 100644 index 000000000..af86f5aeb --- /dev/null +++ b/src/Cuemon.Core/Threading/TaskActionFactory.cs @@ -0,0 +1,68 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Cuemon.Threading +{ + /// + /// Provides an easy way of invoking an delegate regardless of the amount of parameters provided. + /// + /// The type of the n-tuple representation of a . + public sealed class TaskActionFactory : TemplateFactory where TTuple : Template + { + /// + /// Initializes a new instance of the class. + /// + /// The based function delegate to invoke. + /// The n-tuple argument of . + public TaskActionFactory(Func method, TTuple tuple) : this(method, tuple, method) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The based function delegate to invoke. + /// The n-tuple argument of . + /// The original delegate wrapped by . + public TaskActionFactory(Func method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) + { + Method = method; + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); + } + + /// + /// Gets the delegate to invoke. + /// + /// The delegate to invoke. + private Func Method { get; } + + /// + /// Executes the delegate associated with this instance. + /// + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. + /// + /// No delegate was specified on the factory. + /// + /// + /// The was canceled. + /// + public Task ExecuteMethodAsync(CancellationToken ct) + { + ThrowIfNoValidDelegate(Condition.IsNull(Method)); + ct.ThrowIfCancellationRequested(); + return Method.Invoke(GenericArguments, ct); + } + + /// + /// Creates a shallow copy of the current object. + /// + /// A new that is a copy of this instance. + /// When thread safety is required this is the method to invoke. + public override TemplateFactory Clone() + { + return new TaskActionFactory(Method, GenericArguments.Clone() as TTuple); + } + } +} diff --git a/src/Cuemon.Core/Threading/TaskFuncFactory.cs b/src/Cuemon.Core/Threading/TaskFuncFactory.cs new file mode 100644 index 000000000..adb9f0726 --- /dev/null +++ b/src/Cuemon.Core/Threading/TaskFuncFactory.cs @@ -0,0 +1,69 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Cuemon.Threading +{ + /// + /// Provides an easy way of invoking an function delegate regardless of the amount of parameters provided. + /// + /// The type of the n-tuple representation of a . + /// The type of the return value of the function delegate . + public sealed class TaskFuncFactory : TemplateFactory where TTuple : Template + { + /// + /// Initializes a new instance of the class. + /// + /// The function delegate to invoke. + /// The n-tuple argument of . + public TaskFuncFactory(Func> method, TTuple tuple) : this(method, tuple, method) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The function delegate to invoke. + /// The n-tuple argument of . + /// The original delegate wrapped by . + public TaskFuncFactory(Func> method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) + { + Method = method; + DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); + } + + /// + /// Gets the function delegate to invoke. + /// + /// The function delegate to invoke. + private Func> Method { get; set; } + + /// + /// Executes the function delegate associated with this instance. + /// + /// The token to monitor for cancellation requests. The default value is . + /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate associated with this instance. + /// + /// No delegate was specified on the factory. + /// + /// + /// The was canceled. + /// + public Task ExecuteMethodAsync(CancellationToken ct) + { + ThrowIfNoValidDelegate(Condition.IsNull(Method)); + ct.ThrowIfCancellationRequested(); + return Method.Invoke(GenericArguments, ct); + } + + /// + /// Creates a shallow copy of the current object. + /// + /// A new that is a copy of this instance. + /// When thread safety is required this is the method to invoke. + public override TemplateFactory Clone() + { + return new TaskFuncFactory(Method, GenericArguments.Clone() as TTuple); + } + } +} diff --git a/src/Cuemon.Threading/TaskActionFactory.cs b/src/Cuemon.Threading/TaskActionFactory.cs index ef3f77ebd..191201e5b 100644 --- a/src/Cuemon.Threading/TaskActionFactory.cs +++ b/src/Cuemon.Threading/TaskActionFactory.cs @@ -409,66 +409,4 @@ public static TaskActionFactory>((tuple, token) => method(tuple.Arg1, tuple.Arg2, tuple.Arg3, tuple.Arg4, tuple.Arg5, tuple.Arg6, tuple.Arg7, tuple.Arg8, tuple.Arg9, tuple.Arg10, tuple.Arg11, tuple.Arg12, tuple.Arg13, tuple.Arg14, tuple.Arg15, token), Template.CreateFifteen(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15), method); } } - - /// - /// Provides an easy way of invoking an delegate regardless of the amount of parameters provided. - /// - /// The type of the n-tuple representation of a . - public sealed class TaskActionFactory : TemplateFactory where TTuple : Template - { - /// - /// Initializes a new instance of the class. - /// - /// The based function delegate to invoke. - /// The n-tuple argument of . - public TaskActionFactory(Func method, TTuple tuple) : this(method, tuple, method) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The based function delegate to invoke. - /// The n-tuple argument of . - /// The original delegate wrapped by . - internal TaskActionFactory(Func method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) - { - Method = method; - DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); - } - - /// - /// Gets the delegate to invoke. - /// - /// The delegate to invoke. - private Func Method { get; } - - /// - /// Executes the delegate associated with this instance. - /// - /// The token to monitor for cancellation requests. The default value is . - /// A task that represents the asynchronous operation. - /// - /// No delegate was specified on the factory. - /// - /// - /// The was canceled. - /// - public Task ExecuteMethodAsync(CancellationToken ct) - { - ThrowIfNoValidDelegate(Condition.IsNull(Method)); - ct.ThrowIfCancellationRequested(); - return Method.Invoke(GenericArguments, ct); - } - - /// - /// Creates a shallow copy of the current object. - /// - /// A new that is a copy of this instance. - /// When thread safety is required this is the method to invoke. - public override TemplateFactory Clone() - { - return new TaskActionFactory(Method, GenericArguments.Clone() as TTuple); - } - } -} \ No newline at end of file +} diff --git a/src/Cuemon.Threading/TaskFuncFactory.cs b/src/Cuemon.Threading/TaskFuncFactory.cs index 0f23dd52e..c6b640033 100644 --- a/src/Cuemon.Threading/TaskFuncFactory.cs +++ b/src/Cuemon.Threading/TaskFuncFactory.cs @@ -17,7 +17,7 @@ public static class TaskFuncFactory /// An instance of object initialized with the specified . public static TaskFuncFactory Create(Func> method) { - return new TaskFuncFactory((tuple, token) => method(token), Template.CreateZero(), method); + return new TaskFuncFactory((_, token) => method(token), Template.CreateZero(), method); } /// @@ -425,67 +425,4 @@ public static TaskFuncFactory, TResult>((tuple, token) => method(tuple.Arg1, tuple.Arg2, tuple.Arg3, tuple.Arg4, tuple.Arg5, tuple.Arg6, tuple.Arg7, tuple.Arg8, tuple.Arg9, tuple.Arg10, tuple.Arg11, tuple.Arg12, tuple.Arg13, tuple.Arg14, tuple.Arg15, token), Template.CreateFifteen(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15), method); } } - - /// - /// Provides an easy way of invoking an function delegate regardless of the amount of parameters provided. - /// - /// The type of the n-tuple representation of a . - /// The type of the return value of the function delegate . - public sealed class TaskFuncFactory : TemplateFactory where TTuple : Template - { - /// - /// Initializes a new instance of the class. - /// - /// The function delegate to invoke. - /// The n-tuple argument of . - public TaskFuncFactory(Func> method, TTuple tuple) : this(method, tuple, method) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The function delegate to invoke. - /// The n-tuple argument of . - /// The original delegate wrapped by . - internal TaskFuncFactory(Func> method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) - { - Method = method; - DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); - } - - /// - /// Gets the function delegate to invoke. - /// - /// The function delegate to invoke. - private Func> Method { get; set; } - - /// - /// Executes the function delegate associated with this instance. - /// - /// The token to monitor for cancellation requests. The default value is . - /// A task that represents the asynchronous operation. The task result contains the return value of the function delegate associated with this instance. - /// - /// No delegate was specified on the factory. - /// - /// - /// The was canceled. - /// - public Task ExecuteMethodAsync(CancellationToken ct) - { - ThrowIfNoValidDelegate(Condition.IsNull(Method)); - ct.ThrowIfCancellationRequested(); - return Method.Invoke(GenericArguments, ct); - } - - /// - /// Creates a shallow copy of the current object. - /// - /// A new that is a copy of this instance. - /// When thread safety is required this is the method to invoke. - public override TemplateFactory Clone() - { - return new TaskFuncFactory(Method, GenericArguments.Clone() as TTuple); - } - } -} \ No newline at end of file +} From 92c163b6e74f310c34d023bec995c6f24b0ddadf Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Tue, 15 Oct 2024 00:44:07 +0200 Subject: [PATCH 12/12] :recycle: renamed for consistency to Async prefix --- ...ActionFactory.cs => AsyncActionFactory.cs} | 16 +-- ...TaskFuncFactory.cs => AsyncFuncFactory.cs} | 16 +-- src/Cuemon.Diagnostics/TimeMeasure.Async.cs | 48 +++---- .../TransientOperation.Async.cs | 28 ++-- .../AdvancedParallelFactory.ForAsync.cs | 14 +- .../AdvancedParallelFactory.ForResultAsync.cs | 14 +- .../AdvancedParallelFactory.WhileAsync.cs | 14 +- ...dvancedParallelFactory.WhileResultAsync.cs | 14 +- ...ActionFactory.cs => AsyncActionFactory.cs} | 132 +++++++++--------- ...TaskFuncFactory.cs => AsyncFuncFactory.cs} | 132 +++++++++--------- src/Cuemon.Threading/AsyncPatterns.cs | 26 ++-- .../ParallelFactory.ForEachAsync.cs | 14 +- .../ParallelFactory.ForEachResultAsync.cs | 14 +- 13 files changed, 241 insertions(+), 241 deletions(-) rename src/Cuemon.Core/Threading/{TaskActionFactory.cs => AsyncActionFactory.cs} (73%) rename src/Cuemon.Core/Threading/{TaskFuncFactory.cs => AsyncFuncFactory.cs} (73%) rename src/Cuemon.Threading/{TaskActionFactory.cs => AsyncActionFactory.cs} (67%) rename src/Cuemon.Threading/{TaskFuncFactory.cs => AsyncFuncFactory.cs} (69%) diff --git a/src/Cuemon.Core/Threading/TaskActionFactory.cs b/src/Cuemon.Core/Threading/AsyncActionFactory.cs similarity index 73% rename from src/Cuemon.Core/Threading/TaskActionFactory.cs rename to src/Cuemon.Core/Threading/AsyncActionFactory.cs index af86f5aeb..075096cc9 100644 --- a/src/Cuemon.Core/Threading/TaskActionFactory.cs +++ b/src/Cuemon.Core/Threading/AsyncActionFactory.cs @@ -8,24 +8,24 @@ namespace Cuemon.Threading /// Provides an easy way of invoking an delegate regardless of the amount of parameters provided. /// /// The type of the n-tuple representation of a . - public sealed class TaskActionFactory : TemplateFactory where TTuple : Template + public sealed class AsyncActionFactory : TemplateFactory where TTuple : Template { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The based function delegate to invoke. /// The n-tuple argument of . - public TaskActionFactory(Func method, TTuple tuple) : this(method, tuple, method) + public AsyncActionFactory(Func method, TTuple tuple) : this(method, tuple, method) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The based function delegate to invoke. /// The n-tuple argument of . /// The original delegate wrapped by . - public TaskActionFactory(Func method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) + public AsyncActionFactory(Func method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); @@ -56,13 +56,13 @@ public Task ExecuteMethodAsync(CancellationToken ct) } /// - /// Creates a shallow copy of the current object. + /// Creates a shallow copy of the current object. /// - /// A new that is a copy of this instance. + /// A new that is a copy of this instance. /// When thread safety is required this is the method to invoke. public override TemplateFactory Clone() { - return new TaskActionFactory(Method, GenericArguments.Clone() as TTuple); + return new AsyncActionFactory(Method, GenericArguments.Clone() as TTuple); } } } diff --git a/src/Cuemon.Core/Threading/TaskFuncFactory.cs b/src/Cuemon.Core/Threading/AsyncFuncFactory.cs similarity index 73% rename from src/Cuemon.Core/Threading/TaskFuncFactory.cs rename to src/Cuemon.Core/Threading/AsyncFuncFactory.cs index adb9f0726..312e959b5 100644 --- a/src/Cuemon.Core/Threading/TaskFuncFactory.cs +++ b/src/Cuemon.Core/Threading/AsyncFuncFactory.cs @@ -9,24 +9,24 @@ namespace Cuemon.Threading /// /// The type of the n-tuple representation of a . /// The type of the return value of the function delegate . - public sealed class TaskFuncFactory : TemplateFactory where TTuple : Template + public sealed class AsyncFuncFactory : TemplateFactory where TTuple : Template { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The function delegate to invoke. /// The n-tuple argument of . - public TaskFuncFactory(Func> method, TTuple tuple) : this(method, tuple, method) + public AsyncFuncFactory(Func> method, TTuple tuple) : this(method, tuple, method) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The function delegate to invoke. /// The n-tuple argument of . /// The original delegate wrapped by . - public TaskFuncFactory(Func> method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) + public AsyncFuncFactory(Func> method, TTuple tuple, Delegate originalDelegate) : base(tuple, originalDelegate != null) { Method = method; DelegateInfo = Decorator.RawEnclose(method).ResolveDelegateInfo(originalDelegate); @@ -57,13 +57,13 @@ public Task ExecuteMethodAsync(CancellationToken ct) } /// - /// Creates a shallow copy of the current object. + /// Creates a shallow copy of the current object. /// - /// A new that is a copy of this instance. + /// A new that is a copy of this instance. /// When thread safety is required this is the method to invoke. public override TemplateFactory Clone() { - return new TaskFuncFactory(Method, GenericArguments.Clone() as TTuple); + return new AsyncFuncFactory(Method, GenericArguments.Clone() as TTuple); } } } diff --git a/src/Cuemon.Diagnostics/TimeMeasure.Async.cs b/src/Cuemon.Diagnostics/TimeMeasure.Async.cs index ab1b660aa..59f1d6d22 100644 --- a/src/Cuemon.Diagnostics/TimeMeasure.Async.cs +++ b/src/Cuemon.Diagnostics/TimeMeasure.Async.cs @@ -21,7 +21,7 @@ public static partial class TimeMeasure public static Task WithActionAsync(Func action, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action); + var factory = AsyncActionFactory.Create(action); return WithActionAsyncCore(factory, setup); } @@ -39,7 +39,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T arg, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg); + var factory = AsyncActionFactory.Create(action, arg); return WithActionAsyncCore(factory, setup); } @@ -59,7 +59,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T1 arg1, T2 arg2, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2); + var factory = AsyncActionFactory.Create(action, arg1, arg2); return WithActionAsyncCore(factory, setup); } @@ -81,7 +81,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3); return WithActionAsyncCore(factory, setup); } @@ -105,7 +105,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4); return WithActionAsyncCore(factory, setup); } @@ -131,7 +131,7 @@ public static Task WithActionAsync(Func WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5); return WithActionAsyncCore(factory, setup); } @@ -159,7 +159,7 @@ public static Task WithActionAsync(Func public static Task WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6); return WithActionAsyncCore(factory, setup); } @@ -189,7 +189,7 @@ public static Task WithActionAsync( public static Task WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7); return WithActionAsyncCore(factory, setup); } @@ -221,7 +221,7 @@ public static Task WithActionAsync WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); return WithActionAsyncCore(factory, setup); } @@ -255,7 +255,7 @@ public static Task WithActionAsync WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); return WithActionAsyncCore(factory, setup); } @@ -291,7 +291,7 @@ public static Task WithActionAsync WithActionAsync(Func action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, Action setup = null) { Validator.ThrowIfNull(action); - var factory = TaskActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + var factory = AsyncActionFactory.Create(action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); return WithActionAsyncCore(factory, setup); } @@ -306,7 +306,7 @@ public static Task WithActionAsync> WithFuncAsync(Func> function, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function); + var factory = AsyncFuncFactory.Create(function); return WithFunctionAsyncCore(factory, setup); } @@ -322,7 +322,7 @@ public static Task> WithFuncAsync(Func> WithFuncAsync(Func> function, T arg, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg); + var factory = AsyncFuncFactory.Create(function, arg); return WithFunctionAsyncCore(factory, setup); } @@ -340,7 +340,7 @@ public static Task> WithFuncAsync(Func< public static Task> WithFuncAsync(Func> function, T1 arg1, T2 arg2, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2); + var factory = AsyncFuncFactory.Create(function, arg1, arg2); return WithFunctionAsyncCore(factory, setup); } @@ -360,7 +360,7 @@ public static Task> WithFuncAsync( public static Task> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3); return WithFunctionAsyncCore(factory, setup); } @@ -382,7 +382,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4); return WithFunctionAsyncCore(factory, setup); } @@ -406,7 +406,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5); return WithFunctionAsyncCore(factory, setup); } @@ -432,7 +432,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6); return WithFunctionAsyncCore(factory, setup); } @@ -460,7 +460,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7); return WithFunctionAsyncCore(factory, setup); } @@ -490,7 +490,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); return WithFunctionAsyncCore(factory, setup); } @@ -522,7 +522,7 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); return WithFunctionAsyncCore(factory, setup); } @@ -556,11 +556,11 @@ public static Task> WithFuncAsync> WithFuncAsync(Func> function, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, Action setup = null) { Validator.ThrowIfNull(function); - var factory = TaskFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + var factory = AsyncFuncFactory.Create(function, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); return WithFunctionAsyncCore(factory, setup); } - private static async Task WithActionAsyncCore(TaskActionFactory factory, Action setup) where TTuple : Template + private static async Task WithActionAsyncCore(AsyncActionFactory factory, Action setup) where TTuple : Template { var options = Patterns.Configure(setup); var descriptor = options.MethodDescriptor?.Invoke() ?? new MethodDescriptor(factory.DelegateInfo); @@ -573,7 +573,7 @@ private static async Task WithActionAsyncCore(TaskA return profiler; } - private static async Task> WithFunctionAsyncCore(TaskFuncFactory factory, Action setup) where TTuple : Template + private static async Task> WithFunctionAsyncCore(AsyncFuncFactory factory, Action setup) where TTuple : Template { var options = Patterns.Configure(setup); var descriptor = options.MethodDescriptor?.Invoke() ?? new MethodDescriptor(factory.DelegateInfo); diff --git a/src/Cuemon.Resilience/TransientOperation.Async.cs b/src/Cuemon.Resilience/TransientOperation.Async.cs index 362d5a58a..a073f4c24 100644 --- a/src/Cuemon.Resilience/TransientOperation.Async.cs +++ b/src/Cuemon.Resilience/TransientOperation.Async.cs @@ -31,7 +31,7 @@ public static partial class TransientOperation public static Task WithFuncAsync(Func> faultSensitiveMethod, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod); return WithFuncAsyncCore(factory, setup); } @@ -61,7 +61,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T arg, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg); return WithFuncAsyncCore(factory, setup); } @@ -93,7 +93,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T1 arg1, T2 arg2, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg1, arg2); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg1, arg2); return WithFuncAsyncCore(factory, setup); } @@ -127,7 +127,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3); return WithFuncAsyncCore(factory, setup); } @@ -163,7 +163,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4); return WithFuncAsyncCore(factory, setup); } @@ -201,7 +201,7 @@ public static Task WithFuncAsync(Func WithFuncAsync(Func> faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4, arg5); + var factory = AsyncFuncFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4, arg5); return WithFuncAsyncCore(factory, setup); } @@ -227,7 +227,7 @@ public static Task WithFuncAsync(Func faultSensitiveMethod, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod); + var factory = AsyncActionFactory.Create(faultSensitiveMethod); return WithActionAsyncCore(factory, setup); } @@ -255,7 +255,7 @@ public static Task WithActionAsync(Func faultSensitiveM public static Task WithActionAsync(Func faultSensitiveMethod, T arg, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg); return WithActionAsyncCore(factory, setup); } @@ -285,7 +285,7 @@ public static Task WithActionAsync(Func faultSens public static Task WithActionAsync(Func faultSensitiveMethod, T1 arg1, T2 arg2, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg1, arg2); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg1, arg2); return WithActionAsyncCore(factory, setup); } @@ -317,7 +317,7 @@ public static Task WithActionAsync(Func public static Task WithActionAsync(Func faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3); return WithActionAsyncCore(factory, setup); } @@ -351,7 +351,7 @@ public static Task WithActionAsync(Func(Func faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4); return WithActionAsyncCore(factory, setup); } @@ -387,16 +387,16 @@ public static Task WithActionAsync(Func(Func faultSensitiveMethod, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action setup = null) { Validator.ThrowIfNull(faultSensitiveMethod); - var factory = TaskActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4, arg5); + var factory = AsyncActionFactory.Create(faultSensitiveMethod, arg1, arg2, arg3, arg4, arg5); return WithActionAsyncCore(factory, setup); } - private static Task WithActionAsyncCore(TaskActionFactory factory, Action setup) where TTuple : Template + private static Task WithActionAsyncCore(AsyncActionFactory factory, Action setup) where TTuple : Template { return new AsyncActionTransientWorker(factory.DelegateInfo, factory.GenericArguments.ToArray(), setup).ResilientActionAsync(factory.ExecuteMethodAsync); } - private static Task WithFuncAsyncCore(TaskFuncFactory factory, Action setup) where TTuple : Template + private static Task WithFuncAsyncCore(AsyncFuncFactory factory, Action setup) where TTuple : Template { return new AsyncFuncTransientWorker(factory.DelegateInfo, factory.GenericArguments.ToArray(), setup).ResilientFuncAsync(factory.ExecuteMethodAsync); } diff --git a/src/Cuemon.Threading/AdvancedParallelFactory.ForAsync.cs b/src/Cuemon.Threading/AdvancedParallelFactory.ForAsync.cs index cbd971218..426dc8ae7 100644 --- a/src/Cuemon.Threading/AdvancedParallelFactory.ForAsync.cs +++ b/src/Cuemon.Threading/AdvancedParallelFactory.ForAsync.cs @@ -24,7 +24,7 @@ public static Task ForAsync(ForLoopRuleset rules, Func @@ -46,7 +46,7 @@ public static Task ForAsync(ForLoopRuleset rules, Func @@ -70,7 +70,7 @@ public static Task ForAsync(ForLoopRuleset rules, Fu { Validator.ThrowIfNull(rules); Validator.ThrowIfNull(worker); - return ForCoreAsync(rules, TaskActionFactory.Create(worker, default, arg1, arg2), setup); + return ForCoreAsync(rules, AsyncActionFactory.Create(worker, default, arg1, arg2), setup); } /// @@ -96,7 +96,7 @@ public static Task ForAsync(ForLoopRuleset rules { Validator.ThrowIfNull(rules); Validator.ThrowIfNull(worker); - return ForCoreAsync(rules, TaskActionFactory.Create(worker, default, arg1, arg2, arg3), setup); + return ForCoreAsync(rules, AsyncActionFactory.Create(worker, default, arg1, arg2, arg3), setup); } /// @@ -124,7 +124,7 @@ public static Task ForAsync(ForLoopRuleset r { Validator.ThrowIfNull(rules); Validator.ThrowIfNull(worker); - return ForCoreAsync(rules, TaskActionFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); + return ForCoreAsync(rules, AsyncActionFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); } /// @@ -154,10 +154,10 @@ public static Task ForAsync(ForLoopRuleset(ForLoopRuleset rules, TaskActionFactory workerFactory, Action setup) + private static async Task ForCoreAsync(ForLoopRuleset rules, AsyncActionFactory workerFactory, Action setup) where TWorker : Template where TOperand : struct, IComparable, IEquatable, IConvertible { diff --git a/src/Cuemon.Threading/AdvancedParallelFactory.ForResultAsync.cs b/src/Cuemon.Threading/AdvancedParallelFactory.ForResultAsync.cs index 69a4c2e29..a5c2a52af 100644 --- a/src/Cuemon.Threading/AdvancedParallelFactory.ForResultAsync.cs +++ b/src/Cuemon.Threading/AdvancedParallelFactory.ForResultAsync.cs @@ -30,7 +30,7 @@ public static Task> ForResultAsync @@ -54,7 +54,7 @@ public static Task> ForResultAsync @@ -80,7 +80,7 @@ public static Task> ForResultAsync @@ -108,7 +108,7 @@ public static Task> ForResultAsync @@ -138,7 +138,7 @@ public static Task> ForResultAsync @@ -170,10 +170,10 @@ public static Task> ForResultAsync> ForResultCoreAsync(ForLoopRuleset rules, TaskFuncFactory workerFactory, Action setup) + private static async Task> ForResultCoreAsync(ForLoopRuleset rules, AsyncFuncFactory workerFactory, Action setup) where TWorker : Template where TOperand : struct, IComparable, IEquatable, IConvertible { diff --git a/src/Cuemon.Threading/AdvancedParallelFactory.WhileAsync.cs b/src/Cuemon.Threading/AdvancedParallelFactory.WhileAsync.cs index 3873ff8c6..4f0d310ac 100644 --- a/src/Cuemon.Threading/AdvancedParallelFactory.WhileAsync.cs +++ b/src/Cuemon.Threading/AdvancedParallelFactory.WhileAsync.cs @@ -23,7 +23,7 @@ public static Task WhileAsync(TReader reader, Func Validator.ThrowIfNull(condition); Validator.ThrowIfNull(provider); Validator.ThrowIfNull(worker); - return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), TaskActionFactory.Create(worker, default), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default), setup); } /// @@ -44,7 +44,7 @@ public static Task WhileAsync(TReader reader, Func(reader, condition, provider), TaskActionFactory.Create(worker, default, arg), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg), setup); } /// @@ -67,7 +67,7 @@ public static Task WhileAsync(TReader reader, Func(reader, condition, provider), TaskActionFactory.Create(worker, default, arg1, arg2), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg1, arg2), setup); } /// @@ -92,7 +92,7 @@ public static Task WhileAsync(TReader reader, Fun Validator.ThrowIfNull(condition); Validator.ThrowIfNull(provider); Validator.ThrowIfNull(worker); - return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), TaskActionFactory.Create(worker, default, arg1, arg2, arg3), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg1, arg2, arg3), setup); } /// @@ -119,7 +119,7 @@ public static Task WhileAsync(TReader reader, Validator.ThrowIfNull(condition); Validator.ThrowIfNull(provider); Validator.ThrowIfNull(worker); - return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), TaskActionFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); } /// @@ -148,10 +148,10 @@ public static Task WhileAsync(TReader rea Validator.ThrowIfNull(condition); Validator.ThrowIfNull(provider); Validator.ThrowIfNull(worker); - return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), TaskActionFactory.Create(worker, default, arg1, arg2, arg3, arg4, arg5), setup); + return WhileCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncActionFactory.Create(worker, default, arg1, arg2, arg3, arg4, arg5), setup); } - private static async Task WhileCoreAsync(AsyncForwardIterator iterator, TaskActionFactory workerFactory, Action setup) + private static async Task WhileCoreAsync(AsyncForwardIterator iterator, AsyncActionFactory workerFactory, Action setup) where TWorker : Template { var options = Patterns.Configure(setup); diff --git a/src/Cuemon.Threading/AdvancedParallelFactory.WhileResultAsync.cs b/src/Cuemon.Threading/AdvancedParallelFactory.WhileResultAsync.cs index 949c5c97c..e7a568619 100644 --- a/src/Cuemon.Threading/AdvancedParallelFactory.WhileResultAsync.cs +++ b/src/Cuemon.Threading/AdvancedParallelFactory.WhileResultAsync.cs @@ -28,7 +28,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default), setup); } /// @@ -51,7 +51,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg), setup); } /// @@ -76,7 +76,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg1, arg2), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg1, arg2), setup); } /// @@ -103,7 +103,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg1, arg2, arg3), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg1, arg2, arg3), setup); } /// @@ -132,7 +132,7 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg1, arg2, arg3, arg4), setup); } /// @@ -163,10 +163,10 @@ public static Task> WhileResultAsync(reader, condition, provider), TaskFuncFactory.Create(worker, default, arg1, arg2, arg3, arg4, arg5), setup); + return WhileResultCoreAsync(new AsyncForwardIterator(reader, condition, provider), AsyncFuncFactory.Create(worker, default, arg1, arg2, arg3, arg4, arg5), setup); } - private static async Task> WhileResultCoreAsync(AsyncForwardIterator iterator, TaskFuncFactory workerFactory, Action setup) + private static async Task> WhileResultCoreAsync(AsyncForwardIterator iterator, AsyncFuncFactory workerFactory, Action setup) where TWorker : Template { var options = Patterns.Configure(setup); diff --git a/src/Cuemon.Threading/TaskActionFactory.cs b/src/Cuemon.Threading/AsyncActionFactory.cs similarity index 67% rename from src/Cuemon.Threading/TaskActionFactory.cs rename to src/Cuemon.Threading/AsyncActionFactory.cs index 191201e5b..e3ba5f77a 100644 --- a/src/Cuemon.Threading/TaskActionFactory.cs +++ b/src/Cuemon.Threading/AsyncActionFactory.cs @@ -5,48 +5,48 @@ namespace Cuemon.Threading { /// - /// Provides access to factory methods for creating instances that encapsulate a based function delegate with a variable amount of generic arguments. + /// Provides access to factory methods for creating instances that encapsulate a based function delegate with a variable amount of generic arguments. /// - public static class TaskActionFactory + public static class AsyncActionFactory { /// - /// Creates a new instance encapsulating the specified . + /// Creates a new instance encapsulating the specified . /// /// The based function delegate to invoke. - /// An instance of object initialized with the specified . - public static TaskActionFactory