diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index a37ac980..4ddfc73a 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -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(options => diff --git a/MP.IOC/Components/Pages/Index.razor.cs b/MP.IOC/Components/Pages/Index.razor.cs index 1424145f..b5415b74 100644 --- a/MP.IOC/Components/Pages/Index.razor.cs +++ b/MP.IOC/Components/Pages/Index.razor.cs @@ -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(); } diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs index 5a21b239..e0cfe9e4 100644 --- a/MP.IOC/Controllers/IOBController.cs +++ b/MP.IOC/Controllers/IOBController.cs @@ -1003,6 +1003,36 @@ namespace MP.IOC.Controllers return Ok(answ); } + /// + /// Processa una chiamata POST per l'invio di un array Json di oggetti di conf DataItems (es + /// per MTC) + /// PUT: IOB/saveDataItems/SIMUL_03 + /// + /// ID dell'IOB + /// + [HttpPost("saveDataItems/{id}")] + public async Task 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); + } + + /// /// Processa una chiamata POST per l'invio di una Dictionary HashList da salvare in redis /// POST: IOB/saveMachineIobConf/SIMUL_03 diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index d140c18a..4bc65f2a 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -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 logger) + public MpDataService( + IConfiguration configuration, + ILogger 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 /// @@ -1914,45 +1919,6 @@ namespace MP.IOC.Data return result; } - private async Task> ListMasterAsync() - { - HashSet result = new(); - string currKey = $"{Utils.redisBaseAddr}:ListMaster"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); - } - else - { - var fullList = await Macchine2SlaveGetAllAsync(); - result = fullList.Select(x => x.IdxMacchina).ToHashSet(); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10)); - } - return result; - } - private async Task> ListSlaveAsync() - { - HashSet result = new(); - string currKey = $"{Utils.redisBaseAddr}:ListSlave"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); - } - else - { - var fullList = await Macchine2SlaveGetAllAsync(); - result = fullList.Select(x => x.IdxMacchinaSlave).Distinct().ToHashSet(); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10)); - } - return result; - } - /// /// Elenco di tutte le macchine gestite /// @@ -2235,7 +2201,6 @@ namespace MP.IOC.Data return answ; } - /// /// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato /// @@ -3788,6 +3753,28 @@ namespace MP.IOC.Data return answ; } + public async Task SaveDataItemsAsync(string id, string content) + { + bool answ = false; + // se ho content valid... + if (!string.IsNullOrWhiteSpace(content) && content.Length > 2) + { + var dataList = JsonConvert.DeserializeObject>(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(); + answ = await mtcService.ReplaceMachineDataAsync(id, dataList); + } + } + return answ; + } + public async Task 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 _logger = null!; - private static Logger Log = LogManager.GetCurrentClassLogger(); + private readonly IServiceScopeFactory _scopeFactory; /// /// MS max age x dato MSE @@ -4419,6 +4405,46 @@ namespace MP.IOC.Data return answ; } + private async Task> ListMasterAsync() + { + HashSet result = new(); + string currKey = $"{Utils.redisBaseAddr}:ListMaster"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); + } + else + { + var fullList = await Macchine2SlaveGetAllAsync(); + result = fullList.Select(x => x.IdxMacchina).ToHashSet(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10)); + } + return result; + } + + private async Task> ListSlaveAsync() + { + HashSet result = new(); + string currKey = $"{Utils.redisBaseAddr}:ListSlave"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}") ?? new(); + } + else + { + var fullList = await Macchine2SlaveGetAllAsync(); + result = fullList.Select(x => x.IdxMacchinaSlave).Distinct().ToHashSet(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10)); + } + return result; + } + private async Task POdlFlushCache() { bool answ = false; diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 971bdd3a..82a821be 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 6.16.2604.2308 + 6.16.2604.2318 diff --git a/MP.IOC/Program.cs b/MP.IOC/Program.cs index 178dce5c..226dd3a4 100644 --- a/MP.IOC/Program.cs +++ b/MP.IOC/Program.cs @@ -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( builder.Configuration.GetSection("RedisScripts")); logger.Info("RedisScript Provider configured"); +// MP.Data Services Utils - Statistiche DB +builder.Services.AddIocDataLayer(); + // base services builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -83,12 +84,6 @@ string utilsConnString = builder.Configuration.GetConnectionString("MP.Utils") ? builder.Services.AddDbContextFactory(options => options.UseSqlServer(utilsConnString)); -// MP.Data Services Utils - Statistiche DB -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); - // generic controller builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index bd1e5671..b3904823 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 6.16.2604.2308

+

Versione: 6.16.2604.2318


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index 3d97dba4..1b7f8e2f 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2604.2308 +6.16.2604.2318 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index e826cd0a..38fd664c 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2604.2308 + 6.16.2604.2318 https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html false