From a028a7c83f354e8766ef768e868ab35af6720f06 Mon Sep 17 00:00:00 2001 From: Philippe Matray Date: Wed, 13 Sep 2023 21:11:25 +0200 Subject: [PATCH] chore: fix code style --- .../UseCases/GenerateImage/GenerateImageUseCase.cs | 8 ++++---- .../Geometrix.Domain/Cells/CellsCollection.cs | 8 ++++---- .../ValueObjects/TriangleDirection.cs | 2 +- .../FileStorage/FileStorageService.cs | 6 +++--- .../FileStorage/FileStorageServiceV2.cs | 6 +++--- .../ImageCreation/ImageCreationService.cs | 12 +----------- .../ImageCreation/ImageEditionService.cs | 6 +----- .../Modules/Common/AuthenticationExtensions.cs | 2 +- .../Modules/Common/CustomControllersExtensions.cs | 2 +- .../FeatureFlags/CustomControllerFeatureProvider.cs | 12 ++++++------ .../Modules/Common/LoggingExtensions.cs | 2 +- .../Modules/Common/ReverseProxyExtensions.cs | 2 +- .../Common/Swagger/ConfigureSwaggerOptions.cs | 2 +- .../Modules/Common/Swagger/SwaggerExtensions.cs | 12 ++++++------ .../Modules/HealthChecksExtensions.cs | 2 +- geometrix-api/Geometrix.WebApi/Startup.cs | 2 +- 16 files changed, 36 insertions(+), 50 deletions(-) diff --git a/geometrix-api/Geometrix.Application/UseCases/GenerateImage/GenerateImageUseCase.cs b/geometrix-api/Geometrix.Application/UseCases/GenerateImage/GenerateImageUseCase.cs index f785214..ef6e74c 100644 --- a/geometrix-api/Geometrix.Application/UseCases/GenerateImage/GenerateImageUseCase.cs +++ b/geometrix-api/Geometrix.Application/UseCases/GenerateImage/GenerateImageUseCase.cs @@ -33,7 +33,7 @@ public Task Execute( string backgroundColor, string foregroundColor) { - Pattern pattern = _imageDescriptionFactory + var pattern = _imageDescriptionFactory .NewPattern( mirrorPowerHorizontal, mirrorPowerVertical, cellGroupLength, includeEmptyAndFill, seed); @@ -43,7 +43,7 @@ public Task Execute( new ThemeColor(backgroundColor), new ThemeColor(foregroundColor)); - ImageDescription imageDescription = _imageDescriptionFactory + var imageDescription = _imageDescriptionFactory .NewImage(pattern, imageConfiguration); return GeneratePng(imageDescription); @@ -51,10 +51,10 @@ public Task Execute( private async Task GeneratePng(ImageDescription imageDescription) { - byte[] bytes = await _imageCreationService + var bytes = await _imageCreationService .CreateImageAsync(imageDescription); - string? fileName = await _fileStorageService + var fileName = await _fileStorageService .SaveFileAsync(bytes, imageDescription.Id, ".png"); if (fileName is null) diff --git a/geometrix-api/Geometrix.Domain/Cells/CellsCollection.cs b/geometrix-api/Geometrix.Domain/Cells/CellsCollection.cs index 0eb053d..3809998 100644 --- a/geometrix-api/Geometrix.Domain/Cells/CellsCollection.cs +++ b/geometrix-api/Geometrix.Domain/Cells/CellsCollection.cs @@ -47,11 +47,11 @@ public void ExpandDown(int currentPower) private Cell CreateMirrorCell(Cell original, bool isRight, int currentPower) { - int mirrorFactor = _cellGroupLength * 2.Pow(currentPower) - 1; - int x = isRight ? -original.X + mirrorFactor : original.X; - int y = isRight ? original.Y : -original.Y + mirrorFactor; + var mirrorFactor = _cellGroupLength * 2.Pow(currentPower) - 1; + var x = isRight ? -original.X + mirrorFactor : original.X; + var y = isRight ? original.Y : -original.Y + mirrorFactor; - TriangleDirection triangleDirection = isRight + var triangleDirection = isRight ? TriangleDirection.MirrorRight(original.TriangleDirection) : TriangleDirection.MirrorDown(original.TriangleDirection); diff --git a/geometrix-api/Geometrix.Domain/ValueObjects/TriangleDirection.cs b/geometrix-api/Geometrix.Domain/ValueObjects/TriangleDirection.cs index aab812a..92873c2 100644 --- a/geometrix-api/Geometrix.Domain/ValueObjects/TriangleDirection.cs +++ b/geometrix-api/Geometrix.Domain/ValueObjects/TriangleDirection.cs @@ -71,7 +71,7 @@ public static TriangleDirection MirrorDown(TriangleDirection direction) public static TriangleDirection CreateRandom(Random random, bool includeEmptyAndFill) { - Direction direction = includeEmptyAndFill + var direction = includeEmptyAndFill ? (Direction) random.Next(6) : (Direction) (random.Next(4) + 1); diff --git a/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageService.cs b/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageService.cs index 7390370..412e1f9 100644 --- a/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageService.cs +++ b/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageService.cs @@ -24,19 +24,19 @@ public FileStorageService( string extension = "") { var fileName = $"{nameWithoutExtension}.png"; - string path = Path.Combine(_env.ContentRootPath, "wwwroot", "images"); + var path = Path.Combine(_env.ContentRootPath, "wwwroot", "images"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } - string fullFileLocation = Path.Combine(path, fileName); + var fullFileLocation = Path.Combine(path, fileName); await using var fileStream = new FileStream(fullFileLocation, FileMode.Create); // Write the data to the file, byte by byte. - foreach (byte b in dataArray) + foreach (var b in dataArray) { fileStream.WriteByte(b); } diff --git a/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageServiceV2.cs b/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageServiceV2.cs index 94818ad..638594b 100644 --- a/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageServiceV2.cs +++ b/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageServiceV2.cs @@ -25,14 +25,14 @@ public FileStorageServiceV2( string extension = DefaultImageExtension) { var fileName = $"{nameWithoutExtension}{extension}"; - string path = Path.Combine(_env.ContentRootPath, DefaultImageFolder); + var path = Path.Combine(_env.ContentRootPath, DefaultImageFolder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } - string fullFileLocation = GenerateUniquePath(path, fileName); + var fullFileLocation = GenerateUniquePath(path, fileName); try { @@ -49,7 +49,7 @@ public FileStorageServiceV2( private static string GenerateUniquePath(string path, string fileName) { - string fullPath = Path.Combine(path, fileName); + var fullPath = Path.Combine(path, fileName); if (!File.Exists(fullPath)) return fullPath; diff --git a/geometrix-api/Geometrix.Infrastructure/ImageCreation/ImageCreationService.cs b/geometrix-api/Geometrix.Infrastructure/ImageCreation/ImageCreationService.cs index 2b03073..5769524 100644 --- a/geometrix-api/Geometrix.Infrastructure/ImageCreation/ImageCreationService.cs +++ b/geometrix-api/Geometrix.Infrastructure/ImageCreation/ImageCreationService.cs @@ -16,26 +16,16 @@ public ImageCreationService(ImageEditionService imageEdition) public async Task CreateImageAsync(ImageDescription imageDescription) { - ( - Pattern pattern, - Settings settings, - int imageWidthPixel, - int imageHeightPixel - ) = imageDescription; - + var (pattern, settings, imageWidthPixel, imageHeightPixel) = imageDescription; using var image = new Image(imageWidthPixel, imageHeightPixel); - _imageEdition.EditImage(image, pattern, settings); - return await GetImageBytes(image); } public static async Task GetImageBytes(Image image) { await using var memory = new MemoryStream(); - await image.SaveAsPngAsync(memory); - return memory.ToArray(); } } \ No newline at end of file diff --git a/geometrix-api/Geometrix.Infrastructure/ImageCreation/ImageEditionService.cs b/geometrix-api/Geometrix.Infrastructure/ImageCreation/ImageEditionService.cs index 14ca8e2..81d3cad 100644 --- a/geometrix-api/Geometrix.Infrastructure/ImageCreation/ImageEditionService.cs +++ b/geometrix-api/Geometrix.Infrastructure/ImageCreation/ImageEditionService.cs @@ -19,11 +19,7 @@ public void EditImage( Pattern pattern, Settings settings) { - ( - int cellWidthPixel, - ThemeColor backgroundThemeColor, - ThemeColor foregroundThemeColor - ) = settings; + var (cellWidthPixel, backgroundThemeColor, foregroundThemeColor) = settings; Color background = ConvertToSixLaborsColor(backgroundThemeColor); SetBackground(image, background); diff --git a/geometrix-api/Geometrix.WebApi/Modules/Common/AuthenticationExtensions.cs b/geometrix-api/Geometrix.WebApi/Modules/Common/AuthenticationExtensions.cs index 736c9fd..8e75be8 100644 --- a/geometrix-api/Geometrix.WebApi/Modules/Common/AuthenticationExtensions.cs +++ b/geometrix-api/Geometrix.WebApi/Modules/Common/AuthenticationExtensions.cs @@ -20,7 +20,7 @@ public static IServiceCollection AddAuthentication( .BuildServiceProvider() .GetRequiredService(); - bool isEnabled = featureManager + var isEnabled = featureManager .IsEnabledAsync(nameof(CustomFeature.Authentication)) .ConfigureAwait(false) .GetAwaiter() diff --git a/geometrix-api/Geometrix.WebApi/Modules/Common/CustomControllersExtensions.cs b/geometrix-api/Geometrix.WebApi/Modules/Common/CustomControllersExtensions.cs index 3e529af..c55d4dc 100644 --- a/geometrix-api/Geometrix.WebApi/Modules/Common/CustomControllersExtensions.cs +++ b/geometrix-api/Geometrix.WebApi/Modules/Common/CustomControllersExtensions.cs @@ -20,7 +20,7 @@ public static IServiceCollection AddCustomControllers(this IServiceCollection se .BuildServiceProvider() .GetRequiredService(); - bool isErrorFilterEnabled = featureManager + var isErrorFilterEnabled = featureManager .IsEnabledAsync(nameof(CustomFeature.ErrorFilter)) .ConfigureAwait(false) .GetAwaiter() diff --git a/geometrix-api/Geometrix.WebApi/Modules/Common/FeatureFlags/CustomControllerFeatureProvider.cs b/geometrix-api/Geometrix.WebApi/Modules/Common/FeatureFlags/CustomControllerFeatureProvider.cs index 0ffe45e..224097a 100644 --- a/geometrix-api/Geometrix.WebApi/Modules/Common/FeatureFlags/CustomControllerFeatureProvider.cs +++ b/geometrix-api/Geometrix.WebApi/Modules/Common/FeatureFlags/CustomControllerFeatureProvider.cs @@ -24,27 +24,27 @@ public sealed class CustomControllerFeatureProvider : IApplicationFeatureProvide /// public void PopulateFeature(IEnumerable parts, ControllerFeature feature) { - for (int i = feature.Controllers.Count - 1; i >= 0; i--) + for (var i = feature.Controllers.Count - 1; i >= 0; i--) { - Type controller = feature.Controllers[i].AsType(); - foreach (CustomAttributeData customAttribute in controller.CustomAttributes) + var controller = feature.Controllers[i].AsType(); + foreach (var customAttribute in controller.CustomAttributes) { if (customAttribute.AttributeType.FullName != typeof(FeatureGateAttribute).FullName) { continue; } - CustomAttributeTypedArgument constructorArgument = customAttribute.ConstructorArguments.First(); + var constructorArgument = customAttribute.ConstructorArguments.First(); if (constructorArgument.Value is not IEnumerable arguments) { continue; } - foreach (object? argumentValue in arguments) + foreach (var argumentValue in arguments) { var typedArgument = (CustomAttributeTypedArgument)argumentValue!; var typedArgumentValue = (CustomFeature)(int)typedArgument.Value!; - bool isFeatureEnabled = _featureManager + var isFeatureEnabled = _featureManager .IsEnabledAsync(typedArgumentValue.ToString()) .ConfigureAwait(false) .GetAwaiter() diff --git a/geometrix-api/Geometrix.WebApi/Modules/Common/LoggingExtensions.cs b/geometrix-api/Geometrix.WebApi/Modules/Common/LoggingExtensions.cs index 041ddf5..3b456c5 100644 --- a/geometrix-api/Geometrix.WebApi/Modules/Common/LoggingExtensions.cs +++ b/geometrix-api/Geometrix.WebApi/Modules/Common/LoggingExtensions.cs @@ -28,7 +28,7 @@ public static IServiceCollection AddInvalidRequestLogging(this IServiceCollectio .Select(x => x.ErrorMessage) .ToList(); - string jsonModelState = JsonSerializer.Serialize(errors); + var jsonModelState = JsonSerializer.Serialize(errors); logger.LogWarning("Invalid request @jsonModelState", jsonModelState); var problemDetails = new ValidationProblemDetails(actionContext.ModelState); diff --git a/geometrix-api/Geometrix.WebApi/Modules/Common/ReverseProxyExtensions.cs b/geometrix-api/Geometrix.WebApi/Modules/Common/ReverseProxyExtensions.cs index 40dab92..8e61a93 100644 --- a/geometrix-api/Geometrix.WebApi/Modules/Common/ReverseProxyExtensions.cs +++ b/geometrix-api/Geometrix.WebApi/Modules/Common/ReverseProxyExtensions.cs @@ -26,7 +26,7 @@ public static IServiceCollection AddProxy(this IServiceCollection services) /// public static IApplicationBuilder UseProxy(this IApplicationBuilder app, IConfiguration configuration) { - string? basePath = configuration["ASPNETCORE_BASEPATH"]; + var basePath = configuration["ASPNETCORE_BASEPATH"]; if (!string.IsNullOrEmpty(basePath)) { app.Use(async (context, next) => diff --git a/geometrix-api/Geometrix.WebApi/Modules/Common/Swagger/ConfigureSwaggerOptions.cs b/geometrix-api/Geometrix.WebApi/Modules/Common/Swagger/ConfigureSwaggerOptions.cs index 59fe735..1e682a8 100644 --- a/geometrix-api/Geometrix.WebApi/Modules/Common/Swagger/ConfigureSwaggerOptions.cs +++ b/geometrix-api/Geometrix.WebApi/Modules/Common/Swagger/ConfigureSwaggerOptions.cs @@ -35,7 +35,7 @@ public void Configure(SwaggerGenOptions options) { // add a swagger document for each discovered API version // note: you might choose to skip or document deprecated API versions differently - foreach (ApiVersionDescription description in _provider.ApiVersionDescriptions) + foreach (var description in _provider.ApiVersionDescriptions) { options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); } diff --git a/geometrix-api/Geometrix.WebApi/Modules/Common/Swagger/SwaggerExtensions.cs b/geometrix-api/Geometrix.WebApi/Modules/Common/Swagger/SwaggerExtensions.cs index a8acdec..4441bc5 100644 --- a/geometrix-api/Geometrix.WebApi/Modules/Common/Swagger/SwaggerExtensions.cs +++ b/geometrix-api/Geometrix.WebApi/Modules/Common/Swagger/SwaggerExtensions.cs @@ -18,8 +18,8 @@ private static string XmlCommentsFilePath { get { - string basePath = PlatformServices.Default.Application.ApplicationBasePath; - string fileName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml"; + var basePath = PlatformServices.Default.Application.ApplicationBasePath; + var fileName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml"; return Path.Combine(basePath, fileName); } } @@ -33,7 +33,7 @@ public static IServiceCollection AddSwagger(this IServiceCollection services) .BuildServiceProvider() .GetRequiredService(); - bool isEnabled = featureManager + var isEnabled = featureManager .IsEnabledAsync(nameof(CustomFeature.Swagger)) .ConfigureAwait(false) .GetAwaiter() @@ -86,11 +86,11 @@ public static IApplicationBuilder UseVersionedSwagger( app.UseSwaggerUI( options => { - foreach (ApiVersionDescription description in provider.ApiVersionDescriptions) + foreach (var description in provider.ApiVersionDescriptions) { - string? basePath = configuration["ASPNETCORE_BASEPATH"]; + var basePath = configuration["ASPNETCORE_BASEPATH"]; - string swaggerEndpoint = !string.IsNullOrEmpty(basePath) + var swaggerEndpoint = !string.IsNullOrEmpty(basePath) ? $"{basePath}/swagger/{description.GroupName}/swagger.json" : $"/swagger/{description.GroupName}/swagger.json"; diff --git a/geometrix-api/Geometrix.WebApi/Modules/HealthChecksExtensions.cs b/geometrix-api/Geometrix.WebApi/Modules/HealthChecksExtensions.cs index abe9fbd..379f3a8 100644 --- a/geometrix-api/Geometrix.WebApi/Modules/HealthChecksExtensions.cs +++ b/geometrix-api/Geometrix.WebApi/Modules/HealthChecksExtensions.cs @@ -18,7 +18,7 @@ public static IServiceCollection AddHealthChecks( this IServiceCollection services, IConfiguration configuration) { - IHealthChecksBuilder healthChecks = services.AddHealthChecks(); + var healthChecks = services.AddHealthChecks(); //IFeatureManager featureManager = services // .BuildServiceProvider() diff --git a/geometrix-api/Geometrix.WebApi/Startup.cs b/geometrix-api/Geometrix.WebApi/Startup.cs index 73f14fb..11e857b 100644 --- a/geometrix-api/Geometrix.WebApi/Startup.cs +++ b/geometrix-api/Geometrix.WebApi/Startup.cs @@ -40,7 +40,7 @@ public void ConfigureServices(IServiceCollection services) .AddProxy() .AddCustomDataProtection(); - int servicesCount = services.Count; + var servicesCount = services.Count; Console.WriteLine($"Total services registered: {servicesCount}"); }