Aggiunta servizi/repository x MTC (da testare...)
This commit is contained in:
@@ -9,7 +9,7 @@ namespace MP.Data
|
||||
{
|
||||
public static class DataServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddIocSetup(this IServiceCollection services)
|
||||
public static IServiceCollection AddIocDataLayer(this IServiceCollection services)
|
||||
{
|
||||
//// DbContextFactory: preferibile in Blazor Server e scenari concorrenti
|
||||
//services.AddDbContextFactory<DataLayerContext>(options =>
|
||||
|
||||
@@ -43,7 +43,9 @@ namespace MP.IOC.Components.Pages
|
||||
DateTime oggi = DateTime.Today;
|
||||
DateTime adesso = DateTime.Now;
|
||||
var paretoDayCall = await StatsAggrService.GetParetoStatsDayAsync(0);
|
||||
ListGlobalCall = paretoDayCall["Mach.Duration (ms)"];
|
||||
ListGlobalCall.Clear();
|
||||
var rawMachPareto = paretoDayCall["Mach.Duration (ms)"];
|
||||
ListGlobalCall = rawMachPareto.Take(10).ToList();
|
||||
ListParetoCall = await StatsDetService.GetParetoAsync(adesso.AddHours(-1), adesso, 10);
|
||||
paretoWeek = await StatsAggrService.GetParetoStatsWeekAsync();
|
||||
}
|
||||
|
||||
@@ -1003,6 +1003,36 @@ namespace MP.IOC.Controllers
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di un array Json di oggetti di conf DataItems (es
|
||||
/// per MTC)
|
||||
/// PUT: IOB/saveDataItems/SIMUL_03
|
||||
/// </summary>
|
||||
/// <param name="id">ID dell'IOB</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("saveDataItems/{id}")]
|
||||
public async Task<IActionResult> SaveDataItems(string id, [FromBody] string content = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(id)) return BadRequest("Missing ID");
|
||||
|
||||
// Multi: gestione carattere "|" trasformato in "#"
|
||||
id = id.Replace("|", "#");
|
||||
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
bool done = await DService.SaveDataItemsAsync(id, content);
|
||||
answ = done ? "OK" : "KO";
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in SaveDataItems{Environment.NewLine}{exc}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "NO");
|
||||
}
|
||||
return Ok(answ);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di una Dictionary HashList da salvare in redis
|
||||
/// POST: IOB/saveMachineIobConf/SIMUL_03
|
||||
|
||||
@@ -6,6 +6,7 @@ using MP.Data;
|
||||
using MP.Data.DbModels;
|
||||
using MP.Data.DbModels.Anag;
|
||||
using MP.Data.MgModels;
|
||||
using MP.Data.Services.Mtc;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using StackExchange.Redis;
|
||||
@@ -20,11 +21,15 @@ namespace MP.IOC.Data
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public MpDataService(IConfiguration configuration, ILogger<MpDataService> logger)
|
||||
public MpDataService(
|
||||
IConfiguration configuration,
|
||||
ILogger<MpDataService> logger,
|
||||
IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_logger.LogInformation("Starting MpDataService INIT");
|
||||
_configuration = configuration;
|
||||
_scopeFactory = scopeFactory;
|
||||
|
||||
// setup compoenti REDIS
|
||||
redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis"));
|
||||
@@ -1883,7 +1888,7 @@ namespace MP.IOC.Data
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"Macchine2SlaveGetAll | Read from {readType}: {ts.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
@@ -1914,45 +1919,6 @@ namespace MP.IOC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<HashSet<string>> ListMasterAsync()
|
||||
{
|
||||
HashSet<string> result = new();
|
||||
string currKey = $"{Utils.redisBaseAddr}:ListMaster";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<HashSet<string>>($"{rawData}") ?? new();
|
||||
}
|
||||
else
|
||||
{
|
||||
var fullList = await Macchine2SlaveGetAllAsync();
|
||||
result = fullList.Select(x => x.IdxMacchina).ToHashSet<string>();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private async Task<HashSet<string>> ListSlaveAsync()
|
||||
{
|
||||
HashSet<string> result = new();
|
||||
string currKey = $"{Utils.redisBaseAddr}:ListSlave";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<HashSet<string>>($"{rawData}") ?? new();
|
||||
}
|
||||
else
|
||||
{
|
||||
var fullList = await Macchine2SlaveGetAllAsync();
|
||||
result = fullList.Select(x => x.IdxMacchinaSlave).Distinct().ToHashSet<string>();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco di tutte le macchine gestite
|
||||
/// </summary>
|
||||
@@ -2235,7 +2201,6 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato
|
||||
/// </summary>
|
||||
@@ -3788,6 +3753,28 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
public async Task<bool> SaveDataItemsAsync(string id, string content)
|
||||
{
|
||||
bool answ = false;
|
||||
// se ho content valid...
|
||||
if (!string.IsNullOrWhiteSpace(content) && content.Length > 2)
|
||||
{
|
||||
var dataList = JsonConvert.DeserializeObject<List<MachDataItem>>(content) ?? new();
|
||||
if (dataList != null && dataList.Count > 0)
|
||||
{
|
||||
//var mtcData = new MtcSetupModel()
|
||||
//{
|
||||
// IdxMacchina = id,
|
||||
// MtcDataItems = dataList
|
||||
//};
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
var mtcService = scope.ServiceProvider.GetRequiredService<IMtcSetupService>();
|
||||
answ = await mtcService.ReplaceMachineDataAsync(id, dataList);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
public async Task<bool> SaveMachine2Iob(string idxMacchina, string serData)
|
||||
{
|
||||
bool fatto = false;
|
||||
@@ -4164,10 +4151,9 @@ namespace MP.IOC.Data
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
|
||||
private static ILogger<MpDataService> _logger = null!;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
|
||||
/// <summary>
|
||||
/// MS max age x dato MSE
|
||||
@@ -4419,6 +4405,46 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
private async Task<HashSet<string>> ListMasterAsync()
|
||||
{
|
||||
HashSet<string> result = new();
|
||||
string currKey = $"{Utils.redisBaseAddr}:ListMaster";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<HashSet<string>>($"{rawData}") ?? new();
|
||||
}
|
||||
else
|
||||
{
|
||||
var fullList = await Macchine2SlaveGetAllAsync();
|
||||
result = fullList.Select(x => x.IdxMacchina).ToHashSet<string>();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<HashSet<string>> ListSlaveAsync()
|
||||
{
|
||||
HashSet<string> result = new();
|
||||
string currKey = $"{Utils.redisBaseAddr}:ListSlave";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<HashSet<string>>($"{rawData}") ?? new();
|
||||
}
|
||||
else
|
||||
{
|
||||
var fullList = await Macchine2SlaveGetAllAsync();
|
||||
result = fullList.Select(x => x.IdxMacchinaSlave).Distinct().ToHashSet<string>();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<bool> POdlFlushCache()
|
||||
{
|
||||
bool answ = false;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>6.16.2604.2308</Version>
|
||||
<Version>6.16.2604.2318</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+3
-8
@@ -3,8 +3,6 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using MP.Core.Conf;
|
||||
using MP.Data;
|
||||
using MP.Data.Repository.Utils;
|
||||
using MP.Data.Services.Utils;
|
||||
using MP.IOC.Components;
|
||||
using MP.IOC.Data;
|
||||
using MP.IOC.Services;
|
||||
@@ -64,6 +62,9 @@ builder.Services.Configure<RedisScriptsConfig>(
|
||||
builder.Configuration.GetSection("RedisScripts"));
|
||||
logger.Info("RedisScript Provider configured");
|
||||
|
||||
// MP.Data Services Utils - Statistiche DB
|
||||
builder.Services.AddIocDataLayer();
|
||||
|
||||
// base services
|
||||
builder.Services.AddSingleton<PreserveBodyTransformer>();
|
||||
builder.Services.AddSingleton<RouteStatsManager>();
|
||||
@@ -83,12 +84,6 @@ string utilsConnString = builder.Configuration.GetConnectionString("MP.Utils") ?
|
||||
builder.Services.AddDbContextFactory<MoonPro_UtilsContext>(options =>
|
||||
options.UseSqlServer(utilsConnString));
|
||||
|
||||
// MP.Data Services Utils - Statistiche DB
|
||||
builder.Services.AddScoped<IStatsAggrRepository, StatsAggrRepository>();
|
||||
builder.Services.AddScoped<IStatsDetailRepository, StatsDetailRepository>();
|
||||
builder.Services.AddScoped<IStatsAggrService, StatsAggrService>();
|
||||
builder.Services.AddScoped<IStatsDetailService, StatsDetailService>();
|
||||
|
||||
// generic controller
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 6.16.2604.2308</h4>
|
||||
<h4>Versione: 6.16.2604.2318</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2604.2308
|
||||
6.16.2604.2318
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2604.2308</version>
|
||||
<version>6.16.2604.2318</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user