mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Rewords additional code comments as complete sentences
This commit is contained in:
1 parent
36e43b7999
commit
871644b3c9
23 files changed
+171
-140
No files matched your search
@@ -224,18 +224,21 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="fileStream">The stream of the file to upload.</param>
|
||||
/// <param name="fileName">The name of the file to upload.</param>
|
||||
/// <param name="fileStream">The stream of the file to upload, or <see langword="null"/> to send a multipart form without any file.</param>
|
||||
/// <param name="fileName">The name of the file to upload, or <see langword="null"/> when no file is sent.</param>
|
||||
/// <param name="fieldName">The name of the form field carrying the file.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
public async Task<TResponse> PutMultipartAsync<TResponse>(string endpoint, Stream fileStream, string fileName, string fieldName, CancellationToken cancellationToken = default)
|
||||
public async Task<TResponse> PutMultipartAsync<TResponse>(string endpoint, Stream? fileStream, string? fileName, string fieldName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// The file is streamed as a generic binary part, since the exact content type of the uploaded file is not known.
|
||||
using MultipartFormDataContent form = [];
|
||||
using StreamContent fileContent = new(fileStream);
|
||||
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
||||
form.Add(fileContent, fieldName, fileName);
|
||||
if (fileStream is not null)
|
||||
{
|
||||
// The file is streamed as a generic binary part, since the exact content type of the uploaded file is not known.
|
||||
StreamContent fileContent = new(fileStream);
|
||||
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
||||
form.Add(fileContent, fieldName, fileName ?? string.Empty);
|
||||
}
|
||||
|
||||
using HttpRequestMessage request = new(HttpMethod.Put, endpoint)
|
||||
{
|
||||
|
||||
@@ -62,12 +62,12 @@ public interface IApiHttpClient
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="fileStream">The stream of the file to upload.</param>
|
||||
/// <param name="fileName">The name of the file to upload.</param>
|
||||
/// <param name="fileStream">The stream of the file to upload, or <see langword="null"/> to send a multipart form without any file.</param>
|
||||
/// <param name="fileName">The name of the file to upload, or <see langword="null"/> when no file is sent.</param>
|
||||
/// <param name="fieldName">The name of the form field carrying the file.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
Task<TResponse> PutMultipartAsync<TResponse>(string endpoint, Stream fileStream, string fileName, string fieldName, CancellationToken cancellationToken = default);
|
||||
Task<TResponse> PutMultipartAsync<TResponse>(string endpoint, Stream? fileStream, string? fileName, string fieldName, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request with a multipart form containing a single file to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
|
||||
@@ -31,20 +31,20 @@ public class ThemeCachePreferenceService
|
||||
/// Gets whether the theme cache is enabled for the user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the user whose preference is read.</param>
|
||||
/// <param name="defaultValue">The value used when the user did not express a preference yet.</param>
|
||||
/// <param name="isCachingEnabledByDefault">The value used when the user did not express a preference yet.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> when the theme cache is enabled for the user, <see langword="false"/> otherwise.</returns>
|
||||
public async Task<bool> GetAsync(Guid userId, bool defaultValue, CancellationToken cancellationToken = default)
|
||||
public async Task<bool> GetAsync(Guid userId, bool isCachingEnabledByDefault, CancellationToken cancellationToken = default)
|
||||
{
|
||||
bool? preference = await _hybridCache.GetOrCreateAsync(
|
||||
BuildKey(userId),
|
||||
(cancellationToken) => new ValueTask<bool?>(defaultValue),
|
||||
(cancellationToken) => new ValueTask<bool?>(isCachingEnabledByDefault),
|
||||
new HybridCacheEntryOptions()
|
||||
{
|
||||
Expiration = s_preferenceLifetime
|
||||
},
|
||||
cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return preference ?? defaultValue;
|
||||
return preference ?? isCachingEnabledByDefault;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -56,7 +56,7 @@ public class ThemeCachePreferenceService
|
||||
/// <returns>An awaitable task representing the asynchronous operation.</returns>
|
||||
public async Task SetAsync(Guid userId, bool isEnabled, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// the value is stored as a nullable bool, matching the read type, since HybridCache keys entries by their stored type
|
||||
// The value is stored as a nullable bool, matching the read type, since HybridCache keys entries by their stored type.
|
||||
await _hybridCache.SetAsync(BuildKey(userId), (bool?)isEnabled, new HybridCacheEntryOptions()
|
||||
{
|
||||
Expiration = s_preferenceLifetime
|
||||
|
||||
@@ -20,7 +20,7 @@ internal sealed class ValidationRuleForEach<TRequest, TItem> : IValidationRule<T
|
||||
private readonly List<Error> _instanceAwarePredicateErrors = [];
|
||||
private Error currentError = Error.Validation();
|
||||
private Func<TRequest, bool>? condition;
|
||||
private bool lastAddedPredicateIsInstanceAware;
|
||||
private bool isLastAddedPredicateInstanceAware;
|
||||
private AbstractValidator<TItem>? _childValidator;
|
||||
|
||||
/// <summary>
|
||||
@@ -41,7 +41,7 @@ internal sealed class ValidationRuleForEach<TRequest, TItem> : IValidationRule<T
|
||||
{
|
||||
_predicates.Add(predicate);
|
||||
_predicateErrors.Add(currentError);
|
||||
lastAddedPredicateIsInstanceAware = false;
|
||||
isLastAddedPredicateInstanceAware = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ internal sealed class ValidationRuleForEach<TRequest, TItem> : IValidationRule<T
|
||||
{
|
||||
_instanceAwarePredicates.Add(predicate);
|
||||
_instanceAwarePredicateErrors.Add(currentError);
|
||||
lastAddedPredicateIsInstanceAware = true;
|
||||
isLastAddedPredicateInstanceAware = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -76,12 +76,12 @@ internal sealed class ValidationRuleForEach<TRequest, TItem> : IValidationRule<T
|
||||
/// <returns>The current <see cref="IRuleBuilder{TRequest, TItem}"/> instance for method chaining.</returns>
|
||||
public IRuleBuilder<TRequest, TItem> WithError(Error error)
|
||||
{
|
||||
// validation rules always produce validation errors, regardless of the error type of the source error
|
||||
// Validation rules always produce validation errors, regardless of the error type of the source error.
|
||||
Error validationError = Error.Validation(description: error.Description);
|
||||
currentError = validationError;
|
||||
if (lastAddedPredicateIsInstanceAware && _instanceAwarePredicateErrors.Count > 0)
|
||||
if (isLastAddedPredicateInstanceAware && _instanceAwarePredicateErrors.Count > 0)
|
||||
_instanceAwarePredicateErrors[^1] = validationError;
|
||||
else if (!lastAddedPredicateIsInstanceAware && _predicateErrors.Count > 0)
|
||||
else if (!isLastAddedPredicateInstanceAware && _predicateErrors.Count > 0)
|
||||
_predicateErrors[^1] = validationError;
|
||||
return this;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ internal sealed class ValidationRuleForEach<TRequest, TItem> : IValidationRule<T
|
||||
/// <returns>One <see cref="Error"/> per failing predicate, per item; empty if every item passes.</returns>
|
||||
public IEnumerable<Error> Validate(TRequest instance)
|
||||
{
|
||||
// evaluate the condition first, if it returns false, skip validation entirely.
|
||||
// Evaluate the condition first, if it returns false, skip validation entirely..
|
||||
if (condition is not null && !condition(instance))
|
||||
yield break;
|
||||
|
||||
|
||||
Reference in new issue
Block a user