Skip to content

Commit

Permalink
chore: fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
phmatray committed Sep 13, 2023
1 parent 3c3f367 commit a028a7c
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Task Execute(
string backgroundColor,
string foregroundColor)
{
Pattern pattern = _imageDescriptionFactory
var pattern = _imageDescriptionFactory
.NewPattern(
mirrorPowerHorizontal, mirrorPowerVertical, cellGroupLength,
includeEmptyAndFill, seed);
Expand All @@ -43,18 +43,18 @@ public Task Execute(
new ThemeColor(backgroundColor),
new ThemeColor(foregroundColor));

ImageDescription imageDescription = _imageDescriptionFactory
var imageDescription = _imageDescriptionFactory
.NewImage(pattern, imageConfiguration);

return GeneratePng(imageDescription);
}

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)
Expand Down
8 changes: 4 additions & 4 deletions geometrix-api/Geometrix.Domain/Cells/CellsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,16 @@ public ImageCreationService(ImageEditionService imageEdition)

public async Task<byte[]> CreateImageAsync(ImageDescription imageDescription)
{
(
Pattern pattern,
Settings settings,
int imageWidthPixel,
int imageHeightPixel
) = imageDescription;

var (pattern, settings, imageWidthPixel, imageHeightPixel) = imageDescription;
using var image = new Image<Rgba32>(imageWidthPixel, imageHeightPixel);

_imageEdition.EditImage(image, pattern, settings);

return await GetImageBytes(image);
}

public static async Task<byte[]> GetImageBytes(Image image)
{
await using var memory = new MemoryStream();

await image.SaveAsPngAsync(memory);

return memory.ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IServiceCollection AddAuthentication(
.BuildServiceProvider()
.GetRequiredService<IFeatureManager>();

bool isEnabled = featureManager
var isEnabled = featureManager
.IsEnabledAsync(nameof(CustomFeature.Authentication))
.ConfigureAwait(false)
.GetAwaiter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IServiceCollection AddCustomControllers(this IServiceCollection se
.BuildServiceProvider()
.GetRequiredService<IFeatureManager>();

bool isErrorFilterEnabled = featureManager
var isErrorFilterEnabled = featureManager
.IsEnabledAsync(nameof(CustomFeature.ErrorFilter))
.ConfigureAwait(false)
.GetAwaiter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ public sealed class CustomControllerFeatureProvider : IApplicationFeatureProvide
/// </summary>
public void PopulateFeature(IEnumerable<ApplicationPart> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IServiceCollection AddProxy(this IServiceCollection services)
/// </summary>
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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -33,7 +33,7 @@ public static IServiceCollection AddSwagger(this IServiceCollection services)
.BuildServiceProvider()
.GetRequiredService<IFeatureManager>();

bool isEnabled = featureManager
var isEnabled = featureManager
.IsEnabledAsync(nameof(CustomFeature.Swagger))
.ConfigureAwait(false)
.GetAwaiter()
Expand Down Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion geometrix-api/Geometrix.WebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}

Expand Down

0 comments on commit a028a7c

Please sign in to comment.