Enhance framework compatibility and code readability
Added preprocessor directives for .NET framework compatibility. Modified `using` directives to be framework-specific. Improved code formatting for better readability. Introduced obsolete attributes for deprecated methods, recommending `MediatR` as an alternative. Added XML documentation for clarity and maintainability.
This commit is contained in:
parent
07ab7f0c62
commit
74a625a863
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
#if NET
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
|
|
||||||
@ -31,4 +32,5 @@ public static class DIExtensions
|
|||||||
});
|
});
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
#if NET
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace DigitalData.Core.Abstraction.Application.DTO;
|
namespace DigitalData.Core.Abstraction.Application.DTO;
|
||||||
@ -19,7 +20,7 @@ public static class DTOExtensions
|
|||||||
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
||||||
public static T Message<T>(this T result, string? message) where T : Result
|
public static T Message<T>(this T result, string? message) where T : Result
|
||||||
{
|
{
|
||||||
if(message is not null)
|
if (message is not null)
|
||||||
result.Messages.Add(message);
|
result.Messages.Add(message);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -28,7 +29,7 @@ public static class DTOExtensions
|
|||||||
internal static IEnumerable<T> FilterNull<T>(this IEnumerable<T?> list)
|
internal static IEnumerable<T> FilterNull<T>(this IEnumerable<T?> list)
|
||||||
{
|
{
|
||||||
foreach (var item in list)
|
foreach (var item in list)
|
||||||
if(item is not null)
|
if (item is not null)
|
||||||
yield return item;
|
yield return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +329,7 @@ public static class DTOExtensions
|
|||||||
/// <param name="end">The ending string.</param>
|
/// <param name="end">The ending string.</param>
|
||||||
/// <returns>The joined string.</returns>
|
/// <returns>The joined string.</returns>
|
||||||
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
||||||
public static string Join<T>(this IEnumerable<T> values, string start = "", string seperator = ". ", string end = ".")
|
public static string Join<T>(this IEnumerable<T> values, string start = "", string seperator = ". ", string end = ".")
|
||||||
=> new StringBuilder(start).Append(string.Join(seperator, values)).Append(end).ToString();
|
=> new StringBuilder(start).Append(string.Join(seperator, values)).Append(end).ToString();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -342,7 +343,7 @@ public static class DTOExtensions
|
|||||||
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
||||||
public static void LogNotice(this ILogger logger, IEnumerable<Notice> notices, string start = ": ", string seperator = ". ", string end = ".\n")
|
public static void LogNotice(this ILogger logger, IEnumerable<Notice> notices, string start = ": ", string seperator = ". ", string end = ".\n")
|
||||||
{
|
{
|
||||||
foreach(LogLevel level in Enum.GetValues(typeof(LogLevel)))
|
foreach (LogLevel level in Enum.GetValues(typeof(LogLevel)))
|
||||||
{
|
{
|
||||||
var logNotices = notices.Where(n => n.Level == level);
|
var logNotices = notices.Where(n => n.Level == level);
|
||||||
|
|
||||||
@ -350,7 +351,7 @@ public static class DTOExtensions
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
foreach(Notice notice in logNotices)
|
foreach (Notice notice in logNotices)
|
||||||
{
|
{
|
||||||
if (notice.Flag is not null)
|
if (notice.Flag is not null)
|
||||||
sb.Append(notice.Flag);
|
sb.Append(notice.Flag);
|
||||||
@ -390,4 +391,5 @@ public static class DTOExtensions
|
|||||||
/// <returns>True if the data result is false; otherwise, false.</returns>
|
/// <returns>True if the data result is false; otherwise, false.</returns>
|
||||||
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
||||||
public static bool IsWrong(this DataResult<bool> bResult) => !bResult.Data;
|
public static bool IsWrong(this DataResult<bool> bResult) => !bResult.Data;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -1,4 +1,5 @@
|
|||||||
namespace DigitalData.Core.Abstraction.Application.DTO;
|
#if NET
|
||||||
|
namespace DigitalData.Core.Abstraction.Application.DTO;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines flags that indicate specific types of status or conditions in a service operation.
|
/// Defines flags that indicate specific types of status or conditions in a service operation.
|
||||||
@ -47,4 +48,5 @@ public enum Flag
|
|||||||
/// This flag is used when the specified item or condition does not exist or is unavailable.
|
/// This flag is used when the specified item or condition does not exist or is unavailable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
NotFound
|
NotFound
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
#if NET
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace DigitalData.Core.Abstraction.Application.DTO;
|
namespace DigitalData.Core.Abstraction.Application.DTO;
|
||||||
|
|
||||||
@ -25,4 +26,5 @@ public class Notice
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
||||||
public List<string> Messages { get; init; } = new();
|
public List<string> Messages { get; init; } = new();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json.Serialization;
|
#if NET
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace DigitalData.Core.Abstraction.Application.DTO;
|
namespace DigitalData.Core.Abstraction.Application.DTO;
|
||||||
|
|
||||||
@ -105,4 +106,5 @@ public class Result
|
|||||||
Data = default
|
Data = default
|
||||||
};
|
};
|
||||||
#pragma warning restore CS8601 // Possible null reference assignment.
|
#pragma warning restore CS8601 // Possible null reference assignment.
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -1,4 +1,5 @@
|
|||||||
namespace DigitalData.Core.Abstraction.Application;
|
#if NET
|
||||||
|
namespace DigitalData.Core.Abstraction.Application;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides extension methods for retrieving the value of an 'Id' property from objects.
|
/// Provides extension methods for retrieving the value of an 'Id' property from objects.
|
||||||
@ -91,4 +92,5 @@ public static class EntityExtensions
|
|||||||
#pragma warning restore CS8601
|
#pragma warning restore CS8601
|
||||||
return id is not null;
|
return id is not null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -1,4 +1,5 @@
|
|||||||
namespace DigitalData.Core.Abstraction.Application
|
#if NET
|
||||||
|
namespace DigitalData.Core.Abstraction.Application
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implements a simplified CRUD service interface that uses a single Data Transfer Object (DTO) type for all CRUD operations,
|
/// Implements a simplified CRUD service interface that uses a single Data Transfer Object (DTO) type for all CRUD operations,
|
||||||
@ -18,4 +19,5 @@
|
|||||||
where TDto : class where TEntity : class
|
where TDto : class where TEntity : class
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -1,25 +1,26 @@
|
|||||||
using DigitalData.Core.Abstraction.Application.DTO;
|
#if NET
|
||||||
|
using DigitalData.Core.Abstraction.Application.DTO;
|
||||||
|
|
||||||
namespace DigitalData.Core.Abstraction.Application
|
namespace DigitalData.Core.Abstraction.Application;
|
||||||
|
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
|
public interface ICRUDService<TCreateDto, TReadDto, TEntity, TId> : IReadService<TReadDto, TEntity, TId>
|
||||||
|
where TCreateDto : class where TReadDto : class where TEntity : class
|
||||||
{
|
{
|
||||||
[Obsolete("Use MediatR")]
|
/// <summary>
|
||||||
public interface ICRUDService<TCreateDto, TReadDto, TEntity, TId> : IReadService<TReadDto, TEntity, TId>
|
/// Asynchronously creates a new entity based on the provided <paramref name="createDto"/> and returns the identifier of the created entity wrapped in a <see cref="DataResult{TId}"/>.
|
||||||
where TCreateDto : class where TReadDto : class where TEntity : class
|
/// The <see cref="DataResult{TId}"/> contains the identifier of the newly created entity on success or an error message on failure.
|
||||||
{
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="createDto">The data transfer object containing the information for the new entity.</param>
|
||||||
/// Asynchronously creates a new entity based on the provided <paramref name="createDto"/> and returns the identifier of the created entity wrapped in a <see cref="DataResult{TId}"/>.
|
/// <returns>A task representing the asynchronous operation, with a <see cref="DataResult{TId}"/> containing the identifier of the created entity or an error message.</returns>
|
||||||
/// The <see cref="DataResult{TId}"/> contains the identifier of the newly created entity on success or an error message on failure.
|
Task<DataResult<TReadDto>> CreateAsync(TCreateDto createDto);
|
||||||
/// </summary>
|
|
||||||
/// <param name="createDto">The data transfer object containing the information for the new entity.</param>
|
|
||||||
/// <returns>A task representing the asynchronous operation, with a <see cref="DataResult{TId}"/> containing the identifier of the created entity or an error message.</returns>
|
|
||||||
Task<DataResult<TReadDto>> CreateAsync(TCreateDto createDto);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage,
|
/// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage,
|
||||||
/// indicating the success or failure of the operation, including the error messages on failure.
|
/// indicating the success or failure of the operation, including the error messages on failure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="updateDto">The updateDTO with updated values for the entity.</param>
|
/// <param name="updateDto">The updateDTO with updated values for the entity.</param>
|
||||||
/// <returns>An Result indicating the outcome of the update operation, with an appropriate message.</returns>
|
/// <returns>An Result indicating the outcome of the update operation, with an appropriate message.</returns>
|
||||||
Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto);
|
Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto);
|
||||||
}
|
}
|
||||||
}
|
#endif
|
||||||
@ -1,94 +1,96 @@
|
|||||||
using DigitalData.Core.Abstraction.Application.DTO;
|
#if NET
|
||||||
|
using DigitalData.Core.Abstraction.Application.DTO;
|
||||||
using System.DirectoryServices;
|
using System.DirectoryServices;
|
||||||
|
|
||||||
namespace DigitalData.Core.Abstraction.Application
|
namespace DigitalData.Core.Abstraction.Application;
|
||||||
|
|
||||||
|
[Obsolete("Use DigitalData.ActiveDirectory")]
|
||||||
|
public interface IDirectorySearchService
|
||||||
{
|
{
|
||||||
public interface IDirectorySearchService
|
public string ServerName { get; }
|
||||||
{
|
|
||||||
public string ServerName { get; }
|
|
||||||
|
|
||||||
public string Root { get; }
|
public string Root { get; }
|
||||||
|
|
||||||
string SearchRootPath { get; }
|
string SearchRootPath { get; }
|
||||||
|
|
||||||
Dictionary<string, string> CustomSearchFilters { get; }
|
Dictionary<string, string> CustomSearchFilters { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the connections to the server and returns a Boolean value that specifies
|
/// Creates the connections to the server and returns a Boolean value that specifies
|
||||||
/// whether the specified username and password are valid.
|
/// whether the specified username and password are valid.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName">The username that is validated on the server. See the Remarks section
|
/// <param name="userName">The username that is validated on the server. See the Remarks section
|
||||||
/// for more information on the format of userName.</param>
|
/// for more information on the format of userName.</param>
|
||||||
/// <param name="password">The password that is validated on the server.</param>
|
/// <param name="password">The password that is validated on the server.</param>
|
||||||
/// <returns>True if the credentials are valid; otherwise, false.</returns>
|
/// <returns>True if the credentials are valid; otherwise, false.</returns>
|
||||||
bool ValidateCredentials(string userName, string password);
|
bool ValidateCredentials(string userName, string password);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the connections to the server asynchronously and returns a Boolean value that specifies
|
/// Creates the connections to the server asynchronously and returns a Boolean value that specifies
|
||||||
/// whether the specified username and password are valid.
|
/// whether the specified username and password are valid.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName">The username that is validated on the server. See the Remarks section
|
/// <param name="userName">The username that is validated on the server. See the Remarks section
|
||||||
/// for more information on the format of userName.</param>
|
/// for more information on the format of userName.</param>
|
||||||
/// <param name="password">The password that is validated on the server.</param>
|
/// <param name="password">The password that is validated on the server.</param>
|
||||||
/// <returns>True if the credentials are valid; otherwise, false.</returns>
|
/// <returns>True if the credentials are valid; otherwise, false.</returns>
|
||||||
Task<bool> ValidateCredentialsAsync(string userName, string password);
|
Task<bool> ValidateCredentialsAsync(string userName, string password);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds all directory entries matching the specified filter.
|
/// Finds all directory entries matching the specified filter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="searchRoot">The search root.</param>
|
/// <param name="searchRoot">The search root.</param>
|
||||||
/// <param name="filter">The search filter.</param>
|
/// <param name="filter">The search filter.</param>
|
||||||
/// <param name="searchScope">The search scope.</param>
|
/// <param name="searchScope">The search scope.</param>
|
||||||
/// <param name="sizeLimit">The size limit.</param>
|
/// <param name="sizeLimit">The size limit.</param>
|
||||||
/// <param name="properties">The properties to load.</param>
|
/// <param name="properties">The properties to load.</param>
|
||||||
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
||||||
DataResult<IEnumerable<ResultPropertyCollection>> FindAll(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
DataResult<IEnumerable<ResultPropertyCollection>> FindAll(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds all directory entries matching the specified filter asynchronously.
|
/// Finds all directory entries matching the specified filter asynchronously.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="searchRoot">The search root.</param>
|
/// <param name="searchRoot">The search root.</param>
|
||||||
/// <param name="filter">The search filter.</param>
|
/// <param name="filter">The search filter.</param>
|
||||||
/// <param name="searchScope">The search scope.</param>
|
/// <param name="searchScope">The search scope.</param>
|
||||||
/// <param name="sizeLimit">The size limit.</param>
|
/// <param name="sizeLimit">The size limit.</param>
|
||||||
/// <param name="properties">The properties to load.</param>
|
/// <param name="properties">The properties to load.</param>
|
||||||
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
||||||
Task<DataResult<IEnumerable<ResultPropertyCollection>>> FindAllAsync(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
Task<DataResult<IEnumerable<ResultPropertyCollection>>> FindAllAsync(DirectoryEntry searchRoot, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds all directory entries matching the specified filter, using the user cache.
|
/// Finds all directory entries matching the specified filter, using the user cache.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="username">The username.</param>
|
/// <param name="username">The username.</param>
|
||||||
/// <param name="filter">The search filter.</param>
|
/// <param name="filter">The search filter.</param>
|
||||||
/// <param name="searchScope">The search scope.</param>
|
/// <param name="searchScope">The search scope.</param>
|
||||||
/// <param name="sizeLimit">The size limit.</param>
|
/// <param name="sizeLimit">The size limit.</param>
|
||||||
/// <param name="properties">The properties to load.</param>
|
/// <param name="properties">The properties to load.</param>
|
||||||
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
||||||
DataResult<IEnumerable<ResultPropertyCollection>> FindAllByUserCache(string username, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
DataResult<IEnumerable<ResultPropertyCollection>> FindAllByUserCache(string username, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds all directory entries matching the specified filter asynchronously, using the user cache.
|
/// Finds all directory entries matching the specified filter asynchronously, using the user cache.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="username">The username.</param>
|
/// <param name="username">The username.</param>
|
||||||
/// <param name="filter">The search filter.</param>
|
/// <param name="filter">The search filter.</param>
|
||||||
/// <param name="searchScope">The search scope.</param>
|
/// <param name="searchScope">The search scope.</param>
|
||||||
/// <param name="sizeLimit">The size limit.</param>
|
/// <param name="sizeLimit">The size limit.</param>
|
||||||
/// <param name="properties">The properties to load.</param>
|
/// <param name="properties">The properties to load.</param>
|
||||||
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
/// <returns>A <see cref="DataResult{T}"/> containing the results.</returns>
|
||||||
Task<DataResult<IEnumerable<ResultPropertyCollection>>> FindAllByUserCacheAsync(string username, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
Task<DataResult<IEnumerable<ResultPropertyCollection>>> FindAllByUserCacheAsync(string username, string filter, SearchScope searchScope = SearchScope.Subtree, int sizeLimit = 5000, params string[] properties);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the search root in the cache.
|
/// Sets the search root in the cache.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="username">The directory entry username.</param>
|
/// <param name="username">The directory entry username.</param>
|
||||||
/// <param name="password">The directory entry password.</param>
|
/// <param name="password">The directory entry password.</param>
|
||||||
void SetSearchRootCache(string username, string password);
|
void SetSearchRootCache(string username, string password);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the search root from the cache.
|
/// Gets the search root from the cache.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="username">The directory entry username.</param>
|
/// <param name="username">The directory entry username.</param>
|
||||||
/// <returns>The cached <see cref="DirectoryEntry"/> if found; otherwise, null.</returns>
|
/// <returns>The cached <see cref="DirectoryEntry"/> if found; otherwise, null.</returns>
|
||||||
DirectoryEntry? GetSearchRootCache(string username);
|
DirectoryEntry? GetSearchRootCache(string username);
|
||||||
}
|
}
|
||||||
}
|
#endif
|
||||||
@ -1,41 +1,42 @@
|
|||||||
using Microsoft.IdentityModel.Tokens;
|
#if NET
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace DigitalData.Core.Abstraction.Application
|
namespace DigitalData.Core.Abstraction.Application;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines the operations for JWT service handling claims of type <typeparamref name="TClaimValue"/>.
|
||||||
|
/// </summary>
|
||||||
|
public interface IJWTService<TClaimValue>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the operations for JWT service handling claims of type <typeparamref name="TClaimValue"/>.
|
/// Generates a symmetric security key with the specified byte size.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IJWTService<TClaimValue>
|
/// <param name="byteSize">The size of the security key in bytes. Default is 32 bytes.</param>
|
||||||
|
/// <returns>A new instance of <see cref="SymmetricSecurityKey"/>.</returns>
|
||||||
|
public static SymmetricSecurityKey GenerateSecurityKey(int byteSize = 32)
|
||||||
{
|
{
|
||||||
/// <summary>
|
using var rng = RandomNumberGenerator.Create();
|
||||||
/// Generates a symmetric security key with the specified byte size.
|
var randomBytes = new byte[byteSize];
|
||||||
/// </summary>
|
rng.GetBytes(randomBytes);
|
||||||
/// <param name="byteSize">The size of the security key in bytes. Default is 32 bytes.</param>
|
var securityKey = new SymmetricSecurityKey(randomBytes);
|
||||||
/// <returns>A new instance of <see cref="SymmetricSecurityKey"/>.</returns>
|
|
||||||
public static SymmetricSecurityKey GenerateSecurityKey(int byteSize = 32)
|
|
||||||
{
|
|
||||||
using var rng = RandomNumberGenerator.Create();
|
|
||||||
var randomBytes = new byte[byteSize];
|
|
||||||
rng.GetBytes(randomBytes);
|
|
||||||
var securityKey = new SymmetricSecurityKey(randomBytes);
|
|
||||||
|
|
||||||
return securityKey;
|
return securityKey;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generates a token based on the specified claim value.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="claimValue">The claim value to encode in the token.</param>
|
|
||||||
/// <returns>A JWT as a string.</returns>
|
|
||||||
string GenerateToken(TClaimValue claimValue);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reads and validates a security token from a string representation.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="token">The JWT to read.</param>
|
|
||||||
/// <returns>A <see cref="JwtSecurityToken"/> if the token is valid; otherwise, null.</returns>
|
|
||||||
JwtSecurityToken? ReadSecurityToken(string token);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a token based on the specified claim value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="claimValue">The claim value to encode in the token.</param>
|
||||||
|
/// <returns>A JWT as a string.</returns>
|
||||||
|
string GenerateToken(TClaimValue claimValue);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads and validates a security token from a string representation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="token">The JWT to read.</param>
|
||||||
|
/// <returns>A <see cref="JwtSecurityToken"/> if the token is valid; otherwise, null.</returns>
|
||||||
|
JwtSecurityToken? ReadSecurityToken(string token);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@ -1,39 +1,40 @@
|
|||||||
using DigitalData.Core.Abstraction.Application.DTO;
|
#if NET
|
||||||
|
using DigitalData.Core.Abstraction.Application.DTO;
|
||||||
|
|
||||||
namespace DigitalData.Core.Abstraction.Application
|
namespace DigitalData.Core.Abstraction.Application;
|
||||||
|
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
|
public interface IReadService<TReadDto, TEntity, TId>
|
||||||
|
where TReadDto : class where TEntity : class
|
||||||
{
|
{
|
||||||
[Obsolete("Use MediatR")]
|
/// <summary>
|
||||||
public interface IReadService<TReadDto, TEntity, TId>
|
/// Retrieves an entity by its identifier and returns its readDTO representation wrapped in an IServiceResult,
|
||||||
where TReadDto : class where TEntity : class
|
/// including the readDTO on success or null and an error message on failure.
|
||||||
{
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="id">The identifier of the entity to retrieve.</param>
|
||||||
/// Retrieves an entity by its identifier and returns its readDTO representation wrapped in an IServiceResult,
|
/// <returns>An DataResult containing the readDTO representing the found entity or null, with an appropriate message.</returns>
|
||||||
/// including the readDTO on success or null and an error message on failure.
|
Task<DataResult<TReadDto>> ReadByIdAsync(TId id);
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">The identifier of the entity to retrieve.</param>
|
|
||||||
/// <returns>An DataResult containing the readDTO representing the found entity or null, with an appropriate message.</returns>
|
|
||||||
Task<DataResult<TReadDto>> ReadByIdAsync(TId id);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves all entities and returns their readDTO representations wrapped in an IServiceResult,
|
/// Retrieves all entities and returns their readDTO representations wrapped in an IServiceResult,
|
||||||
/// including a collection of readDTOs on success or an error message on failure.
|
/// including a collection of readDTOs on success or an error message on failure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>An DataResult containing a collection of readDTOs representing all entities or an error message.</returns>
|
/// <returns>An DataResult containing a collection of readDTOs representing all entities or an error message.</returns>
|
||||||
Task<DataResult<IEnumerable<TReadDto>>> ReadAllAsync();
|
Task<DataResult<IEnumerable<TReadDto>>> ReadAllAsync();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deletes an entity by its identifier and returns the result wrapped in an IServiceMessage,
|
|
||||||
/// indicating the success or failure of the operation, including the error messages on failure.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">The identifier of the entity to delete.</param>
|
|
||||||
/// <returns>An Result indicating the outcome of the delete operation, with an appropriate message.</returns>
|
|
||||||
Task<Result> DeleteAsyncById(TId id);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Asynchronously checks if an entity with the specified identifier exists within the data store.
|
/// Deletes an entity by its identifier and returns the result wrapped in an IServiceMessage,
|
||||||
/// </summary>
|
/// indicating the success or failure of the operation, including the error messages on failure.
|
||||||
/// <param name="id">The identifier of the entity to check.</param>
|
/// </summary>
|
||||||
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the entity exists.</returns>
|
/// <param name="id">The identifier of the entity to delete.</param>
|
||||||
Task<bool> HasEntity(TId id);
|
/// <returns>An Result indicating the outcome of the delete operation, with an appropriate message.</returns>
|
||||||
}
|
Task<Result> DeleteAsyncById(TId id);
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asynchronously checks if an entity with the specified identifier exists within the data store.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The identifier of the entity to check.</param>
|
||||||
|
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the entity exists.</returns>
|
||||||
|
Task<bool> HasEntity(TId id);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@ -1,4 +1,5 @@
|
|||||||
namespace DigitalData.Core.Abstraction.Application.Repository
|
#if NET
|
||||||
|
namespace DigitalData.Core.Abstraction.Application.Repository
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the contract for CRUD operations on a repository for entities of type TEntity.
|
/// Defines the contract for CRUD operations on a repository for entities of type TEntity.
|
||||||
@ -60,4 +61,5 @@
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
Task<int> CountAsync(TId id);
|
Task<int> CountAsync(TId id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@ -1,4 +1,7 @@
|
|||||||
namespace DigitalData.Core.Abstraction.Application.Repository
|
#if NETFRAMEWORK
|
||||||
|
using System.Collections.Generic;
|
||||||
|
#endif
|
||||||
|
namespace DigitalData.Core.Abstraction.Application.Repository
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines methods for mapping between entities and Data Transfer Objects (DTOs).
|
/// Defines methods for mapping between entities and Data Transfer Objects (DTOs).
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user