diff --git a/DigitalData.Core.Application.Abstraction/DTO/BaseDto.cs b/DigitalData.Core.Application.Abstraction/DTO/BaseDto.cs
index e73bf6c..6d9f479 100644
--- a/DigitalData.Core.Application.Abstraction/DTO/BaseDto.cs
+++ b/DigitalData.Core.Application.Abstraction/DTO/BaseDto.cs
@@ -1,17 +1,17 @@
-namespace DigitalData.Core.Application.Abstraction.DTO
+namespace DigitalData.Core.Application.Abstraction.DTO;
+
+///
+/// Represents a base Data Transfer Object (DTO) with an identifier.
+///
+/// The type of the identifier.
+/// The identifier of the DTO.
+[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+public record BaseDTO(TId Id) where TId : notnull
{
///
- /// Represents a base Data Transfer Object (DTO) with an identifier.
+ /// Returns the hash code for this instance, based on the identifier.
+ /// This override ensures that the hash code is derived consistently from the identifier.
///
- /// The type of the identifier.
- /// The identifier of the DTO.
- public record BaseDTO(TId Id) where TId : notnull
- {
- ///
- /// Returns the hash code for this instance, based on the identifier.
- /// This override ensures that the hash code is derived consistently from the identifier.
- ///
- /// A hash code for the current object, derived from the identifier.
- public override int GetHashCode() => Id.GetHashCode();
- }
+ /// A hash code for the current object, derived from the identifier.
+ public override int GetHashCode() => Id.GetHashCode();
}
\ No newline at end of file
diff --git a/DigitalData.Core.Application.Abstraction/DTO/DIExtensions.cs b/DigitalData.Core.Application.Abstraction/DTO/DIExtensions.cs
index 38b17e2..4d09297 100644
--- a/DigitalData.Core.Application.Abstraction/DTO/DIExtensions.cs
+++ b/DigitalData.Core.Application.Abstraction/DTO/DIExtensions.cs
@@ -2,32 +2,33 @@
using Microsoft.Extensions.DependencyInjection;
using System.Configuration;
-namespace DigitalData.Core.Application.Abstraction.DTO
+namespace DigitalData.Core.Application.Abstraction.DTO;
+
+///
+/// Provides extension methods for dependency injection.
+///
+[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+public static class DIExtensions
{
///
- /// Provides extension methods for dependency injection.
+ /// Adds the to the service collection.
///
- public static class DIExtensions
+ /// The service collection to add the settings to.
+ /// The updated service collection.
+ ///
+ /// Thrown if the 'CookieConsentSettings' section is missing or improperly configured in appsettings.json.
+ ///
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static IServiceCollection AddCookieConsentSettings(this IServiceCollection services)
{
- ///
- /// Adds the to the service collection.
- ///
- /// The service collection to add the settings to.
- /// The updated service collection.
- ///
- /// Thrown if the 'CookieConsentSettings' section is missing or improperly configured in appsettings.json.
- ///
- public static IServiceCollection AddCookieConsentSettings(this IServiceCollection services)
+ services.AddSingleton(sp =>
{
- services.AddSingleton(sp =>
- {
- var configuration = sp.GetRequiredService();
- var settings = configuration.GetSection("CookieConsentSettings").Get();
- return settings is null
- ? throw new ConfigurationErrorsException("The 'CookieConsentSettings' section is missing or improperly configured in appsettings.json.")
- : settings;
- });
- return services;
- }
+ var configuration = sp.GetRequiredService();
+ var settings = configuration.GetSection("CookieConsentSettings").Get();
+ return settings is null
+ ? throw new ConfigurationErrorsException("The 'CookieConsentSettings' section is missing or improperly configured in appsettings.json.")
+ : settings;
+ });
+ return services;
}
}
\ No newline at end of file
diff --git a/DigitalData.Core.Application.Abstraction/DTO/DTOExtensions.cs b/DigitalData.Core.Application.Abstraction/DTO/DTOExtensions.cs
index 870dd1e..d93fed0 100644
--- a/DigitalData.Core.Application.Abstraction/DTO/DTOExtensions.cs
+++ b/DigitalData.Core.Application.Abstraction/DTO/DTOExtensions.cs
@@ -1,367 +1,393 @@
using Microsoft.Extensions.Logging;
using System.Text;
-namespace DigitalData.Core.Application.Abstraction.DTO
+namespace DigitalData.Core.Application.Abstraction.DTO;
+
+///
+/// Provides extension methods for data transfer objects (DTOs).
+///
+[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+public static class DTOExtensions
{
///
- /// Provides extension methods for data transfer objects (DTOs).
+ /// Adds a single message to the result, if not null.
///
- public static class DTOExtensions
+ /// The type of the result.
+ /// The result to add the message to.
+ /// The message to add.
+ /// The updated result.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static T Message(this T result, string? message) where T : Result
{
- ///
- /// Adds a single message to the result, if not null.
- ///
- /// The type of the result.
- /// The result to add the message to.
- /// The message to add.
- /// The updated result.
- public static T Message(this T result, string? message) where T : Result
- {
- if(message is not null)
- result.Messages.Add(message);
- return result;
- }
-
- internal static IEnumerable FilterNull(this IEnumerable list)
- {
- foreach (var item in list)
- if(item is not null)
- yield return item;
- }
-
- ///
- /// Adds multiple messages to the result, after removing nulls.
- ///
- /// The type of the result.
- /// The result to add the messages to.
- /// The messages to add.
- /// The updated result.
- public static T Message(this T result, params string?[] messages) where T : Result
- {
- result.Messages.AddRange(messages.FilterNull());
- return result;
- }
-
- ///
- /// Adds a collection of messages to the result.
- ///
- /// The type of the result.
- /// The result to add the messages to.
- /// The collection of messages to add.
- /// The updated result.
- public static T Message(this T result, IEnumerable messages) where T : Result
- {
- result.Messages.AddRange(messages.FilterNull());
- return result;
- }
-
- ///
- /// Adds a notice to the result.
- ///
- /// The type of the result.
- /// The result to add the notice to.
- /// The notice to add.
- /// The updated result.
- public static T Notice(this T result, Notice notice) where T : Result
- {
- result.Notices.Add(notice);
- return result;
- }
-
- ///
- /// Adds a collection of notices to the result.
- ///
- /// The type of the result.
- /// The result to add the notices to.
- /// The collection of notices to add.
- /// The updated result.
- public static T Notice(this T result, IEnumerable notices) where T : Result
- {
- result.Notices.AddRange(notices);
- return result;
- }
-
- ///
- /// Adds notices with a specific log level and flags to the result.
- ///
- /// The type of the result.
- /// The result to add the notices to.
- /// The log level of the notices.
- /// The flags associated with the notices.
- /// The updated result.
- public static T Notice(this T result, LogLevel level, params Enum[] flags) where T : Result
- {
- var notices = flags.Select(flag => new Notice()
- {
- Flag = flag,
- Level = level
- });
- result.Notices.AddRange(notices);
- return result;
- }
-
- ///
- /// Adds a notice with a specific log level, flag, and messages to the result.
- ///
- /// The type of the result.
- /// The result to add the notice to.
- /// The log level of the notice.
- /// The flag associated with the notice.
- /// The messages to add to the notice.
- /// The updated result.
- public static T Notice(this T result, LogLevel level, Enum flag, params string?[] messages) where T : Result
- {
- result.Notices.Add(new Notice()
- {
- Flag = flag,
- Level = level,
- Messages = messages.FilterNull().ToList()
- });
- return result;
- }
-
- ///
- /// Adds a notice with a specific log level and messages to the result.
- ///
- /// The type of the result.
- /// The result to add the notice to.
- /// The log level of the notice.
- /// The messages to add to the notice.
- /// The updated result.
- public static T Notice(this T result, LogLevel level, params string[] messages) where T : Result
- {
- result.Notices.Add(new Notice()
- {
- Flag = null,
- Level = level,
- Messages = messages.FilterNull().ToList()
- });
- return result;
- }
-
- ///
- /// Checks if any notice has the specified flag.
- ///
- /// The collection of notices to check.
- /// The flag to check for.
- /// True if any notice has the specified flag; otherwise, false.
- public static bool HasFlag(this IEnumerable notices, Enum flag) => notices.Any(n => n.Flag?.ToString() == flag.ToString());
-
- ///
- /// Checks if any notice has any of the specified flags.
- ///
- /// The collection of notices to check.
- /// The flags to check for.
- /// True if any notice has any of the specified flags; otherwise, false.
- public static bool HasAnyFlag(this IEnumerable notices, params Enum[] flags) => flags.Any(f => notices.HasFlag(f));
-
- ///
- /// Executes a function based on the success or failure of the task result,
- /// without using result data.
- ///
- /// The type of the return value.
- /// The task returning a result to evaluate.
- /// The function to execute if the result is successful.
- /// The function to execute if the result is a failure.
- /// The result of the executed function.
- public static I? Then(this Result result, Func Success)
- {
- return result.IsSuccess ? Success() : default;
- }
-
- ///
- /// Executes a function based on the success or failure of the task result,
- /// using the data in the result.
- ///
- /// The type of the data in the result.
- /// The type of the return value.
- /// The task returning a data result to evaluate.
- /// The function to execute if the data result is successful.
- /// The function to execute if the data result is a failure.
- /// The result of the executed function.
- public static async Task ThenAsync(this Result result, Func> SuccessAsync)
- {
- return result.IsSuccess ? await SuccessAsync() : default;
- }
-
- ///
- /// Executes a function based on the success or failure of the result.
- ///
- /// The type of the return value.
- /// The result to evaluate.
- /// The function to execute if the result is successful.
- /// The function to execute if the result is a failure.
- /// The result of the executed function.
- public static I Then(this Result result, Func Success, Func, List, I> Fail)
- {
- return result.IsSuccess ? Success() : Fail(result.Messages, result.Notices);
- }
-
- ///
- /// Asynchronously executes a function based on the success or failure of the result.
- ///
- /// The type of the return value.
- /// The result to evaluate.
- /// The asynchronous function to execute if the result is successful.
- /// The function to execute if the result is a failure.
- /// The result of the executed function.
- public static async Task ThenAsync(this Result result, Func> SuccessAsync, Func, List, I> Fail)
- {
- return result.IsSuccess ? await SuccessAsync() : Fail(result.Messages, result.Notices);
- }
-
- ///
- /// Executes a function based on the success or failure of the data result.
- ///
- /// The type of the data in the result.
- /// The type of the return value.
- /// The data result to evaluate.
- /// The function to execute if the data result is successful.
- /// The function to execute if the data result is a failure.
- /// The result of the executed function.
- public static I Then(this DataResult result, Func Success, Func, List, I> Fail)
- {
- return result.IsSuccess ? Success(result.Data) : Fail(result.Messages, result.Notices);
- }
-
- ///
- /// Asynchronously executes a function based on the success or failure of the data result.
- ///
- /// The type of the data in the result.
- /// The type of the return value.
- /// The data result to evaluate.
- /// The asynchronous function to execute if the data result is successful.
- /// The function to execute if the data result is a failure.
- /// The result of the executed function.
- public static async Task ThenAsync(this DataResult result, Func> SuccessAsync, Func, List, I> Fail)
- {
- return result.IsSuccess ? await SuccessAsync(result.Data) : Fail(result.Messages, result.Notices);
- }
-
- ///
- /// Asynchronously executes a function based on the success or failure of a task returning a result.
- ///
- /// The type of the return value.
- /// The task returning a result to evaluate.
- /// The function to execute if the result is successful.
- /// The function to execute if the result is a failure.
- /// The result of the executed function.
- public static async Task ThenAsync(this Task tResult, Func Success, Func, List, I> Fail)
- {
- Result result = await tResult;
- return result.IsSuccess ? Success() : Fail(result.Messages, result.Notices);
- }
-
- ///
- /// Asynchronously executes a function based on the success or failure of a task returning a result.
- ///
- /// The type of the return value.
- /// The task returning a result to evaluate.
- /// The asynchronous function to execute if the result is successful.
- /// The function to execute if the result is a failure.
- /// The result of the executed function.
- public static async Task ThenAsync(this Task tResult, Func> SuccessAsync, Func, List, I> Fail)
- {
- Result result = await tResult;
- return result.IsSuccess ? await SuccessAsync() : Fail(result.Messages, result.Notices);
- }
-
- ///
- /// Asynchronously executes a function based on the success or failure of a task returning a data result.
- ///
- /// The type of the data in the result.
- /// The type of the return value.
- /// The task returning a data result to evaluate.
- /// The function to execute if the data result is successful.
- /// The function to execute if the data result is a failure.
- /// The result of the executed function.
- public static async Task ThenAsync(this Task> tResult, Func Success, Func, List, I> Fail)
- {
- DataResult result = await tResult;
- return result.IsSuccess ? Success(result.Data) : Fail(result.Messages, result.Notices);
- }
-
- ///
- /// Asynchronously executes a function based on the success or failure of a task returning a data result.
- ///
- /// The type of the data in the result.
- /// The type of the return value.
- /// The task returning a data result to evaluate.
- /// The asynchronous function to execute if the data result is successful.
- /// The function to execute if the data result is a failure.
- /// The result of the executed function.
- public static async Task ThenAsync(this Task> tResult, Func> SuccessAsync, Func, List, I> Fail)
- {
- DataResult result = await tResult;
- return result.IsSuccess ? await SuccessAsync(result.Data) : Fail(result.Messages, result.Notices);
- }
-
- ///
- /// Joins the values into a single string with optional start, separator, and end strings.
- ///
- /// The type of the values.
- /// The values to join.
- /// The starting string.
- /// The separator string.
- /// The ending string.
- /// The joined string.
- public static string Join(this IEnumerable values, string start = "", string seperator = ". ", string end = ".")
- => new StringBuilder(start).Append(string.Join(seperator, values)).Append(end).ToString();
-
- ///
- /// Logs the notices using the specified logger.
- ///
- /// The logger to use.
- /// The collection of notices to log.
- /// The starting string for each notice.
- /// The separator string for messages in each notice.
- /// The ending string for each notice.
- public static void LogNotice(this ILogger logger, IEnumerable notices, string start = ": ", string seperator = ". ", string end = ".\n")
- {
- foreach(LogLevel level in Enum.GetValues(typeof(LogLevel)))
- {
- var logNotices = notices.Where(n => n.Level == level);
-
- if (!logNotices.Any())
- continue;
-
- var sb = new StringBuilder();
- foreach(Notice notice in logNotices)
- {
- if (notice.Flag is not null)
- sb.Append(notice.Flag);
-
- if (notice.Messages.Any())
- sb.Append(start).Append(string.Join(seperator, notice.Messages)).AppendLine(end);
- else sb.Append(end);
- }
- logger.Log(level, sb.ToString());
- }
- }
-
- ///
- /// Logs the notices from a result using the specified logger.
- ///
- /// The logger to use.
- /// The result containing the notices to log.
- /// The starting string for each notice.
- /// The separator string for messages in each notice.
- /// The ending string for each notice.
- public static void LogNotice(this ILogger logger, Result result, string start = ": ", string seperator = ". ", string end = ".\n")
- => logger.LogNotice(notices: result.Notices, start: start, seperator: seperator, end: end);
-
- ///
- /// Determines if the data result is right (true).
- ///
- /// The data result to evaluate.
- /// True if the data result is true; otherwise, false.
- public static bool IsRight(this DataResult bResult) => bResult.Data;
-
- ///
- /// Determines if the data result is wrong (false).
- ///
- /// The data result to evaluate.
- /// True if the data result is false; otherwise, false.
- public static bool IsWrong(this DataResult bResult) => !bResult.Data;
+ if(message is not null)
+ result.Messages.Add(message);
+ return result;
}
+
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ internal static IEnumerable FilterNull(this IEnumerable list)
+ {
+ foreach (var item in list)
+ if(item is not null)
+ yield return item;
+ }
+
+ ///
+ /// Adds multiple messages to the result, after removing nulls.
+ ///
+ /// The type of the result.
+ /// The result to add the messages to.
+ /// The messages to add.
+ /// The updated result.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static T Message(this T result, params string?[] messages) where T : Result
+ {
+ result.Messages.AddRange(messages.FilterNull());
+ return result;
+ }
+
+ ///
+ /// Adds a collection of messages to the result.
+ ///
+ /// The type of the result.
+ /// The result to add the messages to.
+ /// The collection of messages to add.
+ /// The updated result.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static T Message(this T result, IEnumerable messages) where T : Result
+ {
+ result.Messages.AddRange(messages.FilterNull());
+ return result;
+ }
+
+ ///
+ /// Adds a notice to the result.
+ ///
+ /// The type of the result.
+ /// The result to add the notice to.
+ /// The notice to add.
+ /// The updated result.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static T Notice(this T result, Notice notice) where T : Result
+ {
+ result.Notices.Add(notice);
+ return result;
+ }
+
+ ///
+ /// Adds a collection of notices to the result.
+ ///
+ /// The type of the result.
+ /// The result to add the notices to.
+ /// The collection of notices to add.
+ /// The updated result.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static T Notice(this T result, IEnumerable notices) where T : Result
+ {
+ result.Notices.AddRange(notices);
+ return result;
+ }
+
+ ///
+ /// Adds notices with a specific log level and flags to the result.
+ ///
+ /// The type of the result.
+ /// The result to add the notices to.
+ /// The log level of the notices.
+ /// The flags associated with the notices.
+ /// The updated result.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static T Notice(this T result, LogLevel level, params Enum[] flags) where T : Result
+ {
+ var notices = flags.Select(flag => new Notice()
+ {
+ Flag = flag,
+ Level = level
+ });
+ result.Notices.AddRange(notices);
+ return result;
+ }
+
+ ///
+ /// Adds a notice with a specific log level, flag, and messages to the result.
+ ///
+ /// The type of the result.
+ /// The result to add the notice to.
+ /// The log level of the notice.
+ /// The flag associated with the notice.
+ /// The messages to add to the notice.
+ /// The updated result.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static T Notice(this T result, LogLevel level, Enum flag, params string?[] messages) where T : Result
+ {
+ result.Notices.Add(new Notice()
+ {
+ Flag = flag,
+ Level = level,
+ Messages = messages.FilterNull().ToList()
+ });
+ return result;
+ }
+
+ ///
+ /// Adds a notice with a specific log level and messages to the result.
+ ///
+ /// The type of the result.
+ /// The result to add the notice to.
+ /// The log level of the notice.
+ /// The messages to add to the notice.
+ /// The updated result.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static T Notice(this T result, LogLevel level, params string[] messages) where T : Result
+ {
+ result.Notices.Add(new Notice()
+ {
+ Flag = null,
+ Level = level,
+ Messages = messages.FilterNull().ToList()
+ });
+ return result;
+ }
+
+ ///
+ /// Checks if any notice has the specified flag.
+ ///
+ /// The collection of notices to check.
+ /// The flag to check for.
+ /// True if any notice has the specified flag; otherwise, false.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static bool HasFlag(this IEnumerable notices, Enum flag) => notices.Any(n => n.Flag?.ToString() == flag.ToString());
+
+ ///
+ /// Checks if any notice has any of the specified flags.
+ ///
+ /// The collection of notices to check.
+ /// The flags to check for.
+ /// True if any notice has any of the specified flags; otherwise, false.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static bool HasAnyFlag(this IEnumerable notices, params Enum[] flags) => flags.Any(f => notices.HasFlag(f));
+
+ ///
+ /// Executes a function based on the success or failure of the task result,
+ /// without using result data.
+ ///
+ /// The type of the return value.
+ /// The task returning a result to evaluate.
+ /// The function to execute if the result is successful.
+ /// The function to execute if the result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static I? Then(this Result result, Func Success)
+ {
+ return result.IsSuccess ? Success() : default;
+ }
+
+ ///
+ /// Executes a function based on the success or failure of the task result,
+ /// using the data in the result.
+ ///
+ /// The type of the data in the result.
+ /// The type of the return value.
+ /// The task returning a data result to evaluate.
+ /// The function to execute if the data result is successful.
+ /// The function to execute if the data result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static async Task ThenAsync(this Result result, Func> SuccessAsync)
+ {
+ return result.IsSuccess ? await SuccessAsync() : default;
+ }
+
+ ///
+ /// Executes a function based on the success or failure of the result.
+ ///
+ /// The type of the return value.
+ /// The result to evaluate.
+ /// The function to execute if the result is successful.
+ /// The function to execute if the result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static I Then(this Result result, Func Success, Func, List, I> Fail)
+ {
+ return result.IsSuccess ? Success() : Fail(result.Messages, result.Notices);
+ }
+
+ ///
+ /// Asynchronously executes a function based on the success or failure of the result.
+ ///
+ /// The type of the return value.
+ /// The result to evaluate.
+ /// The asynchronous function to execute if the result is successful.
+ /// The function to execute if the result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static async Task ThenAsync(this Result result, Func> SuccessAsync, Func, List, I> Fail)
+ {
+ return result.IsSuccess ? await SuccessAsync() : Fail(result.Messages, result.Notices);
+ }
+
+ ///
+ /// Executes a function based on the success or failure of the data result.
+ ///
+ /// The type of the data in the result.
+ /// The type of the return value.
+ /// The data result to evaluate.
+ /// The function to execute if the data result is successful.
+ /// The function to execute if the data result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static I Then(this DataResult result, Func Success, Func, List, I> Fail)
+ {
+ return result.IsSuccess ? Success(result.Data) : Fail(result.Messages, result.Notices);
+ }
+
+ ///
+ /// Asynchronously executes a function based on the success or failure of the data result.
+ ///
+ /// The type of the data in the result.
+ /// The type of the return value.
+ /// The data result to evaluate.
+ /// The asynchronous function to execute if the data result is successful.
+ /// The function to execute if the data result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static async Task ThenAsync(this DataResult result, Func> SuccessAsync, Func, List, I> Fail)
+ {
+ return result.IsSuccess ? await SuccessAsync(result.Data) : Fail(result.Messages, result.Notices);
+ }
+
+ ///
+ /// Asynchronously executes a function based on the success or failure of a task returning a result.
+ ///
+ /// The type of the return value.
+ /// The task returning a result to evaluate.
+ /// The function to execute if the result is successful.
+ /// The function to execute if the result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static async Task ThenAsync(this Task tResult, Func Success, Func, List, I> Fail)
+ {
+ Result result = await tResult;
+ return result.IsSuccess ? Success() : Fail(result.Messages, result.Notices);
+ }
+
+ ///
+ /// Asynchronously executes a function based on the success or failure of a task returning a result.
+ ///
+ /// The type of the return value.
+ /// The task returning a result to evaluate.
+ /// The asynchronous function to execute if the result is successful.
+ /// The function to execute if the result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static async Task ThenAsync(this Task tResult, Func> SuccessAsync, Func, List, I> Fail)
+ {
+ Result result = await tResult;
+ return result.IsSuccess ? await SuccessAsync() : Fail(result.Messages, result.Notices);
+ }
+
+ ///
+ /// Asynchronously executes a function based on the success or failure of a task returning a data result.
+ ///
+ /// The type of the data in the result.
+ /// The type of the return value.
+ /// The task returning a data result to evaluate.
+ /// The function to execute if the data result is successful.
+ /// The function to execute if the data result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static async Task ThenAsync(this Task> tResult, Func Success, Func, List, I> Fail)
+ {
+ DataResult result = await tResult;
+ return result.IsSuccess ? Success(result.Data) : Fail(result.Messages, result.Notices);
+ }
+
+ ///
+ /// Asynchronously executes a function based on the success or failure of a task returning a data result.
+ ///
+ /// The type of the data in the result.
+ /// The type of the return value.
+ /// The task returning a data result to evaluate.
+ /// The asynchronous function to execute if the data result is successful.
+ /// The function to execute if the data result is a failure.
+ /// The result of the executed function.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static async Task ThenAsync(this Task> tResult, Func> SuccessAsync, Func, List, I> Fail)
+ {
+ DataResult result = await tResult;
+ return result.IsSuccess ? await SuccessAsync(result.Data) : Fail(result.Messages, result.Notices);
+ }
+
+ ///
+ /// Joins the values into a single string with optional start, separator, and end strings.
+ ///
+ /// The type of the values.
+ /// The values to join.
+ /// The starting string.
+ /// The separator string.
+ /// The ending string.
+ /// The joined string.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static string Join(this IEnumerable values, string start = "", string seperator = ". ", string end = ".")
+ => new StringBuilder(start).Append(string.Join(seperator, values)).Append(end).ToString();
+
+ ///
+ /// Logs the notices using the specified logger.
+ ///
+ /// The logger to use.
+ /// The collection of notices to log.
+ /// The starting string for each notice.
+ /// The separator string for messages in each notice.
+ /// The ending string for each notice.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static void LogNotice(this ILogger logger, IEnumerable notices, string start = ": ", string seperator = ". ", string end = ".\n")
+ {
+ foreach(LogLevel level in Enum.GetValues(typeof(LogLevel)))
+ {
+ var logNotices = notices.Where(n => n.Level == level);
+
+ if (!logNotices.Any())
+ continue;
+
+ var sb = new StringBuilder();
+ foreach(Notice notice in logNotices)
+ {
+ if (notice.Flag is not null)
+ sb.Append(notice.Flag);
+
+ if (notice.Messages.Any())
+ sb.Append(start).Append(string.Join(seperator, notice.Messages)).AppendLine(end);
+ else sb.Append(end);
+ }
+ logger.Log(level, sb.ToString());
+ }
+ }
+
+ ///
+ /// Logs the notices from a result using the specified logger.
+ ///
+ /// The logger to use.
+ /// The result containing the notices to log.
+ /// The starting string for each notice.
+ /// The separator string for messages in each notice.
+ /// The ending string for each notice.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static void LogNotice(this ILogger logger, Result result, string start = ": ", string seperator = ". ", string end = ".\n")
+ => logger.LogNotice(notices: result.Notices, start: start, seperator: seperator, end: end);
+
+ ///
+ /// Determines if the data result is right (true).
+ ///
+ /// The data result to evaluate.
+ /// True if the data result is true; otherwise, false.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static bool IsRight(this DataResult bResult) => bResult.Data;
+
+ ///
+ /// Determines if the data result is wrong (false).
+ ///
+ /// The data result to evaluate.
+ /// True if the data result is false; otherwise, false.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static bool IsWrong(this DataResult bResult) => !bResult.Data;
}
\ No newline at end of file
diff --git a/DigitalData.Core.Application.Abstraction/DTO/DataResult.cs b/DigitalData.Core.Application.Abstraction/DTO/DataResult.cs
index f09d19d..79a54b4 100644
--- a/DigitalData.Core.Application.Abstraction/DTO/DataResult.cs
+++ b/DigitalData.Core.Application.Abstraction/DTO/DataResult.cs
@@ -1,26 +1,28 @@
using System.Text.Json.Serialization;
-namespace DigitalData.Core.Application.Abstraction.DTO
+namespace DigitalData.Core.Application.Abstraction.DTO;
+
+///
+/// Represents a result of an operation that includes data, inheriting from .
+///
+/// The type of the data included in the result.
+[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+public class DataResult : Result
{
///
- /// Represents a result of an operation that includes data, inheriting from .
+ /// Gets or sets the data included in the result. This property is required.
+ /// It will be ignored during JSON serialization if the value is null.
///
- /// The type of the data included in the result.
- public class DataResult : Result
- {
- ///
- /// Gets or sets the data included in the result. This property is required.
- /// It will be ignored during JSON serialization if the value is null.
- ///
- [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
- public required T Data { get; set; }
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public required T Data { get; set; }
- ///
- /// Converts the current to a failed ,
- /// preserving the messages and notices.
- ///
- /// The type of the data in the new failed result.
- /// A failed with the current messages and notices.
- public DataResult ToFail() => Fail().Message(Messages).Notice(Notices);
- }
+ ///
+ /// Converts the current to a failed ,
+ /// preserving the messages and notices.
+ ///
+ /// The type of the data in the new failed result.
+ /// A failed with the current messages and notices.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public DataResult ToFail() => Fail().Message(Messages).Notice(Notices);
}
\ No newline at end of file
diff --git a/DigitalData.Core.Application.Abstraction/DTO/Flag.cs b/DigitalData.Core.Application.Abstraction/DTO/Flag.cs
index 766ce7c..dae9e08 100644
--- a/DigitalData.Core.Application.Abstraction/DTO/Flag.cs
+++ b/DigitalData.Core.Application.Abstraction/DTO/Flag.cs
@@ -1,50 +1,50 @@
-namespace DigitalData.Core.Application.Abstraction.DTO
+namespace DigitalData.Core.Application.Abstraction.DTO;
+
+///
+/// Defines flags that indicate specific types of status or conditions in a service operation.
+/// These flags help in categorizing and identifying specific circumstances or issues that may arise during execution.
+///
+[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+public enum Flag
{
///
- /// Defines flags that indicate specific types of status or conditions in a service operation.
- /// These flags help in categorizing and identifying specific circumstances or issues that may arise during execution.
+ /// Indicates a security breach or vulnerability has been detected during the service operation.
///
- public enum Flag
- {
- ///
- /// Indicates a security breach or vulnerability has been detected during the service operation.
- ///
- SecurityBreach,
+ SecurityBreach,
- ///
- /// Indicates a potential issue with data integrity during the service operation.
- /// This flag is used when data may have been altered, corrupted, or is otherwise unreliable,
- /// which could impact the accuracy or trustworthiness of the operation's results.
- ///
- DataIntegrityIssue,
+ ///
+ /// Indicates a potential issue with data integrity during the service operation.
+ /// This flag is used when data may have been altered, corrupted, or is otherwise unreliable,
+ /// which could impact the accuracy or trustworthiness of the operation's results.
+ ///
+ DataIntegrityIssue,
- ///
- /// Indicates that either a security breach, a data integrity issue, or both have been detected during the service operation.
- /// This flag is used when it is not sure whether the problem is security or data integrity. In this case, data integrity should be checked first.
- ///
- SecurityBreachOrDataIntegrity,
+ ///
+ /// Indicates that either a security breach, a data integrity issue, or both have been detected during the service operation.
+ /// This flag is used when it is not sure whether the problem is security or data integrity. In this case, data integrity should be checked first.
+ ///
+ SecurityBreachOrDataIntegrity,
- ///
- /// Indicates a possible security breach during the service operation.
- ///
- PossibleSecurityBreach,
+ ///
+ /// Indicates a possible security breach during the service operation.
+ ///
+ PossibleSecurityBreach,
- ///
- /// Indicates a possible issue with data integrity during the service operation.
- /// This flag is used when there is a suspicion of data alteration, corruption, or unreliability.
- ///
- PossibleDataIntegrityIssue,
+ ///
+ /// Indicates a possible issue with data integrity during the service operation.
+ /// This flag is used when there is a suspicion of data alteration, corruption, or unreliability.
+ ///
+ PossibleDataIntegrityIssue,
- ///
- /// Indicates that either a possible security breach, a possible data integrity issue, or both have been detected during the service operation.
- /// This flag is used when it is uncertain whether the issue is related to security, data integrity, or both.
- ///
- PossibleSecurityBreachOrDataIntegrity,
+ ///
+ /// Indicates that either a possible security breach, a possible data integrity issue, or both have been detected during the service operation.
+ /// This flag is used when it is uncertain whether the issue is related to security, data integrity, or both.
+ ///
+ PossibleSecurityBreachOrDataIntegrity,
- ///
- /// Indicates that the requested resource or operation could not be found.
- /// This flag is used when the specified item or condition does not exist or is unavailable.
- ///
- NotFound
- }
+ ///
+ /// Indicates that the requested resource or operation could not be found.
+ /// This flag is used when the specified item or condition does not exist or is unavailable.
+ ///
+ NotFound
}
\ No newline at end of file
diff --git a/DigitalData.Core.Application.Abstraction/DTO/Notice.cs b/DigitalData.Core.Application.Abstraction/DTO/Notice.cs
index bb31452..ac70581 100644
--- a/DigitalData.Core.Application.Abstraction/DTO/Notice.cs
+++ b/DigitalData.Core.Application.Abstraction/DTO/Notice.cs
@@ -1,25 +1,28 @@
using Microsoft.Extensions.Logging;
-namespace DigitalData.Core.Application.Abstraction.DTO
+namespace DigitalData.Core.Application.Abstraction.DTO;
+
+///
+/// Represents a notice for logging purposes, containing a flag, log level, and associated messages.
+///
+[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+public class Notice
{
///
- /// Represents a notice for logging purposes, containing a flag, log level, and associated messages.
+ /// Gets or sets an optional flag associated with the notice.
///
- public class Notice
- {
- ///
- /// Gets or sets an optional flag associated with the notice.
- ///
- public Enum? Flag { get; init; } = null;
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public Enum? Flag { get; init; } = null;
- ///
- /// Gets or sets the log level for the notice.
- ///
- public LogLevel Level { get; init; } = LogLevel.None;
+ ///
+ /// Gets or sets the log level for the notice.
+ ///
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public LogLevel Level { get; init; } = LogLevel.None;
- ///
- /// Gets a list of messages associated with the notice.
- ///
- public List Messages { get; init; } = new();
- }
+ ///
+ /// Gets a list of messages associated with the notice.
+ ///
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public List Messages { get; init; } = new();
}
\ No newline at end of file
diff --git a/DigitalData.Core.Application.Abstraction/DTO/Result.cs b/DigitalData.Core.Application.Abstraction/DTO/Result.cs
index dff0db8..e7434b3 100644
--- a/DigitalData.Core.Application.Abstraction/DTO/Result.cs
+++ b/DigitalData.Core.Application.Abstraction/DTO/Result.cs
@@ -1,97 +1,108 @@
using System.Text.Json.Serialization;
-namespace DigitalData.Core.Application.Abstraction.DTO
+namespace DigitalData.Core.Application.Abstraction.DTO;
+
+///
+/// Represents the result of an operation, containing information about its success or failure,
+/// messages for the client, and notices for logging.
+///
+[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+public class Result
{
///
- /// Represents the result of an operation, containing information about its success or failure,
- /// messages for the client, and notices for logging.
+ /// Gets or sets a value indicating whether the operation was successful.
///
- public class Result
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public bool IsSuccess { get; set; } = false;
+
+ ///
+ /// Gets a value indicating whether the operation failed.
+ ///
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public bool IsFailed => !IsSuccess;
+
+ ///
+ /// Gets a list of messages intended for the client.
+ ///
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public List Messages { get; init; } = new();
+
+ ///
+ /// Gets a list of notices intended for logging purposes. This property is ignored during JSON serialization.
+ ///
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ [JsonIgnore]
+ public List Notices = new();
+
+ ///
+ /// Creates a with the specified data.
+ ///
+ /// The type of the data.
+ /// The data to include in the result.
+ /// A new instance.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public DataResult Data(T data) => new()
{
- ///
- /// Gets or sets a value indicating whether the operation was successful.
- ///
- public bool IsSuccess { get; set; } = false;
+ IsSuccess = IsSuccess,
+ Messages = Messages,
+ Notices = Notices,
+ Data = data
+ };
- ///
- /// Gets a value indicating whether the operation failed.
- ///
- public bool IsFailed => !IsSuccess;
+ ///
+ /// Checks if any notice has the specified flag.
+ ///
+ /// The flag to check.
+ /// True if any notice has the specified flag; otherwise, false.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public bool HasFlag(Enum flag) => Notices.Any(n => n.Flag?.ToString() == flag.ToString());
- ///
- /// Gets a list of messages intended for the client.
- ///
- public List Messages { get; init; } = new();
+ ///
+ /// Checks if any notice has any of the specified flags.
+ ///
+ /// The flags to check.
+ /// True if any notice has any of the specified flags; otherwise, false.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public bool HasAnyFlag(params Enum[] flags) => flags.Any(HasFlag);
- ///
- /// Gets a list of notices intended for logging purposes. This property is ignored during JSON serialization.
- ///
- [JsonIgnore]
- public List Notices = new();
+ ///
+ /// Creates a new successful .
+ ///
+ /// A new successful .
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static Result Success() => new() { IsSuccess = true };
- ///
- /// Creates a with the specified data.
- ///
- /// The type of the data.
- /// The data to include in the result.
- /// A new instance.
- public DataResult Data(T data) => new()
- {
- IsSuccess = IsSuccess,
- Messages = Messages,
- Notices = Notices,
- Data = data
- };
+ ///
+ /// Creates a new failed .
+ ///
+ /// A new failed .
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static Result Fail() => new() { IsSuccess = false };
- ///
- /// Checks if any notice has the specified flag.
- ///
- /// The flag to check.
- /// True if any notice has the specified flag; otherwise, false.
- public bool HasFlag(Enum flag) => Notices.Any(n => n.Flag?.ToString() == flag.ToString());
+ ///
+ /// Creates a new successful with the specified data.
+ ///
+ /// The type of the data.
+ /// The data to include in the result.
+ /// A new successful with the specified data.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
+ public static DataResult Success(T data) => new()
+ {
+ IsSuccess = true,
+ Data = data
+ };
- ///
- /// Checks if any notice has any of the specified flags.
- ///
- /// The flags to check.
- /// True if any notice has any of the specified flags; otherwise, false.
- public bool HasAnyFlag(params Enum[] flags) => flags.Any(HasFlag);
-
- ///
- /// Creates a new successful .
- ///
- /// A new successful .
- public static Result Success() => new() { IsSuccess = true };
-
- ///
- /// Creates a new failed .
- ///
- /// A new failed .
- public static Result Fail() => new() { IsSuccess = false };
-
- ///
- /// Creates a new successful with the specified data.
- ///
- /// The type of the data.
- /// The data to include in the result.
- /// A new successful with the specified data.
- public static DataResult Success(T data) => new()
- {
- IsSuccess = true,
- Data = data
- };
-
- ///
- /// Creates a new failed with no data.
- ///
- /// The type of the data.
- /// A new failed with no data.
+ ///
+ /// Creates a new failed with no data.
+ ///
+ /// The type of the data.
+ /// A new failed with no data.
+ [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
#pragma warning disable CS8601 // Possible null reference assignment.
- public static DataResult Fail() => new()
- {
- IsSuccess = false,
- Data = default
- };
+ public static DataResult Fail() => new()
+ {
+ IsSuccess = false,
+ Data = default
+ };
#pragma warning restore CS8601 // Possible null reference assignment.
- }
}
\ No newline at end of file