diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index fdbcc114..66f7d364 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2210.1009 + 6.16.2210.1011 diff --git a/MP.SPEC/Program.cs b/MP.SPEC/Program.cs index fae8d42a..75d78ad3 100644 --- a/MP.SPEC/Program.cs +++ b/MP.SPEC/Program.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using MP.SPEC.Components; using MP.SPEC.Data; +using MP.SPEC.Services; using StackExchange.Redis; var builder = WebApplication.CreateBuilder(args); @@ -38,6 +39,9 @@ builder.Services.AddSingleton(redisMultiplexer); builder.Services.AddSingleton(); builder.Services.AddScoped(); +builder.Services.AddHttpClient(); +builder.Services.AddSingleton(); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/MP.SPEC/Services/IOApiService.cs b/MP.SPEC/Services/IOApiService.cs new file mode 100644 index 00000000..9267abcd --- /dev/null +++ b/MP.SPEC/Services/IOApiService.cs @@ -0,0 +1,56 @@ +using Microsoft.Extensions.Configuration; +using MP.SPEC.Data; +using System.Text.Json; + +namespace MP.SPEC.Services +{ + /// + /// Classe per chiamare metodi da MP-IO + /// + /// rif: + /// https://www.ezzylearning.net/tutorial/making-http-requests-in-blazor-server-apps + /// https://wellsb.com/csharp/aspnet/blazor-httpclientfactory-and-web-api/ + /// + public class IOApiService + { + private readonly IHttpClientFactory _clientFactory; + private static ILogger _logger = null!; + private static IConfiguration _configuration = null!; + + + private static string MpIoBaseUrl = ""; + + public IOApiService(IHttpClientFactory clientFactory, IConfiguration configuration, ILogger logger) + { + _logger = logger; + _logger.LogInformation("Starting IOApiService INIT"); + _configuration = configuration; + _clientFactory = clientFactory; + // conf url x chiamate REST + MpIoBaseUrl = _configuration.GetValue("ServerConf:MpIoBaseUrl"); + } + /// + /// Effettua chiamata ad MP-IO + /// + /// URL metodo relativo alla base path di MP-IO + /// + public async Task callMpIoUrlGet(string relUrl) + { + string result = ""; + var request = new HttpRequestMessage(HttpMethod.Get, $"{MpIoBaseUrl}{relUrl}"); + request.Headers.Add("Accept", "application/vnd.github.v3+json"); + var client = _clientFactory.CreateClient(); + var response = await client.SendAsync(request); + if (response.IsSuccessStatusCode) + { + var stringResponse = await response.Content.ReadAsStringAsync(); + result = stringResponse; + } + else + { + result = "NO"; + } + return result; + } + } +} diff --git a/MP.SPEC/appsettings.Production.json b/MP.SPEC/appsettings.Production.json index a5197b52..bd32e3ce 100644 --- a/MP.SPEC/appsettings.Production.json +++ b/MP.SPEC/appsettings.Production.json @@ -12,5 +12,11 @@ "ConnectionStrings": { "Mp.Data": "Server=localhost\\SQLEXPRESS;Database=MoonPro; User ID=steamware;Password=viadante16; integrated security=False; MultipleActiveResultSets=True; App=Blazor.ServerApp;", "Redis": "localhost:6379,DefaultDatabase=13,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false" + }, + "ServerConf": { + "maxAge": "2000", + "cacheCheckArtUsato": 2, + "redisLongTimeCache": 15, + "MpIoBaseUrl": "http://localhost/MP/IO/" } } diff --git a/MP.SPEC/appsettings.json b/MP.SPEC/appsettings.json index f4116e61..098b7be2 100644 --- a/MP.SPEC/appsettings.json +++ b/MP.SPEC/appsettings.json @@ -15,6 +15,7 @@ "ServerConf": { "maxAge": "2000", "cacheCheckArtUsato": 2, - "redisLongTimeCache": 15 + "redisLongTimeCache": 15, + "MpIoBaseUrl": "http://localhost:20967/" } }