Aggiunta servizio x chiamate API REST ad MP-IO
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP.SPEC</RootNamespace>
|
||||
<Version>6.16.2210.1009</Version>
|
||||
<Version>6.16.2210.1011</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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<IConnectionMultiplexer>(redisMultiplexer);
|
||||
builder.Services.AddSingleton<MpDataService>();
|
||||
builder.Services.AddScoped<MessageService>();
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddSingleton<IOApiService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MP.SPEC.Data;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MP.SPEC.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 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/
|
||||
/// </summary>
|
||||
public class IOApiService
|
||||
{
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
private static ILogger<MpDataService> _logger = null!;
|
||||
private static IConfiguration _configuration = null!;
|
||||
|
||||
|
||||
private static string MpIoBaseUrl = "";
|
||||
|
||||
public IOApiService(IHttpClientFactory clientFactory, IConfiguration configuration, ILogger<MpDataService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logger.LogInformation("Starting IOApiService INIT");
|
||||
_configuration = configuration;
|
||||
_clientFactory = clientFactory;
|
||||
// conf url x chiamate REST
|
||||
MpIoBaseUrl = _configuration.GetValue<string>("ServerConf:MpIoBaseUrl");
|
||||
}
|
||||
/// <summary>
|
||||
/// Effettua chiamata ad MP-IO
|
||||
/// </summary>
|
||||
/// <param name="relUrl">URL metodo relativo alla base path di MP-IO</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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/"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"ServerConf": {
|
||||
"maxAge": "2000",
|
||||
"cacheCheckArtUsato": 2,
|
||||
"redisLongTimeCache": 15
|
||||
"redisLongTimeCache": 15,
|
||||
"MpIoBaseUrl": "http://localhost:20967/"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user