From 827000c74f0de7e63bed7cf5c86de58d52d7cd37 Mon Sep 17 00:00:00 2001 From: GiuseppeS Date: Tue, 9 May 2023 10:53:29 +0200 Subject: [PATCH] Add project files. --- ISW - Carelli/ISW - Carelli.csproj | 15 +++++ ISW - Carelli/Program.cs | 11 ++++ Integry Smart Warehouse.sln | 31 ++++++++++ .../Core/Controller/CompanyController.cs | 29 ++++++++++ .../Core/Domain/IContext.cs | 12 ++++ .../Core/Domain/Impl/ISWContext.cs | 56 +++++++++++++++++++ .../Core/Domain/Impl/ISWDataModule.cs | 24 ++++++++ .../Controller/IntegryControllerBase.cs | 28 ++++++++++ .../ResponseBaseExceptionWrapper.cs | 27 +++++++++ .../ResponseBaseWrapperExtension.cs | 16 ++++++ .../WebHost/Converter/JsonDateConverter.cs | 24 ++++++++ .../Core/WebHost/Dto/ResponseBaseDto.cs | 11 ++++ .../Core/WebHost/ISWWebHost.cs | 25 +++++++++ .../Integry Smart Warehouse.csproj | 20 +++++++ Integry Smart Warehouse/Program.cs | 2 + .../Properties/launchSettings.json | 12 ++++ 16 files changed, 343 insertions(+) create mode 100644 ISW - Carelli/ISW - Carelli.csproj create mode 100644 ISW - Carelli/Program.cs create mode 100644 Integry Smart Warehouse.sln create mode 100644 Integry Smart Warehouse/Core/Controller/CompanyController.cs create mode 100644 Integry Smart Warehouse/Core/Domain/IContext.cs create mode 100644 Integry Smart Warehouse/Core/Domain/Impl/ISWContext.cs create mode 100644 Integry Smart Warehouse/Core/Domain/Impl/ISWDataModule.cs create mode 100644 Integry Smart Warehouse/Core/WebHost/Controller/IntegryControllerBase.cs create mode 100644 Integry Smart Warehouse/Core/WebHost/Controller/ResponseBaseExceptionWrapper.cs create mode 100644 Integry Smart Warehouse/Core/WebHost/Controller/ResponseBaseWrapperExtension.cs create mode 100644 Integry Smart Warehouse/Core/WebHost/Converter/JsonDateConverter.cs create mode 100644 Integry Smart Warehouse/Core/WebHost/Dto/ResponseBaseDto.cs create mode 100644 Integry Smart Warehouse/Core/WebHost/ISWWebHost.cs create mode 100644 Integry Smart Warehouse/Integry Smart Warehouse.csproj create mode 100644 Integry Smart Warehouse/Program.cs create mode 100644 Integry Smart Warehouse/Properties/launchSettings.json diff --git a/ISW - Carelli/ISW - Carelli.csproj b/ISW - Carelli/ISW - Carelli.csproj new file mode 100644 index 0000000..a38daca --- /dev/null +++ b/ISW - Carelli/ISW - Carelli.csproj @@ -0,0 +1,15 @@ + + + + Exe + net7.0 + ISW___Carelli + enable + enable + + + + + + + diff --git a/ISW - Carelli/Program.cs b/ISW - Carelli/Program.cs new file mode 100644 index 0000000..a0bfb07 --- /dev/null +++ b/ISW - Carelli/Program.cs @@ -0,0 +1,11 @@ +// See https://aka.ms/new-console-template for more information + +using Integry_Smart_Warehouse.Core.Domain.Impl; + +Console.WriteLine("Hello, World!"); + + + +var iswContext = new ISWContext(); +await iswContext.Init(); +await iswContext.Start(); \ No newline at end of file diff --git a/Integry Smart Warehouse.sln b/Integry Smart Warehouse.sln new file mode 100644 index 0000000..782cf7a --- /dev/null +++ b/Integry Smart Warehouse.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33627.172 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Integry Smart Warehouse", "Integry Smart Warehouse\Integry Smart Warehouse.csproj", "{281A1B5D-BCF8-4DD2-A1A8-94DECC6BFB3A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ISW - Carelli", "ISW - Carelli\ISW - Carelli.csproj", "{B5ABB5A2-D269-424F-ACA0-838F8A591274}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {281A1B5D-BCF8-4DD2-A1A8-94DECC6BFB3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {281A1B5D-BCF8-4DD2-A1A8-94DECC6BFB3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {281A1B5D-BCF8-4DD2-A1A8-94DECC6BFB3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {281A1B5D-BCF8-4DD2-A1A8-94DECC6BFB3A}.Release|Any CPU.Build.0 = Release|Any CPU + {B5ABB5A2-D269-424F-ACA0-838F8A591274}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B5ABB5A2-D269-424F-ACA0-838F8A591274}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B5ABB5A2-D269-424F-ACA0-838F8A591274}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B5ABB5A2-D269-424F-ACA0-838F8A591274}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6954509A-3FC0-4570-A879-00C8E78DEA29} + EndGlobalSection +EndGlobal diff --git a/Integry Smart Warehouse/Core/Controller/CompanyController.cs b/Integry Smart Warehouse/Core/Controller/CompanyController.cs new file mode 100644 index 0000000..8538d75 --- /dev/null +++ b/Integry Smart Warehouse/Core/Controller/CompanyController.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.Mvc; +using System.Net.Mime; +using Integry_Smart_Warehouse.Core.WebHost.Controller; + +namespace Integry_Smart_Warehouse.Core.Controller; + +[Route("[controller]")] +[ApiController] +[Produces(MediaTypeNames.Application.Json)] +public class CompanyController : IntegryControllerBase +{ + [HttpGet] + [Route("")] + public async Task DetchDefaultData() + { + return Ok(new + { + nomeDitta = "INTEGRY S.R.L.", + indirizzo = "VIA GIOIA, 40", + cap = "70017", + citta = "PUTIGNANO", + prov = "BA", + partIva = "05061620729", + numTel = "080/4055215", + numFax = "080/4933245", + eMail = "amministrazione@integry.it" + }); + } +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Core/Domain/IContext.cs b/Integry Smart Warehouse/Core/Domain/IContext.cs new file mode 100644 index 0000000..b56818c --- /dev/null +++ b/Integry Smart Warehouse/Core/Domain/IContext.cs @@ -0,0 +1,12 @@ +namespace Integry_Smart_Warehouse.Core.Domain; + +public interface IContext +{ + + Task Init(); + + Task Start(); + + Task Stop(); + +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Core/Domain/Impl/ISWContext.cs b/Integry Smart Warehouse/Core/Domain/Impl/ISWContext.cs new file mode 100644 index 0000000..31c9411 --- /dev/null +++ b/Integry Smart Warehouse/Core/Domain/Impl/ISWContext.cs @@ -0,0 +1,56 @@ +using Autofac; +using Autofac.Extensions.DependencyInjection; +using Integry_Smart_Warehouse.Core.WebHost; +using Integry_Smart_Warehouse.Core.WebHost.Converter; + +namespace Integry_Smart_Warehouse.Core.Domain.Impl; + +public class ISWContext : IContext +{ + public async Task Init() + { + } + + public Task Start() + { + return CreateHostBuilder().Build().RunAsync(); + } + + private IHostBuilder CreateHostBuilder() + { + var builder = Host.CreateDefaultBuilder(); + + builder.UseServiceProviderFactory(new AutofacServiceProviderFactory()) + .ConfigureContainer(configure => { configure.RegisterModule(); }); + + + builder.ConfigureWebHostDefaults(webHost => + { + webHost.UseStartup(); + + webHost.UseUrls("http://0.0.0.0:5000", "https://0.0.0.0:5001"); + }); + + builder.ConfigureServices(services => + { + var mvcBuilder = services.AddControllers(); + + mvcBuilder.AddJsonOptions(config => + config.JsonSerializerOptions.Converters.Add(new JsonDateConverter())); + + + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + services.AddEndpointsApiExplorer(); + services.AddSwaggerGen(); + }); + + + return builder; + } + + + public async Task Stop() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Core/Domain/Impl/ISWDataModule.cs b/Integry Smart Warehouse/Core/Domain/Impl/ISWDataModule.cs new file mode 100644 index 0000000..b519a97 --- /dev/null +++ b/Integry Smart Warehouse/Core/Domain/Impl/ISWDataModule.cs @@ -0,0 +1,24 @@ +using Autofac; +using Module = Autofac.Module; + +namespace Integry_Smart_Warehouse.Core.Domain.Impl; + +public class ISWDataModule : Module +{ + + protected override void Load(ContainerBuilder builder) + { + base.Load(builder); + + //builder.RegisterType() + // .As() + // .SingleInstance() + // .OnActivated(x => + // { + // x.Instance.BaseUrl = "https://tuidi-essegrande-staging.azurewebsites.net/api/v2/terminal/"; + // //x.Instance.BaseUrl = "http://192.168.1.107:8080/api/v2/terminal/"; + // x.Instance.ApiKey = "YjJlYzA2NTc0MjA4NzEwZWM3YmY2NTRlM2MzZmRjY2MgIC0K"; + // }); + } + +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Core/WebHost/Controller/IntegryControllerBase.cs b/Integry Smart Warehouse/Core/WebHost/Controller/IntegryControllerBase.cs new file mode 100644 index 0000000..492acc3 --- /dev/null +++ b/Integry Smart Warehouse/Core/WebHost/Controller/IntegryControllerBase.cs @@ -0,0 +1,28 @@ +using Integry_Smart_Warehouse.Core.WebHost.Dto; +using Microsoft.AspNetCore.Mvc; + +namespace Integry_Smart_Warehouse.Core.WebHost.Controller; + +public class IntegryControllerBase : ControllerBase +{ + + [NonAction] + public override OkObjectResult Ok(object? value) + { + return base.Ok(new ResponseBaseDto() + { + Dto = value, + Esito = 1 + }); + } + + + [NonAction] + protected new OkObjectResult Ok() + { + return base.Ok(new ResponseBaseDto() + { + Esito = 1 + }); + } +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Core/WebHost/Controller/ResponseBaseExceptionWrapper.cs b/Integry Smart Warehouse/Core/WebHost/Controller/ResponseBaseExceptionWrapper.cs new file mode 100644 index 0000000..f9de86e --- /dev/null +++ b/Integry Smart Warehouse/Core/WebHost/Controller/ResponseBaseExceptionWrapper.cs @@ -0,0 +1,27 @@ +using System.Text.Json; +using Integry_Smart_Warehouse.Core.WebHost.Dto; +using Microsoft.AspNetCore.Diagnostics; + +namespace Integry_Smart_Warehouse.Core.WebHost.Controller; + +public class ResponseBaseExceptionWrapper +{ + public async Task Invoke(HttpContext context) + { + var contextFeature = context.Features.Get(); + if (contextFeature is { Error: { } }) + { + context.Response.StatusCode = StatusCodes.Status200OK; + context.Response.ContentType = "application/json"; + + await context.Response.WriteAsync(JsonSerializer.Serialize(new ResponseBaseDto() + { + Esito = -1, + ErrorMessage = contextFeature.Error.Message + }, new JsonSerializerOptions() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + })); + } + } +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Core/WebHost/Controller/ResponseBaseWrapperExtension.cs b/Integry Smart Warehouse/Core/WebHost/Controller/ResponseBaseWrapperExtension.cs new file mode 100644 index 0000000..858442d --- /dev/null +++ b/Integry Smart Warehouse/Core/WebHost/Controller/ResponseBaseWrapperExtension.cs @@ -0,0 +1,16 @@ +namespace Integry_Smart_Warehouse.Core.WebHost.Controller; + +public static class ResponseBaseWrapperExtension +{ + public static IApplicationBuilder UseResponseWrapper(this IApplicationBuilder builder) + { + //return builder.UseMiddleware(); + return builder + .UseExceptionHandler(new ExceptionHandlerOptions() + { + ExceptionHandler = new ResponseBaseExceptionWrapper().Invoke + }); + + //.UseMiddleware(); + } +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Core/WebHost/Converter/JsonDateConverter.cs b/Integry Smart Warehouse/Core/WebHost/Converter/JsonDateConverter.cs new file mode 100644 index 0000000..d4eded8 --- /dev/null +++ b/Integry Smart Warehouse/Core/WebHost/Converter/JsonDateConverter.cs @@ -0,0 +1,24 @@ +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Integry_Smart_Warehouse.Core.WebHost.Converter; + +public class JsonDateConverter : JsonConverter +{ + + private const string DateFormat = "dd/MM/yyyy HH:mm:ss"; + + public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + using var jsonDoc = JsonDocument.ParseValue(ref reader); + var stringValue = jsonDoc.RootElement.GetRawText().Trim('"').Trim('\''); + var value = DateTime.ParseExact(stringValue, DateFormat, CultureInfo.InvariantCulture); + return value; + } + + public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.ToString(DateFormat, CultureInfo.InvariantCulture)); + } +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Core/WebHost/Dto/ResponseBaseDto.cs b/Integry Smart Warehouse/Core/WebHost/Dto/ResponseBaseDto.cs new file mode 100644 index 0000000..bd5db17 --- /dev/null +++ b/Integry Smart Warehouse/Core/WebHost/Dto/ResponseBaseDto.cs @@ -0,0 +1,11 @@ +namespace Integry_Smart_Warehouse.Core.WebHost.Dto; + +public class ResponseBaseDto +{ + public int Esito { get; set; } + + public string? ErrorMessage { get; set; } + + public object? Dto { get; set; } + +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Core/WebHost/ISWWebHost.cs b/Integry Smart Warehouse/Core/WebHost/ISWWebHost.cs new file mode 100644 index 0000000..5d128d0 --- /dev/null +++ b/Integry Smart Warehouse/Core/WebHost/ISWWebHost.cs @@ -0,0 +1,25 @@ +using Integry_Smart_Warehouse.Core.WebHost.Controller; + +namespace Integry_Smart_Warehouse.Core.WebHost; + +public class ISWWebHost +{ + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + app.UseSwagger(); + app.UseSwaggerUI(); + + app.UseHttpsRedirection(); + + + app.UseRouting(); + app.UseAuthorization(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + + app.UseResponseWrapper(); + } + +} \ No newline at end of file diff --git a/Integry Smart Warehouse/Integry Smart Warehouse.csproj b/Integry Smart Warehouse/Integry Smart Warehouse.csproj new file mode 100644 index 0000000..81c3768 --- /dev/null +++ b/Integry Smart Warehouse/Integry Smart Warehouse.csproj @@ -0,0 +1,20 @@ + + + + Exe + net7.0 + Integry_Smart_Warehouse + enable + enable + + + + + + + + + + + + diff --git a/Integry Smart Warehouse/Program.cs b/Integry Smart Warehouse/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/Integry Smart Warehouse/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/Integry Smart Warehouse/Properties/launchSettings.json b/Integry Smart Warehouse/Properties/launchSettings.json new file mode 100644 index 0000000..f0175b6 --- /dev/null +++ b/Integry Smart Warehouse/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "Integry Smart Warehouse": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:51218;http://localhost:51219" + } + } +} \ No newline at end of file