-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from NiceOneFox/develop
Sprint 2
- Loading branch information
Showing
40 changed files
with
508 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
backend/ServiceSimulation/Api/Configuration/ApiMapperConfigurator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
backend/ServiceSimulation/Api/Configuration/CorsPolicies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Microsoft.AspNetCore.Cors.Infrastructure; | ||
|
||
namespace Api.Configuration; | ||
|
||
public static class CorsPolicies | ||
{ | ||
public static readonly (string Name, Action<CorsPolicyBuilder> ConfigurePolicy) AllowRemoteFrontendWithCredentials = | ||
( | ||
"AllowRemoteFrontendWithCredentials", | ||
builder => | ||
{ | ||
var host = Environment.GetEnvironmentVariable("REMOTE_FRONTEND_HOST"); | ||
var port = Environment.GetEnvironmentVariable("REMOTE_FRONTEND_PORT"); | ||
var scheme = Environment.GetEnvironmentVariable("REMOTE_FRONTEND_SCHEME"); | ||
var origin = $"{scheme}://{host}:{port}"; | ||
builder | ||
.WithOrigins(origin) | ||
.AllowAnyHeader() | ||
.AllowAnyMethod() | ||
.AllowCredentials(); | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
backend/ServiceSimulation/Api/Extensions/CorsOptionsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.AspNetCore.Cors.Infrastructure; | ||
|
||
namespace Api.Extensions; | ||
|
||
public static class CorsOptionsExtensions | ||
{ | ||
public static void AddPolicy(this CorsOptions options, (string Name, Action<CorsPolicyBuilder> ConfigurePolicy) arg) | ||
{ | ||
options.AddPolicy(arg.Name, arg.ConfigurePolicy); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
backend/ServiceSimulation/Api/Extensions/CustomExceptionHandlerMiddlewareExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Api.Middlewares; | ||
|
||
namespace Api.Extensions | ||
{ | ||
public static class CustomExceptionHandlerMiddlewareExtensions | ||
{ | ||
public static IApplicationBuilder UseCustomExceptionHandler(this IApplicationBuilder builder) | ||
{ | ||
return builder.UseMiddleware<CustomExceptionHandlerMiddleware>(); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
backend/ServiceSimulation/Api/Middlewares/CustomExceptionHandlerMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Net; | ||
using System.Text.Json; | ||
using FluentValidation; | ||
|
||
namespace Api.Middlewares | ||
{ | ||
public class CustomExceptionHandlerMiddleware | ||
{ | ||
private readonly RequestDelegate _next; | ||
|
||
private readonly ILogger _logger; | ||
public CustomExceptionHandlerMiddleware(RequestDelegate next, | ||
ILogger<CustomExceptionHandlerMiddleware> logger) | ||
{ | ||
_next = next; | ||
_logger = logger; | ||
} | ||
|
||
public async Task Invoke(HttpContext context) | ||
{ | ||
try | ||
{ | ||
await _next(context); | ||
} | ||
catch (Exception ex) | ||
{ | ||
await HandleExceptionAsync(context, ex); | ||
} | ||
} | ||
|
||
private Task HandleExceptionAsync(HttpContext context, Exception ex) | ||
{ | ||
var statusCode = HttpStatusCode.InternalServerError; | ||
var result = string.Empty; | ||
|
||
switch (ex) | ||
{ | ||
case ValidationException validationException: | ||
statusCode = HttpStatusCode.BadRequest; | ||
result = JsonSerializer.Serialize(validationException.Errors); | ||
_logger.LogDebug(validationException.Message); | ||
break; | ||
|
||
default: | ||
statusCode = HttpStatusCode.NotFound; | ||
break; | ||
|
||
} | ||
context.Response.ContentType = "application/json"; | ||
context.Response.StatusCode = (int)statusCode; | ||
|
||
if (result == string.Empty) | ||
{ | ||
result = JsonSerializer.Serialize(new { error = ex.Message }); | ||
} | ||
return context.Response.WriteAsync(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
backend/ServiceSimulation/Api/Validation/InputParametersValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using FluentValidation; | ||
using Bll.Domain.Models; | ||
using Api.enums; | ||
|
||
namespace Api.Validation | ||
{ | ||
public class InputParametersValidator : AbstractValidator<InputParameters> | ||
{ | ||
public InputParametersValidator() | ||
{ | ||
RuleFor(p => p.NumberOfSources).NotEmpty().InclusiveBetween(1, 100); | ||
RuleFor(p => p.NumberOfDevices).NotEmpty().InclusiveBetween(1, 100); | ||
RuleFor(p => p.AmountOfRequests).NotEmpty().InclusiveBetween(1, 5000); | ||
RuleFor(p => p.BufferSize).NotEmpty().InclusiveBetween(1, 100); | ||
RuleFor(p => p.LambdaForDevice).NotEmpty().ExclusiveBetween(0, 10000); | ||
RuleFor(p => p.NumberOfSources).NotEmpty().ExclusiveBetween(0, 10000); | ||
RuleFor(p => p.ModelingTime).NotEmpty().ExclusiveBetween(0, 10000); | ||
RuleFor(p => p.BufferType).IsInEnum(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
"Default": "Trace", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
autoReload="true" | ||
internalLogLevel="Info" | ||
internalLogFile="c:\temp\internal-nlog-AspNetCore.txt"> | ||
|
||
<!-- enable asp.net core layout renderers --> | ||
<extensions> | ||
<add assembly="NLog.Web.AspNetCore"/> | ||
</extensions> | ||
|
||
<!-- the targets to write to --> | ||
<targets> | ||
<!-- File Target for all log messages with basic details --> | ||
<target xsi:type="File" name="allfile" fileName="c:\temp\nlog-AspNetCore-all-${shortdate}.log" | ||
layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}" /> | ||
|
||
<!-- File Target for own log messages with extra web details using some ASP.NET core renderers --> | ||
<target xsi:type="File" name="ownFile-web" fileName="c:\temp\nlog-AspNetCore-own-${shortdate}.log" | ||
layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}|${callsite}" /> | ||
|
||
<!--Console Target for hosting lifetime messages to improve Docker / Visual Studio startup detection --> | ||
<target xsi:type="Console" name="lifetimeConsole" layout="${MicrosoftConsoleLayout}" /> | ||
</targets> | ||
|
||
<!-- rules to map from logger name to target --> | ||
<rules> | ||
<!--All logs, including from Microsoft--> | ||
<logger name="*" minlevel="Trace" writeTo="allfile" /> | ||
|
||
<!--Output hosting lifetime messages to console target for faster startup detection --> | ||
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole, ownFile-web" final="true" /> | ||
|
||
<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) --> | ||
<logger name="Microsoft.*" maxlevel="Info" final="true" /> | ||
<logger name="System.Net.Http.*" maxlevel="Info" final="true" /> | ||
|
||
<logger name="*" minlevel="Trace" writeTo="ownFile-web" /> | ||
</rules> | ||
</nlog> |
22 changes: 22 additions & 0 deletions
22
backend/ServiceSimulation/Bll.Domain.Tests/Bll.Domain.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="Moq" Version="4.17.2" /> | ||
<PackageReference Include="NUnit" Version="3.13.2" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Bll.Domain\Bll.Domain.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.