mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 07:11:10 +00:00
Adds editorconfig and refactors to the established rules
This commit is contained in:
1 parent
712a0f2b27
commit
cd44f11d9e
138 files changed
+1799
-1629
No files matched your search
@@ -39,7 +39,7 @@ public class ApiHttpClient : IApiHttpClient
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
// read the API server configuration values from the configuration, and assign them to the injected client
|
||||
var serverConfigurationModel = serverConfigurationOptions.Value;
|
||||
ServerConfigurationModel serverConfigurationModel = serverConfigurationOptions.Value;
|
||||
httpClient.BaseAddress = new Uri($"{serverConfigurationModel.BaseAddress}:{serverConfigurationModel.Port}/api/v{serverConfigurationModel.ApiVersion}/");
|
||||
|
||||
_jsonOptions = new JsonSerializerOptions
|
||||
@@ -62,7 +62,7 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <returns>The deserialized response containing the result of the GET request.</returns>
|
||||
public async Task<TResponse> GetAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
@@ -78,7 +78,7 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <returns>An <see cref="IAsyncEnumerable{T}"/> object, which allows for asynchronous iteration over the deserialized items.</returns>
|
||||
public async IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, string? token = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
// HttpClient is implemented differently in Blazor WASM, because there are no sockets in the browser, so its BrowserHttpHandler is implemented on top of Fetch API,
|
||||
// which can provide response content in one of two forms: BrowserHttpContent, which is based on arrayBuffer method (this means that it will always read the response stream to its completion,
|
||||
// before making the content available), and StreamContent that is wrapping WasmHttpReadStream, which is based on readable streams (this one allows for reading response as it comes).
|
||||
@@ -88,11 +88,11 @@ public class ApiHttpClient : IApiHttpClient
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
// send the request and expect only headers initially - this prevents the client from buffering the entire response
|
||||
using var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
||||
using HttpResponseMessage response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
await using System.IO.Stream stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
// Deserialize the JSON content asynchronously as an enumerable of TResponse items
|
||||
await foreach (var item in JsonSerializer.DeserializeAsyncEnumerable<TResponse>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false))
|
||||
await foreach (TResponse? item in JsonSerializer.DeserializeAsyncEnumerable<TResponse>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
@@ -109,14 +109,14 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <returns>A model containing the deserialized blob.</returns>
|
||||
public async Task<BlobDataModel> GetBlobAsync(string endpoint, string? token = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
using var response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
using HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
// read the content as a string, for error messages
|
||||
var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
string content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
ProblemDetailsModel? problemDetails = null;
|
||||
try
|
||||
{
|
||||
@@ -141,7 +141,7 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <returns>The deserialized response containing the result of the DELETE request.</returns>
|
||||
public async Task<TResponse> DeleteAsync<TResponse>(string endpoint, string? token = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Delete, endpoint);
|
||||
using HttpRequestMessage request = new(HttpMethod.Delete, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
@@ -159,7 +159,7 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
public async Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Put, endpoint);
|
||||
using HttpRequestMessage request = new(HttpMethod.Put, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
request.Content = new StringContent(JsonSerializer.Serialize(data, _jsonOptions), Encoding.UTF8, "application/json");
|
||||
@@ -178,7 +178,7 @@ public class ApiHttpClient : IApiHttpClient
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
public async Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, string? token = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, endpoint);
|
||||
using HttpRequestMessage request = new(HttpMethod.Post, endpoint);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
request.Content = new StringContent(JsonSerializer.Serialize(data, _jsonOptions), Encoding.UTF8, "application/json");
|
||||
@@ -197,8 +197,8 @@ public class ApiHttpClient : IApiHttpClient
|
||||
private async Task<TResponse> SendRequestAsync<TResponse>(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
// send the HTTP request and read the response
|
||||
var response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
string content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
// if the response is successful, deserialize the content to TResponse and return it
|
||||
if (response.IsSuccessStatusCode)
|
||||
return JsonSerializer.Deserialize<TResponse>(content, _jsonOptions)!;
|
||||
|
||||
+4
-4
@@ -29,7 +29,7 @@ public static class PresentationWebLayerServices
|
||||
services.AddValidatorsFromAssemblyContaining<Program>(ServiceLifetime.Singleton);
|
||||
|
||||
// handle transient errors like network timeouts or intermittent failures
|
||||
var retryPolicy = Policy
|
||||
Polly.Retry.AsyncRetryPolicy<HttpResponseMessage> retryPolicy = Policy
|
||||
.Handle<HttpRequestException>()
|
||||
.OrResult<HttpResponseMessage>(r =>
|
||||
!r.IsSuccessStatusCode &&
|
||||
@@ -39,17 +39,17 @@ public static class PresentationWebLayerServices
|
||||
TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
||||
|
||||
// use a circuit breaker to prevent repeatedly calling a failing service
|
||||
var circuitBreakerPolicy = Policy
|
||||
Polly.CircuitBreaker.AsyncCircuitBreakerPolicy<HttpResponseMessage> circuitBreakerPolicy = Policy
|
||||
.Handle<HttpRequestException>()
|
||||
.OrResult<HttpResponseMessage>(r => r.StatusCode == HttpStatusCode.InternalServerError)
|
||||
.CircuitBreakerAsync(3, TimeSpan.FromSeconds(30));
|
||||
|
||||
var policy = Policy.WrapAsync(retryPolicy, circuitBreakerPolicy);
|
||||
Polly.Wrap.AsyncPolicyWrap<HttpResponseMessage> policy = Policy.WrapAsync(retryPolicy, circuitBreakerPolicy);
|
||||
|
||||
// register the typed client used for the API interaction
|
||||
services.AddHttpClient<IApiHttpClient, ApiHttpClient>()
|
||||
.AddPolicyHandler(retryPolicy)
|
||||
.AddPolicyHandler(circuitBreakerPolicy);
|
||||
.AddPolicyHandler(circuitBreakerPolicy);
|
||||
|
||||
services.AddSingleton<ComboboxService>();
|
||||
services.AddScoped<INotificationService, NotificationService>();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -52,15 +52,15 @@ public class FluentValidationOptions<TOptions> : IValidateOptions<TOptions> wher
|
||||
|
||||
ArgumentNullException.ThrowIfNull(options, nameof(options)); // don't go further if the options are null
|
||||
|
||||
var validationResult = _validator.Validate(options); // validate the options using the validator
|
||||
FluentValidation.Results.ValidationResult validationResult = _validator.Validate(options); // validate the options using the validator
|
||||
|
||||
// return a response based on the validation result
|
||||
if (validationResult.IsValid)
|
||||
return ValidateOptionsResult.Success;
|
||||
|
||||
|
||||
// if the validation fails, collect the error messages
|
||||
// TODO: add translation support for the error messages
|
||||
var errors = validationResult.Errors.Select(x => $"Options validation failed for '{x.PropertyName}' with error: '{x.ErrorMessage}'")
|
||||
string[] errors = validationResult.Errors.Select(x => $"Options validation failed for '{x.PropertyName}' with error: '{x.ErrorMessage}'")
|
||||
.ToArray();
|
||||
|
||||
// and return them with a failure result
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\client\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -22,5 +22,4 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
<PackageReference Include="Polly" Version="8.4.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,4 +1,4 @@
|
||||
@page "/library/manage/item"
|
||||
@page "/library/manage/item"
|
||||
@page "/library/manage/item/{id:guid}"
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Enums.AudioLibrary
|
||||
@@ -51,7 +51,7 @@
|
||||
<td>@item.Column1</td>
|
||||
<td>@item.Column2</td>
|
||||
<td>
|
||||
<MultiDirectorySelector />
|
||||
@* <MultiDirectorySelector /> *@
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@@ -165,14 +165,19 @@
|
||||
// Perform save operation
|
||||
isSaving = false;
|
||||
Console.WriteLine("saved");
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task CancelOperation()
|
||||
{
|
||||
isCancelling = true;
|
||||
// Perform cancel operation
|
||||
isCancelling = false;
|
||||
Console.WriteLine("cancelled");
|
||||
if (!isCancelling)
|
||||
isCancelling = false;
|
||||
selectedValue2 = new ComboboxItem<string>();
|
||||
if (selectedValue2 is not null)
|
||||
Console.WriteLine("cancelled");
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private List<TableItem> tableData = new List<TableItem>
|
||||
@@ -183,8 +188,8 @@
|
||||
|
||||
public class TableItem
|
||||
{
|
||||
public string Column1 { get; set; }
|
||||
public string Column2 { get; set; }
|
||||
public List<string> Directories { get; set; }
|
||||
public string? Column1 { get; set; }
|
||||
public string? Column2 { get; set; }
|
||||
public List<string>? Directories { get; set; }
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -1,4 +1,4 @@
|
||||
@page "/library/written-content-library/books-library/books/item/{id:guid}"
|
||||
@page "/library/written-content-library/books-library/books/item/{id:guid}"
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Enums.BookLibrary
|
||||
@using Lumina.Presentation.Web.Common.Models.Common
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<div class="form-group">
|
||||
<label for="title">Title<span class="mandatory-field">*</span>:</label>
|
||||
<InputText id="title" @bind-Value="bookRequest.Metadata.Title" class="form-control" />
|
||||
<InputText id="title" @bind-Value="bookRequest.Metadata!.Title" class="form-control" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -33,7 +33,7 @@
|
||||
<h3>Release Information</h3>
|
||||
<div class="form-group">
|
||||
<label for="originalReleaseDate">Original Release Date:</label>
|
||||
<InputDate id="originalReleaseDate" @bind-Value="bookRequest.Metadata.ReleaseInfo.OriginalReleaseDate" class="form-control" />
|
||||
<InputDate id="originalReleaseDate" @bind-Value="bookRequest.Metadata.ReleaseInfo!.OriginalReleaseDate" class="form-control" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
|
||||
<h3>Genres</h3>
|
||||
@foreach (var genre in bookRequest.Metadata.Genres)
|
||||
@foreach (var genre in bookRequest.Metadata.Genres!)
|
||||
{
|
||||
<div class="form-group">
|
||||
<InputText @bind-Value="genre.Name" class="form-control" />
|
||||
@@ -53,7 +53,7 @@
|
||||
<h3>Language</h3>
|
||||
<div class="form-group">
|
||||
<label for="languageCode">Language Code:</label>
|
||||
<InputText id="languageCode" @bind-Value="bookRequest.Metadata.Language.LanguageCode" class="form-control" />
|
||||
<InputText id="languageCode" @bind-Value="bookRequest.Metadata.Language!.LanguageCode" class="form-control" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -80,7 +80,7 @@
|
||||
<h3>Identifiers</h3>
|
||||
<div class="form-group">
|
||||
<label for="isbn">ISBN:</label>
|
||||
<InputText id="isbn" @bind-Value="bookRequest.ISBNs[0].Value" class="form-control" />
|
||||
<InputText id="isbn" @bind-Value="bookRequest.ISBNs![0].Value" class="form-control" />
|
||||
<InputSelect @bind-Value="bookRequest.ISBNs[0].Format" class="form-control">
|
||||
@foreach (var format in Enum.GetValues(typeof(IsbnFormat)))
|
||||
{
|
||||
@@ -90,11 +90,11 @@
|
||||
</div>
|
||||
|
||||
<h3>Contributors</h3>
|
||||
@foreach (var contributor in bookRequest.Contributors)
|
||||
@foreach (var contributor in bookRequest.Contributors!)
|
||||
{
|
||||
<div class="form-group">
|
||||
@* <InputText @bind-Value="contributor.Name" placeholder="Name" class="form-control" /> *@
|
||||
<InputText @bind-Value="contributor.Role.Name" placeholder="Role" class="form-control" />
|
||||
<InputText @bind-Value="contributor.Role!.Name" placeholder="Role" class="form-control" />
|
||||
</div>
|
||||
}
|
||||
<button type="button" class="btn btn-secondary" @onclick="AddContributor">Add Contributor</button>
|
||||
@@ -117,12 +117,12 @@
|
||||
|
||||
private void AddGenre()
|
||||
{
|
||||
bookRequest.Metadata.Genres.Add(new GenreModel());
|
||||
bookRequest.Metadata!.Genres!.Add(new GenreModel());
|
||||
}
|
||||
|
||||
private void AddContributor()
|
||||
{
|
||||
bookRequest.Contributors.Add(new MediaContributorModel { Role = new MediaContributorRoleModel() });
|
||||
bookRequest.Contributors!.Add(new MediaContributorModel { Role = new MediaContributorRoleModel() });
|
||||
}
|
||||
|
||||
private async Task HandleValidSubmit()
|
||||
@@ -143,4 +143,4 @@
|
||||
@code {
|
||||
[Parameter]
|
||||
public Guid? Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class Program
|
||||
/// <param name="args">Optional command line arguments.</param>
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
WebAssemblyHostBuilder builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
|
||||
builder.RootComponents.Add<App>("#app");
|
||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||
@@ -29,7 +29,7 @@ public class Program
|
||||
|
||||
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||
|
||||
var webAssemblyHost = builder.Build();
|
||||
WebAssemblyHost webAssemblyHost = builder.Build();
|
||||
|
||||
await webAssemblyHost.RunAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user