Add project files.

This commit is contained in:
Giuseppe Scorrano 2023-05-09 10:53:29 +02:00
parent 0ab11efcf3
commit 827000c74f
16 changed files with 343 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>ISW___Carelli</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Integry Smart Warehouse\Integry Smart Warehouse.csproj" />
</ItemGroup>
</Project>

11
ISW - Carelli/Program.cs Normal file
View File

@ -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();

View File

@ -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

View File

@ -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<IActionResult> 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"
});
}
}

View File

@ -0,0 +1,12 @@
namespace Integry_Smart_Warehouse.Core.Domain;
public interface IContext
{
Task Init();
Task Start();
Task Stop();
}

View File

@ -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<ContainerBuilder>(configure => { configure.RegisterModule<ISWDataModule>(); });
builder.ConfigureWebHostDefaults(webHost =>
{
webHost.UseStartup<ISWWebHost>();
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();
}
}

View File

@ -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<TuidiApiRestClient>()
// .As<ITuidiApiRestClient>()
// .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";
// });
}
}

View File

@ -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
});
}
}

View File

@ -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<IExceptionHandlerFeature>();
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
}));
}
}
}

View File

@ -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<ResponseBaseExceptionWrapper>();
return builder
.UseExceptionHandler(new ExceptionHandlerOptions()
{
ExceptionHandler = new ResponseBaseExceptionWrapper().Invoke
});
//.UseMiddleware<ResponseBaseWrapper>();
}
}

View File

@ -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<DateTime>
{
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));
}
}

View File

@ -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; }
}

View File

@ -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();
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Integry_Smart_Warehouse</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Core\Controller\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

View File

@ -0,0 +1,12 @@
{
"profiles": {
"Integry Smart Warehouse": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:51218;http://localhost:51219"
}
}
}