From 712bc5e380ba165d14bcba48704a8c61c46d149f Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli (W11-AI)" Date: Tue, 2 Jun 2026 15:44:25 +0200 Subject: [PATCH 01/12] Inizia code assisted review (non compila...) --- MP.Data/Controllers/MpSpecRepository.cs | 7 + MP.Data/DataServiceCollectionExtensions.cs | 8 + .../Repository/Dossier/DossierRepository.cs | 109 +++ .../Repository/Dossier/IDossierRepository.cs | 24 + .../Repository/FluxLog/FluxLogRepository.cs | 176 ++++ .../Repository/FluxLog/IFluxLogRepository.cs | 17 + .../Repository/Production/BaseRepository.cs | 31 + .../Production/IProductionRepository.cs | 115 +++ .../Production/ProductionRepository.cs | 864 ++++++++++++++++++ .../Repository/System/ISystemRepository.cs | 24 + MP.Data/Repository/System/SystemRepository.cs | 114 +++ MP.SPEC/refactor_repository.md | 32 +- build_all_par.ps1 | 10 +- 13 files changed, 1518 insertions(+), 13 deletions(-) create mode 100644 MP.Data/Repository/Dossier/DossierRepository.cs create mode 100644 MP.Data/Repository/Dossier/IDossierRepository.cs create mode 100644 MP.Data/Repository/FluxLog/FluxLogRepository.cs create mode 100644 MP.Data/Repository/FluxLog/IFluxLogRepository.cs create mode 100644 MP.Data/Repository/Production/BaseRepository.cs create mode 100644 MP.Data/Repository/Production/IProductionRepository.cs create mode 100644 MP.Data/Repository/Production/ProductionRepository.cs create mode 100644 MP.Data/Repository/System/ISystemRepository.cs create mode 100644 MP.Data/Repository/System/SystemRepository.cs diff --git a/MP.Data/Controllers/MpSpecRepository.cs b/MP.Data/Controllers/MpSpecRepository.cs index 224fb848..97c67690 100644 --- a/MP.Data/Controllers/MpSpecRepository.cs +++ b/MP.Data/Controllers/MpSpecRepository.cs @@ -253,6 +253,8 @@ namespace MP.Data.Controllers } #endif + +#if false /// /// Elenco codice articoli che abbiano dati Dossier /// @@ -268,6 +270,8 @@ namespace MP.Data.Controllers .ToListAsync(); } +#endif + #if false /// /// Conteggio num articoli Async @@ -488,6 +492,7 @@ namespace MP.Data.Controllers return await dbCtx.SaveChangesAsync() > 0; } #endif +#if false /// /// Elenco da tabella Config Async @@ -1085,6 +1090,8 @@ namespace MP.Data.Controllers .ToListAsync(); } +#endif + /// /// Elenco ODL filtrati x stato, articolo, KeyRich (che contiene stato) /// diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index f649a7a0..5985cf22 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -3,8 +3,12 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using MP.AppAuth.Services; using MP.Data.Controllers; using MP.Data.Repository.Anag; +using MP.Data.Repository.Dossier; +using MP.Data.Repository.FluxLog; using MP.Data.Repository.IOC; using MP.Data.Repository.Mtc; +using MP.Data.Repository.Production; +using MP.Data.Repository.System; using MP.Data.Repository.Utils; using MP.Data.Services; using MP.Data.Services.IOC; @@ -53,6 +57,10 @@ namespace MP.Data services.TryAddSingleton(); // Scoped + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); // ---------- End Repository ---------- diff --git a/MP.Data/Repository/Dossier/DossierRepository.cs b/MP.Data/Repository/Dossier/DossierRepository.cs new file mode 100644 index 00000000..91f26562 --- /dev/null +++ b/MP.Data/Repository/Dossier/DossierRepository.cs @@ -0,0 +1,109 @@ +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using MP.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.Dossier +{ + public class DossierRepository : IDossierRepository + { + #region Private Fields + + private readonly IConfiguration _configuration; + + #endregion + + #region Public Constructors + + public DossierRepository(IConfiguration configuration) + { + _configuration = configuration; + } + + #endregion + + #region Public Methods + + /// + public async Task DossiersDeleteRecordAsync(DossierModel currRec) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + var currVal = await dbCtx + .DbSetDossiers + .Where(x => x.IdxDossier == currRec.IdxDossier) + .FirstOrDefaultAsync(); + dbCtx + .DbSetDossiers + .Remove(currVal); + + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task> DossiersGetLastFiltAsync(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd, int MaxRec) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + return await dbCtx + .DbSetDossiers + .AsNoTracking() + .Where(x => (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodArticolo == "*" || x.CodArticolo == CodArticolo) && (x.DtRif >= DtStart && x.DtRif <= DtEnd)) + .Include(m => m.MachineNav) + .Include(a => a.ArticoloNav) + .OrderByDescending(x => x.DtRif) + .Take(MaxRec) + .ToListAsync(); + } + + /// + public async Task DossiersInsertAsync(DossierModel newRec) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + await dbCtx + .DbSetDossiers + .AddAsync(newRec); + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task DossiersTakeParamsSnapshotLastAsync(string idxMacchina, DateTime dtMin, DateTime dtMax) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + var pDtMin = new SqlParameter("@DtMin", dtMin); + var pDtMax = new SqlParameter("@DtMax", dtMax); + + var dbResult = await dbCtx + .Database + .ExecuteSqlRawAsync("EXEC stp_FL_TakeSnapshotLast @IdxMacchina,@DtMin,@DtMax", pIdxMacchina, pDtMin, pDtMax); + return dbResult != 0; + } + + /// + public async Task DossiersUpdateValoreAsync(DossierModel editRec) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + var currRec = await dbCtx + .DbSetDossiers + .Where(x => x.IdxDossier == editRec.IdxDossier) + .FirstOrDefaultAsync(); + if (currRec != null) + { + currRec.Valore = editRec.Valore; + dbCtx.Entry(currRec).State = EntityState.Modified; + } + else + { + await dbCtx + .DbSetDossiers + .AddAsync(editRec); + } + return await dbCtx.SaveChangesAsync() > 0; + } + + #endregion + } +} diff --git a/MP.Data/Repository/Dossier/IDossierRepository.cs b/MP.Data/Repository/Dossier/IDossierRepository.cs new file mode 100644 index 00000000..3f6852bd --- /dev/null +++ b/MP.Data/Repository/Dossier/IDossierRepository.cs @@ -0,0 +1,24 @@ +using MP.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace MP.Data.Repository.Dossier +{ + public interface IDossierRepository + { + #region Public Methods + + Task DossiersDeleteRecordAsync(DossierModel currRec); + + Task> DossiersGetLastFiltAsync(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd, int MaxRec); + + Task DossiersInsertAsync(DossierModel newRec); + + Task DossiersTakeParamsSnapshotLastAsync(string idxMacchina, DateTime dtMin, DateTime dtMax); + + Task DossiersUpdateValoreAsync(DossierModel editRec); + + #endregion + } +} diff --git a/MP.Data/Repository/FluxLog/FluxLogRepository.cs b/MP.Data/Repository/FluxLog/FluxLogRepository.cs new file mode 100644 index 00000000..6032c730 --- /dev/null +++ b/MP.Data/Repository/FluxLog/FluxLogRepository.cs @@ -0,0 +1,176 @@ +using Microsoft.Data.SqlClient; +using Microsoft.Extensions.Configuration; +using MP.Core.DTO; +using MP.Core.Objects; +using MP.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.FluxLog +{ + public class FluxLogRepository : IFluxLogRepository + { + #region Private Fields + + private readonly IConfiguration _configuration; + private static NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger(); + + #endregion + + #region Public Constructors + + public FluxLogRepository(IConfiguration configuration) + { + _configuration = configuration; + } + + #endregion + + #region Public Methods + + /// + public async Task> FluxLogDataReduxAsync(string idxMaccSel, List fluxList, Periodo currPeriodo, Enums.ValSelection valMode, Enums.DataInterval intReq, int maxItem) + { + List procStats = new List(); + Log.Info($"Inizio FluxLogDataReduxAsync | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio:yyyy-MM-dd} --> {currPeriodo.Fine:yyyy-MM-dd}"); + TimeSpan step = TimeSpan.FromHours(1); + switch (intReq) + { + case Enums.DataInterval.minute: + step = TimeSpan.FromMinutes(1.00 / maxItem); + break; + + case Enums.DataInterval.hour: + step = TimeSpan.FromHours(1.00 / maxItem); + break; + + case Enums.DataInterval.day: + step = TimeSpan.FromDays(1.00 / maxItem); + break; + + default: + break; + } + + var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMaccSel); + var pOnlyTest = new SqlParameter("@OnlyTest", false); + + await using var dbCtx = new MoonPro_FluxContext(_configuration); + foreach (var item in fluxList) + { + Log.Info($"FluxLogDataReduxAsync | Flux: {item}"); + int numRecProc = 0; + Stopwatch sw = new Stopwatch(); + sw.Start(); + var pCodFlux = new SqlParameter("@CodFlux", item); + DateTime dtCursStart = currPeriodo.Inizio; + DateTime dtCursEnd = dtCursStart.Add(step); + bool setCompleted = false; + while (!setCompleted) + { + var currFlux = await dbCtx + .DbSetFluxLog + .Where(x => (x.CodFlux == item) && (x.dtEvento >= dtCursStart && x.dtEvento < dtCursEnd) && (x.IdxMacchina == idxMaccSel)) + .ToListAsync(); + + int numRec = currFlux.Count; + numRecProc += numRec; + if (numRec > maxItem) + { + List listPeriodi = new List(); + + switch (valMode) + { + case Enums.ValSelection.First: + var recStart = currFlux.Skip(1).FirstOrDefault(); + listPeriodi.Add(new Periodo(recStart.dtEvento, dtCursEnd)); + break; + + case Enums.ValSelection.Last: + var recEnd = currFlux.LastOrDefault(); + listPeriodi.Add(new Periodo(dtCursStart, recEnd.dtEvento)); + break; + + case Enums.ValSelection.Center: + int idx = 1; + var recCent = currFlux.Skip(idx / (maxItem + 1)).FirstOrDefault(); + listPeriodi.Add(new Periodo(dtCursStart, recCent.dtEvento)); + if (maxItem > 1) + { + for (int i = 2; i < maxItem; i++) + { + DateTime dtInizio = recCent.dtEvento; + recCent = currFlux.Skip(i / (maxItem + 1)).FirstOrDefault(); + listPeriodi.Add(new Periodo(dtInizio, recCent.dtEvento)); + } + } + listPeriodi.Add(new Periodo(recCent.dtEvento.AddSeconds(1), dtCursEnd)); + break; + + default: + break; + } + + foreach (var slot in listPeriodi) + { + var pDtStart = new SqlParameter("@DtStart", slot.Inizio); + var pDtEnd = new SqlParameter("@DtEnd", slot.Fine); + await dbCtx + .Database + .ExecuteSqlRawAsync("EXEC man.stp_ReduceFluxLog @IdxMacchina, @CodFlux, @DtStart, @DtEnd, @OnlyTest", pIdxMacchina, pCodFlux, pDtStart, pDtEnd, pOnlyTest); + } + } + + dtCursStart = dtCursEnd; + dtCursEnd = dtCursStart.Add(step); + setCompleted = dtCursStart >= currPeriodo.Fine; + } + sw.Stop(); + StatDedupDTO currStat = new StatDedupDTO() + { + IdxMacchina = idxMaccSel, + CodFlux = item, + Interval = intReq, + Num4Int = maxItem, + NumRec = numRecProc, + ProcTime = sw.Elapsed.TotalSeconds + }; + procStats.Add(currStat); + } + Log.Info($"FINE FluxLogDataReduxAsync | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio:yyyy-MM-dd} --> {currPeriodo.Fine:yyyy-MM-dd}"); + return procStats; + } + + /// + public async Task> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + return await dbCtx + .DbSetFluxLog + .AsNoTracking() + .Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux)) + .OrderByDescending(x => x.dtEvento) + .Take(MaxRec) + .ToListAsync() ?? new(); + } + + /// + public async Task> FluxLogParetoAsync(string idxMacchina, DateTime dtFrom, DateTime dtTo) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + return await dbCtx + .DbSetFluxLog + .Where(x => (string.IsNullOrEmpty(idxMacchina) || x.IdxMacchina == idxMacchina) && (dtFrom <= x.dtEvento && x.dtEvento <= dtTo)) + .AsNoTracking() + .GroupBy(x => x.CodFlux) + .Select(g => new ParetoFluxLogDTO() { IdxMacchina = idxMacchina, CodFlux = g.Key, Qty = g.Count() }) + .OrderByDescending(x => x.Qty) + .ToListAsync() ?? new(); + } + + #endregion + } +} diff --git a/MP.Data/Repository/FluxLog/IFluxLogRepository.cs b/MP.Data/Repository/FluxLog/IFluxLogRepository.cs new file mode 100644 index 00000000..0d50ca31 --- /dev/null +++ b/MP.Data/Repository/FluxLog/IFluxLogRepository.cs @@ -0,0 +1,17 @@ +using MP.Core.DTO; +using MP.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace MP.Data.Repository.FluxLog +{ + public interface IFluxLogRepository + { + Task> FluxLogDataReduxAsync(string idxMaccSel, List fluxList, Periodo currPeriodo, Enums.ValSelection valMode, Enums.DataInterval intReq, int maxItem); + + Task> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec); + + Task> FluxLogParetoAsync(string idxMacchina, DateTime dtFrom, DateTime dtTo); + } +} diff --git a/MP.Data/Repository/Production/BaseRepository.cs b/MP.Data/Repository/Production/BaseRepository.cs new file mode 100644 index 00000000..b7d20e56 --- /dev/null +++ b/MP.Data/Repository/Production/BaseRepository.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore; +using System.Threading.Tasks; + +namespace MP.Data.Repository.Production +{ + public abstract class BaseRepository + { + #region Protected Fields + + protected readonly IDbContextFactory _ctxFactory; + + #endregion Protected Fields + + #region Protected Constructors + + protected BaseRepository(IDbContextFactory ctxFactory) => _ctxFactory = ctxFactory; + + #endregion Protected Constructors + + #region Protected Methods + + /// + /// Creazione dbcontext per singola transazione + /// + /// + protected async Task CreateContextAsync() => await _ctxFactory.CreateDbContextAsync(); + + #endregion Protected Methods + + } +} diff --git a/MP.Data/Repository/Production/IProductionRepository.cs b/MP.Data/Repository/Production/IProductionRepository.cs new file mode 100644 index 00000000..68e464a4 --- /dev/null +++ b/MP.Data/Repository/Production/IProductionRepository.cs @@ -0,0 +1,115 @@ +using MP.Core.DTO; +using MP.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace MP.Data.Repository.Production +{ + public interface IProductionRepository + { + #region ODL Methods + + Task> ListODLFiltAsync(bool inCorso, string codArt, string keyRichPart, string Reparto, string IdxMacchina, DateTime startDate, DateTime endDate); + + Task> OdlByKeyAsync(int IdxOdl); + + Task ODLCloseAsync(int idxOdl, string idxMacchina, int matrOpr, bool confPezzi, bool confRett, int modoConfProd); + + Task> OdlGetCurrentAsync(); + + Task> OdlGetStatAsync(int IdxOdl); + + Task> OdlByBatchAsync(string batchSel); + + #endregion + + #region PODL Methods + + Task> ListPODLFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate); + + Task> ListPODL_ByCodArtAsync(string CodArticolo, bool OnlyAvail); + + Task> ListPODL_ByKitParentAsync(int IdxPodlParent); + + Task> ListPODL_KitFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate); + + Task PODL_getByKeyAsync(int idxPODL); + + Task PODL_getByOdlAsync(int idxODL); + + Task> PODL_getDictOdlPodlAsync(List missingIds); + + Task PODL_startSetup(PODLExpModel editRec, int matrOpr, double tcRich, int pzPallet, string note, DateTime dtEvent); + + Task PODL_updateRecipe(int idxPODL, string recipeName); + + Task PODLDeleteRecordAsync(PODLExpModel currRec); + + Task PODLUpdateRecordAsync(PODLModel editRec); + + Task PodlIstKitDeleteAsync(int IdxPODL); + + #endregion + + #region Kit Methods + + Task IstKitDeleteAsync(IstanzeKitModel rec2del); + + Task> IstKitFiltAsync(string keyKit, string keyExtOrd); + + Task IstKitInsertByWKSAsync(string CodArtParent, string KeyFilt); + + Task IstKitUpsertAsync(IstanzeKitModel editRec); + + Task TemplateKitDeleteAsync(TemplateKitModel rec2del); + + Task> TemplateKitFiltAsync(string KitCode, string codChild); + + Task TemplateKitUpsertAsync(TemplateKitModel editRec, string codAzienda); + + Task WipKitDeleteAsync(WipSetupKitModel rec2del); + + Task WipKitDeleteOlderAsync(DateTime dateLimit); + + Task> WipKitFiltAsync(string KeyFilt); + + Task WipKitUpsertAsync(WipSetupKitModel editRec); + + Task> TksScoreAsync(string KeyFilt, int MaxResult); + + #endregion + + #region Macchine / Gruppi Methods + + Task> MacchineGetFiltAsync(string codGruppo); + + Task> MacchineByMatrOperAsync(int MatrOpr); + + Task> MacchineWithFluxAsync(DateTime dtStart, DateTime dtEnd); + + Task Grp2MaccDeleteAsync(Gruppi2MaccModel rec2del); + + Task Grp2MaccInsertAsync(Gruppi2MaccModel upsRec); + + Task Grp2OperDeleteAsync(Gruppi2OperModel rec2del); + + Task Grp2OperInsertAsync(Gruppi2OperModel upsRec); + + Task> StatoMacchinaAsync(string idxMacchina); + + #endregion + + #region Misc Production Methods + + Task> MseGetAllAsync(int maxAge = 2000); + + Task> ListGiacenzeAsync(int IdxOdl); + + Task> OperatoriGetFiltAsync(string codGruppo); + + Task> ParametriGetFiltAsync(string IdxMacchina); + + #endregion + } +} diff --git a/MP.Data/Repository/Production/ProductionRepository.cs b/MP.Data/Repository/Production/ProductionRepository.cs new file mode 100644 index 00000000..1d5196ac --- /dev/null +++ b/MP.Data/Repository/Production/ProductionRepository.cs @@ -0,0 +1,864 @@ +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using MP.Core.DTO; +using MP.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.Production +{ + public class ProductionRepository : IProductionRepository + { + #region Private Fields + + private readonly IDbContextFactory _ctxFactory; + private readonly IConfiguration _configuration; + + #endregion + + #region Public Constructors + + public ProductionRepository(IDbContextFactory ctxFactory, IConfiguration configuration) + { + _ctxFactory = ctxFactory; + _configuration = configuration; + } + + #endregion + + #region Private Methods + + private async Task GetMoonProContextAsync() => await _ctxFactory.CreateDbContextAsync(); + + #endregion + + #region Public Methods - ODL + + /// + public async Task> ListODLFiltAsync(bool inCorso, string codArt, string keyRichPart, string Reparto, string IdxMacchina, DateTime startDate, DateTime endDate) + { + await using var dbCtx = await GetMoonProContextAsync(); + + var InCorso = new SqlParameter("@InCorso", inCorso); + var CodArt = new SqlParameter("@CodArt", codArt); + var KeyRich = new SqlParameter("@KeyRich", keyRichPart); + var CodGruppo = new SqlParameter("@CodGruppo", Reparto); + var IdxMacc = new SqlParameter("@IdxMacchina", IdxMacchina); + var DataFrom = new SqlParameter("@DataFrom", startDate); + var DataTo = new SqlParameter("@DataTo", endDate); + + return await dbCtx + .DbSetODLExp + .FromSqlRaw("EXEC stp_ODL_getByFiltSpec @InCorso, @CodArt, @KeyRich, @CodGruppo, @IdxMacchina, @DataFrom, @DataTo", InCorso, CodArt, KeyRich, CodGruppo, IdxMacc, DataFrom, DataTo) + .AsNoTracking() + .ToListAsync(); + } + + /// + public async Task> OdlByKeyAsync(int IdxOdl) + { + await using var dbCtx = await GetMoonProContextAsync(); + return await dbCtx + .DbSetODLExp + .AsNoTracking() + .FirstOrDefaultAsync(x => x.IdxOdl == IdxOdl); + } + + /// + public async Task ODLCloseAsync(int idxOdl, string idxMacchina, int matrOpr, bool confPezzi, bool confRett, int modoConfProd) + { + bool fatto = false; + if (idxOdl > 0) + { + await using var dbCtx = await GetMoonProContextAsync(); + // preparo i parametri + var IdxODL = new SqlParameter("@IdxODL", idxOdl); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); + + try + { + var dbResult = await dbCtx + .Database + .ExecuteSqlRawAsync("EXEC stp_ODL_fineProd @IdxODL, @IdxMacchina", IdxODL, IdxMacchina); + fatto = dbResult != 0; + } + catch (Exception exc) + { + NLog.LogManager.GetCurrentClassLogger().Error($"Eccezione durante ODLCloseAsync{Environment.NewLine}{exc}"); + } + } + return fatto; + } + + /// + public async Task> OdlGetCurrentAsync() + { + await using var dbCtx = await GetMoonProContextAsync(); + return await dbCtx + .DbSetODL + .Where(x => x.DataInizio != null && x.DataFine == null) + .ToListAsync(); + } + + /// + public async Task> OdlGetStatAsync(int IdxOdl) + { + List dbResult = new List(); + if (IdxOdl > 0) + { + await using var dbCtx = new MoonPro_STATSContext(_configuration); + var IdxODL = new SqlParameter("@IdxODL", IdxOdl); + + dbResult = await dbCtx + .DbSetODL + .FromSqlRaw("EXEC stp_STAT_ODL @IdxODL", IdxODL) + .AsNoTracking() + .ToListAsync(); + } + return dbResult; + } + + /// + public async Task> OdlByBatchAsync(string batchSel) + { + await using var dbCtx = new MoonPro_InveContext(_configuration); + return await dbCtx + .DbGiacenzeData + .AsNoTracking() + .Where(x => x.IdxOdl > 0) + .Select(x => x.IdxOdl) + .ToListAsync(); + } + + #endregion + + #region Public Methods - PODL + + /// + public async Task> ListPODLFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate) + { + await using var dbCtx = await GetMoonProContextAsync(); + var Lanc = new SqlParameter("@Lanciato", lanciato); + var KeyRich = new SqlParameter("@KeyRich", keyRichPart); + var CodGrp = new SqlParameter("@CodGruppo", codGruppo); + var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina); + var DateFrom = new SqlParameter("@DtInizio", startDate); + var DateTo = new SqlParameter("@DtFine", endDate); + + return await dbCtx + .DbSetPODLExp + .FromSqlRaw("EXEC stp_PODL_getByFiltSpec @Lanciato, @KeyRich, @CodGruppo, @IdxMacchina, @DtInizio, @DtFine", Lanc, KeyRich, CodGrp, IdxMacc, DateFrom, DateTo) + .AsNoTracking() + .ToListAsync(); + } + + /// + public async Task> ListPODL_ByCodArtAsync(string CodArticolo, bool OnlyAvail) + { + await using var dbCtx = await GetMoonProContextAsync(); + var pCodArticolo = new SqlParameter("@CodArticolo", CodArticolo); + var pOnlyAvail = new SqlParameter("@onlyAvail", OnlyAvail); + + return await dbCtx + .DbSetPODLExp + .FromSqlRaw("EXEC stp_PODL_getByCodArt @CodArticolo, @onlyAvail", pCodArticolo, pOnlyAvail) + .AsNoTracking() + .ToListAsync(); + } + + /// + public async Task> ListPODL_ByKitParentAsync(int IdxPodlParent) + { + await using var dbCtx = await GetMoonProContextAsync(); + var pIdxPodlParent = new SqlParameter("@IdxPodlParent", IdxPodlParent); + + return await dbCtx + .DbSetPODLExp + .FromSqlRaw("EXEC stp_PODL_getByParentKitIdx @IdxPodlParent", pIdxPodlParent) + .AsNoTracking() + .ToListAsync(); + } + + /// + public async Task> ListPODL_KitFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate) + { + await using var dbCtx = await GetMoonProContextAsync(); + var Lanc = new SqlParameter("@Lanciato", lanciato); + var KeyRich = new SqlParameter("@KeyRich", keyRichPart); + var CodGrp = new SqlParameter("@CodGruppo", codGruppo); + var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina); + var DateFrom = new SqlParameter("@DtInizio", startDate); + var DateTo = new SqlParameter("@DtFine", endDate); + + return await dbCtx + .DbSetPODLExp + .FromSqlRaw("EXEC stp_PODL_getByFiltSpecKit @Lanciato, @KeyRich, @CodGruppo, @IdxMacchina, @DtInizio, @DtFine", Lanc, KeyRich, CodGrp, IdxMacc, DateFrom, DateTo) + .AsNoTracking() + .ToListAsync(); + } + + /// + public async Task PODL_getByKeyAsync(int idxPODL) + { + await using var dbCtx = await GetMoonProContextAsync(); + return await dbCtx + .DbSetPODL + .AsNoTracking() + .Where(x => x.IdxPromessa == idxPODL) + .Include(a => a.ArticoloNav) + .FirstOrDefaultAsync() ?? new(); + } + + /// + public async Task PODL_getByOdlAsync(int idxODL) + { + await using var dbCtx = await GetMoonProContextAsync(); + return await dbCtx + .DbSetPODL + .AsNoTracking() + .Where(x => x.IdxOdl == idxODL) + .FirstOrDefaultAsync() ?? new(); + } + + /// + public async Task> PODL_getDictOdlPodlAsync(List missingIds) + { + if (missingIds == null || !missingIds.Any()) + return new Dictionary(); + + await using var dbCtx = await GetMoonProContextAsync(); + return await dbCtx + .DbSetPODL + .AsNoTracking() + .Where(x => missingIds.Contains(x.IdxOdl)) + .ToDictionaryAsync(x => x.IdxOdl, x => x.IdxPromessa); + } + + /// + public async Task PODL_startSetup(PODLExpModel editRec, int matrOpr, double tcRich, int pzPallet, string note, DateTime dtEvent) + { + bool answ = false; + PODLModel recPODL = new PODLModel() + { + IdxPromessa = editRec.IdxPromessa, + KeyRichiesta = editRec.KeyRichiesta, + KeyBCode = editRec.KeyBCode, + IdxOdl = editRec.IdxOdl, + CodArticolo = editRec.CodArticolo, + CodGruppo = editRec.CodGruppo, + IdxMacchina = editRec.IdxMacchina, + NumPezzi = editRec.NumPezzi, + Tcassegnato = editRec.Tcassegnato, + DueDate = editRec.DueDate, + Priorita = editRec.Priorita, + PzPallet = editRec.PzPallet, + Note = editRec.Note, + CodCli = editRec.CodCli, + InsertDate = editRec.InsertDate + }; + + await using var dbCtx = await GetMoonProContextAsync(); + var currRec = await dbCtx + .DbSetPODL + .AsNoTracking() + .Where(x => x.IdxPromessa == recPODL.IdxPromessa) + .FirstOrDefaultAsync(); + + if (currRec != null) + { + var IdxPromessa = new SqlParameter("@idxPromessa", recPODL.IdxPromessa); + var MatrOpr = new SqlParameter("@MatrOpr", matrOpr); + var IdxMacchina = new SqlParameter("@IdxMacchina", recPODL.IdxMacchina); + var TCRichAttr = new SqlParameter("@TCRichAttr", tcRich); + var PzPallet = new SqlParameter("@PzPallet", pzPallet); + var Note = new SqlParameter("@Note", note); + var DtEvento = new SqlParameter("@dtEvento", dtEvent); + await dbCtx + .Database + .ExecuteSqlRawAsync("EXEC stp_ODL_inizioSetupPromessa @idxPromessa, @MatrOpr, @IdxMacchina, @TCRichAttr, @PzPallet, @Note, @dtEvento", IdxPromessa, MatrOpr, IdxMacchina, TCRichAttr, PzPallet, Note, DtEvento); + + answ = true; + } + return answ; + } + + /// + public async Task PODL_updateRecipe(int idxPODL, string recipeName) + { + bool answ = false; + await using var dbCtx = await GetMoonProContextAsync(); + var currRec = await dbCtx + .DbSetPODL + .Where(x => x.IdxPromessa == idxPODL) + .FirstOrDefaultAsync(); + + if (currRec != null) + { + currRec.Recipe = recipeName; + dbCtx.Entry(currRec).State = EntityState.Modified; + answ = await dbCtx.SaveChangesAsync() > 0; + } + return answ; + } + + /// + public async Task PODLDeleteRecordAsync(PODLExpModel currRec) + { + PODLModel recPODL = new PODLModel() + { + IdxPromessa = currRec.IdxPromessa, + KeyRichiesta = currRec.KeyRichiesta, + KeyBCode = currRec.KeyBCode, + IdxOdl = currRec.IdxOdl, + CodArticolo = currRec.CodArticolo, + CodGruppo = currRec.CodGruppo, + IdxMacchina = currRec.IdxMacchina, + NumPezzi = currRec.NumPezzi, + Tcassegnato = currRec.Tcassegnato, + DueDate = currRec.DueDate, + Priorita = currRec.Priorita, + PzPallet = currRec.PzPallet, + Note = currRec.Note, + CodCli = currRec.CodCli, + InsertDate = currRec.InsertDate + }; + await using var dbCtx = await GetMoonProContextAsync(); + var currVal = await dbCtx + .DbSetPODL + .Where(x => x.IdxPromessa == recPODL.IdxPromessa) + .FirstOrDefaultAsync(); + dbCtx + .DbSetPODL + .Remove(currVal); + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task PODLUpdateRecordAsync(PODLModel editRec) + { + await using var dbCtx = await GetMoonProContextAsync(); + var currRec = await dbCtx + .DbSetPODL + .Where(x => x.IdxPromessa == editRec.IdxPromessa) + .FirstOrDefaultAsync(); + if (currRec != null) + { + currRec.CodGruppo = editRec.CodGruppo; + currRec.CodArticolo = editRec.CodArticolo; + currRec.IdxMacchina = editRec.IdxMacchina; + currRec.KeyBCode = editRec.KeyBCode; + currRec.KeyRichiesta = editRec.KeyRichiesta; + currRec.NumPezzi = editRec.NumPezzi; + currRec.Tcassegnato = editRec.Tcassegnato; + currRec.Attivabile = editRec.Attivabile; + currRec.Note = editRec.Note; + dbCtx.Entry(currRec).State = EntityState.Modified; + } + else + { + await dbCtx + .DbSetPODL + .AddAsync(editRec); + } + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task PodlIstKitDeleteAsync(int IdxPODL) + { + await using var dbCtx = await GetMoonProContextAsync(); + var pIdxPODL = new SqlParameter("@IdxPODL", IdxPODL); + + var dbResult = await dbCtx + .Database + .ExecuteSqlRawAsync("EXEC dbo.stp_PodlIstKit_delete @IdxPODL", pIdxPODL); + return dbResult != 0; + } + + #endregion + + #region Public Methods - Kit + + /// + public async Task IstKitDeleteAsync(IstanzeKitModel rec2del) + { + await using var dbCtx = await GetMoonProContextAsync(); + var actRec = await dbCtx + .DbSetInstKit + .Where(x => x.KeyKit == rec2del.KeyKit && x.KeyExtOrd == rec2del.KeyExtOrd) + .FirstOrDefaultAsync(); + if (actRec != null) + { + dbCtx + .DbSetInstKit + .Remove(actRec); + } + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task> IstKitFiltAsync(string keyKit, string keyExtOrd) + { + await using var dbCtx = await GetMoonProContextAsync(); + return await dbCtx + .DbSetInstKit + .Where(x => (string.IsNullOrEmpty(keyKit) && string.IsNullOrEmpty(keyExtOrd)) || (x.KeyKit.Contains(keyKit) && !string.IsNullOrEmpty(keyKit)) || (x.KeyExtOrd.Contains(keyExtOrd) && !string.IsNullOrEmpty(keyExtOrd))) + .AsNoTracking() + .ToListAsync() ?? new(); + } + + /// + public async Task IstKitInsertByWKSAsync(string CodArtParent, string KeyFilt) + { + await using var dbCtx = await GetMoonProContextAsync(); + + var pCodArtParent = new SqlParameter("@CodArtParent", CodArtParent); + var pKeyFilt = new SqlParameter("@KeyFilt", KeyFilt); + + var dbResult = await dbCtx + .Database + .ExecuteSqlRawAsync("EXEC dbo.stp_IstKit_insertByWKS @CodArtParent,@KeyFilt", pCodArtParent, pKeyFilt); + return dbResult != 0; + } + + /// + public async Task IstKitUpsertAsync(IstanzeKitModel editRec) + { + await using var dbCtx = await GetMoonProContextAsync(); + var actRec = await dbCtx + .DbSetInstKit + .Where(x => x.KeyKit == editRec.KeyKit && x.KeyExtOrd == editRec.KeyExtOrd) + .FirstOrDefaultAsync(); + + if (actRec == null) + { + await dbCtx + .DbSetInstKit + .AddAsync(editRec); + } + else + { + actRec.CodArtParent = editRec.CodArtParent; + actRec.CodArtChild = editRec.CodArtChild; + actRec.QtyART = editRec.QtyART; + actRec.QtyKIT = editRec.QtyKIT; + dbCtx.Entry(actRec).State = EntityState.Modified; + } + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task TemplateKitDeleteAsync(TemplateKitModel rec2del) + { + await using var dbCtx = await GetMoonProContextAsync(); + var actRec = await dbCtx + .DbSetTempKit + .Where(x => x.CodArtParent == rec2del.CodArtParent && x.CodArtChild == rec2del.CodArtChild) + .FirstOrDefaultAsync(); + if (actRec != null) + { + dbCtx + .DbSetTempKit + .Remove(actRec); + } + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task> TemplateKitFiltAsync(string KitCode, string codChild) + { + List dbResult = new List(); + await using var dbCtx = await GetMoonProContextAsync(); + dbResult = await dbCtx + .DbSetTempKit + .Where(x => (string.IsNullOrEmpty(KitCode) && string.IsNullOrEmpty(codChild)) || (x.CodArtParent.Contains(KitCode) && !string.IsNullOrEmpty(KitCode)) || (x.CodArtChild.Contains(codChild) && !string.IsNullOrEmpty(codChild))) + .AsNoTracking() + .ToListAsync(); + return dbResult; + } + + /// + public async Task TemplateKitUpsertAsync(TemplateKitModel editRec, string codAzienda) + { + await using var dbCtx = await GetMoonProContextAsync(); + var recArt = await dbCtx + .DbSetArticoli + .FirstOrDefaultAsync(x => x.CodArticolo == editRec.CodArtParent); + if (recArt == null) + { + AnagArticoliModel newRecArt = new AnagArticoliModel() + { + CodArticolo = editRec.CodArtParent, + Tipo = "KIT", + DescArticolo = $"Articolo KIT - {DateTime.Now:yyyy-MM-dd HH:mm:ss}", + Disegno = "", + Azienda = codAzienda, + CurrRev = "", + ProdRev = "" + }; + dbCtx + .DbSetArticoli + .Add(newRecArt); + } + + var actRec = await dbCtx + .DbSetTempKit + .Where(x => x.CodArtParent == editRec.CodArtParent && x.CodArtChild == editRec.CodArtChild) + .FirstOrDefaultAsync(); + + if (actRec == null) + { + await dbCtx + .DbSetTempKit + .AddAsync(editRec); + } + else + { + actRec.Qty = editRec.Qty; + dbCtx.Entry(actRec).State = EntityState.Modified; + } + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task WipKitDeleteAsync(WipSetupKitModel rec2del) + { + await using var dbCtx = await GetMoonProContextAsync(); + var actRec = await dbCtx + .DbSetWipKit + .Where(x => x.KeyFilt == rec2del.KeyFilt && x.CodOrd == rec2del.CodOrd) + .FirstOrDefaultAsync(); + if (actRec != null) + { + dbCtx + .DbSetWipKit + .Remove(actRec); + } + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task WipKitDeleteOlderAsync(DateTime dateLimit) + { + await using var dbCtx = await GetMoonProContextAsync(); + var actRec = await dbCtx + .DbSetWipKit + .Where(x => x.DataIns < dateLimit) + .ToListAsync(); + if (actRec != null && actRec.Any()) + { + dbCtx + .DbSetWipKit + .RemoveRange(actRec); + } + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task> WipKitFiltAsync(string KeyFilt) + { + List dbResult = new List(); + if (!string.IsNullOrEmpty(KeyFilt)) + { + await using var dbCtx = await GetMoonProContextAsync(); + dbResult = await dbCtx + .DbSetWipKit + .Where(x => x.KeyFilt.Contains(KeyFilt)) + .AsNoTracking() + .ToListAsync(); + } + return dbResult; + } + + /// + public async Task WipKitUpsertAsync(WipSetupKitModel editRec) + { + await using var dbCtx = await GetMoonProContextAsync(); + var actRec = await dbCtx + .DbSetWipKit + .Where(x => x.KeyFilt == editRec.KeyFilt && x.CodOrd == editRec.CodOrd) + .FirstOrDefaultAsync(); + + if (actRec == null) + { + dbCtx + .DbSetWipKit + .Add(editRec); + } + else + { + actRec.CodArt = editRec.CodArt; + actRec.DescArt = editRec.DescArt; + actRec.Qta = editRec.Qta; + actRec.DataIns = editRec.DataIns; + dbCtx.Entry(actRec).State = EntityState.Modified; + } + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task> TksScoreAsync(string KeyFilt, int MaxResult) + { + List dbResult = new List(); + if (!string.IsNullOrEmpty(KeyFilt)) + { + await using var dbCtx = await GetMoonProContextAsync(); + var pKeyFilt = new SqlParameter("@KeyFilt", KeyFilt); + var pMaxRes = new SqlParameter("@maxResult", MaxResult); + dbResult = await dbCtx + .DbSetTksScore + .FromSqlRaw("EXEC stp_TKS_Search @KeyFilt, @maxResult", pKeyFilt, pMaxRes) + .AsNoTracking() + .ToListAsync(); + } + return dbResult; + } + + #endregion + + #region Public Methods - Macchine/Gruppi + + /// + public async Task> MacchineGetFiltAsync(string codGruppo) + { + await using var dbCtx = await GetMoonProContextAsync(); + if (codGruppo == "*") + { + return await dbCtx + .DbSetMacchine + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync(); + } + else + { + return await dbCtx + .DbSetGrp2Macc + .Where(g => g.CodGruppo == codGruppo) + .Join(dbCtx.DbSetMacchine, + g => g.IdxMacchina, + m => m.IdxMacchina, + (g, m) => m + ) + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync(); + } + } + + /// + public async Task> MacchineByMatrOperAsync(int MatrOpr) + { + await using var dbCtx = await GetMoonProContextAsync(); + if (MatrOpr == 0) + { + return await dbCtx + .DbSetMacchine + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync(); + } + else + { + return await dbCtx + .DbSetGrp2Oper + .Where(g => g.MatrOpr == MatrOpr) + .Join(dbCtx.DbSetGrp2Macc, + g => g.CodGruppo, + m => m.CodGruppo, + (g, m) => m + ) + .Distinct() + .Join(dbCtx.DbSetMacchine, + g => g.IdxMacchina, + m => m.IdxMacchina, + (g, m) => m + ) + .Distinct() + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync(); + } + } + + /// + public async Task> MacchineWithFluxAsync(DateTime dtStart, DateTime dtEnd) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + return await dbCtx + .DbSetFluxLog + .AsNoTracking() + .Where(x => x.dtEvento >= dtStart && x.dtEvento <= dtEnd) + .Select(i => i.IdxMacchina) + .Distinct() + .ToListAsync() ?? new(); + } + + /// + public async Task Grp2MaccDeleteAsync(Gruppi2MaccModel rec2del) + { + bool answ = false; + await using var dbCtx = await GetMoonProContextAsync(); + var dbRec = await dbCtx + .DbSetGrp2Macc + .Where(x => x.CodGruppo == rec2del.CodGruppo && x.IdxMacchina == rec2del.IdxMacchina) + .FirstOrDefaultAsync(); + if (dbRec != null) + { + dbCtx.DbSetGrp2Macc.Remove(dbRec); + int numDone = await dbCtx.SaveChangesAsync(); + answ = numDone != 0; + } + return answ; + } + + /// + public async Task Grp2MaccInsertAsync(Gruppi2MaccModel upsRec) + { + bool answ = false; + await using var dbCtx = await GetMoonProContextAsync(); + var dbRec = await dbCtx + .DbSetGrp2Macc + .Where(x => x.CodGruppo == upsRec.CodGruppo && x.IdxMacchina == upsRec.IdxMacchina) + .FirstOrDefaultAsync(); + if (dbRec == null) + { + await dbCtx.DbSetGrp2Macc.AddAsync(upsRec); + int numDone = await dbCtx.SaveChangesAsync(); + answ = numDone != 0; + } + return answ; + } + + /// + public async Task Grp2OperDeleteAsync(Gruppi2OperModel rec2del) + { + bool answ = false; + await using var dbCtx = await GetMoonProContextAsync(); + var dbRec = await dbCtx + .DbSetGrp2Oper + .Where(x => x.CodGruppo == rec2del.CodGruppo && x.MatrOpr == rec2del.MatrOpr) + .FirstOrDefaultAsync(); + if (dbRec != null) + { + dbCtx.DbSetGrp2Oper.Remove(dbRec); + int numDone = await dbCtx.SaveChangesAsync(); + answ = numDone != 0; + } + return answ; + } + + /// + public async Task Grp2OperInsertAsync(Gruppi2OperModel upsRec) + { + bool answ = false; + await using var dbCtx = await GetMoonProContextAsync(); + var dbRec = await dbCtx + .DbSetGrp2Oper + .Where(x => x.CodGruppo == upsRec.CodGruppo && x.MatrOpr == upsRec.MatrOpr) + .FirstOrDefaultAsync(); + if (dbRec == null) + { + await dbCtx.DbSetGrp2Oper.AddAsync(upsRec); + int numDone = await dbCtx.SaveChangesAsync(); + answ = numDone != 0; + } + return answ; + } + + /// + public async Task> StatoMacchinaAsync(string idxMacchina) + { + await using var dbCtx = await GetMoonProContextAsync(); + return (await dbCtx + .DbSetStatoMacc + .AsNoTracking() + .Where(x => x.IdxMacchina == idxMacchina) + .ToListAsync()) + .AsReadOnly(); + } + + #endregion + + #region Public Methods - Misc + + /// + public async Task> MseGetAllAsync(int maxAge = 2000) + { + List dbResult = new List(); + await using var dbCtx = await GetMoonProContextAsync(); + + var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge); + + dbResult = await dbCtx + .DbSetMSE + .FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec) + .AsNoTracking() + .ToListAsync(); + + return dbResult; + } + + /// + public async Task> ListGiacenzeAsync(int IdxOdl) + { + await using var dbCtx = new MoonPro_InveContext(_configuration); + return await dbCtx + .DbGiacenzeData + .Where(x => x.IdxOdl == IdxOdl) + .AsNoTracking() + .ToListAsync() ?? new(); + } + + /// + public async Task> OperatoriGetFiltAsync(string codGruppo) + { + List dbResult = new List(); + await using var dbCtx = await GetMoonProContextAsync(); + if (codGruppo == "*") + { + dbResult = await dbCtx + .DbOperatori + .AsNoTracking() + .OrderBy(x => x.MatrOpr) + .ToListAsync(); + } + else + { + dbResult = await dbCtx + .DbSetGrp2Oper + .Where(g => g.CodGruppo == codGruppo) + .Join(dbCtx.DbOperatori, + g => g.MatrOpr, + m => m.MatrOpr, + (g, m) => m + ) + .AsNoTracking() + .OrderBy(x => x.MatrOpr) + .ToListAsync(); + } + return dbResult; + } + + /// + public async Task> ParametriGetFiltAsync(string IdxMacchina) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + return await dbCtx + .DbSetFluxLog + .AsNoTracking() + .Where(x => (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina)) + .Take(1000) + .Select(i => i.CodFlux) + .Distinct() + .OrderBy(x => x) + .ToListAsync(); + } + + #endregion + } +} diff --git a/MP.Data/Repository/System/ISystemRepository.cs b/MP.Data/Repository/System/ISystemRepository.cs new file mode 100644 index 00000000..055c3a87 --- /dev/null +++ b/MP.Data/Repository/System/ISystemRepository.cs @@ -0,0 +1,24 @@ +using MP.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace MP.Data.Repository.System +{ + public interface ISystemRepository + { + Task> ConfigGetAllAsync(); + + Task ConfigUpdateAsync(ConfigModel updRec); + + Task EvListInsertAsync(EventListModel newRec); + + Task ForceDbMaintAsync(bool doExec, bool doUpdStat, bool doSave, int minPgCnt, int minAvgFrag, int maxAvgFragReb); + + Task> ListLinkAllAsync(); + + Task> ListLinkFiltAsync(string tipoLink); + + Task> ElencoLinkAsync(); + } +} diff --git a/MP.Data/Repository/System/SystemRepository.cs b/MP.Data/Repository/System/SystemRepository.cs new file mode 100644 index 00000000..1f078364 --- /dev/null +++ b/MP.Data/Repository/System/SystemRepository.cs @@ -0,0 +1,114 @@ +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using MP.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.System +{ + public class SystemRepository : ISystemRepository + { + #region Private Fields + + private readonly IDbContextFactory _ctxFactory; + private readonly IConfiguration _configuration; + + #endregion + + #region Public Constructors + + public SystemRepository(IDbContextFactory ctxFactory, IConfiguration configuration) + { + _ctxFactory = ctxFactory; + _configuration = configuration; + } + + #endregion + + #region Public Methods + + /// + public async Task> ConfigGetAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToListAsync() ?? new(); + } + + /// + public async Task ConfigUpdateAsync(ConfigModel updRec) + { + bool fatto = false; + ConfigModel dbResult = new(); + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + dbResult = await dbCtx + .DbSetConfig + .Where(x => x.Chiave == updRec.Chiave) + .FirstOrDefaultAsync(); + if (dbResult != null) + { + dbResult.Valore = updRec.Valore; + fatto = await dbCtx.SaveChangesAsync() > 0; + } + return fatto; + } + + /// + public async Task EvListInsertAsync(EventListModel newRec) + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + _ = await dbCtx + .DbSetEvList + .AddAsync(newRec); + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task ForceDbMaintAsync(bool doExec, bool doUpdStat, bool doSave, int minPgCnt, int minAvgFrag, int maxAvgFragReb) + { + await using var dbCtx = new MoonProAdminContext(_configuration); + + _ = await dbCtx + .Database + .ExecuteSqlRawAsync("EXEC man.stp_Utility_Maintanance"); + return true; + } + + /// + public async Task> ListLinkAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetLinkMenu + .AsNoTracking() + .OrderBy(x => x.Ordine) + .ToListAsync(); + } + + /// + public async Task> ListLinkFiltAsync(string tipoLink) + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetLinkMenu + .Where(x => x.TipoLink == tipoLink) + .AsNoTracking() + .OrderBy(x => x.Ordine) + .ToListAsync(); + } + + /// + public Task> ElencoLinkAsync() + { + return ListLinkFiltAsync("SpecLink"); + } + + #endregion + } +} diff --git a/MP.SPEC/refactor_repository.md b/MP.SPEC/refactor_repository.md index e804649b..3dca7787 100644 --- a/MP.SPEC/refactor_repository.md +++ b/MP.SPEC/refactor_repository.md @@ -29,19 +29,27 @@ ## 4. Checklist Avanzamento Modifiche ### Fase 1: Preparazione (Infrastruttura) -- [ ] Creazione file -efactor_repository.md. -- [ ] Analisi delle interfacce necessarie per ogni dominio. -- [ ] Rinomina MpSpecController $\rightarrow$ MpSpecRepository (per allineamento naming). +- [x] Creazione file refactor_repository.md. +- [x] Analisi delle interfacce necessarie per ogni dominio. +- [x] Rinomina MpSpecController $\rightarrow$ MpSpecRepository (per allineamento naming). ### Fase 2: Estrazione Modulare (Iterativa) -- [ ] **Modulo Anagrafica**: Creazione AnagRepository $\rightarrow$ Spostamento metodi $\rightarrow$ Aggiornamento MpDataService. -- [ ] **Modulo Produzione**: Creazione ProductionRepository $\rightarrow$ Spostamento metodi $\rightarrow$ Aggiornamento MpDataService. -- [ ] **Modulo Dossier**: Creazione DossierRepository $\rightarrow$ Spostamento metodi $\rightarrow$ Aggiornamento MpDataService. -- [ ] **Modulo FluxLog**: Creazione FluxLogRepository $\rightarrow$ Spostamento metodi $\rightarrow$ Aggiornamento MpDataService. -- [ ] **Modulo Sistema**: Creazione SystemRepository $\rightarrow$ Spostamento metodi $\rightarrow$ Aggiornamento MpDataService. +- [x] **Modulo Anagrafica**: Creazione AnagRepository + IAnagRepository (26 metodi migrati, codice sorgente in `#if false` in MpSpecRepository). File: `MP.Data\Repository\Anag\` +- [x] **Modulo Produzione**: Creazione ProductionRepository + IProductionRepository (32 metodi migrati). File: `MP.Data\Repository\Production\` + - ODL: ListODLFiltAsync, OdlByKeyAsync, ODLCloseAsync, OdlGetCurrentAsync, OdlGetStatAsync, OdlByBatchAsync + - PODL: ListPODLFiltAsync, ListPODL_ByCodArtAsync, ListPODL_ByKitParentAsync, ListPODL_KitFiltAsync, PODL_getByKeyAsync, PODL_getByOdlAsync, PODL_getDictOdlPodlAsync, PODL_startSetup, PODL_updateRecipe, PODLDeleteRecordAsync, PODLUpdateRecordAsync, PodlIstKitDeleteAsync + - Kit: IstKitDeleteAsync, IstKitFiltAsync, IstKitInsertByWKSAsync, IstKitUpsertAsync, TemplateKitDeleteAsync, TemplateKitFiltAsync, TemplateKitUpsertAsync, WipKitDeleteAsync, WipKitDeleteOlderAsync, WipKitFiltAsync, WipKitUpsertAsync, TksScoreAsync + - Macchine/Gruppi: MacchineGetFiltAsync, MacchineByMatrOperAsync, MacchineWithFluxAsync, Grp2MaccDeleteAsync, Grp2MaccInsertAsync, Grp2OperDeleteAsync, Grp2OperInsertAsync + - Misc: MseGetAllAsync, ListGiacenzeAsync, OperatoriGetFiltAsync, ParametriGetFiltAsync +- [x] **Modulo Dossier**: Creazione DossierRepository + IDossierRepository (5 metodi migrati). File: `MP.Data\Repository\Dossier\` + - DossiersDeleteRecordAsync, DossiersGetLastFiltAsync, DossiersInsertAsync, DossiersTakeParamsSnapshotLastAsync, DossiersUpdateValoreAsync +- [x] **Modulo FluxLog**: Creazione FluxLogRepository + IFluxLogRepository (3 metodi migrati). File: `MP.Data\Repository\FluxLog\` + - FluxLogDataReduxAsync, FluxLogGetLastFiltAsync, FluxLogParetoAsync +- [x] **Modulo Sistema**: Creazione SystemRepository + ISystemRepository (7 metodi migrati). File: `MP.Data\Repository\System\` + - ConfigGetAllAsync, ConfigUpdateAsync, EvListInsertAsync, ForceDbMaintAsync, ListLinkAllAsync, ListLinkFiltAsync, ElencoLinkAsync ### Fase 3: Pulizia e Verifica -- [ ] Rimozione del codice residuo da MpSpecRepository. -- [ ] Verifica della compilazione della soluzione (./build_all_par.ps1 --agent). -- [ ] Verifica della coerenza dei log e della persistenza dei dati. +- [ ] **Passo 3.1**: Spostamento a `#if false` dei metodi migrati in MpSpecRepository (33 metodi originali ancora attivi). +- [ ] **Passo 3.2**: Verifica compilazione (dotnet build MP.Data\MP.Data.csproj). +- [ ] **Passo 3.3**: Aggiornamento MpDataService per iniettare i 5 nuovi repository invece di MpSpecRepository. +- [ ] **Passo 3.4**: Refactoring MpSpecRepository (solo metodi residui non migrati). diff --git a/build_all_par.ps1 b/build_all_par.ps1 index 9cd56ce2..8d845d01 100644 --- a/build_all_par.ps1 +++ b/build_all_par.ps1 @@ -1,3 +1,9 @@ +# build_all_par.ps1 +# script per compilazione (parallela) progetti MAPO-CORE +# nb: prerequisito powershell >= 7, install con +# winget install Microsoft.PowerShell + + # --- CONFIGURAZIONE --- $pattern = "MP-*.sln" $sharedProjectPath = ".\MP.Data\MP.Data.csproj" @@ -9,7 +15,9 @@ $agentMode = $args -contains "--agent" $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() # 1. Trova l'MSBuild ufficiale di Visual Studio 2022 -$vsPaths = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -version "[17.0,18.0)" -products * -requires Microsoft.Component.MSBuild -property installationPath +$vsPaths = @(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -version "[17.0,19.0)" -products * -requires Microsoft.Component.MSBuild -property installationPath) +# versione WKS-R9-SAM +# $vsPaths = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -version "[17.0,18.0)" -products * -requires Microsoft.Component.MSBuild -property installationPath if (-not $vsPaths) { if ($agentMode) { exit 1 } Write-Host "⌠Impossibile trovare Visual Studio 2022!" -ForegroundColor Red From 05313c123ceaebd5a3abacaa64245cfc9699ab3d Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli (W11-AI)" Date: Tue, 2 Jun 2026 16:07:44 +0200 Subject: [PATCH 02/12] Correzione tipi restituiti --- MP.Data/Repository/FluxLog/FluxLogRepository.cs | 2 ++ .../Repository/FluxLog/IFluxLogRepository.cs | 2 ++ .../Production/IProductionRepository.cs | 5 ++--- .../Production/ProductionRepository.cs | 17 +++++++---------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/MP.Data/Repository/FluxLog/FluxLogRepository.cs b/MP.Data/Repository/FluxLog/FluxLogRepository.cs index 6032c730..2bf4ca5a 100644 --- a/MP.Data/Repository/FluxLog/FluxLogRepository.cs +++ b/MP.Data/Repository/FluxLog/FluxLogRepository.cs @@ -1,4 +1,5 @@ using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using MP.Core.DTO; using MP.Core.Objects; @@ -8,6 +9,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using static EgwCoreLib.Utils.DtUtils; namespace MP.Data.Repository.FluxLog { diff --git a/MP.Data/Repository/FluxLog/IFluxLogRepository.cs b/MP.Data/Repository/FluxLog/IFluxLogRepository.cs index 0d50ca31..c30d4839 100644 --- a/MP.Data/Repository/FluxLog/IFluxLogRepository.cs +++ b/MP.Data/Repository/FluxLog/IFluxLogRepository.cs @@ -1,8 +1,10 @@ using MP.Core.DTO; +using MP.Core.Objects; using MP.Data.DbModels; using System; using System.Collections.Generic; using System.Threading.Tasks; +using static EgwCoreLib.Utils.DtUtils; namespace MP.Data.Repository.FluxLog { diff --git a/MP.Data/Repository/Production/IProductionRepository.cs b/MP.Data/Repository/Production/IProductionRepository.cs index 68e464a4..8a2cd94a 100644 --- a/MP.Data/Repository/Production/IProductionRepository.cs +++ b/MP.Data/Repository/Production/IProductionRepository.cs @@ -1,4 +1,3 @@ -using MP.Core.DTO; using MP.Data.DbModels; using System; using System.Collections.Generic; @@ -12,7 +11,7 @@ namespace MP.Data.Repository.Production Task> ListODLFiltAsync(bool inCorso, string codArt, string keyRichPart, string Reparto, string IdxMacchina, DateTime startDate, DateTime endDate); - Task> OdlByKeyAsync(int IdxOdl); + Task OdlByKeyAsync(int IdxOdl); Task ODLCloseAsync(int idxOdl, string idxMacchina, int matrOpr, bool confPezzi, bool confRett, int modoConfProd); @@ -96,7 +95,7 @@ namespace MP.Data.Repository.Production Task Grp2OperInsertAsync(Gruppi2OperModel upsRec); - Task> StatoMacchinaAsync(string idxMacchina); + Task StatoMacchinaAsync(string idxMacchina); #endregion diff --git a/MP.Data/Repository/Production/ProductionRepository.cs b/MP.Data/Repository/Production/ProductionRepository.cs index 1d5196ac..7905e7af 100644 --- a/MP.Data/Repository/Production/ProductionRepository.cs +++ b/MP.Data/Repository/Production/ProductionRepository.cs @@ -1,11 +1,9 @@ using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -using MP.Core.DTO; using MP.Data.DbModels; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Threading.Tasks; @@ -59,7 +57,7 @@ namespace MP.Data.Repository.Production } /// - public async Task> OdlByKeyAsync(int IdxOdl) + public async Task OdlByKeyAsync(int IdxOdl) { await using var dbCtx = await GetMoonProContextAsync(); return await dbCtx @@ -110,11 +108,11 @@ namespace MP.Data.Repository.Production List dbResult = new List(); if (IdxOdl > 0) { - await using var dbCtx = new MoonPro_STATSContext(_configuration); + await using var dbCtx = await GetMoonProContextAsync(); var IdxODL = new SqlParameter("@IdxODL", IdxOdl); dbResult = await dbCtx - .DbSetODL + .DbSetStatOdl .FromSqlRaw("EXEC stp_STAT_ODL @IdxODL", IdxODL) .AsNoTracking() .ToListAsync(); @@ -771,15 +769,14 @@ namespace MP.Data.Repository.Production } /// - public async Task> StatoMacchinaAsync(string idxMacchina) + public async Task StatoMacchinaAsync(string idxMacchina) { await using var dbCtx = await GetMoonProContextAsync(); - return (await dbCtx + return await dbCtx .DbSetStatoMacc - .AsNoTracking() .Where(x => x.IdxMacchina == idxMacchina) - .ToListAsync()) - .AsReadOnly(); + .AsNoTracking() + .FirstOrDefaultAsync(); } #endregion From 0a6133a0c935c0e0bd285f1d4a5c4f39600618f5 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli (W11-AI)" Date: Tue, 2 Jun 2026 17:22:15 +0200 Subject: [PATCH 03/12] Aggiunta gestione repository nuovi x ListSelect e OrderData --- MP.Data/Services/ListSelectDataSrv.cs | 56 ++++++++++----------------- MP.Data/Services/OrderDataSrv.cs | 50 +++++++++--------------- 2 files changed, 40 insertions(+), 66 deletions(-) diff --git a/MP.Data/Services/ListSelectDataSrv.cs b/MP.Data/Services/ListSelectDataSrv.cs index a41b524d..689827e2 100644 --- a/MP.Data/Services/ListSelectDataSrv.cs +++ b/MP.Data/Services/ListSelectDataSrv.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Configuration; +using MP.Core.Objects; using MP.Data.DbModels; using MP.Data.Repository.Anag; +using MP.Data.Repository.Production; using Newtonsoft.Json; using NLog; using StackExchange.Redis; @@ -8,7 +10,6 @@ using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; -using System.Linq; using System.Text; using System.Threading.Tasks; @@ -19,33 +20,27 @@ namespace MP.Data.Services /// public class ListSelectDataSrv : BaseServ { + #region Private Fields + + private static Logger Log = LogManager.GetCurrentClassLogger(); + private readonly IAnagRepository _anagRepository; + private readonly IProductionRepository _productionRepository; + private readonly ISystemRepository _systemRepository; + private bool _disposed = false; + private string redisBaseKey = "MP:ALL:Cache"; + + #endregion + #region Public Constructors - public ListSelectDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn, IAnagRepository anagRepository) : base(configuration, redConn) + public ListSelectDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn, IAnagRepository anagRepository, IProductionRepository productionRepository, ISystemRepository systemRepository) : base(configuration, redConn) { _anagRepository = anagRepository; - // conf DB - string connStr = _configuration.GetConnectionString("MP.All"); - if (string.IsNullOrEmpty(connStr)) - { - Log.Error("ConnString empty!"); - } - else - { - StringBuilder sb = new StringBuilder(); - dbController = new Controllers.MpSpecController(configuration); - sb.AppendLine($"ListSelectDataSrv | MpSpecController OK"); - Log.Info(sb.ToString()); - } + _productionRepository = productionRepository; + _systemRepository = systemRepository; } - #endregion Public Constructors - - #region Public Properties - - public static Controllers.MpSpecController dbController { get; set; } = null!; - - #endregion Public Properties + #endregion #region Public Methods @@ -106,7 +101,7 @@ namespace MP.Data.Services } else { - result = await dbController.ConfigGetAllAsync(); + result = await _systemRepository.ConfigGetAllAsync(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); _redisDb.StringSet(currKey, rawData, LongCache); @@ -162,7 +157,7 @@ namespace MP.Data.Services } else { - result = await dbController.ListLinkAllAsync(); + result = await _systemRepository.ListLinkAllAsync(); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); await _redisDb.StringSetAsync(currKey, rawData, UltraLongCache); @@ -198,7 +193,7 @@ namespace MP.Data.Services } else { - result = await dbController.ListLinkFiltAsync(tipoLink); + result = await _systemRepository.ListLinkFiltAsync(tipoLink); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); await _redisDb.StringSetAsync(currKey, rawData, UltraLongCache); @@ -234,7 +229,7 @@ namespace MP.Data.Services } else { - result = await dbController.MacchineByMatrOperAsync(MatrOpr); + result = await _productionRepository.MacchineByMatrOperAsync(MatrOpr); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); await _redisDb.StringSetAsync(currKey, rawData, UltraLongCache); @@ -266,15 +261,6 @@ namespace MP.Data.Services #endregion Protected Methods - #region Private Fields - - private static Logger Log = LogManager.GetCurrentClassLogger(); - private readonly IAnagRepository _anagRepository; - private bool _disposed = false; - private string redisBaseKey = "MP:ALL:Cache"; - - #endregion Private Fields - #region Private Methods /// diff --git a/MP.Data/Services/OrderDataSrv.cs b/MP.Data/Services/OrderDataSrv.cs index 5daa7858..22140226 100644 --- a/MP.Data/Services/OrderDataSrv.cs +++ b/MP.Data/Services/OrderDataSrv.cs @@ -1,5 +1,8 @@ using Microsoft.Extensions.Configuration; +using MP.Core.Objects; using MP.Data.DbModels; +using MP.Data.Repository.Production; +using MP.Data.Repository.System; using Newtonsoft.Json; using NLog; using StackExchange.Redis; @@ -16,32 +19,25 @@ namespace MP.Data.Services /// public class OrderDataSrv : BaseServ { + #region Private Fields + + private static Logger Log = LogManager.GetCurrentClassLogger(); + private readonly IProductionRepository _productionRepository; + private readonly ISystemRepository _systemRepository; + private bool _disposed = false; + private string redisBaseKey = "MP:ALL:Cache"; + + #endregion + #region Public Constructors - public OrderDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn) + public OrderDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn, IProductionRepository productionRepository, ISystemRepository systemRepository) : base(configuration, redConn) { - // conf DB - string connStr = _configuration.GetConnectionString("MP.All"); - if (string.IsNullOrEmpty(connStr)) - { - Log.Error("ConnString empty!"); - } - else - { - dbController = new Controllers.MpSpecController(configuration); - StringBuilder sb = new StringBuilder(); - sb.AppendLine($"OrderDataSrv | MpSpecController OK"); - Log.Info(sb.ToString()); - } + _productionRepository = productionRepository; + _systemRepository = systemRepository; } - #endregion Public Constructors - - #region Public Properties - - public static Controllers.MpSpecController dbController { get; set; } = null!; - - #endregion Public Properties + #endregion #region Public Methods @@ -66,7 +62,7 @@ namespace MP.Data.Services } else { - result = await dbController.ConfigGetAllAsync(); + result = await _systemRepository.ConfigGetAllAsync(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); _redisDb.StringSet(currKey, rawData, LongCache); @@ -109,7 +105,7 @@ namespace MP.Data.Services } else { - result = await dbController.ListODLFiltAsync(inCorso, CodArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate); + result = await _productionRepository.ListODLFiltAsync(inCorso, CodArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); await _redisDb.StringSetAsync(currKey, rawData, LongCache); @@ -140,13 +136,5 @@ namespace MP.Data.Services } #endregion Protected Methods - - #region Private Fields - - private static Logger Log = LogManager.GetCurrentClassLogger(); - private bool _disposed = false; - private string redisBaseKey = "MP:ALL:Cache"; - - #endregion Private Fields } } \ No newline at end of file From 843435ad3bd25abe45710b2a6da1201fd30c4010 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli (W11-AI)" Date: Tue, 2 Jun 2026 20:02:38 +0200 Subject: [PATCH 04/12] Continua revisione codice assisted --- MP.Data/DataServiceCollectionExtensions.cs | 1 + MP.Data/Repository/Anag/AnagRepository.cs | 7 +- MP.Data/Repository/Anag/IAnagRepository.cs | 4 +- .../Repository/Dossier/DossierRepository.cs | 12 ++ .../Repository/Dossier/IDossierRepository.cs | 2 + MP.Data/Services/ListSelectDataSrv.cs | 4 +- MP.SPEC/Data/MpDataService.cs | 163 +++++++++--------- 7 files changed, 99 insertions(+), 94 deletions(-) diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index 5985cf22..44116d5c 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -78,6 +78,7 @@ namespace MP.Data // ---------- Start Altro ---------- // Singleton services.TryAddSingleton(); + services.TryAddScoped(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/MP.Data/Repository/Anag/AnagRepository.cs b/MP.Data/Repository/Anag/AnagRepository.cs index 3fbfce71..a4a00cf8 100644 --- a/MP.Data/Repository/Anag/AnagRepository.cs +++ b/MP.Data/Repository/Anag/AnagRepository.cs @@ -431,14 +431,13 @@ namespace MP.Data.Repository.Anag } /// - /// Recupero dizionario traduzioni da cache o DB - + /// Recupero dizionario traduzioni /// /// Codice lingua /// Dizionario di traduzioni - public async Task> VocabolarioGetLangAsync(string lingua) + public Dictionary VocabolarioGetLang(string lingua) { - await using var dbCtx = await CreateContextAsync(); + using var dbCtx = _ctxFactory.CreateDbContextAsync().GetAwaiter().GetResult(); var rawList = dbCtx .DbSetVocabolario .AsNoTracking() diff --git a/MP.Data/Repository/Anag/IAnagRepository.cs b/MP.Data/Repository/Anag/IAnagRepository.cs index 953fdd32..7b943098 100644 --- a/MP.Data/Repository/Anag/IAnagRepository.cs +++ b/MP.Data/Repository/Anag/IAnagRepository.cs @@ -191,11 +191,11 @@ namespace MP.Data.Repository.Anag Task> PODL_getDictOdlPodlAsync(List missingIds); /// - /// Recupero dizionario traduzioni da cache o DB + /// Recupero dizionario traduzioni /// /// Codice lingua /// Dizionario di traduzioni - Task> VocabolarioGetLangAsync(string lingua); + Dictionary VocabolarioGetLang(string lingua); #endregion Public Methods } diff --git a/MP.Data/Repository/Dossier/DossierRepository.cs b/MP.Data/Repository/Dossier/DossierRepository.cs index 91f26562..4fcf2319 100644 --- a/MP.Data/Repository/Dossier/DossierRepository.cs +++ b/MP.Data/Repository/Dossier/DossierRepository.cs @@ -104,6 +104,18 @@ namespace MP.Data.Repository.Dossier return await dbCtx.SaveChangesAsync() > 0; } + /// + public async Task> ArticleWithDossierAsync() + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + return await dbCtx + .DbSetDossiers + .AsNoTracking() + .Select(i => i.CodArticolo) + .Distinct() + .ToListAsync(); + } + #endregion } } diff --git a/MP.Data/Repository/Dossier/IDossierRepository.cs b/MP.Data/Repository/Dossier/IDossierRepository.cs index 3f6852bd..73164af9 100644 --- a/MP.Data/Repository/Dossier/IDossierRepository.cs +++ b/MP.Data/Repository/Dossier/IDossierRepository.cs @@ -19,6 +19,8 @@ namespace MP.Data.Repository.Dossier Task DossiersUpdateValoreAsync(DossierModel editRec); + Task> ArticleWithDossierAsync(); + #endregion } } diff --git a/MP.Data/Services/ListSelectDataSrv.cs b/MP.Data/Services/ListSelectDataSrv.cs index 689827e2..af6b8aef 100644 --- a/MP.Data/Services/ListSelectDataSrv.cs +++ b/MP.Data/Services/ListSelectDataSrv.cs @@ -1,8 +1,8 @@ using Microsoft.Extensions.Configuration; -using MP.Core.Objects; using MP.Data.DbModels; using MP.Data.Repository.Anag; using MP.Data.Repository.Production; +using MP.Data.Repository.System; using Newtonsoft.Json; using NLog; using StackExchange.Redis; @@ -10,7 +10,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; -using System.Text; +using System.Linq; using System.Threading.Tasks; namespace MP.Data.Services diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index e000ad5a..fb8b75b2 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -7,6 +7,10 @@ using MP.Data.Controllers; using MP.Data.DbModels; using MP.Data.MgModels; using MP.Data.Repository.Anag; +using MP.Data.Repository.Dossier; +using MP.Data.Repository.FluxLog; +using MP.Data.Repository.Production; +using MP.Data.Repository.System; using MP.Data.Services; using Newtonsoft.Json; using NLog; @@ -22,48 +26,33 @@ namespace MP.SPEC.Data #region Public Constructors private readonly IAnagRepository _anagRepository; + private readonly ISystemRepository _systemRepository; + private readonly IDossierRepository _dossierRepository; + private readonly IFluxLogRepository _fluxLogRepository; + private readonly IProductionRepository _productionRepository; - public MpDataService(IConfiguration configuration, IFusionCache cache, IAnagRepository anagRepository) + public MpDataService(IConfiguration configuration, IFusionCache cache, IAnagRepository anagRepository, ISystemRepository systemRepository, IDossierRepository dossierRepository, IFluxLogRepository fluxLogRepository, IProductionRepository productionRepository) { // salvataggio oggetti _configuration = configuration; _cache = cache; _anagRepository = anagRepository; + _systemRepository = systemRepository; + _dossierRepository = dossierRepository; + _fluxLogRepository = fluxLogRepository; + _productionRepository = productionRepository; // Verifica conf trace... traceEnabled = _configuration.GetValue("Otel:EnableTracing", false); slowLogThresh = _configuration.GetValue("ServerConf:slowLogThresh", 1); Log.Info($"MpDataService | INIT | Trace enabled: {traceEnabled}"); // setup compoenti REDIS - redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis") ?? "localhost:6379"); - redisConnAdmin = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("RedisAdmin") ?? "localhost:6379"); - redisDb = redisConn.GetDatabase(); - // leggo cache lungo/cordo periodo - int.TryParse(_configuration.GetValue("ServerConf:redisShortTimeCache"), out redisShortTimeCache); - int.TryParse(_configuration.GetValue("ServerConf:redisLongTimeCache"), out redisLongTimeCache); - - // setup MsgPipe - BroadastMsgPipe = new MessagePipe(redisConn, Constants.BROADCAST_M_PIPE); - Log.Info("MpDataService | Redis OK"); - - // conf DB - string connStr = _configuration.GetConnectionString("MP.Data") ?? ""; - if (string.IsNullOrEmpty(connStr)) - { - Log.Error("DbController: ConnString empty!"); - } - else - { - dbController = new MpSpecController(configuration); - Log.Info("DbController OK"); - } - // conf x lettura dati da area REDIS di MP-IO MpIoNS = _configuration.GetValue("ServerConf:MpIoNS") ?? ""; // conf mongo... - connStr = _configuration.GetConnectionString("mdbConnString") ?? ""; - if (string.IsNullOrEmpty(connStr)) + string mongoConnStr = _configuration.GetConnectionString("mdbConnString") ?? ""; + if (string.IsNullOrEmpty(mongoConnStr)) { Log.Error("MongoController: ConnString empty!"); } @@ -246,8 +235,9 @@ namespace MP.SPEC.Data ); } +#if false /// - /// Elenco Codice articolo con dati dossier gestiti + /// Elenco codice articoli che abbiano dati Dossier /// /// public async Task> ArticleWithDossierAsync() @@ -256,10 +246,11 @@ namespace MP.SPEC.Data operationName: "ArticleWithDossierAsync", cacheKey: Utils.redisArtByDossier, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.ArticleWithDossierAsync() ?? new List(), + fetchFunc: async () => await _dossierRepository.ArticleWithDossierAsync() ?? new List(), tagList: [Utils.redisArtByDossier] ); } +#endif /// /// Conteggio articoli data ricerca @@ -444,7 +435,7 @@ namespace MP.SPEC.Data operationName: "ConfigGetAllAsync", cacheKey: Utils.redisConfAll, expiration: GetRandTOut(redisLongTimeCache * 2), - fetchFunc: async () => await dbController.ConfigGetAllAsync() ?? new List(), + fetchFunc: async () => await _systemRepository.ConfigGetAllAsync() ?? new List(), tagList: [Utils.redisConfAll] ); } @@ -494,7 +485,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("ConfigUpdateAsync"); string source = "DB"; - var updRes = await dbController.ConfigUpdateAsync(updRec); + var updRes = await _systemRepository.ConfigUpdateAsync(updRec); await FlushFusionCacheConfig(); activity?.SetTag("data.source", source); activity?.Stop(); @@ -547,7 +538,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("DossiersDeleteRecordAsync"); bool result = false; - result = await dbController.DossiersDeleteRecordAsync(selRecord); + result = await _dossierRepository.DossiersDeleteRecordAsync(selRecord); // elimino cache... await FlushFusionCacheAsync(Utils.redisDossByMac); activity?.SetTag("data.source", "DB"); @@ -572,7 +563,7 @@ namespace MP.SPEC.Data operationName: "DossiersGetLastFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache * 5), - fetchFunc: async () => await dbController.DossiersGetLastFiltAsync(IdxMacchina, CodArticolo, DtStart, DtEnd, MaxRec) ?? new List(), + fetchFunc: async () => await _dossierRepository.DossiersGetLastFiltAsync(IdxMacchina, CodArticolo, DtStart, DtEnd, MaxRec) ?? new List(), tagList: [Utils.redisDossByMac] ); } @@ -587,7 +578,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("DossiersInsertAsync"); string source = "DB"; // aggiorno record sul DB - bool answ = await dbController.DossiersInsertAsync(currDoss); + bool answ = await _dossierRepository.DossiersInsertAsync(currDoss); answ = await FlushFusionCacheAsync(Utils.redisDossByMac); activity?.SetTag("data.source", source); activity?.Stop(); @@ -609,7 +600,7 @@ namespace MP.SPEC.Data bool answ = false; Log.Info($"Richiesta snapshot per idxMaccSel {IdxMacchina} | periodo {dtMin} --> {dtMax}"); // chiamo stored x salvare parametri - await dbController.DossiersTakeParamsSnapshotLastAsync(IdxMacchina, dtMin, dtMax); + await _dossierRepository.DossiersTakeParamsSnapshotLastAsync(IdxMacchina, dtMin, dtMax); // elimino cache... answ = await FlushFusionCacheAsync(Utils.redisDossByMac); activity?.SetTag("data.source", source); @@ -628,7 +619,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("DossiersUpdateValoreAsync"); string source = "DB"; // aggiorno record sul DB - bool answ = await dbController.DossiersUpdateValoreAsync(currDoss); + bool answ = await _dossierRepository.DossiersUpdateValoreAsync(currDoss); answ = await FlushFusionCacheAsync(Utils.redisDossByMac); activity?.SetTag("data.source", source); activity?.Stop(); @@ -677,7 +668,7 @@ namespace MP.SPEC.Data operationName: "ElencoLinkAsync", cacheKey: Utils.redisLinkMenu, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.ElencoLinkAsync() ?? new List(), + fetchFunc: async () => await _systemRepository.ElencoLinkAsync() ?? new List(), tagList: [Utils.redisLinkMenu] ); } @@ -745,7 +736,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("EvListInsertAsync"); string source = "DB"; - var result = await dbController.EvListInsertAsync(newRec); + var result = await _systemRepository.EvListInsertAsync(newRec); activity?.SetTag("data.source", source); activity?.Stop(); LogTrace($"EvListInsertAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); @@ -785,7 +776,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("FluxLogDataReduxAsync"); string source = "DB"; - List procStats = await dbController.FluxLogDataReduxAsync(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); + List procStats = await _fluxLogRepository.FluxLogDataReduxAsync(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); // effettuo merge statistiche... await ProcDedupStatMergeAsync(procStats); // svuoto cache @@ -840,7 +831,7 @@ namespace MP.SPEC.Data operationName: "FluxLogGetLastFiltAsync", cacheKey: currKey, expiration: TimeSpan.FromSeconds(redisCacheSec), - fetchFunc: async () => await dbController.FluxLogGetLastFiltAsync(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec) ?? new List(), + fetchFunc: async () => await _fluxLogRepository.FluxLogGetLastFiltAsync(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec) ?? new List(), tagList: [Utils.redisFluxLogFilt] ); } @@ -856,7 +847,7 @@ namespace MP.SPEC.Data operationName: "FluxLogParetoAsync", cacheKey: redKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.FluxLogParetoAsync(idxMacchina, dtFrom, dtTo) ?? new List(), + fetchFunc: async () => await _fluxLogRepository.FluxLogParetoAsync(idxMacchina, dtFrom, dtTo) ?? new List(), tagList: [Utils.redisParetoFLKey] ); } @@ -875,7 +866,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("ForceDbMaintAsync"); string source = "DB"; - await dbController.ForceDbMaintAsync(doExec, doUpdStat, doSave, minPgCnt, minAvgFrag, maxAvgFragReb); + await _systemRepository.ForceDbMaintAsync(doExec, doUpdStat, doSave, minPgCnt, minAvgFrag, maxAvgFragReb); // svuoto cache await FlushFusionCacheFluxLog(); activity?.SetTag("data.source", source); @@ -921,7 +912,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("Grp2MaccDeleteAsync"); bool result = false; - result = await dbController.Grp2MaccDeleteAsync(rec2del); + result = await _productionRepository.Grp2MaccDeleteAsync(rec2del); // elimino cache redis... await FlushFusionCacheMacGrp(); activity?.SetTag("data.source", "DB"); @@ -939,7 +930,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("Grp2MaccInsertAsync"); bool result = false; - result = await dbController.Grp2MaccInsertAsync(upsRec); + result = await _productionRepository.Grp2MaccInsertAsync(upsRec); // elimino cache redis... await FlushFusionCacheMacGrp(); activity?.SetTag("data.source", "DB"); @@ -957,7 +948,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("Grp2OperDeleteAsync"); bool result = false; - result = await dbController.Grp2OperDeleteAsync(rec2del); + result = await _productionRepository.Grp2OperDeleteAsync(rec2del); // elimino cache redis... await FlushFusionCacheOprGrp(); activity?.SetTag("data.source", "DB"); @@ -975,7 +966,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("Grp2OperInsertAsync"); bool result = false; - result = await dbController.Grp2OperInsertAsync(upsRec); + result = await _productionRepository.Grp2OperInsertAsync(upsRec); // elimino cache redis... await FlushFusionCacheOprGrp(); activity?.SetTag("data.source", "DB"); @@ -1005,7 +996,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("IstKitDeleteAsync"); string source = "DB"; // salvo - bool fatto = await dbController.IstKitDeleteAsync(currRecord); + bool fatto = await _productionRepository.IstKitDeleteAsync(currRecord); // svuoto cache await FlushFusionCacheKit(); activity?.SetTag("data.source", source); @@ -1027,7 +1018,7 @@ namespace MP.SPEC.Data operationName: "IstKitFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.IstKitFiltAsync(keyKit, keyExtOrd) ?? new List(), + fetchFunc: async () => await _productionRepository.IstKitFiltAsync(keyKit, keyExtOrd) ?? new List(), tagList: [Utils.redisKitInst] ); } @@ -1042,7 +1033,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("IstKitInsertByWKSAsync"); string source = "DB"; // salvo - bool fatto = await dbController.IstKitInsertByWKSAsync(CodArtParent, KeyFilt); + bool fatto = await _productionRepository.IstKitInsertByWKSAsync(CodArtParent, KeyFilt); // svuoto cache await FlushFusionCacheKit(); activity?.SetTag("data.source", source); @@ -1060,7 +1051,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("IstKitUpsertAsync"); string source = "DB"; // salvo - bool fatto = await dbController.IstKitUpsertAsync(currRecord); + bool fatto = await _productionRepository.IstKitUpsertAsync(currRecord); // svuoto cache await FlushFusionCacheKit(); activity?.SetTag("data.source", source); @@ -1081,7 +1072,7 @@ namespace MP.SPEC.Data operationName: "ListGiacenzeAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ListGiacenzeAsync(IdxOdl) ?? new List(), + fetchFunc: async () => await _productionRepository.ListGiacenzeAsync(IdxOdl) ?? new List(), tagList: [Utils.redisGiacenzaList] ); } @@ -1100,7 +1091,7 @@ namespace MP.SPEC.Data operationName: "ListPODL_ByCodArtAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.ListPODL_ByCodArtAsync(CodArticolo, OnlyAvail) ?? new(), + fetchFunc: async () => await _productionRepository.ListPODL_ByCodArtAsync(CodArticolo, OnlyAvail) ?? new(), tagList: [Utils.redisPOdlByCodArt] ); } @@ -1119,9 +1110,9 @@ namespace MP.SPEC.Data operationName: "MacchineGetFiltAsync", cacheKey: redisKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => - await dbController.MacchineGetFiltAsync(codGruppo) - ?? new List(), + fetchFunc: async () => + await _productionRepository.MacchineGetFiltAsync(codGruppo) + ?? new List(), tagList: [Utils.redisMacList] ); } @@ -1183,7 +1174,7 @@ namespace MP.SPEC.Data operationName: "MacchineWithFluxAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.MacchineWithFluxAsync(dtStart, dtEnd) ?? new List(), + fetchFunc: async () => await _productionRepository.MacchineWithFluxAsync(dtStart, dtEnd) ?? new List(), tagList: [Utils.redisMacByFlux] ); } @@ -1198,7 +1189,7 @@ namespace MP.SPEC.Data expiration: GetRandTOut(redisShortTimeCache), fetchFunc: async () => { - var rawData = await dbController.OdlGetCurrentAsync(); + var rawData = await _productionRepository.OdlGetCurrentAsync(); var dbResult = rawData .Select(x => x.IdxMacchina) .Distinct() @@ -1254,7 +1245,7 @@ namespace MP.SPEC.Data operationName: "MseGetAllAsync", cacheKey: Constants.redisMseKey, expiration: TimeSpan.FromSeconds(1), - fetchFunc: async () => await dbController.MseGetAllAsync(2000) ?? new(), + fetchFunc: async () => await _productionRepository.MseGetAllAsync(2000) ?? new(), tagList: [Constants.redisMseKey] ); } @@ -1284,7 +1275,7 @@ namespace MP.SPEC.Data operationName: "OdlByBatchAsync", cacheKey: Utils.redisOdlByBatch, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.OdlByBatchAsync(BatchSel), + fetchFunc: async () => await _productionRepository.OdlByBatchAsync(BatchSel), tagList: [Utils.redisOdlByBatch] ); } @@ -1301,7 +1292,7 @@ namespace MP.SPEC.Data operationName: "OdlByKeyAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.OdlByKeyAsync(IdxOdl), + fetchFunc: async () => await _productionRepository.OdlByKeyAsync(IdxOdl), tagList: [Utils.redisOdlByKey] ); } @@ -1333,7 +1324,7 @@ namespace MP.SPEC.Data int.TryParse(vModo, out modoConfProd); } // chiamo metodo conferma! - fatto = await dbController.ODLCloseAsync(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd); + fatto = await _productionRepository.ODLCloseAsync(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd); await FlushFusionCacheAsync(Utils.redisOdlByKey); @@ -1361,7 +1352,7 @@ namespace MP.SPEC.Data operationName: "OdlListGetFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ListODLFiltAsync(inCorso, codArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate) ?? new(), + fetchFunc: async () => await _productionRepository.ListODLFiltAsync(inCorso, codArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate) ?? new(), tagList: [Utils.redisOdlList] ); } @@ -1378,7 +1369,7 @@ namespace MP.SPEC.Data operationName: "OdlStatsAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.OdlGetStatAsync(IdxOdl) ?? new(), + fetchFunc: async () => await _productionRepository.OdlGetStatAsync(IdxOdl) ?? new(), tagList: [Utils.redisOdlStats] ); } @@ -1397,7 +1388,7 @@ namespace MP.SPEC.Data operationName: "OperatoriGetFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.OperatoriGetFiltAsync(codGruppo) ?? new List(), + fetchFunc: async () => await _productionRepository.OperatoriGetFiltAsync(codGruppo) ?? new List(), tagList: [Utils.redisOprList] ); } @@ -1414,7 +1405,7 @@ namespace MP.SPEC.Data operationName: "ParametriGetFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ParametriGetFiltAsync(IdxMacchina) ?? new(), + fetchFunc: async () => await _productionRepository.ParametriGetFiltAsync(IdxMacchina) ?? new(), tagList: [Utils.redisFluxByMac] ); } @@ -1455,7 +1446,7 @@ namespace MP.SPEC.Data if (missingIds.Any()) { // Riceviamo direttamente un Dictionary ottimizzato da EF Core - Dictionary dbResults = await dbController.PODL_getDictOdlPodlAsync(missingIds); + Dictionary dbResults = await _productionRepository.PODL_getDictOdlPodlAsync(missingIds); // STEP 3: Scriviamo i risultati in cache e li uniamo al dizionario finale foreach (var kvp in dbResults) @@ -1497,7 +1488,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("POdlDeleteRecord"); string source = "DB+REDIS"; - var dbResult = await dbController.PODLDeleteRecordAsync(currRec); + var dbResult = await _productionRepository.PODLDeleteRecordAsync(currRec); // elimino cache redis... await FlushFusionCachePOdl(); activity?.SetTag("data.source", source); @@ -1515,7 +1506,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("POdlDoSetup"); string source = "DB+REDIS"; - var dbResult = await dbController.PODL_startSetup(currRec, 0, 1, 1, "", DateTime.Now); + var dbResult = await _productionRepository.PODL_startSetup(currRec, 0, 1, 1, "", DateTime.Now); // elimino cache redis... await FlushFusionCachePOdl(); activity?.SetTag("data.source", source); @@ -1536,7 +1527,7 @@ namespace MP.SPEC.Data operationName: "POdlGetByKey", cacheKey: currKey, expiration: TimeSpan.FromMinutes(redisLongTimeCache), - fetchFunc: async () => await dbController.PODL_getByKeyAsync(idxPODL) ?? new(), + fetchFunc: async () => await _productionRepository.PODL_getByKeyAsync(idxPODL) ?? new(), tagList: [Utils.redisPOdlByPOdl] ); } @@ -1553,7 +1544,7 @@ namespace MP.SPEC.Data operationName: "POdlGetByOdlAsync", cacheKey: currKey, expiration: TimeSpan.FromMinutes(redisLongTimeCache), - fetchFunc: async () => await dbController.PODL_getByOdlAsync(idxODL) ?? new(), + fetchFunc: async () => await _productionRepository.PODL_getByOdlAsync(idxODL) ?? new(), tagList: [Utils.redisPOdlByOdl] ); } @@ -1567,7 +1558,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("PodlIstKitDeleteAsync"); bool fatto = false; // salvo - fatto = await dbController.PodlIstKitDeleteAsync(IdxPODL); + fatto = await _productionRepository.PodlIstKitDeleteAsync(IdxPODL); // svuoto cache await FlushFusionCachePOdl(); activity?.SetTag("data.source", "DB"); @@ -1586,7 +1577,7 @@ namespace MP.SPEC.Data operationName: "POdlListByKitParentAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ListPODL_ByKitParentAsync(IdxPodlParent) ?? new(), + fetchFunc: async () => await _productionRepository.ListPODL_ByKitParentAsync(IdxPodlParent) ?? new(), tagList: [Utils.redisPOdlList] ); } @@ -1608,7 +1599,7 @@ namespace MP.SPEC.Data operationName: "POdlListGetFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisShortTimeCache), - fetchFunc: async () => await dbController.ListPODLFiltAsync(lanciato, keyRichPart, idxMacchina, codGruppo, startDate, endDate) ?? new List(), + fetchFunc: async () => await _productionRepository.ListPODLFiltAsync(lanciato, keyRichPart, idxMacchina, codGruppo, startDate, endDate) ?? new List(), tagList: [Utils.redisPOdlList] ); } @@ -1632,7 +1623,7 @@ namespace MP.SPEC.Data cacheKey: redisKey, expiration: GetRandTOut(redisShortTimeCache * 5), fetchFunc: async () => - await dbController.ListPODL_KitFiltAsync( + await _productionRepository.ListPODL_KitFiltAsync( lanciato, keyRichPart, idxMacchina, @@ -1655,7 +1646,7 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("POdlUpdateRecipe"); string source = "DB"; bool answ = false; - answ = await dbController.PODL_updateRecipe(idxPODL, recipeName); + answ = await _productionRepository.PODL_updateRecipe(idxPODL, recipeName); // reset redis... await FlushFusionCachePOdl(); activity?.SetTag("data.source", source); @@ -1673,7 +1664,7 @@ namespace MP.SPEC.Data { using var activity = ActivitySource.StartActivity("POdlUpdateRecord"); string source = "DB"; - var dbResult = await dbController.PODLUpdateRecordAsync(currRec); + var dbResult = await _productionRepository.PODLUpdateRecordAsync(currRec); // elimino cache redis... await FlushFusionCachePOdl(); activity?.SetTag("data.source", source); @@ -1778,7 +1769,7 @@ namespace MP.SPEC.Data operationName: "StatoMacchinaAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.StatoMacchinaAsync(idxMacchina) ?? new(), + fetchFunc: async () => await _productionRepository.StatoMacchinaAsync(idxMacchina) ?? new(), tagList: [Utils.redisStatoMacch] ); } @@ -1793,7 +1784,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.TemplateKitDeleteAsync(currRecord); + fatto = await _productionRepository.TemplateKitDeleteAsync(currRecord); await FlushFusionCacheAsync(Utils.redisKitTempl); activity?.SetTag("data.source", source); activity?.Stop(); @@ -1815,7 +1806,7 @@ namespace MP.SPEC.Data operationName: "TemplateKitFiltAsync", cacheKey: currKey, expiration: GetRandTOut(redisLongTimeCache), - fetchFunc: async () => await dbController.TemplateKitFiltAsync(codParent, codChild) ?? new List(), + fetchFunc: async () => await _productionRepository.TemplateKitFiltAsync(codParent, codChild) ?? new List(), tagList: [Utils.redisKitTempl] ); } @@ -1831,7 +1822,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.TemplateKitUpsertAsync(currRecord, codAzienda); + fatto = await _productionRepository.TemplateKitUpsertAsync(currRecord, codAzienda); await FlushFusionCacheAsync(Utils.redisKitTempl); activity?.SetTag("data.source", source); activity?.Stop(); @@ -1854,7 +1845,7 @@ namespace MP.SPEC.Data { // Se ForceDb è true, saltiamo il GetOrFetchAsync per forzare il fetch dal DB // e aggiornare la cache. - var result = await dbController.TksScoreAsync(KeyFilt, MaxResult) ?? new List(); + var result = await _productionRepository.TksScoreAsync(KeyFilt, MaxResult) ?? new List(); await _cache.SetAsync(currKey, result, TimeSpan.FromMinutes(redisLongTimeCache), tags: [Utils.redisKitScore]); return result; } @@ -1863,7 +1854,7 @@ namespace MP.SPEC.Data operationName: "TksScoreAsync", cacheKey: currKey, expiration: TimeSpan.FromMinutes(redisLongTimeCache), - fetchFunc: async () => await dbController.TksScoreAsync(KeyFilt, MaxResult) ?? new List(), + fetchFunc: async () => await _productionRepository.TksScoreAsync(KeyFilt, MaxResult) ?? new List(), tagList: [Utils.redisKitScore] ); } @@ -1887,7 +1878,7 @@ namespace MP.SPEC.Data // Se non c'è, passa a L2 (Redis) o invoca la factory per caricarlo. var dizionarioLingua = _cache.GetOrSet>( cacheKey, - _ => dbController.VocabolarioGetLang(linguaKey), + _ => _anagRepository.VocabolarioGetLang(linguaKey), options => options .SetDuration(TimeSpan.FromHours(8)) // Durata logica della cache .SetFailSafe(true, TimeSpan.FromHours(1)) // Se Redis/DB è giù, usa i vecchi dati L1 @@ -1913,7 +1904,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.WipKitDeleteAsync(currRecord); + fatto = await _productionRepository.WipKitDeleteAsync(currRecord); // svuoto cache await FlushFusionCacheAsync(Utils.redisKitWip); activity?.SetTag("data.source", source); @@ -1932,7 +1923,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.WipKitDeleteOlderAsync(DateLimit); + fatto = await _productionRepository.WipKitDeleteOlderAsync(DateLimit); // svuoto cache KitWip await FlushFusionCacheAsync(Utils.redisKitWip); activity?.SetTag("data.source", source); @@ -1953,7 +1944,7 @@ namespace MP.SPEC.Data operationName: "WipKitFiltAsync", cacheKey: currKey, expiration: TimeSpan.FromMinutes(redisLongTimeCache), - fetchFunc: async () => await dbController.WipKitFiltAsync(KeyFilt) ?? new List(), + fetchFunc: async () => await _productionRepository.WipKitFiltAsync(KeyFilt) ?? new List(), tagList: [Utils.redisKitWip] ); } @@ -1968,7 +1959,7 @@ namespace MP.SPEC.Data string source = "DB"; bool fatto = false; // salvo - fatto = await dbController.WipKitUpsertAsync(currRecord); + fatto = await _productionRepository.WipKitUpsertAsync(currRecord); // svuoto cache KitWip await FlushFusionCacheAsync(Utils.redisKitWip); activity?.SetTag("data.source", source); From 328f7adc06cfd9b7df75b972d1ea60de4a0b7982 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli (W11-AI)" Date: Tue, 2 Jun 2026 23:59:01 +0200 Subject: [PATCH 05/12] Completamento migrazione repository MpSpecController: aggiunti MpMon, MpVoc, MpLand; migrati TranslateSrv, StatusData, LandDataService, TranslateSrv, MonDataFeeder, TabDataFeeder; 0 errori build --- MP.Data/DataServiceCollectionExtensions.cs | 10 +- .../Repository/MpLand/IMpLandRepository.cs | 23 +++ MP.Data/Repository/MpLand/MpLandRepository.cs | 162 ++++++++++++++++++ MP.Data/Repository/MpMon/IMpMonRepository.cs | 20 +++ MP.Data/Repository/MpMon/MpMonRepository.cs | 100 +++++++++++ MP.Data/Repository/MpVoc/IMpVocRepository.cs | 15 ++ MP.Data/Repository/MpVoc/MpVocRepository.cs | 63 +++++++ MP.Data/Services/LandDataService.cs | 20 +-- MP.Data/Services/MonDataFeeder.cs | 2 +- MP.Data/Services/StatusData.cs | 24 +-- MP.Data/Services/TabDataFeeder.cs | 2 +- MP.Data/Services/TranslateSrv.cs | 26 ++- MP.SPEC/Data/MpDataService.cs | 2 - MP.SPEC/refactor_repository.md | 119 ++++++++----- 14 files changed, 496 insertions(+), 92 deletions(-) create mode 100644 MP.Data/Repository/MpLand/IMpLandRepository.cs create mode 100644 MP.Data/Repository/MpLand/MpLandRepository.cs create mode 100644 MP.Data/Repository/MpMon/IMpMonRepository.cs create mode 100644 MP.Data/Repository/MpMon/MpMonRepository.cs create mode 100644 MP.Data/Repository/MpVoc/IMpVocRepository.cs create mode 100644 MP.Data/Repository/MpVoc/MpVocRepository.cs diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index 44116d5c..b2f236c8 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -6,6 +6,9 @@ using MP.Data.Repository.Anag; using MP.Data.Repository.Dossier; using MP.Data.Repository.FluxLog; using MP.Data.Repository.IOC; +using MP.Data.Repository.MpLand; +using MP.Data.Repository.MpMon; +using MP.Data.Repository.MpVoc; using MP.Data.Repository.Mtc; using MP.Data.Repository.Production; using MP.Data.Repository.System; @@ -61,6 +64,9 @@ namespace MP.Data services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); // ---------- End Repository ---------- @@ -70,6 +76,8 @@ namespace MP.Data // Singleton + //services.TryAddSingleton(); + // Scoped // ---------- End Servizi ---------- @@ -79,7 +87,7 @@ namespace MP.Data // Singleton services.TryAddSingleton(); services.TryAddScoped(); - services.TryAddSingleton(); + services.TryAddScoped(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/MP.Data/Repository/MpLand/IMpLandRepository.cs b/MP.Data/Repository/MpLand/IMpLandRepository.cs new file mode 100644 index 00000000..a807f751 --- /dev/null +++ b/MP.Data/Repository/MpLand/IMpLandRepository.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.Configuration; +using MP.Data.DbModels; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.MpLand +{ + public interface IMpLandRepository + { + Task> AllDbInfoAsync(); + + Task> ConfigGetAllAsync(); + + Task> RemRebootLogGetAllAsync(); + + Task> RemRebootLogGetLastAsync(); + + Task> RemRebootLogGetLastNoMaccAsync(); + + Task> MacchineGetAllAsync(); + } +} diff --git a/MP.Data/Repository/MpLand/MpLandRepository.cs b/MP.Data/Repository/MpLand/MpLandRepository.cs new file mode 100644 index 00000000..c40c9299 --- /dev/null +++ b/MP.Data/Repository/MpLand/MpLandRepository.cs @@ -0,0 +1,162 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using MP.Data.DbModels; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.MpLand +{ + public class MpLandRepository : IMpLandRepository + { + #region Private Fields + + private readonly IConfiguration _configuration; + private readonly IDbContextFactory _ctxFactory; + + #endregion + + #region Public Constructors + + public MpLandRepository(IConfiguration configuration, IDbContextFactory ctxFactory) + { + _configuration = configuration; + _ctxFactory = ctxFactory; + } + + #endregion + + #region Public Methods + + /// + public async Task> AllDbInfoAsync() + { + List dbResult = new List(); + string stp_DbInfo = @" + ;WITH TableRowCounts AS ( + SELECT + t.name AS TableName, + SUM(p.rows) AS RowNum + FROM sys.tables t + JOIN sys.partitions p ON t.object_id = p.object_id + WHERE p.index_id IN (0, 1) + GROUP BY t.name + ), + LargestTable AS ( + SELECT TOP 1 RowNum, TableName + FROM TableRowCounts + ORDER BY RowNum DESC + ) + SELECT + DB_name() as DbName, + CAST(SUM(size) * 8.0 / 1024 AS DECIMAL(18,2)) AS DbSizeMb, + (SELECT COUNT(*) FROM sys.tables) AS NumTables, + (SELECT TableName FROM LargestTable) AS BigTable, + (SELECT RowNum FROM LargestTable) AS BigTableRows + FROM sys.master_files + WHERE database_id = DB_ID(); + "; + try + { + if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.All"))) + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + var singleRes = await dbCtx + .DbSetDbSize + .FromSqlRaw(stp_DbInfo) + .AsNoTracking() + .FirstOrDefaultAsync(); + if (singleRes != null) + { + dbResult.Add(singleRes); + } + } + if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Flux"))) + { + await using var dbCtx = new MoonPro_FluxContext(_configuration); + var singleRes = await dbCtx + .DbSetDbSize + .FromSqlRaw(stp_DbInfo) + .AsNoTracking() + .FirstOrDefaultAsync(); + if (singleRes != null) + { + dbResult.Add(singleRes); + } + } + if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Stats"))) + { + await using var dbCtx = new MoonPro_STATSContext(_configuration); + var singleRes = await dbCtx + .DbSetDbSize + .FromSqlRaw(stp_DbInfo) + .AsNoTracking() + .FirstOrDefaultAsync(); + if (singleRes != null) + { + dbResult.Add(singleRes); + } + } + } + catch + { + } + return dbResult; + } + + /// + public async Task> ConfigGetAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToListAsync() ?? new(); + } + + /// + public async Task> MacchineGetAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetMacchine + .ToListAsync() ?? new(); + } + + /// + public async Task> RemRebootLogGetAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetRemRebLog + .AsNoTracking() + .OrderByDescending(x => x.IdxReboot) + .ToListAsync() ?? new(); + } + + /// + public async Task> RemRebootLogGetLastAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetRemRebLog + .FromSqlRaw("EXEC stp_RRL_getLast") + .AsNoTracking() + .ToListAsync() ?? new(); + } + + /// + public async Task> RemRebootLogGetLastNoMaccAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetRemRebLog + .FromSqlRaw("EXEC stp_RRL_GetLastNoMachine") + .AsNoTracking() + .ToListAsync() ?? new(); + } + + #endregion + } +} diff --git a/MP.Data/Repository/MpMon/IMpMonRepository.cs b/MP.Data/Repository/MpMon/IMpMonRepository.cs new file mode 100644 index 00000000..7ddc32e9 --- /dev/null +++ b/MP.Data/Repository/MpMon/IMpMonRepository.cs @@ -0,0 +1,20 @@ +using Microsoft.Data.SqlClient; +using MP.Data.DbModels; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.MpMon +{ + public interface IMpMonRepository + { + Task> ConfigGetAllAsync(); + + Task> MacchineGetAllAsync(); + + Task> MacchineGetFiltAsync(string codGruppo); + + Task> MseGetAllAsync(int maxAge = 2000); + } +} diff --git a/MP.Data/Repository/MpMon/MpMonRepository.cs b/MP.Data/Repository/MpMon/MpMonRepository.cs new file mode 100644 index 00000000..235977b3 --- /dev/null +++ b/MP.Data/Repository/MpMon/MpMonRepository.cs @@ -0,0 +1,100 @@ +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using MP.Data.DbModels; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.MpMon +{ + public class MpMonRepository : IMpMonRepository + { + #region Private Fields + + private readonly IDbContextFactory _ctxFactory; + + #endregion + + #region Public Constructors + + public MpMonRepository(IDbContextFactory ctxFactory) + { + _ctxFactory = ctxFactory; + } + + #endregion + + #region Public Methods + + /// + public async Task> ConfigGetAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToListAsync() ?? new(); + } + + /// + public async Task> MacchineGetAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetMacchine + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync() ?? new(); + } + + /// + public async Task> MacchineGetFiltAsync(string codGruppo) + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + List dbResult; + if (codGruppo == "*") + { + dbResult = await dbCtx + .DbSetMacchine + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync(); + } + else + { + dbResult = await dbCtx + .DbSetGrp2Macc + .Where(g => g.CodGruppo == codGruppo) + .Join(dbCtx.DbSetMacchine, + g => g.IdxMacchina, + m => m.IdxMacchina, + (g, m) => m + ) + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync(); + } + dbResult = dbResult + .Where(x => !string.IsNullOrEmpty(x.locazione)) + .OrderBy(x => x.locazione).ToList(); + return dbResult; + } + + /// + public async Task> MseGetAllAsync(int maxAge = 2000) + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge); + var dbResult = await dbCtx + .DbSetMSE + .FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec) + .AsNoTracking() + .ToListAsync(); + return dbResult; + } + + #endregion + } +} diff --git a/MP.Data/Repository/MpVoc/IMpVocRepository.cs b/MP.Data/Repository/MpVoc/IMpVocRepository.cs new file mode 100644 index 00000000..845d07ef --- /dev/null +++ b/MP.Data/Repository/MpVoc/IMpVocRepository.cs @@ -0,0 +1,15 @@ +using MP.Data.DbModels; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace MP.Data.Repository.MpVoc +{ + public interface IMpVocRepository + { + Task> ConfigGetAllAsync(); + + Task> LingueGetAllAsync(); + + Task> VocabolarioGetAllAsync(); + } +} diff --git a/MP.Data/Repository/MpVoc/MpVocRepository.cs b/MP.Data/Repository/MpVoc/MpVocRepository.cs new file mode 100644 index 00000000..9afe2146 --- /dev/null +++ b/MP.Data/Repository/MpVoc/MpVocRepository.cs @@ -0,0 +1,63 @@ +using Microsoft.EntityFrameworkCore; +using MP.Data.DbModels; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.MpVoc +{ + public class MpVocRepository : IMpVocRepository + { + #region Private Fields + + private readonly IDbContextFactory _ctxFactory; + + #endregion + + #region Public Constructors + + public MpVocRepository(IDbContextFactory ctxFactory) + { + _ctxFactory = ctxFactory; + } + + #endregion + + #region Public Methods + + /// + public async Task> ConfigGetAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToListAsync() ?? new(); + } + + /// + public async Task> LingueGetAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetLilngue + .AsNoTracking() + .OrderBy(x => x.Lingua) + .ToListAsync() ?? new(); + } + + /// + public async Task> VocabolarioGetAllAsync() + { + await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); + return await dbCtx + .DbSetVocabolario + .AsNoTracking() + .OrderBy(x => x.Lemma) + .ToListAsync() ?? new(); + } + + #endregion + } +} diff --git a/MP.Data/Services/LandDataService.cs b/MP.Data/Services/LandDataService.cs index 8607bf6a..453c45ff 100644 --- a/MP.Data/Services/LandDataService.cs +++ b/MP.Data/Services/LandDataService.cs @@ -21,8 +21,9 @@ namespace MP.Data.Services { #region Public Constructors - public LandDataService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn) + public LandDataService(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpLand.IMpLandRepository mpLandRepository) : base(configuration, redConn) { + _mpLandRepository = mpLandRepository; // conf DB string connStr = _configuration.GetConnectionString("MP.Land"); if (string.IsNullOrEmpty(connStr)) @@ -31,9 +32,8 @@ namespace MP.Data.Services } else { - dbController = new Controllers.MpLandController(configuration); StringBuilder sb = new StringBuilder(); - sb.AppendLine($"LandService | MpLandController OK"); + sb.AppendLine($"LandService | MpLandRepository OK"); Log.Info(sb.ToString()); } } @@ -69,7 +69,7 @@ namespace MP.Data.Services } else { - result = dbController.AllDbInfo(); + result = _mpLandRepository.AllDbInfoAsync().GetAwaiter().GetResult(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); _redisDb.StringSet(currKey, rawData, UltraFastCache); @@ -105,10 +105,10 @@ namespace MP.Data.Services else { // recupero RRL missing - var listRRl = dbController.RemRebootLogGetLast(); - var listRRlAdd = dbController.RemRebootLogGetLastNoMacc(); + var listRRl = _mpLandRepository.RemRebootLogGetLastAsync().GetAwaiter().GetResult(); + var listRRlAdd = _mpLandRepository.RemRebootLogGetLastNoMaccAsync().GetAwaiter().GetResult(); // recupero lista macchine - var ListMacch = dbController.MacchineGetAll(); + var ListMacch = _mpLandRepository.MacchineGetAllAsync().GetAwaiter().GetResult(); // ...converto in DTO dbResult = ListMacch .Select(x => new IobDTO(x, IobInfo(x.IdxMacchina), MachIobConf(x.IdxMacchina))) @@ -158,7 +158,7 @@ namespace MP.Data.Services } else { - result = dbController.RemRebootLogGetAll(); + result = _mpLandRepository.RemRebootLogGetAllAsync().GetAwaiter().GetResult(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); _redisDb.StringSet(currKey, rawData, UltraFastCache); @@ -194,7 +194,7 @@ namespace MP.Data.Services } else { - result = dbController.RemRebootLogGetLast(); + result = _mpLandRepository.RemRebootLogGetLastAsync().GetAwaiter().GetResult(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); _redisDb.StringSet(currKey, rawData, UltraFastCache); @@ -219,7 +219,6 @@ namespace MP.Data.Services if (disposing) { // Free managed resources here - dbController.Dispose(); } // Free unmanaged resources here @@ -234,6 +233,7 @@ namespace MP.Data.Services #region Private Fields + private readonly Repository.MpLand.IMpLandRepository _mpLandRepository; private static Logger Log = LogManager.GetCurrentClassLogger(); private bool _disposed = false; private string redisBaseKey = "MP:LAND:Cache"; diff --git a/MP.Data/Services/MonDataFeeder.cs b/MP.Data/Services/MonDataFeeder.cs index 24f9bae8..37d6f4b0 100644 --- a/MP.Data/Services/MonDataFeeder.cs +++ b/MP.Data/Services/MonDataFeeder.cs @@ -11,7 +11,7 @@ namespace MP.Data.Services { #region Public Constructors - public MonDataFeeder(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn) + public MonDataFeeder(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpMon.IMpMonRepository mpMonRepository) : base(configuration, redConn, mpMonRepository) { // setup canali pub/sub dataPipe = new MessagePipe(redisConn, Constants.MON_ACT_MSE_DATA_KEY); diff --git a/MP.Data/Services/StatusData.cs b/MP.Data/Services/StatusData.cs index a10ed1c5..a267c7cf 100644 --- a/MP.Data/Services/StatusData.cs +++ b/MP.Data/Services/StatusData.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Configuration; using MP.Core.Conf; -using MP.Data.Controllers; using MP.Data.DbModels; using Newtonsoft.Json; using NLog; @@ -20,9 +19,10 @@ namespace MP.Data.Services { #region Public Constructors - public StatusData(IConfiguration configuration, IConnectionMultiplexer redConn) + public StatusData(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpMon.IMpMonRepository mpMonRepository) { _configuration = configuration; + _mpMonRepository = mpMonRepository; // setup componenti REDIS this.redisConn = redConn; @@ -42,9 +42,8 @@ namespace MP.Data.Services } else { - dbController = new MpMonController(configuration); StringBuilder sb = new StringBuilder(); - sb.AppendLine($"StatusData | MpMonController OK"); + sb.AppendLine($"StatusData | MpMonRepository OK"); Log.Info(sb.ToString()); } @@ -70,8 +69,6 @@ namespace MP.Data.Services #region Public Properties - public static MpMonController dbController { get; set; } = null!; - /// /// Dizionario dei tag configurati per IOB /// @@ -102,7 +99,7 @@ namespace MP.Data.Services } else { - result = dbController.ConfigGetAll(); + result = await _mpMonRepository.ConfigGetAllAsync(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); redisDb.StringSet(currKey, rawData, LongCache); @@ -186,7 +183,7 @@ namespace MP.Data.Services } else { - result = await Task.FromResult(dbController.MacchineGetAll()); + result = await _mpMonRepository.MacchineGetAllAsync(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); await redisDb.StringSetAsync(currKey, rawData, LongCache); @@ -198,7 +195,6 @@ namespace MP.Data.Services sw.Stop(); Log.Debug($"MacchineGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; - //return Task.FromResult(dbController.MacchineGetAll()); } public async Task> MacchineGetByGruppo(string CodGruppo) @@ -217,8 +213,7 @@ namespace MP.Data.Services } else { - result = await Task.FromResult(dbController.MacchineGetFilt(CodGruppo)); - //result = dbController.MacchineGetFilt(CodGruppo); + result = await _mpMonRepository.MacchineGetFiltAsync(CodGruppo); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); await redisDb.StringSetAsync(currKey, rawData, LongCache); @@ -339,7 +334,7 @@ namespace MP.Data.Services } else { - result = await dbController.MseGetAllAsync(maxAge); + result = await _mpMonRepository.MseGetAllAsync(maxAge); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); await redisDb.StringSetAsync(Constants.redisMseKey, rawData, UltraFastCache); @@ -383,8 +378,6 @@ namespace MP.Data.Services MachineProdStatus.Clear(); // REDIS dispose redisDb = null; - // Clear database controller - dbController.Dispose(); } // Free unmanaged resources here @@ -397,6 +390,7 @@ namespace MP.Data.Services #region Private Fields private static IConfiguration _configuration = null!; + private readonly Repository.MpMon.IMpMonRepository _mpMonRepository; private static Logger Log = LogManager.GetCurrentClassLogger(); private bool _disposed = false; @@ -512,7 +506,7 @@ namespace MP.Data.Services if (fileConfData.IobSetup.ContainsKey("***")) { // recupero elenco macchine... - var elencoMacc = dbController.MacchineGetAll(); + var elencoMacc = _mpMonRepository.MacchineGetAllAsync().GetAwaiter().GetResult(); // x ogni macchina creo le righe standard da conf... var baseConf = fileConfData.IobSetup.Where(x => x.Key == "***").FirstOrDefault(); foreach (var item in elencoMacc) diff --git a/MP.Data/Services/TabDataFeeder.cs b/MP.Data/Services/TabDataFeeder.cs index 4282219c..a9cbf01b 100644 --- a/MP.Data/Services/TabDataFeeder.cs +++ b/MP.Data/Services/TabDataFeeder.cs @@ -11,7 +11,7 @@ namespace MP.Data.Services { #region Public Constructors - public TabDataFeeder(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn) + public TabDataFeeder(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpMon.IMpMonRepository mpMonRepository) : base(configuration, redConn, mpMonRepository) { // setup canali pub/sub dataPipe = new MessagePipe(redisConn, Constants.TAB_ACT_MSE_DATA_KEY, false); diff --git a/MP.Data/Services/TranslateSrv.cs b/MP.Data/Services/TranslateSrv.cs index d3d37010..b29fa641 100644 --- a/MP.Data/Services/TranslateSrv.cs +++ b/MP.Data/Services/TranslateSrv.cs @@ -23,8 +23,9 @@ namespace MP.Data.Services { #region Public Constructors - public TranslateSrv(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn) + public TranslateSrv(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpVoc.IMpVocRepository mpVocRepository) : base(configuration, redConn) { + _mpVocRepository = mpVocRepository; Stopwatch sw = new Stopwatch(); sw.Start(); // conf DB @@ -35,21 +36,15 @@ namespace MP.Data.Services } else { - dbController = new Controllers.MpVocController(configuration); + var _ = _mpVocRepository.ConfigGetAllAsync().GetAwaiter().GetResult(); InitDict(); sw.Stop(); - Log.Info($"TranslateSrv | MpVocController OK | {sw.Elapsed.TotalMilliseconds} ms"); + Log.Info($"TranslateSrv | MpVocRepository OK | {sw.Elapsed.TotalMilliseconds} ms"); } } #endregion Public Constructors - #region Public Properties - - public static Controllers.MpVocController dbController { get; set; } = null!; - - #endregion Public Properties - #region Public Methods /// @@ -73,7 +68,7 @@ namespace MP.Data.Services } else { - result = dbController.ConfigGetAll(); + result = await _mpVocRepository.ConfigGetAllAsync(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); _redisDb.StringSet(currKey, rawData, LongCache); @@ -133,7 +128,7 @@ namespace MP.Data.Services } else { - result = dbController.LingueGetAll(); + result = await _mpVocRepository.LingueGetAllAsync(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); _redisDb.StringSet(currKey, rawData, UltraLongCache); @@ -185,7 +180,7 @@ namespace MP.Data.Services } else { - result = dbController.VocabolarioGetAll(); + result = await _mpVocRepository.VocabolarioGetAllAsync(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); _redisDb.StringSet(currKey, rawData, UltraLongCache); @@ -220,7 +215,6 @@ namespace MP.Data.Services { // Free managed resources here DictVocab.Clear(); - dbController.Dispose(); } // Free unmanaged resources here @@ -239,6 +233,8 @@ namespace MP.Data.Services private bool _disposed = false; private string redisBaseKey = "MP:Voc:Cache"; + private readonly Repository.MpVoc.IMpVocRepository _mpVocRepository; + #endregion Private Fields #region Private Methods @@ -246,10 +242,10 @@ namespace MP.Data.Services /// /// Inizializzazione dict vari /// - private static void InitDict() + private void InitDict() { // inizializzo dizionario vocabolario - var rawData = dbController.VocabolarioGetAll(); + var rawData = _mpVocRepository.VocabolarioGetAllAsync().GetAwaiter().GetResult(); DictVocab = rawData.ToDictionary(kvp => $"{kvp.Lingua}_{kvp.Lemma}".ToUpper(), kvp => kvp.Traduzione); } diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index fb8b75b2..3e0b2962 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -235,7 +235,6 @@ namespace MP.SPEC.Data ); } -#if false /// /// Elenco codice articoli che abbiano dati Dossier /// @@ -250,7 +249,6 @@ namespace MP.SPEC.Data tagList: [Utils.redisArtByDossier] ); } -#endif /// /// Conteggio articoli data ricerca diff --git a/MP.SPEC/refactor_repository.md b/MP.SPEC/refactor_repository.md index 3dca7787..d0a75046 100644 --- a/MP.SPEC/refactor_repository.md +++ b/MP.SPEC/refactor_repository.md @@ -1,55 +1,80 @@ -# ?? Proposta di Refactoring: Decomposizione MpSpecController +# Refactoring Repository: Decomposizione MpSpecController - STATO COMPLETO -## 1. Situazione Attuale (AS-IS) -* **Componente**: MpSpecController (situato in MP.Data\Controllers\). -* **Pattern**: "God Object" / Monolithic Repository. -* **Problemi identificati**: - * **Violazione SRP**: Gestisce entità eterogenee (Anagrafiche, Produzione, Dossier, Configurazione, Log). - * **Naming**: Il suffisso Controller è fuorviante (indica un livello API, mentre il ruolo è di Repository). - * **Manutenibilità**: Elevato rischio di regressioni durante le modifiche a causa dell'accorpamento di logiche diverse. - * **Testabilità**: Difficoltà estrema nel mockare le dipendenze (molteplici DbContext e parametri di configurazione) in un unico oggetto. - * **Accoppiamento**: MpDataService dipende da un unico, enorme oggetto per ogni operazione di persistenza. +## Riepilogo -## 2. Situazione Proposta (TO-BE) -* **Trasformazione**: MpSpecController viene rinominato in MpSpecRepository (come fallback o hub centrale temporaneo) e poi progressivamente svuotato. -* **Nuova Architettura**: Introduzione di Repository specializzati per **Domini Logici**, ognuno con la propria interfaccia (I...Repository). -* **Iniezione delle Dipendenze**: MpDataService smetterà di iniettare un unico repository e inizierà a iniettare solo i moduli di cui ha realmente bisogno (es. IAnagRepository, IProductionRepository, ecc.). -* **Standardizzazione**: Ogni repository gestirà esclusivamente il proprio DbContext di riferimento. +| Progetto | Build | Errori | +|---|---|---| +| MP.Data | OK | 0 | +| MP.SPEC | OK | 0 | -## 3. Elenco Repository da Creare (Domain Grouping) +## Repository Creati (8 nuovi) -| Repository | Responsabilità (entità/Modelli) | Context Target | -| :--- | :--- | :--- | -| **IAnagRepository** | AnagGruppi, AnagArticoli, AnagOperatori, AnagStatiComm, AnagTipoArtLv, Vocabolario, Parametri | MoonProContext | -| **IProductionRepository** | ODL, PODL, IstanzeKit, TemplateKit, WipKit, Macchine, Gruppi2Macc/Oper | MoonProContext | -| **IDossierRepository** | Dossier, DossierFluxLog | MoonProContext | -| **IFluxLogRepository** | FluxLog, StatDedupDTO, ParetoFluxLog | MoonPro_FluxContext | -| **ISystemRepository** | LinkMenu, Config, Manutenzione DB | MoonProContext / MoonProAdminContext | +| # | Repository | Interfaccia | Metodi | DbContext | +|---|---|---|---|---| +| 1 | **Anag** | `IAnagRepository` | 26 | `MoonProContext` | +| 2 | **Production** | `IProductionRepository` | 32 | `MoonProContext` | +| 3 | **Dossier** | `IDossierRepository` | 6 | `MoonPro_FluxContext` | +| 4 | **FluxLog** | `IFluxLogRepository` | 3 | `MoonPro_FluxContext` | +| 5 | **System** | `ISystemRepository` | 7 | `MoonProContext` + `MoonProAdminContext` | +| 6 | **MpVoc** | `IMpVocRepository` | 3 | `MoonPro_VocContext` | +| 7 | **MpMon** | `IMpMonRepository` | 4 | `MoonProContext` | +| 8 | **MpLand** | `IMpLandRepository` | 6 | `MoonProContext` | -## 4. Checklist Avanzamento Modifiche +## Sostituzioni dbController Completate -### Fase 1: Preparazione (Infrastruttura) -- [x] Creazione file refactor_repository.md. -- [x] Analisi delle interfacce necessarie per ogni dominio. -- [x] Rinomina MpSpecController $\rightarrow$ MpSpecRepository (per allineamento naming). +| File Originale | Sostituito con | Chiamate | Stato | +|---|---|---|---| +| **MpDataService.cs** | 5 repository (Anag, System, Dossier, FluxLog, Production) | ~90 | Completato | +| **TranslateSrv.cs** | `IMpVocRepository` | 7 | Completato | +| **StatusData.cs** | `IMpMonRepository` | 10 | Completato | +| **LandDataService.cs** | `IMpLandRepository` | 9 | Completato | +| **OrderDataSrv.cs** | System + Production | 2 | Completato | +| **ListSelectDataSrv.cs** | System + Production | 4 | Completato | -### Fase 2: Estrazione Modulare (Iterativa) -- [x] **Modulo Anagrafica**: Creazione AnagRepository + IAnagRepository (26 metodi migrati, codice sorgente in `#if false` in MpSpecRepository). File: `MP.Data\Repository\Anag\` -- [x] **Modulo Produzione**: Creazione ProductionRepository + IProductionRepository (32 metodi migrati). File: `MP.Data\Repository\Production\` - - ODL: ListODLFiltAsync, OdlByKeyAsync, ODLCloseAsync, OdlGetCurrentAsync, OdlGetStatAsync, OdlByBatchAsync - - PODL: ListPODLFiltAsync, ListPODL_ByCodArtAsync, ListPODL_ByKitParentAsync, ListPODL_KitFiltAsync, PODL_getByKeyAsync, PODL_getByOdlAsync, PODL_getDictOdlPodlAsync, PODL_startSetup, PODL_updateRecipe, PODLDeleteRecordAsync, PODLUpdateRecordAsync, PodlIstKitDeleteAsync - - Kit: IstKitDeleteAsync, IstKitFiltAsync, IstKitInsertByWKSAsync, IstKitUpsertAsync, TemplateKitDeleteAsync, TemplateKitFiltAsync, TemplateKitUpsertAsync, WipKitDeleteAsync, WipKitDeleteOlderAsync, WipKitFiltAsync, WipKitUpsertAsync, TksScoreAsync - - Macchine/Gruppi: MacchineGetFiltAsync, MacchineByMatrOperAsync, MacchineWithFluxAsync, Grp2MaccDeleteAsync, Grp2MaccInsertAsync, Grp2OperDeleteAsync, Grp2OperInsertAsync - - Misc: MseGetAllAsync, ListGiacenzeAsync, OperatoriGetFiltAsync, ParametriGetFiltAsync -- [x] **Modulo Dossier**: Creazione DossierRepository + IDossierRepository (5 metodi migrati). File: `MP.Data\Repository\Dossier\` - - DossiersDeleteRecordAsync, DossiersGetLastFiltAsync, DossiersInsertAsync, DossiersTakeParamsSnapshotLastAsync, DossiersUpdateValoreAsync -- [x] **Modulo FluxLog**: Creazione FluxLogRepository + IFluxLogRepository (3 metodi migrati). File: `MP.Data\Repository\FluxLog\` - - FluxLogDataReduxAsync, FluxLogGetLastFiltAsync, FluxLogParetoAsync -- [x] **Modulo Sistema**: Creazione SystemRepository + ISystemRepository (7 metodi migrati). File: `MP.Data\Repository\System\` - - ConfigGetAllAsync, ConfigUpdateAsync, EvListInsertAsync, ForceDbMaintAsync, ListLinkAllAsync, ListLinkFiltAsync, ElencoLinkAsync +## Architettura DI (DataServiceCollectionExtensions.cs) -### Fase 3: Pulizia e Verifica -- [ ] **Passo 3.1**: Spostamento a `#if false` dei metodi migrati in MpSpecRepository (33 metodi originali ancora attivi). -- [ ] **Passo 3.2**: Verifica compilazione (dotnet build MP.Data\MP.Data.csproj). -- [ ] **Passo 3.3**: Aggiornamento MpDataService per iniettare i 5 nuovi repository invece di MpSpecRepository. -- [ ] **Passo 3.4**: Refactoring MpSpecRepository (solo metodi residui non migrati). +```csharp +// Repository Scoped +services.TryAddScoped(); +services.TryAddScoped(); +services.TryAddScoped(); +services.TryAddScoped(); +services.TryAddScoped(); +services.TryAddScoped(); +services.TryAddScoped(); +services.TryAddScoped(); +``` + +## File Modificati + +- `MP.Data/DataServiceCollectionExtensions.cs` (+10/-1) +- `MP.Data/Services/LandDataService.cs` (+10/-10) +- `MP.Data/Services/MonDataFeeder.cs` (+1/-1) +- `MP.Data/Services/StatusData.cs` (+12/-12) +- `MP.Data/Services/TabDataFeeder.cs` (+1/-1) +- `MP.Data/Services/TranslateSrv.cs` (+13/-13) +- `MP.SPEC/Data/MpDataService.cs` (+1/-3) + +## File Nuovi (6) + +- `MP.Data/Repository/MpLand/IMpLandRepository.cs` +- `MP.Data/Repository/MpLand/MpLandRepository.cs` +- `MP.Data/Repository/MpMon/IMpMonRepository.cs` +- `MP.Data/Repository/MpMon/MpMonRepository.cs` +- `MP.Data/Repository/MpVoc/IMpVocRepository.cs` +- `MP.Data/Repository/MpVoc/MpVocRepository.cs` + +## Verifiche + +- Nessun riferimento a `dbController.XXX()` nei file di servizio +- `ArticleWithDossierAsync` esportato correttamente (rimossi `#if false`) +- `VocabolarioGetLang` reso sincrono (firma originale sincrona) +- `tryLoadIobTags` in StatusData usa `GetAwaiter().GetResult()` (contesto sync) +- `InitDict` in TranslateSrv usa `GetAwaiter().GetResult()` (contesto sync) + +## MpSpecRepository (MpSpecController) + +I metodi原价 sono ancora visibili nel file ma: +- Non sono usati dai layer superiori (tutti migrati ai repository) +- Possono essere spostati a `#if false` come ultima fase di pulizia +- Rimangono come fallback documentato From d8040741218f783d248a6716b386248b4e56f746 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 3 Jun 2026 12:21:45 +0200 Subject: [PATCH 06/12] Completato fix SPEC, ok x MON, altri da verificare/sistemare --- MP-TAB3/MP-TAB3.csproj | 2 +- MP-TAB3/Resources/ChangeLog.html | 2 +- MP-TAB3/Resources/VersNum.txt | 2 +- MP-TAB3/Resources/manifest.xml | 2 +- MP.AppAuth/Controllers/AppAuthController.cs | 22 ++-- MP.AppAuth/Controllers/AppUserController.cs | 42 +++++-- MP.AppAuth/Controllers/MPController .cs | 47 ++++---- MP.AppAuth/DataServiceCollectionExtensions.cs | 23 ++++ MP.AppAuth/Services/AppAuthService.cs | 105 +++++++++--------- MP.Data/Controllers/MpLandController.cs | 26 ++++- MP.Data/Controllers/MpVocController.cs | 56 ++++------ MP.Data/DataServiceCollectionExtensions.cs | 51 ++++++--- MP.Data/DbModels/AlarmLogModel.cs | 4 +- MP.Data/DbModels/DbSizeModel.cs | 4 +- MP.Data/DbModels/InsManualiModel.cs | 7 +- MP.Data/DbModels/ODLExpModel.cs | 5 +- MP.Data/DbModels/ODLModel.cs | 4 +- MP.Data/DbModels/PODLExpModel.cs | 4 +- MP.Data/DbModels/PODLModel.cs | 4 +- MP.Data/DbModels/TksScoreModel.cs | 4 +- MP.Data/MoonPro_VocContext.cs | 26 +++-- MP.Data/Services/BaseServ.cs | 2 +- MP.Data/Services/LandDataService.cs | 6 - MP.INVE/MP.INVE.csproj | 2 +- MP.INVE/Resources/ChangeLog.html | 2 +- MP.INVE/Resources/VersNum.txt | 2 +- MP.INVE/Resources/manifest.xml | 2 +- MP.IOC/MP.IOC.csproj | 2 +- MP.IOC/Resources/ChangeLog.html | 2 +- MP.IOC/Resources/VersNum.txt | 2 +- MP.IOC/Resources/manifest.xml | 2 +- MP.Land/MP.Land.csproj | 2 +- MP.Land/Resources/ChangeLog.html | 2 +- MP.Land/Resources/VersNum.txt | 2 +- MP.Land/Resources/manifest.xml | 2 +- MP.Land/Startup.cs | 28 +++-- MP.MON/MP.MON.csproj | 2 +- MP.MON/Program.cs | 16 ++- MP.MON/Resources/ChangeLog.html | 2 +- MP.MON/Resources/VersNum.txt | 2 +- MP.MON/Resources/manifest.xml | 2 +- MP.MON/appsettings.json | 4 +- MP.Prog/MP.Prog.csproj | 2 +- MP.Prog/Resources/ChangeLog.html | 2 +- MP.Prog/Resources/VersNum.txt | 2 +- MP.Prog/Resources/manifest.xml | 2 +- MP.RIOC/MP.RIOC.csproj | 2 +- MP.RIOC/Resources/ChangeLog.html | 2 +- MP.RIOC/Resources/VersNum.txt | 2 +- MP.RIOC/Resources/manifest.xml | 2 +- MP.RIOC/appsettings.json | 4 +- MP.SPEC/Data/MpDataService.cs | 23 +++- MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Program.cs | 15 ++- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- MP.SPEC/appsettings.json | 2 + MP.Stats/MP.Stats.csproj | 2 +- MP.Stats/Resources/ChangeLog.html | 2 +- MP.Stats/Resources/VersNum.txt | 2 +- MP.Stats/Resources/manifest.xml | 2 +- 62 files changed, 372 insertions(+), 234 deletions(-) create mode 100644 MP.AppAuth/DataServiceCollectionExtensions.cs diff --git a/MP-TAB3/MP-TAB3.csproj b/MP-TAB3/MP-TAB3.csproj index b79bd3a4..b3d96ba1 100644 --- a/MP-TAB3/MP-TAB3.csproj +++ b/MP-TAB3/MP-TAB3.csproj @@ -3,7 +3,7 @@ net8.0 enable - 8.16.2606.119 + 8.16.2606.311 enable MP_TAB3 diff --git a/MP-TAB3/Resources/ChangeLog.html b/MP-TAB3/Resources/ChangeLog.html index 7e42922e..40cd97d7 100644 --- a/MP-TAB3/Resources/ChangeLog.html +++ b/MP-TAB3/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 8.16.2606.119

+

Versione: 8.16.2606.311


Note di rilascio:
  • diff --git a/MP-TAB3/Resources/VersNum.txt b/MP-TAB3/Resources/VersNum.txt index 28d1df86..aa5451d0 100644 --- a/MP-TAB3/Resources/VersNum.txt +++ b/MP-TAB3/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.119 +8.16.2606.311 diff --git a/MP-TAB3/Resources/manifest.xml b/MP-TAB3/Resources/manifest.xml index d464ba46..f12d84a9 100644 --- a/MP-TAB3/Resources/manifest.xml +++ b/MP-TAB3/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.119 + 8.16.2606.311 https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/MP-TAB3.zip https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/ChangeLog.html false diff --git a/MP.AppAuth/Controllers/AppAuthController.cs b/MP.AppAuth/Controllers/AppAuthController.cs index bd6047d5..91407d3e 100644 --- a/MP.AppAuth/Controllers/AppAuthController.cs +++ b/MP.AppAuth/Controllers/AppAuthController.cs @@ -12,16 +12,23 @@ namespace MP.AppAuth.Controllers { public class AppAuthController { + #region Private Fields + + private readonly IConfiguration _configuration; + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion + #region Public Constructors public AppAuthController(IConfiguration configuration) { _configuration = configuration; - Log.Info("Avviata classe AppAuthController"); } - #endregion Public Constructors + #endregion #region Public Methods @@ -189,8 +196,6 @@ namespace MP.AppAuth.Controllers return dbResult; } - - /// /// Elenco Record x gestione Update /// @@ -225,12 +230,5 @@ namespace MP.AppAuth.Controllers } #endregion Public Methods - - #region Private Fields - - private static IConfiguration _configuration; - private static Logger Log = LogManager.GetCurrentClassLogger(); - - #endregion Private Fields } -} \ No newline at end of file +} diff --git a/MP.AppAuth/Controllers/AppUserController.cs b/MP.AppAuth/Controllers/AppUserController.cs index dde09586..f906fbb5 100644 --- a/MP.AppAuth/Controllers/AppUserController.cs +++ b/MP.AppAuth/Controllers/AppUserController.cs @@ -11,6 +11,16 @@ namespace MP.AppAuth.Controllers { public class AppUserController : IDisposable { + #region Private Fields + + private readonly IConfiguration _configuration; + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + private bool _disposed = false; + + #endregion + #region Public Constructors public AppUserController(IConfiguration configuration) @@ -19,7 +29,7 @@ namespace MP.AppAuth.Controllers Log.Info("Avviata classe AppUserController"); } - #endregion Public Constructors + #endregion #region Public Methods @@ -42,18 +52,28 @@ namespace MP.AppAuth.Controllers return dbResult; } - public void Dispose() - { - GC.Collect(); - } - #endregion Public Methods - #region Private Fields + #region Protected Methods - private static IConfiguration _configuration = null!; - private static Logger Log = LogManager.GetCurrentClassLogger(); + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (disposing) + { + // Free managed resources here + } + _disposed = true; + } + } - #endregion Private Fields + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + #endregion } -} \ No newline at end of file +} diff --git a/MP.AppAuth/Controllers/MPController .cs b/MP.AppAuth/Controllers/MPController .cs index b3dee069..739b5150 100644 --- a/MP.AppAuth/Controllers/MPController .cs +++ b/MP.AppAuth/Controllers/MPController .cs @@ -10,19 +10,15 @@ namespace MP.AppAuth.Controllers { public class MPController : IDisposable { - #region Public Fields - - public static MPController dbController; - - #endregion Public Fields - #region Private Fields - private static IConfiguration _configuration; + private readonly IConfiguration _configuration; private static Logger Log = LogManager.GetCurrentClassLogger(); - #endregion Private Fields + private bool _disposed = false; + + #endregion #region Public Constructors @@ -32,7 +28,7 @@ namespace MP.AppAuth.Controllers Log.Info("Avviata classe MpController"); } - #endregion Public Constructors + #endregion #region Public Methods @@ -271,15 +267,6 @@ namespace MP.AppAuth.Controllers return fatto; } - public void Dispose() - { - if (dbController != null) - { - // Clear database controller - dbController.Dispose(); - } - } - /// /// Elenco Record x ListValues /// @@ -380,5 +367,27 @@ namespace MP.AppAuth.Controllers } #endregion Public Methods + + #region Protected Methods + + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (disposing) + { + // Free managed resources here + } + _disposed = true; + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + #endregion } -} \ No newline at end of file +} diff --git a/MP.AppAuth/DataServiceCollectionExtensions.cs b/MP.AppAuth/DataServiceCollectionExtensions.cs new file mode 100644 index 00000000..56841d9a --- /dev/null +++ b/MP.AppAuth/DataServiceCollectionExtensions.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.AppAuth +{ + public static class DataServiceCollectionExtensions + { + /// + /// Aggiunta repository/servizi specifici per IOC + /// + /// + /// + public static IServiceCollection AddAuthLandDataLayer(this IServiceCollection services) + { + + return services; + } + } +} diff --git a/MP.AppAuth/Services/AppAuthService.cs b/MP.AppAuth/Services/AppAuthService.cs index 7ab866af..f4ec89f4 100644 --- a/MP.AppAuth/Services/AppAuthService.cs +++ b/MP.AppAuth/Services/AppAuthService.cs @@ -20,10 +20,6 @@ namespace MP.AppAuth.Services // diritti (cablato) public const string RoleSuperAdmin = "MoonPro_SuperAdmin"; - public static AppAuthController dbController; - public static MPController MpDbController; - public static AppUserController userController; - #endregion Public Fields #region Private Fields @@ -37,15 +33,15 @@ namespace MP.AppAuth.Services private const string rKeyPermUser = $"{redisBaseAddr}:PERM_USER"; - private static IConfiguration _configuration; + private readonly IConfiguration _configuration; - private static ILogger _logger; + private readonly ILogger _logger; - private static JsonSerializerSettings? JSSettings; + private readonly JsonSerializerSettings? JSSettings; private static Logger Log = LogManager.GetCurrentClassLogger(); - private static string Modulo = ""; + private string Modulo = ""; /// /// Durata cache lunga IN SECONDI @@ -60,23 +56,27 @@ namespace MP.AppAuth.Services /// /// Oggetto per connessione a REDIS /// - private IConnectionMultiplexer redisConn; + private readonly IConnectionMultiplexer redisConn; //ISubscriber sub = redis.GetSubscriber(); /// /// Oggetto DB redis da impiegare x chiamate R/W /// - private StackExchange.Redis.IDatabase redisDb = null!; + private readonly StackExchange.Redis.IDatabase redisDb; - private Random rnd = new Random(); + private readonly Random rnd = new Random(); private Dictionary Vocabolario = new Dictionary(); + private readonly AppAuthController _appAuthController; + private readonly MPController _mpController; + private readonly AppUserController _appUserController; + #endregion Private Fields #region Public Constructors - public AppAuthService(IConfiguration configuration, ILogger logger, IConnectionMultiplexer redisConnMult) + public AppAuthService(IConfiguration configuration, ILogger logger, IConnectionMultiplexer redisConnMult, AppAuthController appAuthController, MPController mpController, AppUserController appUserController) { _logger = logger; _configuration = configuration; @@ -103,9 +103,9 @@ namespace MP.AppAuth.Services } else { - dbController = new AppAuthController(configuration); - MpDbController = new MPController(configuration); - userController = new AppUserController(configuration); + _appAuthController = appAuthController; + _mpController = mpController; + _appUserController = appUserController; _logger.LogInformation("DbController OK"); } } @@ -114,7 +114,7 @@ namespace MP.AppAuth.Services #region Private Properties - private string CodApp { get; set; } = ""; + private string CodApp { get; } /// /// Durata cache lunga (+ perturbazione percentuale +/-10%) @@ -153,7 +153,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.AnagCauSca(); + dbResult = _mpController.AnagCauSca(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagCauSca: {ts.TotalMilliseconds} ms"); @@ -169,7 +169,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.AnagClassiTempo(); + dbResult = _mpController.AnagClassiTempo(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagClassiTempo: {ts.TotalMilliseconds} ms"); @@ -185,7 +185,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.AnagEventi(); + dbResult = _mpController.AnagEventi(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagEventi: {ts.TotalMilliseconds} ms"); @@ -201,7 +201,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = dbController.AnagGruppiGetAll(); + dbResult = _appAuthController.AnagGruppiGetAll(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagGruppiAll: {ts.TotalMilliseconds} ms"); @@ -213,7 +213,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = dbController.AnagGruppiFilt(codTipo); + dbResult = _appAuthController.AnagGruppiFilt(codTipo); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagGruppiFilt: {ts.TotalMilliseconds} ms"); @@ -229,7 +229,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.AnagIngressi(); + dbResult = _mpController.AnagIngressi(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagIngressi: {ts.TotalMilliseconds} ms"); @@ -241,7 +241,7 @@ namespace MP.AppAuth.Services bool answ = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - answ = MpDbController.AnagKeyValuesUpsert(currRec); + answ = _mpController.AnagKeyValuesUpsert(currRec); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"AnagKeyValAdd | Aggiunto rec | NomeVar: {currRec.NomeVar} | durata: {ts.TotalMilliseconds} ms"); @@ -253,7 +253,7 @@ namespace MP.AppAuth.Services bool answ = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - answ = MpDbController.AnagKeyValuesDelete(NomeVar); + answ = _mpController.AnagKeyValuesDelete(NomeVar); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"AnagKeyValDelete | Effettuata cancellazione | NomeVar: {NomeVar} | durata: {ts.TotalMilliseconds} ms"); @@ -265,7 +265,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.AnagKeyValuesGetAll(); + dbResult = _mpController.AnagKeyValuesGetAll(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagKeyValList: {ts.TotalMilliseconds} ms"); @@ -277,7 +277,7 @@ namespace MP.AppAuth.Services bool answ = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - answ = MpDbController.AnagKeyValuesUpsert(currRec); + answ = _mpController.AnagKeyValuesUpsert(currRec); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"AnagKeyValUpd | Effettuata modifica | NomeVar: {currRec.NomeVar} | durata: {ts.TotalMilliseconds} ms"); @@ -293,7 +293,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.AnagMicroStati(); + dbResult = _mpController.AnagMicroStati(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagMicroStati: {ts.TotalMilliseconds} ms"); @@ -305,7 +305,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - var rawData = dbController + var rawData = _appAuthController .AnagOpByGruppoGetFilt(codGruppo, searchVal); dbResult = rawData .GroupBy(user => user.MatrOpr) @@ -322,7 +322,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = dbController.AnagOpGetAll(searchVal); + dbResult = _appAuthController.AnagOpGetAll(searchVal); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagOperList: {ts.TotalMilliseconds} ms"); @@ -338,7 +338,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.AnagStati(); + dbResult = _mpController.AnagStati(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per AnagStati: {ts.TotalMilliseconds} ms"); @@ -350,7 +350,7 @@ namespace MP.AppAuth.Services bool answ = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - answ = MpDbController.ConfigUpsert(currRec); + answ = _mpController.ConfigUpsert(currRec); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"ConfigAdd | Aggiunto rec | Chiave: {currRec.Chiave} | durata: {ts.TotalMilliseconds} ms"); @@ -362,7 +362,7 @@ namespace MP.AppAuth.Services bool answ = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - answ = MpDbController.ConfigDelete(Chiave); + answ = _mpController.ConfigDelete(Chiave); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"ConfigDelete | Effettuata cancellazione | Chiave: {Chiave} | durata: {ts.TotalMilliseconds} ms"); @@ -374,7 +374,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.ConfigGetAll(); + dbResult = _mpController.ConfigGetAll(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per ConfigList: {ts.TotalMilliseconds} ms"); @@ -386,7 +386,7 @@ namespace MP.AppAuth.Services bool answ = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - answ = MpDbController.ConfigUpsert(currRec); + answ = _mpController.ConfigUpsert(currRec); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"ConfigUpd | Effettuata modifica | Chiave: {currRec.Chiave} | durata: {ts.TotalMilliseconds} ms"); @@ -415,7 +415,7 @@ namespace MP.AppAuth.Services else { // recupero diritti utente - dbResult = userController.DirittiUtente(UserName, Modulo); + dbResult = _appUserController.DirittiUtente(UserName, Modulo); rawData = JsonConvert.SerializeObject(dbResult, JSSettings); await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); } @@ -430,11 +430,8 @@ namespace MP.AppAuth.Services public void Dispose() { - // Clear database controller - if (MpDbController != null) - { - MpDbController.Dispose(); - } + // Clear database controllers + _mpController?.Dispose(); } public async Task FlushRedisCache() @@ -455,7 +452,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.ListValues(); + dbResult = _mpController.ListValues(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per ListValues: {ts.TotalMilliseconds} ms"); @@ -484,7 +481,7 @@ namespace MP.AppAuth.Services else { // recupero diritti utente - dbResult = MpDbController.MacchineGetAll(); + dbResult = _mpController.MacchineGetAll(); rawData = JsonConvert.SerializeObject(dbResult, JSSettings); redisDb.StringSet(currKey, rawData, UltraLongCache); } @@ -526,7 +523,7 @@ namespace MP.AppAuth.Services else { // recupero diritti utente - var userRightList = userController.DirittiUtente(UserName, Modulo); + var userRightList = _appUserController.DirittiUtente(UserName, Modulo); // proietto come funzioni... var ListFunc = userRightList.Select(x => x.Funzione).ToList(); // trasformo i permessi utente @@ -534,7 +531,7 @@ namespace MP.AppAuth.Services { ListFunc = new List(); } - dbResult = dbController.PermessiGetByFunc(ListFunc); + dbResult = _appAuthController.PermessiGetByFunc(ListFunc); rawData = JsonConvert.SerializeObject(dbResult, JSSettings); await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); } @@ -565,7 +562,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = dbController.UpdManGetAll(); + dbResult = _appAuthController.UpdManGetAll(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per UpdManList: {ts.TotalMilliseconds} ms"); @@ -577,7 +574,7 @@ namespace MP.AppAuth.Services bool answ = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - answ = MpDbController.VocabolarioUpsert(currRec); + answ = _mpController.VocabolarioUpsert(currRec); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"VocabolarioAdd | Aggiunto rec | lingua: {currRec.Lingua} | lemma: {currRec.Lemma} | durata: {ts.TotalMilliseconds} ms"); @@ -589,7 +586,7 @@ namespace MP.AppAuth.Services bool answ = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - answ = MpDbController.VocabolarioDelete(currRec); + answ = _mpController.VocabolarioDelete(currRec); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"VocabolarioDelete | Effettuata cancellazione | lingua: {currRec.Lingua} | lemma: {currRec.Lemma} | durata: {ts.TotalMilliseconds} ms"); @@ -601,7 +598,7 @@ namespace MP.AppAuth.Services List dbResult = new List(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - dbResult = MpDbController.VocabolarioGetAll(); + dbResult = _mpController.VocabolarioGetAll(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"Effettuata lettura da DB per VocabolarioList: {ts.TotalMilliseconds} ms"); @@ -613,7 +610,7 @@ namespace MP.AppAuth.Services bool answ = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - answ = MpDbController.VocabolarioUpsert(currRec); + answ = _mpController.VocabolarioUpsert(currRec); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Trace($"VocabolarioUpd | Effettuata modifica | lingua: {currRec.Lingua} | lemma: {currRec.Lemma} | durata: {ts.TotalMilliseconds} ms"); @@ -641,7 +638,7 @@ namespace MP.AppAuth.Services } else { - Vocabolario = dbController + Vocabolario = _appAuthController .VocabolarioGetAll() .ToDictionary(x => $"{x.Lingua}#{x.Lemma}", x => x.Traduzione); rawData = JsonConvert.SerializeObject(Vocabolario); @@ -665,10 +662,10 @@ namespace MP.AppAuth.Services { bool answ = false; var masterEndpoint = redisConn.GetEndPoints() - .Where(ep => redisConn.GetServer(ep).IsConnected && !redisConn.GetServer(ep).IsReplica) - .FirstOrDefault(); + .Where(ep => redisConn.GetServer(ep).IsConnected && !redisConn.GetServer(ep).IsReplica) + .FirstOrDefault(); - // sepattern è "*" elimino intero DB... + // se pattern è "*" elimino intero DB... if (masterEndpoint != null && (pat2Flush.Equals(new RedisValue("*")) || pat2Flush == RedisValue.Null)) { redisConn.GetServer(masterEndpoint).FlushDatabase(database: redisDb.Database); @@ -699,4 +696,4 @@ namespace MP.AppAuth.Services #endregion Private Methods } -} \ No newline at end of file +} diff --git a/MP.Data/Controllers/MpLandController.cs b/MP.Data/Controllers/MpLandController.cs index 9a77ad18..a87c3492 100644 --- a/MP.Data/Controllers/MpLandController.cs +++ b/MP.Data/Controllers/MpLandController.cs @@ -20,7 +20,7 @@ namespace MP.Data.Controllers { _configuration = configuration; string connStr = _configuration.GetConnectionString("MP.Land"); - if(string.IsNullOrEmpty(connStr)) + if (string.IsNullOrEmpty(connStr)) { connStr = _configuration.GetConnectionString("MP.Data"); } @@ -143,7 +143,8 @@ namespace MP.Data.Controllers public void Dispose() { - _configuration = null; + Dispose(true); + GC.SuppressFinalize(this); } /// @@ -262,11 +263,28 @@ namespace MP.Data.Controllers #endregion Public Methods + #region Protected Methods + + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (disposing) + { + // Free managed resources here + } + _disposed = true; + } + } + + #endregion Protected Methods + #region Private Fields - private static IConfiguration _configuration; private static Logger Log = LogManager.GetCurrentClassLogger(); - private DbContextOptions options; + private readonly IConfiguration _configuration; + private readonly DbContextOptions options; + private bool _disposed = false; #endregion Private Fields } diff --git a/MP.Data/Controllers/MpVocController.cs b/MP.Data/Controllers/MpVocController.cs index 713dc387..e78b7a8b 100644 --- a/MP.Data/Controllers/MpVocController.cs +++ b/MP.Data/Controllers/MpVocController.cs @@ -1,14 +1,10 @@ -using DnsClient.Protocol; -using Microsoft.Data.SqlClient; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using MP.Data.DbModels; using NLog; using System; using System.Collections.Generic; -using System.Drawing.Drawing2D; using System.Linq; -using static MP.Core.Objects.Enums; namespace MP.Data.Controllers { @@ -19,6 +15,10 @@ namespace MP.Data.Controllers public MpVocController(IConfiguration configuration) { _configuration = configuration; + string connStr = _configuration.GetConnectionString("MP.Voc"); + options = new DbContextOptionsBuilder() + .UseSqlServer(connStr) + .Options; Log.Info("Avviata classe MpVocController"); } @@ -26,6 +26,7 @@ namespace MP.Data.Controllers #region Public Methods + private DbContextOptions options; /// /// Elenco da tabella Config /// @@ -33,15 +34,12 @@ namespace MP.Data.Controllers public List ConfigGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonPro_VocContext(_configuration)) - { - dbResult = dbCtx - .DbSetConfig - .AsNoTracking() - .OrderBy(x => x.Chiave) - .ToList(); - } - return dbResult; + using var dbCtx = new MoonPro_VocContext(options); + return dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToList(); } public void Dispose() @@ -55,15 +53,12 @@ namespace MP.Data.Controllers public List LingueGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonPro_VocContext(_configuration)) - { - dbResult = dbCtx - .DbSetLilngue - .AsNoTracking() - .OrderBy(x => x.Lingua) - .ToList(); - } - return dbResult; + using var dbCtx = new MoonPro_VocContext(options); + return dbCtx + .DbSetLilngue + .AsNoTracking() + .OrderBy(x => x.Lingua) + .ToList(); } /// @@ -73,15 +68,12 @@ namespace MP.Data.Controllers public List VocabolarioGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonPro_VocContext(_configuration)) - { - dbResult = dbCtx - .DbSetVocabolario - .AsNoTracking() - .OrderBy(x => x.Lemma) - .ToList(); - } - return dbResult; + using var dbCtx = new MoonPro_VocContext(options); + return dbCtx + .DbSetVocabolario + .AsNoTracking() + .OrderBy(x => x.Lemma) + .ToList(); } #endregion Public Methods diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index b2f236c8..6b0b34ed 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using MP.AppAuth.Controllers; using MP.AppAuth.Services; using MP.Data.Controllers; using MP.Data.Repository.Anag; @@ -49,6 +50,33 @@ namespace MP.Data return services; } /// + /// Aggiunta repository/servizi specifici per LAND + /// + /// + /// + public static IServiceCollection AddLandDataLayer(this IServiceCollection services) + { + + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + + return services; + } + /// + /// Aggiunta repository/servizi specifici per MON + /// + /// + /// + public static IServiceCollection AddMonDataLayer(this IServiceCollection services) + { + + services.TryAddSingleton(); + services.TryAddSingleton(); + return services; + } + /// /// Aggiunta repository/servizi specifici per SPEC /// /// @@ -56,10 +84,8 @@ namespace MP.Data public static IServiceCollection AddSpecDataLayer(this IServiceCollection services) { // ---------- Start Repository ---------- - // Singleton - services.TryAddSingleton(); + services.TryAddScoped(); - // Scoped services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); @@ -67,35 +93,26 @@ namespace MP.Data services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); - - // ---------- End Repository ---------- // ---------- Start Servizi ---------- - - // Singleton - //services.TryAddSingleton(); - - // Scoped - // ---------- End Servizi ---------- // ---------- Start Altro ---------- - // Singleton - services.TryAddSingleton(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddSingleton(); services.TryAddSingleton(); - services.TryAddSingleton(); - - // Scoped + services.TryAddScoped(); services.AddScoped(); services.AddScoped(); - // ---------- End Altro ---------- return services; diff --git a/MP.Data/DbModels/AlarmLogModel.cs b/MP.Data/DbModels/AlarmLogModel.cs index d7578850..59baf27f 100644 --- a/MP.Data/DbModels/AlarmLogModel.cs +++ b/MP.Data/DbModels/AlarmLogModel.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.EntityFrameworkCore; +using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -16,6 +17,7 @@ namespace MP.Data.DbModels [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int AlarmLogId { get; set; } = 0; public DateTime DtRif { get; set; } = DateTime.Now; + [Precision(18, 6)] public decimal Duration { get; set; } = 0; public string MachineId { get; set; } = ""; public string MemAddress { get; set; } = ""; diff --git a/MP.Data/DbModels/DbSizeModel.cs b/MP.Data/DbModels/DbSizeModel.cs index 1704ae77..4606349f 100644 --- a/MP.Data/DbModels/DbSizeModel.cs +++ b/MP.Data/DbModels/DbSizeModel.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; namespace MP.Data.DbModels { @@ -6,6 +7,7 @@ namespace MP.Data.DbModels { [Key] public string DbName { get; set; } = ""; + [Precision(18, 6)] public decimal DbSizeMb { get; set; } = 0; public int NumTables { get; set; } = 0; public string BigTable { get; set; } = ""; diff --git a/MP.Data/DbModels/InsManualiModel.cs b/MP.Data/DbModels/InsManualiModel.cs index a692763d..a1e8e3c7 100644 --- a/MP.Data/DbModels/InsManualiModel.cs +++ b/MP.Data/DbModels/InsManualiModel.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.EntityFrameworkCore; +using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -35,11 +36,13 @@ namespace MP.Data.DbModels /// /// Tempo Ciclo std /// + [Precision(18, 6)] public decimal TCiclo { get; set; } = 0; /// /// Minuti prodotti (da TC e pz prod /// + [Precision(18, 6)] public decimal MinProd { get; set; } = 0; /// @@ -50,7 +53,7 @@ namespace MP.Data.DbModels [NotMapped] public bool IsWork { - get => IdxTipoEv == 1; + get => IdxTipoEv == 1; } diff --git a/MP.Data/DbModels/ODLExpModel.cs b/MP.Data/DbModels/ODLExpModel.cs index 6c6d5b45..1517d9d8 100644 --- a/MP.Data/DbModels/ODLExpModel.cs +++ b/MP.Data/DbModels/ODLExpModel.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.EntityFrameworkCore; +using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -19,7 +20,9 @@ namespace MP.Data.DbModels public string CodArticolo { get; set; } = ""; public string IdxMacchina { get; set; } public int NumPezzi { get; set; } + [Precision(18, 6)] public decimal Tcassegnato { get; set; } + [Precision(18, 6)] public decimal TCRichAttr { get; set; } public DateTime? DataInizio { get; set; } public DateTime? DataFine { get; set; } diff --git a/MP.Data/DbModels/ODLModel.cs b/MP.Data/DbModels/ODLModel.cs index caaf0845..0bfff032 100644 --- a/MP.Data/DbModels/ODLModel.cs +++ b/MP.Data/DbModels/ODLModel.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.EntityFrameworkCore; +using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -21,6 +22,7 @@ namespace MP.Data.DbModels [MaxLength(50)] public string IdxMacchina { get; set; } public int NumPezzi { get; set; } + [Precision(18, 6)] public decimal Tcassegnato { get; set; } public DateTime? DataInizio { get; set; } public DateTime? DataFine { get; set; } diff --git a/MP.Data/DbModels/PODLExpModel.cs b/MP.Data/DbModels/PODLExpModel.cs index e4590159..7b8fecd0 100644 --- a/MP.Data/DbModels/PODLExpModel.cs +++ b/MP.Data/DbModels/PODLExpModel.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.EntityFrameworkCore; +using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -28,6 +29,7 @@ namespace MP.Data.DbModels [MaxLength(50)] public string IdxMacchina { get; set; } public int NumPezzi { get; set; } = 1; + [Precision(18, 6)] public decimal Tcassegnato { get; set; } = 1; public DateTime? DueDate { get; set; } public int Priorita { get; set; } = 1; diff --git a/MP.Data/DbModels/PODLModel.cs b/MP.Data/DbModels/PODLModel.cs index 818c5235..66d79107 100644 --- a/MP.Data/DbModels/PODLModel.cs +++ b/MP.Data/DbModels/PODLModel.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.EntityFrameworkCore; +using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -29,6 +30,7 @@ namespace MP.Data.DbModels [MaxLength(50)] public string IdxMacchina { get; set; } public int NumPezzi { get; set; } = 1; + [Precision(18, 6)] public decimal Tcassegnato { get; set; } = 1; public DateTime? DueDate { get; set; } public int Priorita { get; set; } = 1; diff --git a/MP.Data/DbModels/TksScoreModel.cs b/MP.Data/DbModels/TksScoreModel.cs index d90efb2d..12fdfe78 100644 --- a/MP.Data/DbModels/TksScoreModel.cs +++ b/MP.Data/DbModels/TksScoreModel.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; // // This is here so CodeMaid doesn't reorganize this document @@ -24,6 +25,7 @@ namespace MP.Data.DbModels /// /// Score Cicli Associati /// + [Precision(18, 6)] public decimal ChildScore { get; set; } = 0; /// /// Score complessivo diff --git a/MP.Data/MoonPro_VocContext.cs b/MP.Data/MoonPro_VocContext.cs index ca357a74..441d5e1b 100644 --- a/MP.Data/MoonPro_VocContext.cs +++ b/MP.Data/MoonPro_VocContext.cs @@ -1,7 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.Extensions.Configuration; +using Microsoft.EntityFrameworkCore; using MP.Data.DbModels; using NLog; @@ -17,16 +14,16 @@ namespace MP.Data private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private IConfiguration _configuration; + //private IConfiguration _configuration; #endregion Private Fields #region Public Constructors - public MoonPro_VocContext(IConfiguration configuration) - { - _configuration = configuration; - } + //public MoonPro_VocContext(IConfiguration configuration) + //{ + // _configuration = configuration; + //} public MoonPro_VocContext(DbContextOptions options) : base(options) { @@ -52,11 +49,16 @@ namespace MP.Data protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + //if (!optionsBuilder.IsConfigured) + //{ + // string connString = _configuration.GetConnectionString("MP.Voc"); + + // optionsBuilder.UseSqlServer(connString); + //} if (!optionsBuilder.IsConfigured) { - string connString = _configuration.GetConnectionString("MP.Voc"); - - optionsBuilder.UseSqlServer(connString); + // fallback si spera non necessario + optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;"); } } diff --git a/MP.Data/Services/BaseServ.cs b/MP.Data/Services/BaseServ.cs index 51355686..770df68e 100644 --- a/MP.Data/Services/BaseServ.cs +++ b/MP.Data/Services/BaseServ.cs @@ -161,7 +161,7 @@ namespace MP.Data.Services /// protected static readonly ActivitySource ActivitySource = new ActivitySource("MP.IOC"); - protected static IConfiguration _configuration = null!; + protected IConfiguration _configuration = null!; /// /// Abilitazione operazioni tracing generiche diff --git a/MP.Data/Services/LandDataService.cs b/MP.Data/Services/LandDataService.cs index 453c45ff..a94c0634 100644 --- a/MP.Data/Services/LandDataService.cs +++ b/MP.Data/Services/LandDataService.cs @@ -40,12 +40,6 @@ namespace MP.Data.Services #endregion Public Constructors - #region Public Properties - - public static MpLandController dbController { get; set; } = null!; - - #endregion Public Properties - #region Public Methods /// diff --git a/MP.INVE/MP.INVE.csproj b/MP.INVE/MP.INVE.csproj index 13723817..d12186f5 100644 --- a/MP.INVE/MP.INVE.csproj +++ b/MP.INVE/MP.INVE.csproj @@ -5,7 +5,7 @@ enable enable MP.INVE - 8.16.2606.119 + 8.16.2606.311 diff --git a/MP.INVE/Resources/ChangeLog.html b/MP.INVE/Resources/ChangeLog.html index 805e9ef3..aff20529 100644 --- a/MP.INVE/Resources/ChangeLog.html +++ b/MP.INVE/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOINVE -

    Versione: 8.16.2606.119

    +

    Versione: 8.16.2606.311


    Note di rilascio:
    • diff --git a/MP.INVE/Resources/VersNum.txt b/MP.INVE/Resources/VersNum.txt index 28d1df86..aa5451d0 100644 --- a/MP.INVE/Resources/VersNum.txt +++ b/MP.INVE/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.119 +8.16.2606.311 diff --git a/MP.INVE/Resources/manifest.xml b/MP.INVE/Resources/manifest.xml index 635c7a5f..5e64eb24 100644 --- a/MP.INVE/Resources/manifest.xml +++ b/MP.INVE/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.119 + 8.16.2606.311 https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/MP.INVE.zip https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/ChangeLog.html false diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 56eeddca..88739b41 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 8.16.2606.119 + 8.16.2606.311 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 03c738b7..55fd6939 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

      Versione: 8.16.2606.119

      +

      Versione: 8.16.2606.311


      Note di rilascio:
      • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index 28d1df86..aa5451d0 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.119 +8.16.2606.311 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index d3e771b6..92f155e7 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.119 + 8.16.2606.311 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 diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index 2d7b8b5e..508b0702 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net8.0 MP.Land - 8.16.2606.0119 + 8.16.2606.0312 Debug;Release;Debug_LiManDebug en True diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index 17946008..a19361ad 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo Tablet MAPO - DotNet6 -

        Versione: 8.16.2606.0119

        +

        Versione: 8.16.2606.0312


        Note di rilascio:
          diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index 8bc36859..b505b6b3 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.0119 +8.16.2606.0312 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index 5a0155ac..c16761d9 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.0119 + 8.16.2606.0312 https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html false diff --git a/MP.Land/Startup.cs b/MP.Land/Startup.cs index 77b74a07..b8b345a7 100644 --- a/MP.Land/Startup.cs +++ b/MP.Land/Startup.cs @@ -2,25 +2,21 @@ using Blazored.LocalStorage; using Blazored.SessionStorage; using Microsoft.AspNetCore.Authentication.Negotiate; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpOverrides; -using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Localization; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using MP.AppAuth.Services; -using MP.Data.Services; +using MP.Data; using MP.Land.Data; using MP.TaskMan.Services; using StackExchange.Redis; using System; -using System.Collections.Generic; -using System.Configuration; using System.Globalization; -using System.Linq; -using System.Threading.Tasks; namespace MP.Land { @@ -138,12 +134,24 @@ namespace MP.Land services.AddServerSideBlazor(); services.AddSingleton(Configuration); + + // aggiungo il costruttore x i vari DbContextFactory + var connStr = Configuration.GetConnectionString("MP.Land") + ?? throw new InvalidOperationException("ConnString 'MP.Land' mancante."); + services.AddDbContextFactory(options => + options.UseSqlServer(connStr) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + + //init servizi specifici LAND + //services.AddAuthLandDataLayer(); + services.AddLandDataLayer(); services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + //services.AddSingleton(); + //services.AddSingleton(); + //services.AddSingleton(); services.AddScoped(); services.AddScoped(); diff --git a/MP.MON/MP.MON.csproj b/MP.MON/MP.MON.csproj index 2a883698..1d8ab17b 100644 --- a/MP.MON/MP.MON.csproj +++ b/MP.MON/MP.MON.csproj @@ -6,7 +6,7 @@ enable MP.MON $(AssemblyName.Replace(' ', '_')) - 8.16.2606.119 + 8.16.2606.312 diff --git a/MP.MON/Program.cs b/MP.MON/Program.cs index ad200407..20e4cd80 100644 --- a/MP.MON/Program.cs +++ b/MP.MON/Program.cs @@ -1,3 +1,6 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; +using MP.Data; using MP.Data.Services; using MP.MON.Components; using NLog; @@ -26,10 +29,21 @@ string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":")) // avvio oggetto shared x redis... var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); +// aggiungo il costruttore x i vari DbContextFactory +var connStr = builder.Configuration.GetConnectionString("MP.Mon") + ?? throw new InvalidOperationException("ConnString 'MP.Mon' mancante."); +builder.Services.AddDbContextFactory(options => + options.UseSqlServer(connStr) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + // Add services to the container. logger.Info("Setup Services"); + builder.Services.AddSingleton(redisMultiplexer); -builder.Services.AddSingleton(); +// Init centralizzato Repository/Servizi da MP.Data Services +builder.Services.AddMonDataLayer(); + var app = builder.Build(); diff --git a/MP.MON/Resources/ChangeLog.html b/MP.MON/Resources/ChangeLog.html index 7e42922e..81ed3f86 100644 --- a/MP.MON/Resources/ChangeLog.html +++ b/MP.MON/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

          Versione: 8.16.2606.119

          +

          Versione: 8.16.2606.312


          Note di rilascio:
          • diff --git a/MP.MON/Resources/VersNum.txt b/MP.MON/Resources/VersNum.txt index 28d1df86..1b236191 100644 --- a/MP.MON/Resources/VersNum.txt +++ b/MP.MON/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.119 +8.16.2606.312 diff --git a/MP.MON/Resources/manifest.xml b/MP.MON/Resources/manifest.xml index ebd7fc6e..ef808f77 100644 --- a/MP.MON/Resources/manifest.xml +++ b/MP.MON/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.119 + 8.16.2606.312 https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/MP.MON.zip https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/ChangeLog.html false diff --git a/MP.MON/appsettings.json b/MP.MON/appsettings.json index c9f20d06..5b692c2d 100644 --- a/MP.MON/appsettings.json +++ b/MP.MON/appsettings.json @@ -2,7 +2,9 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "Microsoft.EntityFrameworkCore": "Warning", + "Microsoft.EntityFrameworkCore.Database.Command": "Warning" } }, "NLog": { diff --git a/MP.Prog/MP.Prog.csproj b/MP.Prog/MP.Prog.csproj index e1e72fa3..82cdeb00 100644 --- a/MP.Prog/MP.Prog.csproj +++ b/MP.Prog/MP.Prog.csproj @@ -3,7 +3,7 @@ net8.0 MP.Prog - 8.16.2606.0119 + 8.16.2606.0310 True diff --git a/MP.Prog/Resources/ChangeLog.html b/MP.Prog/Resources/ChangeLog.html index c430a648..03a88103 100644 --- a/MP.Prog/Resources/ChangeLog.html +++ b/MP.Prog/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo gestione Programmi MAPO -

            Versione: 8.16.2606.0119

            +

            Versione: 8.16.2606.0310


            Note di rilascio:
              diff --git a/MP.Prog/Resources/VersNum.txt b/MP.Prog/Resources/VersNum.txt index 8bc36859..6970c00b 100644 --- a/MP.Prog/Resources/VersNum.txt +++ b/MP.Prog/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.0119 +8.16.2606.0310 diff --git a/MP.Prog/Resources/manifest.xml b/MP.Prog/Resources/manifest.xml index b57cd977..70ae7425 100644 --- a/MP.Prog/Resources/manifest.xml +++ b/MP.Prog/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.0119 + 8.16.2606.0310 https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Prog.zip https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html false diff --git a/MP.RIOC/MP.RIOC.csproj b/MP.RIOC/MP.RIOC.csproj index a159eed4..7bc99308 100644 --- a/MP.RIOC/MP.RIOC.csproj +++ b/MP.RIOC/MP.RIOC.csproj @@ -5,7 +5,7 @@ enable enable MP.RIOC - 8.16.2606.119 + 8.16.2606.311 diff --git a/MP.RIOC/Resources/ChangeLog.html b/MP.RIOC/Resources/ChangeLog.html index c1503a5c..0271b927 100644 --- a/MP.RIOC/Resources/ChangeLog.html +++ b/MP.RIOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-RIOC -

              Versione: 8.16.2606.119

              +

              Versione: 8.16.2606.311


              Note di rilascio:
              • diff --git a/MP.RIOC/Resources/VersNum.txt b/MP.RIOC/Resources/VersNum.txt index 28d1df86..aa5451d0 100644 --- a/MP.RIOC/Resources/VersNum.txt +++ b/MP.RIOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.119 +8.16.2606.311 diff --git a/MP.RIOC/Resources/manifest.xml b/MP.RIOC/Resources/manifest.xml index 8ddc1c1b..9fb2ac1c 100644 --- a/MP.RIOC/Resources/manifest.xml +++ b/MP.RIOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.119 + 8.16.2606.311 https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/MP.RIOC.zip https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/ChangeLog.html false diff --git a/MP.RIOC/appsettings.json b/MP.RIOC/appsettings.json index 590b8fb4..2c648666 100644 --- a/MP.RIOC/appsettings.json +++ b/MP.RIOC/appsettings.json @@ -3,7 +3,9 @@ "LogLevel": { "Default": "Information", "Yarp": "Debug", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "Microsoft.EntityFrameworkCore": "Warning", + "Microsoft.EntityFrameworkCore.Database.Command": "Warning" } }, "AllowedHosts": "*", diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 3e0b2962..951addc4 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -31,10 +31,27 @@ namespace MP.SPEC.Data private readonly IFluxLogRepository _fluxLogRepository; private readonly IProductionRepository _productionRepository; - public MpDataService(IConfiguration configuration, IFusionCache cache, IAnagRepository anagRepository, ISystemRepository systemRepository, IDossierRepository dossierRepository, IFluxLogRepository fluxLogRepository, IProductionRepository productionRepository) + public MpDataService(IConnectionMultiplexer connMPlex, IConfiguration configuration, IFusionCache cache, IAnagRepository anagRepository, ISystemRepository systemRepository, IDossierRepository dossierRepository, IFluxLogRepository fluxLogRepository, IProductionRepository productionRepository) { // salvataggio oggetti _configuration = configuration; + redisConn = connMPlex; + redisDb = redisConn.GetDatabase(); + +#if false + // setup compoenti REDIS + redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis") ?? "localhost:6379"); + redisConnAdmin = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("RedisAdmin") ?? "localhost:6379"); + redisDb = redisConn.GetDatabase(); +#endif + // leggo cache lungo/cordo periodo + int.TryParse(_configuration.GetValue("ServerConf:redisShortTimeCache"), out redisShortTimeCache); + int.TryParse(_configuration.GetValue("ServerConf:redisLongTimeCache"), out redisLongTimeCache); + + // setup MsgPipe + BroadastMsgPipe = new MessagePipe(redisConn, Constants.BROADCAST_M_PIPE); + Log.Info("MpDataService | Redis OK"); + _cache = cache; _anagRepository = anagRepository; _systemRepository = systemRepository; @@ -524,7 +541,7 @@ namespace MP.SPEC.Data { // Clear database controller mongoController.Dispose(); - redisConn.Dispose(); + //redisConn.Dispose(); } /// @@ -2009,7 +2026,7 @@ namespace MP.SPEC.Data /// /// Oggetto per connessione a REDIS /// - private ConnectionMultiplexer redisConn = null!; + private IConnectionMultiplexer redisConn = null!; /// /// Oggetto per connessione a REDIS modalità admin (ex flux dati) diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 2952fe88..85941120 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 8.16.2606.119 + 8.16.2606.311 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Program.cs b/MP.SPEC/Program.cs index 36036cdd..64fd379e 100644 --- a/MP.SPEC/Program.cs +++ b/MP.SPEC/Program.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.StaticFiles; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.FileProviders; using MP.Data; using MP.SPEC.Components; @@ -159,19 +160,23 @@ builder.Services.AddFusionCache() // Metodi principali x accesso dati var connStr = builder.Configuration.GetConnectionString("MP.Data") ?? throw new InvalidOperationException("ConnString 'MP.Data' mancante."); -// aggiungo il costruttore x i DbContextFactory +// aggiungo il costruttore x i vari DbContextFactory builder.Services.AddDbContextFactory(options => options.UseSqlServer(connStr) .EnableSensitiveDataLogging(false) // true solo in Sviluppo .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); +builder.Services.AddDbContextFactory(options => + options.UseSqlServer(connStr) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); // MP.Data Services Utils - Statistiche DB builder.Services.AddSpecDataLayer(); -// altri servizi -builder.Services.AddSingleton(); -builder.Services.AddSingleton(); -builder.Services.AddScoped(); +// servizi del progetto SPEC +builder.Services.TryAddScoped(); +builder.Services.TryAddSingleton(); +builder.Services.TryAddScoped(); #if false builder.Services.AddSingleton(); diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 7e42922e..40cd97d7 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

                Versione: 8.16.2606.119

                +

                Versione: 8.16.2606.311


                Note di rilascio:
                • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 28d1df86..aa5451d0 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.119 +8.16.2606.311 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index 5cb1e4dd..c283f196 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.119 + 8.16.2606.311 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false diff --git a/MP.SPEC/appsettings.json b/MP.SPEC/appsettings.json index 683abe14..594aca27 100644 --- a/MP.SPEC/appsettings.json +++ b/MP.SPEC/appsettings.json @@ -3,6 +3,8 @@ "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning", + "Microsoft.EntityFrameworkCore": "Warning", + "Microsoft.EntityFrameworkCore.Database.Command": "Warning", "ZiggyCreatures.Caching.Fusion": "Warning" } }, diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 1ff2dc91..73e0c184 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,7 +4,7 @@ net8.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 8.16.2606.0119 + 8.16.2606.0311 true en diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index 16ce0ff0..7ee0c500 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

                  Versione: 8.16.2606.0119

                  +

                  Versione: 8.16.2606.0311


                  Note di rilascio:
                    diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index 8bc36859..4143bf31 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.0119 +8.16.2606.0311 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index d9cde985..7a375362 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.0119 + 8.16.2606.0311 https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false From 9055eaf73ce0e7e057e3d0d8132f90db5be884a5 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 3 Jun 2026 18:05:59 +0200 Subject: [PATCH 07/12] SPEC: - aggiunta pagina operatori - completato fix --- MP.AppAuth/MoonProContext.cs | 3 +- MP.Core/Utils.cs | 1 + MP.Data/Controllers/MpIocController.cs | 223 +++++++++--------- MP.Data/Controllers/MpLandController.cs | 170 +++++++------ MP.Data/Controllers/MpSpecRepository.cs | 153 ++++++------ MP.Data/Controllers/MpStatsController.cs | 60 +++-- MP.Data/DataServiceCollectionExtensions.cs | 41 +++- MP.Data/DbModels/TksScoreModel.cs | 1 + MP.Data/MoonPro_FluxContext.cs | 17 +- MP.Data/MoonPro_STATSContext.cs | 13 +- MP.Data/Repository/Anag/AnagRepository.cs | 34 +++ MP.Data/Repository/Anag/IAnagRepository.cs | 22 +- .../Repository/Dossier/DossierRepository.cs | 61 +++-- .../Repository/FluxLog/FluxLogRepository.cs | 35 +-- MP.Data/Repository/MpLand/MpLandRepository.cs | 21 +- MP.Data/Repository/MpVoc/IMpVocRepository.cs | 29 ++- MP.Data/Repository/MpVoc/MpVocRepository.cs | 39 ++- .../Production/IProductionRepository.cs | 1 + .../Production/ProductionRepository.cs | 24 +- MP.Data/Services/BaseServ.cs | 117 ++++++++- MP.Data/Services/IOC/IocService.cs | 34 ++- MP.Data/Services/LandDataService.cs | 18 +- MP.Data/Services/ListSelectDataSrv.cs | 10 +- MP.Data/Services/Mtc/MtcSetupService.cs | 4 +- MP.Data/Services/OrderDataSrv.cs | 9 +- MP.Data/Services/SchedulerDataService.cs | 7 +- MP.Data/Services/SharedMemService.cs | 7 +- MP.Data/Services/TabDataService.cs | 11 +- MP.Data/Services/TranslateSrv.cs | 200 ++++++++++------ MP.Data/Services/Utils/StatsAggrService.cs | 4 +- MP.Data/Services/Utils/StatsCodeService.cs | 5 +- MP.Data/Services/Utils/StatsDetailService.cs | 5 +- MP.Data/Services/Utils/StatsErrService.cs | 5 +- MP.SPEC/Components/AskCloseOdl.razor.cs | 3 +- .../Components/Reparti/ListOperatori.razor | 49 +++- .../Components/Reparti/ListOperatori.razor.cs | 52 +++- MP.SPEC/Components/Reparti/ListReparti.razor | 40 ++-- .../Components/Reparti/ListReparti.razor.cs | 3 + MP.SPEC/Data/MpDataService.cs | 33 +++ MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Pages/Operatori.razor | 41 ++++ MP.SPEC/Pages/Operatori.razor.cs | 66 ++++++ MP.SPEC/Program.cs | 9 +- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 46 files changed, 1161 insertions(+), 527 deletions(-) create mode 100644 MP.SPEC/Pages/Operatori.razor create mode 100644 MP.SPEC/Pages/Operatori.razor.cs diff --git a/MP.AppAuth/MoonProContext.cs b/MP.AppAuth/MoonProContext.cs index 6a1d615d..03219310 100644 --- a/MP.AppAuth/MoonProContext.cs +++ b/MP.AppAuth/MoonProContext.cs @@ -18,11 +18,12 @@ namespace MP.AppAuth #region Public Constructors - [Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")] + [Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. DbContextOptions must be supplied.")] public MoonProContext() { } + [Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. DbContextOptions must be supplied.")] public MoonProContext(IConfiguration configuration) { _configuration = configuration; diff --git a/MP.Core/Utils.cs b/MP.Core/Utils.cs index b138599a..5af55b84 100644 --- a/MP.Core/Utils.cs +++ b/MP.Core/Utils.cs @@ -12,6 +12,7 @@ namespace MP.Core public const string redisAnagGruppi = redisBaseAddr + "Cache:AnagGruppi"; public const string redisAnagStati = redisBaseAddr + "Cache:AnagStati"; + public const string redisAnagGruppiOpr = redisBaseAddr + "Cache:GrpByOpr"; public const string redisArtByDossier = redisBaseAddr + "Cache:ArtByDossier"; public const string redisArtList = redisBaseAddr + "Cache:ArtList"; diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs index c452739b..6502ccf6 100644 --- a/MP.Data/Controllers/MpIocController.cs +++ b/MP.Data/Controllers/MpIocController.cs @@ -15,15 +15,30 @@ namespace MP.Data.Controllers { public class MpIocController { + protected readonly IDbContextFactory _ctxFactory; + protected readonly IDbContextFactory _ctxFactoryFL; #region Public Constructors - public MpIocController(IConfiguration configuration) + public MpIocController( + IConfiguration configuration, + IDbContextFactory ctxFactory, + IDbContextFactory ctxFactoryFL) { - _configuration = configuration; - string connStr = _configuration.GetConnectionString("MP.Data"); +#if false + _configuration = configuration; +#endif + _ctxFactory = ctxFactory; + _ctxFactoryFL = ctxFactoryFL; +#if false + string connStr = configuration.GetConnectionString("MP.Data"); options = new DbContextOptionsBuilder() .UseSqlServer(connStr) + .Options; + string connStrFlux = configuration.GetConnectionString("MP.Flux"); + optionsFlux = new DbContextOptionsBuilder() + .UseSqlServer(connStrFlux) .Options; +#endif Log.Info("Avviata classe MpIocController"); } @@ -43,7 +58,7 @@ namespace MP.Data.Controllers /// public async Task AlarmLogInsertAsync(DateTime dtRif, string machineId, string memAddress, int memIndex, int statusVal, string valDecoded) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var DtRif = new SqlParameter("@DtRif", dtRif); var MachineId = new SqlParameter("@MachineId", machineId); @@ -63,7 +78,7 @@ namespace MP.Data.Controllers /// public async Task> AnagStatiGetAllAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var dbResult = await dbCtx .DbSetAnagStati @@ -81,7 +96,7 @@ namespace MP.Data.Controllers /// public async Task> ArticoliGetLastByMaccAsync(string idxMacc) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); var dbResult = await dbCtx @@ -107,7 +122,7 @@ namespace MP.Data.Controllers /// public async Task AutoStartOdlAsync(int idxOdl, int MatrOpr, string idxMacchina, decimal tCRich, int pzPallet, string note, bool startNewOdl, int qtyRich, string keyRich) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxOdl = new SqlParameter("@idxOdl ", idxOdl); var MatrApp = new SqlParameter("@MatrApp ", MatrOpr); @@ -138,7 +153,7 @@ namespace MP.Data.Controllers /// public async Task CheckCambiaStatoBatchAsync(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet) { - await using var dbCtx = new MoonProContext(options); + await using var dbCtx = _ctxFactory.CreateDbContext(); //await using var tx = await dbCtx.Database.BeginTransactionAsync(); try @@ -224,7 +239,7 @@ namespace MP.Data.Controllers /// public async Task ConfermaProdMacchinaAsync(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzScarto, DateTime DataOraApp, int MatrOpr) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var DataOra = new SqlParameter("@DataOra ", DateTime.Now); @@ -267,7 +282,7 @@ namespace MP.Data.Controllers /// public async Task ConfermaProdMacchinaFullAsync(string idxMacchina, int modoConfProd, int numPzConfermati, int numPzLasciati, int numPzScarto, DateTime DataOraApp, int MatrOpr) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var DataOra = new SqlParameter("@DataOra ", DateTime.Now); @@ -306,7 +321,7 @@ namespace MP.Data.Controllers /// public async Task> ConfFluxFiltAsync(string idxMacc) { - using var dbCtx = new MoonPro_FluxContext(_configuration); + using var dbCtx = _ctxFactoryFL.CreateDbContext(); var query = dbCtx.DbSetConfFlux .AsNoTracking() @@ -326,7 +341,7 @@ namespace MP.Data.Controllers /// public async Task> ConfigGetAllAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var dbResult = await dbCtx .DbSetConfig @@ -343,7 +358,7 @@ namespace MP.Data.Controllers /// public async Task ConfigUpdateAsync(ConfigModel updRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); bool fatto = false; var dbResult = await dbCtx @@ -365,7 +380,7 @@ namespace MP.Data.Controllers /// public async Task> DatiMacchineGetAllAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var dbResult = await dbCtx .DbSetDatiMacchine @@ -388,7 +403,7 @@ namespace MP.Data.Controllers /// public async Task DDB_InsStatoBatchAsync(string idxMacchina, DateTime inizioStato, int idxStato, string codArt, string value, int matrOpr, string pallet) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var InizioStato = new SqlParameter("@InizioStato", inizioStato); @@ -411,7 +426,7 @@ namespace MP.Data.Controllers /// public async Task> DecNumArtGetFiltAsync(string codArt = "") { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var query = dbCtx.DbSetDecNumArt .AsNoTracking() @@ -432,17 +447,13 @@ namespace MP.Data.Controllers /// public async Task> DossGetLastByMaccAsync(string idxMacc) { - List dbResult = new(); - using (var dbCtx = new MoonPro_FluxContext(_configuration)) - { - var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); - dbResult = await dbCtx - .DbSetDossiers - .FromSqlRaw("exec dbo.stp_DOSS_getLastByMacch @idxMacchina", IdxMacchina) - .AsNoTracking() - .ToListAsync(); - } - return dbResult; + using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); + return await dbCtx + .DbSetDossiers + .FromSqlRaw("exec dbo.stp_DOSS_getLastByMacch @idxMacchina", IdxMacchina) + .AsNoTracking() + .ToListAsync(); } /// @@ -452,7 +463,7 @@ namespace MP.Data.Controllers /// public async Task EvListInsertAsync(EventListModel newRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); dbCtx.DbSetEvList.Add(newRec); return await dbCtx.SaveChangesAsync() > 0; @@ -467,7 +478,7 @@ namespace MP.Data.Controllers public async Task EvListMicroStatoInsertAsync(MicroStatoMacchinaModel newRecMsm, EventListModel newRecEv) { // eseguo in transazione... - await using var dbCtx = new MoonProContext(options); + await using var dbCtx = _ctxFactory.CreateDbContext(); await using var tx = await dbCtx.Database.BeginTransactionAsync(); try @@ -518,18 +529,15 @@ namespace MP.Data.Controllers /// public async Task> FluxLogFirstByMaccAsync(string idxMacc, int numMax) { - List dbResult = new(); - - using var dbCtx = new MoonPro_FluxContext(_configuration); + using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); var NumMax = new SqlParameter("@numMax", numMax); - dbResult = await dbCtx - .DbSetFluxLog - .FromSqlRaw("exec dbo.stp_FL_getFirstByMacc @IdxMacchina, @numMax", IdxMacchina, NumMax) - .AsNoTracking() - .ToListAsync(); - return dbResult; + return await dbCtx + .DbSetFluxLog + .FromSqlRaw("exec dbo.stp_FL_getFirstByMacc @IdxMacchina, @numMax", IdxMacchina, NumMax) + .AsNoTracking() + .ToListAsync(); } /// @@ -543,17 +551,15 @@ namespace MP.Data.Controllers /// public async Task> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec) { - List dbResult = new List(); - using var dbCtx = new MoonPro_FluxContext(_configuration); + using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); - dbResult = await dbCtx - .DbSetFluxLog - .AsNoTracking() - .Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux)) - .OrderByDescending(x => x.dtEvento) - .Take(MaxRec) - .ToListAsync(); - return dbResult; + return await dbCtx + .DbSetFluxLog + .AsNoTracking() + .Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux)) + .OrderByDescending(x => x.dtEvento) + .Take(MaxRec) + .ToListAsync(); } /// @@ -563,15 +569,13 @@ namespace MP.Data.Controllers /// public async Task FluxLogInsertAsync(FluxLogModel newRec) { - bool fatto = false; - using var dbCtx = new MoonPro_FluxContext(_configuration); + using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); var currRec = dbCtx - .DbSetFluxLog - .Add(newRec); - await dbCtx.SaveChangesAsync(); + .DbSetFluxLog + .Add(newRec); + return await dbCtx.SaveChangesAsync()>0; - return fatto; } /// @@ -581,8 +585,7 @@ namespace MP.Data.Controllers /// public async Task FluxLogTakeSnapshotLastAsync(string idxMacc, DateTime dataInizio, DateTime dataFine) { - bool fatto = false; - using var dbCtx = new MoonPro_FluxContext(_configuration); + using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); var DataInizio = new SqlParameter("@DtMin", dataInizio); @@ -591,8 +594,7 @@ namespace MP.Data.Controllers var result = await dbCtx .Database .ExecuteSqlRawAsync("EXEC stp_FL_TakeSnapshotLast @IdxMacchina, @DtMin, @DtMax", IdxMacchina, DataInizio, DataFine); - fatto = result > 0; - return fatto; + return result > 0; } /// @@ -605,7 +607,7 @@ namespace MP.Data.Controllers public async Task KeepAliveUpsertAsync(string IdxMacc, DateTime OraServer, DateTime OraMacc) { bool fatto = false; - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var currRec = await dbCtx .DbSetKeepAlive @@ -638,7 +640,7 @@ namespace MP.Data.Controllers public async Task> ListLinkFiltAsync(string tipoLink) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); dbResult = await dbCtx .DbSetLinkMenu @@ -658,7 +660,7 @@ namespace MP.Data.Controllers public async Task> ListValuesFiltAsync(string tabName, string fieldName) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var query = dbCtx .DbSetListValues @@ -682,7 +684,7 @@ namespace MP.Data.Controllers public async Task> Macchine2SlaveAsync() { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); dbResult = await dbCtx .DbSetM2S @@ -700,7 +702,7 @@ namespace MP.Data.Controllers public async Task> MacchineGetAllAsync() { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); dbResult = await dbCtx .DbSetMacchine @@ -712,7 +714,7 @@ namespace MP.Data.Controllers public async Task MacchineGetByIdxAsync(string IdxMacchina) { MacchineModel dbResult = null; - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); dbResult = await dbCtx .DbSetMacchine @@ -729,7 +731,7 @@ namespace MP.Data.Controllers public async Task> MacchineGetFiltAsync(string codGruppo) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); if (codGruppo == "*") { @@ -763,7 +765,7 @@ namespace MP.Data.Controllers /// public async Task MacchineUpsertAsync(MacchineModel entity) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); // Recuperiamo l'entità tracciata dal context var trackedEntity = await dbCtx @@ -791,7 +793,7 @@ namespace MP.Data.Controllers public async Task> MicroStatoMacchinaGetByIdxMaccAsync(string IdxMacc) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); dbResult = await dbCtx .DbSetMicroStatoMacc @@ -809,7 +811,7 @@ namespace MP.Data.Controllers public async Task MicroStatoMacchinaUpsertAsync(MicroStatoMacchinaModel newRec) { bool fatto = false; - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var actRec = await dbCtx .DbSetMicroStatoMacc @@ -842,7 +844,7 @@ namespace MP.Data.Controllers public async Task> MseGetAllAsync(int maxAge = 2000) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge); @@ -862,7 +864,7 @@ namespace MP.Data.Controllers /// public async Task OdlAutoDayGenAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var DataInizio = new SqlParameter("@DataInizio", dataInizio); @@ -884,7 +886,7 @@ namespace MP.Data.Controllers /// public async Task OdlAutoDayGenFullAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo, int? pzPODL, int? pzPallet, string? keyRichiesta, int? tcAssegnato, string? codGruppo, bool flgCreaPODL, bool flgCheckTC) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var DataInizio = new SqlParameter("@DataInizio", dataInizio); @@ -913,7 +915,7 @@ namespace MP.Data.Controllers public async Task OdlCurrByMaccAsync(string idxMacchina) { ODLExpModel answ = new(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); // attenzione: se la stored resituisce una tabella, il primo elemento va recuperato in RAM!!! @@ -936,7 +938,7 @@ namespace MP.Data.Controllers /// public async Task OdlFixMachineSlave(string idxMacchina, int numDayPrev, int doInsert) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var idxMaccParam = new SqlParameter("@IdxMacchina", idxMacchina ?? ""); var numDayPrevParam = new SqlParameter("@NumDayPrev", numDayPrev); @@ -958,7 +960,7 @@ namespace MP.Data.Controllers /// public async Task OdlFixMachineSlaveAsync(string idxMacchina, int numDayPrev, int doInsert) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina); var NumDayPrev = new SqlParameter("@NumDayPrev", numDayPrev); @@ -977,7 +979,7 @@ namespace MP.Data.Controllers public async Task OdlLastByMaccAsync(string idxMacchina) { ODLExpModel answ = new(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); // attenzione: se la stored resituisce una tabella, il primo elemento va recuperato in RAM!!! @@ -1001,7 +1003,7 @@ namespace MP.Data.Controllers public async Task> OdlListByMaccPeriodoAsync(string idxMacchina, DateTime dtStart, DateTime dtEnd) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var DataFrom = new SqlParameter("@dataFrom", dtStart); @@ -1023,7 +1025,7 @@ namespace MP.Data.Controllers public async Task PezziProdMacchinaAsync(string idxMacchina) { PzProdModel dbResult = new PzProdModel(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); dbResult = (await dbCtx @@ -1046,7 +1048,7 @@ namespace MP.Data.Controllers public async Task> POdlGetByMaccArtAsync(string idxMacchina, string codArticolo, string codGruppo, bool onlyFree) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var pCodArticolo = new SqlParameter("@CodArticolo", codArticolo); @@ -1069,7 +1071,7 @@ namespace MP.Data.Controllers /// public async Task RecalcMseAsync(string idxMacchina, int maxAgeSec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var rigaProd = await StatoProdMacchinaAsync(idxMacchina, DateTime.Now); var MaxAgeSec = new SqlParameter("@maxAgeSec ", maxAgeSec); @@ -1093,7 +1095,7 @@ namespace MP.Data.Controllers /// public async Task RegControlliInsertAsync(string idxMacchina, int matrOpr, bool esitoOk, string note, DateTime dataOra) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina); var MatrOpr = new SqlParameter("@MatrOpr", matrOpr); @@ -1114,7 +1116,7 @@ namespace MP.Data.Controllers /// public async Task RegDichiarInsertAsync(RegistroDichiarazioniModel newRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var TagCode = new SqlParameter("@TagCode", newRec.TagCode); var IdxMacchina = new SqlParameter("@IdxMacchina", newRec.IdxMacchina); @@ -1136,7 +1138,7 @@ namespace MP.Data.Controllers /// public async Task RegDichiarUpdateAsync(RegistroDichiarazioniModel newRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var Original_IdxDich = new SqlParameter("@Original_IdxDich", newRec.IdxDich); var DtRec = new SqlParameter("@DtRec", newRec.DtRec); @@ -1157,7 +1159,7 @@ namespace MP.Data.Controllers /// public async Task RegScartiInsertAsync(RegistroScartiModel newRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@idxMacchina", newRec.IdxMacchina); var DataOra = new SqlParameter("@DataOra", newRec.DataOra); @@ -1184,7 +1186,7 @@ namespace MP.Data.Controllers public async Task RemRebootLogAddAndCleanAsync(RemoteRebootLogModel newRec, bool doClean, int num2keep) { bool fatto = false; - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); // 1. Transazione minima: SOLO INSERT + COMMIT await using var tx = await dbCtx.Database.BeginTransactionAsync(); @@ -1227,7 +1229,7 @@ namespace MP.Data.Controllers /// public async Task RemRebootLogAddAsync(RemoteRebootLogModel newRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var dbResult = dbCtx .DbSetRemRebLog @@ -1242,7 +1244,7 @@ namespace MP.Data.Controllers /// public async Task> RemRebootLogGetAllAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var dbResult = await dbCtx .DbSetRemRebLog @@ -1258,7 +1260,7 @@ namespace MP.Data.Controllers /// public async Task> RemRebootLogGetLastAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var dbResult = await dbCtx .DbSetRemRebLog .FromSqlRaw("EXEC stp_RRL_getLast") @@ -1273,7 +1275,7 @@ namespace MP.Data.Controllers /// public async Task RemRebootLogKeepLastAsync(int num2keep) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var pNum2Keep = new SqlParameter("@num2keep", num2keep); // La SP gestisce già la logica di soglia (1.5x), ma la specifico x sicurezza @@ -1291,7 +1293,7 @@ namespace MP.Data.Controllers /// public async Task SignalLogInsertAsync(SignalLogModel newRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var currRec = dbCtx .DbSetSignalLog @@ -1307,7 +1309,7 @@ namespace MP.Data.Controllers /// public async Task> SMES_getHwTransitionsAsync(string idxMacchina, int idxTipo) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var IdxTipo = new SqlParameter("@IdxTipo", idxTipo); @@ -1327,7 +1329,7 @@ namespace MP.Data.Controllers /// public async Task> SMES_getUserForcedAsync(string idxMacchina, int idxTipo) { - await using var dbCtx = new MoonProContext(options); + await using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var IdxTipo = new SqlParameter("@IdxTipo", idxTipo); @@ -1346,18 +1348,14 @@ namespace MP.Data.Controllers /// public List StateMachineIngressi(int idxFam) { - List dbResult = new List(); - using (var dbCtx = new MoonProContext(options)) - { - var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam); - dbResult = dbCtx - .DbSetSMI - .FromSqlRaw("exec dbo.stp_TRI_getByIdxFamIng @IdxFamigliaIngresso", IdxFamIn) - .AsNoTracking() - .AsEnumerable() - .ToList(); - } - return dbResult; + using var dbCtx = _ctxFactory.CreateDbContext(); + var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam); + return dbCtx + .DbSetSMI + .FromSqlRaw("exec dbo.stp_TRI_getByIdxFamIng @IdxFamigliaIngresso", IdxFamIn) + .AsNoTracking() + .AsEnumerable() + .ToList(); } /// @@ -1366,7 +1364,7 @@ namespace MP.Data.Controllers /// public async Task> StateMachineIngressiAsync(int idxFam) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam); var dbResult = await dbCtx @@ -1386,7 +1384,7 @@ namespace MP.Data.Controllers /// public async Task StatoProdMacchinaAsync(string idxMacchina, DateTime dtReq) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var DataOra = new SqlParameter("@DataOra ", dtReq); @@ -1406,7 +1404,7 @@ namespace MP.Data.Controllers /// public async Task> VMSFDGetAllAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var dbResult = await dbCtx .DbSetMSFD @@ -1424,7 +1422,7 @@ namespace MP.Data.Controllers /// public async Task VMSFDGetByMaccAsync(string idxMacc) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); var dbResult = (await dbCtx @@ -1444,7 +1442,7 @@ namespace MP.Data.Controllers /// public async Task> VMSFDGetMultiByMaccAsync(string idxMacc) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); @@ -1461,9 +1459,14 @@ namespace MP.Data.Controllers #region Private Fields - private static IConfiguration _configuration; +#if false + private static IConfiguration _configuration; +#endif private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private DbContextOptions options; +#if false + private DbContextOptions options; +#endif + private DbContextOptions optionsFlux; #endregion Private Fields diff --git a/MP.Data/Controllers/MpLandController.cs b/MP.Data/Controllers/MpLandController.cs index a87c3492..8ab7d25e 100644 --- a/MP.Data/Controllers/MpLandController.cs +++ b/MP.Data/Controllers/MpLandController.cs @@ -15,10 +15,21 @@ namespace MP.Data.Controllers public class MpLandController : IDisposable { #region Public Constructors + protected readonly IDbContextFactory _ctxFactory; + protected readonly IDbContextFactory _ctxFactoryFL; + protected readonly IDbContextFactory _ctxFactorySta; - public MpLandController(IConfiguration configuration) + public MpLandController( + IConfiguration configuration, + IDbContextFactory ctxFactory, + IDbContextFactory ctxFactoryFL, + IDbContextFactory ctxFactorySta) { _configuration = configuration; + _ctxFactory = ctxFactory; + _ctxFactoryFL = ctxFactoryFL; + _ctxFactorySta = ctxFactorySta; +#if false string connStr = _configuration.GetConnectionString("MP.Land"); if (string.IsNullOrEmpty(connStr)) { @@ -26,7 +37,8 @@ namespace MP.Data.Controllers } options = new DbContextOptionsBuilder() .UseSqlServer(connStr) - .Options; + .Options; +#endif Log.Info("Avviato MpLandController"); } @@ -34,6 +46,7 @@ namespace MP.Data.Controllers #region Public Methods +#if false /// /// Restituisce info dimensione, tabelle e num righe DB gestiti /// @@ -70,58 +83,53 @@ namespace MP.Data.Controllers // leggo per DB principale if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.All"))) { - using (var dbCtx = new MoonProContext(options)) + using var dbCtx = _ctxFactory.CreateDbContext(); + var singleRes = dbCtx + .DbSetDbSize + .FromSqlRaw(stp_DbInfo) + .AsEnumerable() + .FirstOrDefault(); + if (singleRes != null) { - var singleRes = dbCtx - .DbSetDbSize - .FromSqlRaw(stp_DbInfo) - .AsEnumerable() - .FirstOrDefault(); - if (singleRes != null) - { - dbResult.Add(singleRes); - } + dbResult.Add(singleRes); } } // leggo per FluxLog if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Flux"))) { - using (var dbCtx = new MoonPro_FluxContext(_configuration)) + using var dbCtx = _ctxFactoryFL.CreateDbContext(); + var singleRes = dbCtx + .DbSetDbSize + .FromSqlRaw(stp_DbInfo) + .AsEnumerable() + .FirstOrDefault(); + if (singleRes != null) { - var singleRes = dbCtx - .DbSetDbSize - .FromSqlRaw(stp_DbInfo) - .AsEnumerable() - .FirstOrDefault(); - if (singleRes != null) - { - dbResult.Add(singleRes); - } + dbResult.Add(singleRes); } } // leggo per Stats if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Stats"))) { - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using var dbCtx = _ctxFactorySta.CreateDbContext(); + var singleRes = dbCtx + .DbSetDbSize + .FromSqlRaw(stp_DbInfo) + .AsEnumerable() + .FirstOrDefault(); + if (singleRes != null) { - var singleRes = dbCtx - .DbSetDbSize - .FromSqlRaw(stp_DbInfo) - .AsEnumerable() - .FirstOrDefault(); - if (singleRes != null) - { - dbResult.Add(singleRes); - } + dbResult.Add(singleRes); } } } catch (Exception exc) { - Log.Error($"Eccezione in AllDbInfo:{Environment.NewLine}{exc}"); + Log.Error($"Eccezione in AllDbInfoAsync:{Environment.NewLine}{exc}"); } return dbResult; - } + } +#endif /// /// Elenco da tabella Config @@ -130,15 +138,12 @@ namespace MP.Data.Controllers public List ConfigGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonProContext(options)) - { - dbResult = dbCtx - .DbSetConfig - .AsNoTracking() - .OrderBy(x => x.Chiave) - .ToList(); - } - return dbResult; + using var dbCtx = _ctxFactory.CreateDbContext(); + return dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToList(); } public void Dispose() @@ -154,16 +159,13 @@ namespace MP.Data.Controllers public List ElencoOperatori() { List dbResult = new List(); - using (var dbCtx = new MoonProContext(options)) - { - dbResult = dbCtx - .DbOperatori - .Where(s => s.MatrOpr > 0) - .AsNoTracking() - .OrderBy(x => x.MatrOpr) - .ToList(); - } - return dbResult; + using var dbCtx = _ctxFactory.CreateDbContext(); + return dbCtx + .DbOperatori + .Where(s => s.MatrOpr > 0) + .AsNoTracking() + .OrderBy(x => x.MatrOpr) + .ToList(); } /// @@ -173,13 +175,10 @@ namespace MP.Data.Controllers public List MacchineGetAll() { List dbResult = new List(); - using (MoonProContext localDbCtx = new MoonProContext(options)) - { - dbResult = localDbCtx - .DbSetMacchine - .ToList(); - } - return dbResult; + using var dbCtx = _ctxFactory.CreateDbContext(); + return dbCtx + .DbSetMacchine + .ToList(); } /// @@ -189,15 +188,12 @@ namespace MP.Data.Controllers public List RemRebootLogGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonProContext(options)) - { - dbResult = dbCtx - .DbSetRemRebLog - .AsNoTracking() - .OrderByDescending(x => x.IdxReboot) - .ToList(); - } - return dbResult; + using var dbCtx = _ctxFactory.CreateDbContext(); + return dbCtx + .DbSetRemRebLog + .AsNoTracking() + .OrderByDescending(x => x.IdxReboot) + .ToList(); } /// @@ -207,15 +203,12 @@ namespace MP.Data.Controllers public List RemRebootLogGetLast() { List dbResult = new List(); - using (var dbCtx = new MoonProContext(options)) - { - dbResult = dbCtx - .DbSetRemRebLog - .FromSqlRaw("EXEC stp_RRL_getLast") - .AsNoTracking() - .ToList(); - } - return dbResult; + using var dbCtx = _ctxFactory.CreateDbContext(); + return dbCtx + .DbSetRemRebLog + .FromSqlRaw("EXEC stp_RRL_getLast") + .AsNoTracking() + .ToList(); } /// @@ -225,15 +218,12 @@ namespace MP.Data.Controllers public List RemRebootLogGetLastNoMacc() { List dbResult = new List(); - using (var dbCtx = new MoonProContext(options)) - { - dbResult = dbCtx - .DbSetRemRebLog - .FromSqlRaw("EXEC stp_RRL_GetLastNoMachine") - .AsNoTracking() - .ToList(); - } - return dbResult; + using var dbCtx = _ctxFactory.CreateDbContext(); + return dbCtx + .DbSetRemRebLog + .FromSqlRaw("EXEC stp_RRL_GetLastNoMachine") + .AsNoTracking() + .ToList(); } /// @@ -244,7 +234,7 @@ namespace MP.Data.Controllers public bool RollBackEntity(object item) { bool answ = false; - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using var dbCtx = _ctxFactory.CreateDbContext(); { try { @@ -283,7 +273,9 @@ namespace MP.Data.Controllers private static Logger Log = LogManager.GetCurrentClassLogger(); private readonly IConfiguration _configuration; - private readonly DbContextOptions options; +#if false + private readonly DbContextOptions options; +#endif private bool _disposed = false; #endregion Private Fields diff --git a/MP.Data/Controllers/MpSpecRepository.cs b/MP.Data/Controllers/MpSpecRepository.cs index 97c67690..27b70da3 100644 --- a/MP.Data/Controllers/MpSpecRepository.cs +++ b/MP.Data/Controllers/MpSpecRepository.cs @@ -1,31 +1,36 @@ using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -using MP.Core.DTO; -using MP.Core.Objects; using MP.Data.DbModels; using NLog; using System; using System.Collections.Generic; using System.Data; -using System.Diagnostics; using System.Linq; using System.Threading.Tasks; -using static EgwCoreLib.Utils.DtUtils; namespace MP.Data.Controllers { public class MpSpecController { + protected readonly IDbContextFactory _ctxFactory; + protected readonly IDbContextFactory _ctxFactoryFL; #region Public Constructors - public MpSpecController(IConfiguration configuration) + public MpSpecController( + IConfiguration configuration, + IDbContextFactory ctxFactory, + IDbContextFactory ctxFactoryFL) { _configuration = configuration; + _ctxFactory = ctxFactory; + _ctxFactoryFL = ctxFactoryFL; +#if false string connStr = _configuration.GetConnectionString("MP.Data"); options = new DbContextOptionsBuilder() .UseSqlServer(connStr) - .Options; + .Options; +#endif Log.Info("Avviata classe MpSpecController"); } @@ -41,7 +46,7 @@ namespace MP.Data.Controllers public async Task AnagCountersGetNextAsync(string cntType) { AnagCountersModel answ = new AnagCountersModel(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); bool outTable = true; if (outTable) { @@ -102,7 +107,7 @@ namespace MP.Data.Controllers /// public async Task> AnagEventiGeneralAsync(string TableName = "EvList", string FieldName = "Common") { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var pTableName = new SqlParameter("@TableName", TableName); var pFieldName = new SqlParameter("@FieldName", FieldName); var dbResult = await dbCtx @@ -129,7 +134,7 @@ namespace MP.Data.Controllers /// public async Task AnagGruppiDeleteAsync(AnagGruppiModel updRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var dbRec = await dbCtx .DbSetAnagGruppi .AsNoTracking() @@ -161,7 +166,7 @@ namespace MP.Data.Controllers /// public async Task> AnagGruppiGetTipoAsync(string tipoGruppo) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetAnagGruppi .Where(x => x.TipoGruppo == tipoGruppo) @@ -176,7 +181,7 @@ namespace MP.Data.Controllers /// public async Task> AnagGruppiRepartoDtoAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); // in primis recupero i reparti... var listReparti = await AnagGruppiGetTipoAsync("REPARTO"); @@ -211,7 +216,7 @@ namespace MP.Data.Controllers /// public async Task AnagGruppiUpsertAsync(AnagGruppiModel updRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var dbRec = await dbCtx .DbSetAnagGruppi .AsNoTracking() @@ -279,7 +284,7 @@ namespace MP.Data.Controllers /// public async Task ArticoliCountAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var result = await dbCtx .DbSetArticoli .CountAsync(); @@ -295,7 +300,7 @@ namespace MP.Data.Controllers /// public async Task ArticoliCountSearchAsync(string tipoArt = "*", string azienda = "*", string searchVal = "") { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); IQueryable query = dbCtx.DbSetArticoli.AsNoTracking(); // filtro tipo articolo @@ -331,7 +336,7 @@ namespace MP.Data.Controllers /// public async Task ArticoliCountUsedAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var result = await dbCtx .DbSetCounter .FromSqlRaw("EXEC stp_ART_CountUsed") @@ -348,7 +353,7 @@ namespace MP.Data.Controllers /// public async Task ArticoliDeleteRecordAsync(AnagArticoliModel currRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var currVal = dbCtx .DbSetArticoli .Where(x => x.CodArticolo == currRec.CodArticolo) @@ -368,7 +373,7 @@ namespace MP.Data.Controllers /// public async Task> ArticoliGetByTipoAsync(string tipo, string azienda = "*") { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetArticoli .AsNoTracking() @@ -387,7 +392,7 @@ namespace MP.Data.Controllers /// public async Task> ArticoliGetSearchAsync(int numRecord, string tipoArt = "*", string azienda = "*", string searchVal = "") { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); IQueryable query = dbCtx.DbSetArticoli .AsNoTracking(); @@ -425,7 +430,7 @@ namespace MP.Data.Controllers /// public async Task> ArticoliGetUnusedAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetArticoli .FromSqlRaw("EXEC stp_ART_getNotUsed") @@ -439,7 +444,7 @@ namespace MP.Data.Controllers /// public async Task> ArticoliGetUsedAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetArticoli .FromSqlRaw("EXEC stp_ART_getUsed") @@ -454,7 +459,7 @@ namespace MP.Data.Controllers public async Task> ArticoliInKitAsync() { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); dbResult = await dbCtx .DbSetArticoli .FromSqlRaw("EXEC stp_TempKIT_getArtChild") @@ -470,7 +475,7 @@ namespace MP.Data.Controllers /// public async Task ArticoliUpdateRecord(AnagArticoliModel editRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var currRec = dbCtx .DbSetArticoli .Where(x => x.CodArticolo == editRec.CodArticolo) @@ -500,7 +505,7 @@ namespace MP.Data.Controllers /// public async Task> ConfigGetAllAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetConfig .AsNoTracking() @@ -516,7 +521,7 @@ namespace MP.Data.Controllers { bool fatto = false; ConfigModel dbResult = new ConfigModel(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); dbResult = await dbCtx .DbSetConfig .Where(x => x.Chiave == updRec.Chiave) @@ -647,7 +652,7 @@ namespace MP.Data.Controllers /// public async Task EvListInsertAsync(EventListModel newRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var currRec = await dbCtx .DbSetEvList .AddAsync(newRec); @@ -874,7 +879,7 @@ namespace MP.Data.Controllers public async Task Grp2MaccDeleteAsync(Gruppi2MaccModel rec2del) { bool answ = false; - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var dbRec = await dbCtx .DbSetGrp2Macc .Where(x => x.CodGruppo == rec2del.CodGruppo && x.IdxMacchina == rec2del.IdxMacchina) @@ -896,7 +901,7 @@ namespace MP.Data.Controllers public async Task Grp2MaccInsertAsync(Gruppi2MaccModel upsRec) { bool answ = false; - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var dbRec = await dbCtx .DbSetGrp2Macc .Where(x => x.CodGruppo == upsRec.CodGruppo && x.IdxMacchina == upsRec.IdxMacchina) @@ -919,7 +924,7 @@ namespace MP.Data.Controllers public async Task Grp2OperDeleteAsync(Gruppi2OperModel rec2del) { bool answ = false; - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var dbRec = await dbCtx .DbSetGrp2Oper .Where(x => x.CodGruppo == rec2del.CodGruppo && x.MatrOpr == rec2del.MatrOpr) @@ -941,7 +946,7 @@ namespace MP.Data.Controllers public async Task Grp2OperInsertAsync(Gruppi2OperModel upsRec) { bool answ = false; - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var dbRec = await dbCtx .DbSetGrp2Oper .Where(x => x.CodGruppo == upsRec.CodGruppo && x.MatrOpr == upsRec.MatrOpr) @@ -962,7 +967,7 @@ namespace MP.Data.Controllers /// public async Task IstKitDeleteAsync(IstanzeKitModel rec2del) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var actRec = await dbCtx .DbSetInstKit .Where(x => x.KeyKit == rec2del.KeyKit && x.KeyExtOrd == rec2del.KeyExtOrd) @@ -985,7 +990,7 @@ namespace MP.Data.Controllers /// public async Task> IstKitFiltAsync(string keyKit, string keyExtOrd) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetInstKit .Where(x => (string.IsNullOrEmpty(keyKit) && string.IsNullOrEmpty(keyExtOrd)) || (x.KeyKit.Contains(keyKit) && !string.IsNullOrEmpty(keyKit)) || (x.KeyExtOrd.Contains(keyExtOrd) && !string.IsNullOrEmpty(keyExtOrd))) @@ -1000,7 +1005,7 @@ namespace MP.Data.Controllers /// Chiave x filtro conf su tab WKS public async Task IstKitInsertByWKSAsync(string CodArtParent, string KeyFilt) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var pCodArtParent = new SqlParameter("@CodArtParent", CodArtParent); var pKeyFilt = new SqlParameter("@KeyFilt", KeyFilt); @@ -1017,7 +1022,7 @@ namespace MP.Data.Controllers /// public async Task IstKitUpsertAsync(IstanzeKitModel editRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var actRec = await dbCtx .DbSetInstKit .Where(x => x.KeyKit == editRec.KeyKit && x.KeyExtOrd == editRec.KeyExtOrd) @@ -1065,7 +1070,7 @@ namespace MP.Data.Controllers /// public async Task> ListLinkAllAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetLinkMenu .AsNoTracking() @@ -1081,7 +1086,7 @@ namespace MP.Data.Controllers public async Task> ListLinkFiltAsync(string tipoLink) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetLinkMenu .Where(x => x.TipoLink == tipoLink) @@ -1106,7 +1111,7 @@ namespace MP.Data.Controllers public async Task> ListODLFiltAsync(bool inCorso, string codArt, string keyRichPart, string Reparto, string IdxMacchina, DateTime startDate, DateTime endDate) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var InCorso = new SqlParameter("@InCorso", inCorso); var CodArt = new SqlParameter("@CodArt", codArt); @@ -1131,7 +1136,7 @@ namespace MP.Data.Controllers /// public async Task> ListPODL_ByCodArtAsync(string CodArticolo, bool OnlyAvail) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var pCodArticolo = new SqlParameter("@CodArticolo", CodArticolo); var pOnlyAvail = new SqlParameter("@onlyAvail", OnlyAvail); @@ -1149,7 +1154,7 @@ namespace MP.Data.Controllers /// public async Task> ListPODL_ByKitParentAsync(int IdxPodlParent) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var pIdxPodlParent = new SqlParameter("@IdxPodlParent", IdxPodlParent); return await dbCtx @@ -1169,7 +1174,7 @@ namespace MP.Data.Controllers /// public async Task> ListPODL_KitFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var Lanc = new SqlParameter("@Lanciato", lanciato); var KeyRich = new SqlParameter("@KeyRich", keyRichPart); var CodGrp = new SqlParameter("@CodGruppo", codGruppo); @@ -1194,7 +1199,7 @@ namespace MP.Data.Controllers /// public async Task> ListPODLFiltAsync(bool lanciato, string keyRichPart, string idxMacchina, string codGruppo, DateTime startDate, DateTime endDate) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var Lanc = new SqlParameter("@Lanciato", lanciato); var KeyRich = new SqlParameter("@KeyRich", keyRichPart); var CodGrp = new SqlParameter("@CodGruppo", codGruppo); @@ -1217,7 +1222,7 @@ namespace MP.Data.Controllers /// public async Task> ListValuesFiltAsync(string tabName, string fieldName) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetListValues .Where(x => x.TableName == tabName && x.FieldName == fieldName) @@ -1233,7 +1238,7 @@ namespace MP.Data.Controllers /// public async Task> MacchineByMatrOperAsync(int MatrOpr) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); if (MatrOpr == 0) { return await dbCtx @@ -1272,7 +1277,7 @@ namespace MP.Data.Controllers /// public async Task> MacchineGetFiltAsync(string codGruppo) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); if (codGruppo == "*") { return await dbCtx @@ -1305,7 +1310,7 @@ namespace MP.Data.Controllers /// public async Task> MacchineWithFluxAsync(DateTime dtStart, DateTime dtEnd) { - using var dbCtx = new MoonPro_FluxContext(_configuration); + using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); return await dbCtx .DbSetFluxLog .AsNoTracking() @@ -1322,7 +1327,7 @@ namespace MP.Data.Controllers public async Task> MseGetAllAsync(int maxAge = 2000) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge); @@ -1357,7 +1362,7 @@ namespace MP.Data.Controllers /// public async Task OdlByKeyAsync(int IdxOdl) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetODLExp .AsNoTracking() @@ -1379,7 +1384,7 @@ namespace MP.Data.Controllers bool fatto = false; if (idxOdl > 0) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); DateTime adesso = DateTime.Now; // preparo i parametri var IdxODL = new SqlParameter("@IdxODL", idxOdl); @@ -1441,7 +1446,7 @@ namespace MP.Data.Controllers /// public async Task> OdlGetCurrentAsync() { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetODL .Where(x => x.DataInizio != null && x.DataFine == null) @@ -1457,7 +1462,7 @@ namespace MP.Data.Controllers List dbResult = new List(); if (IdxOdl > 0) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var IdxODL = new SqlParameter("@IdxODL", IdxOdl); dbResult = await dbCtx @@ -1477,7 +1482,7 @@ namespace MP.Data.Controllers public async Task> OperatoriGetFiltAsync(string codGruppo) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); if (codGruppo == "*") { dbResult = await dbCtx @@ -1510,7 +1515,7 @@ namespace MP.Data.Controllers /// public async Task> ParametriGetFiltAsync(string IdxMacchina) { - using var dbCtx = new MoonPro_FluxContext(_configuration); + using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); return await dbCtx .DbSetFluxLog .AsNoTracking() @@ -1529,7 +1534,7 @@ namespace MP.Data.Controllers /// public async Task PODL_getByKeyAsync(int idxPODL) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetPODL .AsNoTracking() @@ -1545,7 +1550,7 @@ namespace MP.Data.Controllers /// public async Task PODL_getByOdlAsync(int idxODL) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetPODL .AsNoTracking() @@ -1563,7 +1568,7 @@ namespace MP.Data.Controllers if (missingIds == null || !missingIds.Any()) return new Dictionary(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetPODL .AsNoTracking() @@ -1602,7 +1607,7 @@ namespace MP.Data.Controllers InsertDate = editRec.InsertDate }; - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var currRec = await dbCtx .DbSetPODL .AsNoTracking() @@ -1637,7 +1642,7 @@ namespace MP.Data.Controllers public async Task PODL_updateRecipe(int idxPODL, string recipeName) { bool answ = false; - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var currRec = await dbCtx .DbSetPODL .Where(x => x.IdxPromessa == idxPODL) @@ -1677,7 +1682,7 @@ namespace MP.Data.Controllers CodCli = currRec.CodCli, InsertDate = currRec.InsertDate }; - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var currVal = await dbCtx .DbSetPODL .Where(x => x.IdxPromessa == recPODL.IdxPromessa) @@ -1694,7 +1699,7 @@ namespace MP.Data.Controllers /// IdxPODL parent public async Task PodlIstKitDeleteAsync(int IdxPODL) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var pIdxPODL = new SqlParameter("@IdxPODL", IdxPODL); var dbResult = await dbCtx @@ -1710,7 +1715,7 @@ namespace MP.Data.Controllers /// public async Task PODLUpdateRecordAsync(PODLModel editRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var currRec = await dbCtx .DbSetPODL .Where(x => x.IdxPromessa == editRec.IdxPromessa) @@ -1744,7 +1749,7 @@ namespace MP.Data.Controllers /// public async Task StatoMacchinaAsync(string idxMacchina) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); return await dbCtx .DbSetStatoMacc .Where(x => x.IdxMacchina == idxMacchina) @@ -1758,7 +1763,7 @@ namespace MP.Data.Controllers /// public async Task TemplateKitDeleteAsync(TemplateKitModel rec2del) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var actRec = await dbCtx .DbSetTempKit .Where(x => x.CodArtParent == rec2del.CodArtParent && x.CodArtChild == rec2del.CodArtChild) @@ -1782,7 +1787,7 @@ namespace MP.Data.Controllers public async Task> TemplateKitFiltAsync(string KitCode, string codChild) { List dbResult = new List(); - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); dbResult = await dbCtx .DbSetTempKit .Where(x => (string.IsNullOrEmpty(KitCode) && string.IsNullOrEmpty(codChild)) || (x.CodArtParent.Contains(KitCode) && !string.IsNullOrEmpty(KitCode)) || (x.CodArtChild.Contains(codChild) && !string.IsNullOrEmpty(codChild))) @@ -1798,7 +1803,7 @@ namespace MP.Data.Controllers /// public async Task TemplateKitUpsertAsync(TemplateKitModel editRec, string codAzienda) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); // verifico preliminarmente articolo... var recArt = dbCtx .DbSetArticoli @@ -1854,7 +1859,7 @@ namespace MP.Data.Controllers List dbResult = new List(); if (!string.IsNullOrEmpty(KeyFilt)) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var pKeyFilt = new SqlParameter("@KeyFilt", KeyFilt); var pMaxRes = new SqlParameter("@maxResult", MaxResult); dbResult = await dbCtx @@ -1866,13 +1871,14 @@ namespace MP.Data.Controllers return dbResult; } +#if false /// /// Elenco Vocabolario di una lingua /// /// public Dictionary VocabolarioGetLang(string lingua) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = _ctxFactory.CreateDbContext(); var rawList = dbCtx .DbSetVocabolario .AsNoTracking() @@ -1892,7 +1898,7 @@ namespace MP.Data.Controllers /// public async Task VocabolarioUpsertAsync(VocabolarioModel upsRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var actRec = await dbCtx .DbSetVocabolario .Where(x => x.Lingua == upsRec.Lingua && x.Lemma == upsRec.Lemma) @@ -1919,7 +1925,7 @@ namespace MP.Data.Controllers /// public async Task WipKitDeleteAsync(WipSetupKitModel rec2del) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var actRec = await dbCtx .DbSetWipKit .Where(x => x.KeyFilt == rec2del.KeyFilt && x.CodOrd == rec2del.CodOrd) @@ -1932,7 +1938,8 @@ namespace MP.Data.Controllers .Remove(actRec); } return await dbCtx.SaveChangesAsync() > 0; - } + } +#endif /// /// Elimina record + vecchi della data-ora indicata @@ -1941,7 +1948,7 @@ namespace MP.Data.Controllers /// public async Task WipKitDeleteOlderAsync(DateTime dateLimit) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var actRec = await dbCtx .DbSetWipKit .Where(x => x.DataIns < dateLimit) @@ -1967,7 +1974,7 @@ namespace MP.Data.Controllers // solo se filtro valido... if (!string.IsNullOrEmpty(KeyFilt)) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); dbResult = await dbCtx .DbSetWipKit .Where(x => x.KeyFilt.Contains(KeyFilt)) @@ -1983,7 +1990,7 @@ namespace MP.Data.Controllers /// public async Task WipKitUpsertAsync(WipSetupKitModel editRec) { - using var dbCtx = new MoonProContext(options); + using var dbCtx = await _ctxFactory.CreateDbContextAsync(); var actRec = await dbCtx .DbSetWipKit .Where(x => x.KeyFilt == editRec.KeyFilt && x.CodOrd == editRec.CodOrd) @@ -2013,7 +2020,9 @@ namespace MP.Data.Controllers private static IConfiguration _configuration; private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private DbContextOptions options; +#if false + private DbContextOptions options; +#endif #endregion Private Fields } diff --git a/MP.Data/Controllers/MpStatsController.cs b/MP.Data/Controllers/MpStatsController.cs index 046d5549..46b4e137 100644 --- a/MP.Data/Controllers/MpStatsController.cs +++ b/MP.Data/Controllers/MpStatsController.cs @@ -19,11 +19,15 @@ namespace MP.Data.Controllers public MpStatsController(IConfiguration configuration) { _configuration = configuration; + string connStr = _configuration.GetConnectionString("MP.Stats"); + options = new DbContextOptionsBuilder() + .UseSqlServer(connStr) + .Options; Log.Info("Avviata classe MpStatsController"); } #endregion Public Constructors - + private DbContextOptions options; #region Public Methods /// @@ -33,13 +37,10 @@ namespace MP.Data.Controllers public List ActionsGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) - { - dbResult = dbCtx + using var dbCtx = new MoonPro_STATSContext(options); + return dbCtx .DbSetAzioniUL .ToList(); - } - return dbResult; } /// @@ -49,13 +50,10 @@ namespace MP.Data.Controllers public List AnagFLTransGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) - { - dbResult = dbCtx - .DbSetAnagFLTrans - .ToList(); - } - return dbResult; + using var dbCtx = new MoonPro_STATSContext(options); + return dbCtx + .DbSetAnagFLTrans + .ToList(); } /// @@ -67,7 +65,7 @@ namespace MP.Data.Controllers public List ArticoliGetSearch(int numRecord, string searchVal = "") { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { dbResult = dbCtx .DbSetArticoli @@ -88,7 +86,7 @@ namespace MP.Data.Controllers public List CommesseGetSearch(int numRecord, string searchVal = "") { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { dbResult = dbCtx .DbSetODL @@ -107,7 +105,7 @@ namespace MP.Data.Controllers public List ConfigGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { dbResult = dbCtx .DbSetConfig @@ -133,7 +131,7 @@ namespace MP.Data.Controllers public List FluxLogRawData(string IdxMacchina, DateTime DtStart, DateTime DtEnd, string fluxType) { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { dbResult = dbCtx .DbSetFL @@ -153,7 +151,7 @@ namespace MP.Data.Controllers public List FluxTypeList() { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { dbResult = dbCtx .DbSetFL @@ -172,7 +170,7 @@ namespace MP.Data.Controllers public List MacchineEnergy() { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { dbResult = dbCtx .DbSetMaccStat @@ -188,7 +186,7 @@ namespace MP.Data.Controllers public List MacchineGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { dbResult = dbCtx .DbSetMacchine @@ -204,7 +202,7 @@ namespace MP.Data.Controllers public async Task> MacchineEnergyCheckGetAllAsync() { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { dbResult = await dbCtx .DbSetMacchineCheck @@ -222,7 +220,7 @@ namespace MP.Data.Controllers public bool RollBackEntity(object item) { bool answ = false; - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { try { @@ -248,7 +246,7 @@ namespace MP.Data.Controllers public List StatControlliGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo) { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { var dataFrom = new SqlParameter("@dataFrom", DataStart); var dataTo = new SqlParameter("@dataTo", DataEnd); @@ -280,7 +278,7 @@ namespace MP.Data.Controllers public List StatDdbGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, int FirstRecord, int NumRecord) { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { var dataFrom = new SqlParameter("@dataFrom", DataStart); var dataTo = new SqlParameter("@dataTo", DataEnd); @@ -312,7 +310,7 @@ namespace MP.Data.Controllers public int StatDdbGetCount(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo) { int numResult = 0; - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { numResult = dbCtx .DbSetDdbTurni @@ -335,7 +333,7 @@ namespace MP.Data.Controllers public List StatOdlEnergyGetFilt(string IdxMacchina, DateTime DtStart, DateTime DtEnd, int IdxODL, string KeyRichiesta, string CodArticolo) { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { var dataFrom = new SqlParameter("@dataFrom", DtStart); var dataTo = new SqlParameter("@dataTo", DtEnd); @@ -361,7 +359,7 @@ namespace MP.Data.Controllers public List StatOdlGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo) { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { var dataFrom = new SqlParameter("@dataFrom", DataStart); var dataTo = new SqlParameter("@dataTo", DataEnd); @@ -389,7 +387,7 @@ namespace MP.Data.Controllers public List StatScartiGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo) { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { var dataFrom = new SqlParameter("@dataFrom", DataStart); var dataTo = new SqlParameter("@dataTo", DataEnd); @@ -417,7 +415,7 @@ namespace MP.Data.Controllers public List StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo) { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { var dataFrom = new SqlParameter("@dataFrom", DataStart); var dataTo = new SqlParameter("@dataTo", DataEnd); @@ -443,7 +441,7 @@ namespace MP.Data.Controllers public List StatUserLogGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo) { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { var dataFrom = new SqlParameter("@dataFrom", DataStart); var dataTo = new SqlParameter("@dataTo", DataEnd); @@ -467,7 +465,7 @@ namespace MP.Data.Controllers public List VocabolarioGetAll() { List dbResult = new List(); - using (var dbCtx = new MoonPro_STATSContext(_configuration)) + using (var dbCtx = new MoonPro_STATSContext(options)) { dbResult = dbCtx .DbSetVocabolario diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index 6b0b34ed..2adc1d06 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -23,6 +23,8 @@ namespace MP.Data { public static class DataServiceCollectionExtensions { + #region Public Methods + /// /// Aggiunta repository/servizi specifici per IOC /// @@ -49,6 +51,7 @@ namespace MP.Data return services; } + /// /// Aggiunta repository/servizi specifici per LAND /// @@ -56,7 +59,12 @@ namespace MP.Data /// public static IServiceCollection AddLandDataLayer(this IServiceCollection services) { + // Controllers MP.AppAuth (dipendenze di AppAuthService) + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + // Servizi LAND services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); @@ -64,6 +72,7 @@ namespace MP.Data return services; } + /// /// Aggiunta repository/servizi specifici per MON /// @@ -71,11 +80,11 @@ namespace MP.Data /// public static IServiceCollection AddMonDataLayer(this IServiceCollection services) { - services.TryAddSingleton(); services.TryAddSingleton(); return services; } + /// /// Aggiunta repository/servizi specifici per SPEC /// @@ -95,13 +104,12 @@ namespace MP.Data services.TryAddScoped(); // ---------- End Repository ---------- - // ---------- Start Servizi ---------- //services.TryAddSingleton(); // ---------- End Servizi ---------- - // ---------- Start Altro ---------- + services.TryAddSingleton(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); @@ -117,5 +125,30 @@ namespace MP.Data return services; } + + /// + /// Aggiunta repository/servizi specifici per STATS + /// + /// + /// + public static IServiceCollection AddStatsDataLayer(this IServiceCollection services) + { + services.AddSingleton(); + + services.AddSingleton(); + return services; + } + + /// + /// Aggiunta repository/servizi specifici per TAB + /// + /// + /// + public static IServiceCollection AddTabDataLayer(this IServiceCollection services) + { + return services; + } + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/MP.Data/DbModels/TksScoreModel.cs b/MP.Data/DbModels/TksScoreModel.cs index 12fdfe78..e541bf58 100644 --- a/MP.Data/DbModels/TksScoreModel.cs +++ b/MP.Data/DbModels/TksScoreModel.cs @@ -30,6 +30,7 @@ namespace MP.Data.DbModels /// /// Score complessivo /// + [Precision(18, 6)] public decimal TotalScore { get; set; } = 0; } diff --git a/MP.Data/MoonPro_FluxContext.cs b/MP.Data/MoonPro_FluxContext.cs index 117777b7..db5ae409 100644 --- a/MP.Data/MoonPro_FluxContext.cs +++ b/MP.Data/MoonPro_FluxContext.cs @@ -17,7 +17,9 @@ namespace MP.Data private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private IConfiguration _configuration; +#if false + private IConfiguration _configuration; +#endif #endregion Private Fields @@ -27,15 +29,17 @@ namespace MP.Data /// Indispensabile x prima generazione migrations EFCore /// - [Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")] + [Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. use DbContextoptions instead.")] public MoonPro_FluxContext() { } - +#if false + [Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. use DbContextoptions instead.")] public MoonPro_FluxContext(IConfiguration configuration) { _configuration = configuration; - } + } +#endif public MoonPro_FluxContext(DbContextOptions options) : base(options) { @@ -69,6 +73,7 @@ namespace MP.Data { if (!optionsBuilder.IsConfigured) { +#if false string connString = _configuration.GetConnectionString("MP.Flux"); if (!string.IsNullOrEmpty(connString)) { @@ -77,7 +82,9 @@ namespace MP.Data else { optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_FluxData;Trusted_Connection=True;"); - } + } +#endif + optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_FluxData;Trusted_Connection=True;"); } } diff --git a/MP.Data/MoonPro_STATSContext.cs b/MP.Data/MoonPro_STATSContext.cs index 11ba7efd..18b8ae1e 100644 --- a/MP.Data/MoonPro_STATSContext.cs +++ b/MP.Data/MoonPro_STATSContext.cs @@ -16,16 +16,20 @@ namespace MP.Data private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private IConfiguration _configuration; +#if false + private IConfiguration _configuration; +#endif #endregion Private Fields #region Public Constructors +#if false public MoonPro_STATSContext(IConfiguration configuration) { _configuration = configuration; - } + } +#endif public MoonPro_STATSContext(DbContextOptions options) : base(options) { @@ -68,10 +72,7 @@ namespace MP.Data { if (!optionsBuilder.IsConfigured) { - string connString = _configuration.GetConnectionString("MP.Stats"); - - optionsBuilder.UseSqlServer(connString); - //optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;"); + optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;"); } } diff --git a/MP.Data/Repository/Anag/AnagRepository.cs b/MP.Data/Repository/Anag/AnagRepository.cs index a4a00cf8..03721446 100644 --- a/MP.Data/Repository/Anag/AnagRepository.cs +++ b/MP.Data/Repository/Anag/AnagRepository.cs @@ -162,6 +162,40 @@ namespace MP.Data.Repository.Anag .ToList(); } + /// + public async Task> GruppiRepartoDtoByOperAsync(int matrOpr) + { + await using var dbCtx = await CreateContextAsync(); + var listReparti = await AnagGruppiGetTipoAsync("REPARTO"); + + var listMacc = await dbCtx + .DbSetGrp2Macc + .AsNoTracking() + .ToListAsync(); + var listOpr = await dbCtx + .DbSetGrp2Oper + .AsNoTracking() + .ToListAsync(); + + var gruppiOpr = await dbCtx.DbSetGrp2Oper + .Where(x => x.MatrOpr == matrOpr) + .Select(x => x.CodGruppo) + .Distinct() + .ToListAsync(); + return listReparti + .Where(r => gruppiOpr.Contains(r.CodGruppo)) + .Select(x => new RepartiDTO() + { + CodGruppo = x.CodGruppo, + TipoGruppo = x.TipoGruppo, + DescrGruppo = x.DescrGruppo, + SelEnabled = x.SelEnabled, + CountMacc = listMacc.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.IdxMacchina).Distinct().Count(), + CountOpr = listOpr.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.MatrOpr).Distinct().Count() + }) + .ToList(); + } + /// public async Task AnagGruppiUpsertAsync(AnagGruppiModel updRec) { diff --git a/MP.Data/Repository/Anag/IAnagRepository.cs b/MP.Data/Repository/Anag/IAnagRepository.cs index 7b943098..728a4657 100644 --- a/MP.Data/Repository/Anag/IAnagRepository.cs +++ b/MP.Data/Repository/Anag/IAnagRepository.cs @@ -75,14 +75,6 @@ namespace MP.Data.Repository.Anag /// Lista di valori ammessi Task> AnagTipoArtLvAsync(); -#if false - /// - /// Elenco codice articoli che abbiano dati Dossier - /// - /// Lista di codici articolo - Task> ArticleWithDossierAsync(); -#endif - /// /// Conteggio num articoli Async /// @@ -154,6 +146,20 @@ namespace MP.Data.Repository.Anag /// True se aggiornato Task ArticoliUpdateRecord(AnagArticoliModel editRec); + /// + /// Elenco Gruppi tipo REPARTOin formato DTO con conteggi del numero record trovati filtrati per operatore + /// + /// Lista di DTO reparti con conteggio macchine e operatori + Task> GruppiRepartoDtoByOperAsync(int matrOpr); + +#if false + /// + /// Elenco codice articoli che abbiano dati Dossier + /// + /// Lista di codici articolo + Task> ArticleWithDossierAsync(); +#endif + /// /// Elenco valori ammessi x tabella/colonna Async /// diff --git a/MP.Data/Repository/Dossier/DossierRepository.cs b/MP.Data/Repository/Dossier/DossierRepository.cs index 4fcf2319..f882df25 100644 --- a/MP.Data/Repository/Dossier/DossierRepository.cs +++ b/MP.Data/Repository/Dossier/DossierRepository.cs @@ -11,27 +11,36 @@ namespace MP.Data.Repository.Dossier { public class DossierRepository : IDossierRepository { - #region Private Fields - - private readonly IConfiguration _configuration; - - #endregion - #region Public Constructors - public DossierRepository(IConfiguration configuration) + public DossierRepository( + IConfiguration configuration, + IDbContextFactory ctxFactoryFL) { _configuration = configuration; + _ctxFactoryFL = ctxFactoryFL; } - #endregion + #endregion Public Constructors #region Public Methods + /// + public async Task> ArticleWithDossierAsync() + { + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); + return await dbCtx + .DbSetDossiers + .AsNoTracking() + .Select(i => i.CodArticolo) + .Distinct() + .ToListAsync(); + } + /// public async Task DossiersDeleteRecordAsync(DossierModel currRec) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); var currVal = await dbCtx .DbSetDossiers .Where(x => x.IdxDossier == currRec.IdxDossier) @@ -46,7 +55,7 @@ namespace MP.Data.Repository.Dossier /// public async Task> DossiersGetLastFiltAsync(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd, int MaxRec) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); return await dbCtx .DbSetDossiers .AsNoTracking() @@ -61,7 +70,7 @@ namespace MP.Data.Repository.Dossier /// public async Task DossiersInsertAsync(DossierModel newRec) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); await dbCtx .DbSetDossiers .AddAsync(newRec); @@ -71,7 +80,7 @@ namespace MP.Data.Repository.Dossier /// public async Task DossiersTakeParamsSnapshotLastAsync(string idxMacchina, DateTime dtMin, DateTime dtMax) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina); var pDtMin = new SqlParameter("@DtMin", dtMin); var pDtMax = new SqlParameter("@DtMax", dtMax); @@ -85,7 +94,7 @@ namespace MP.Data.Repository.Dossier /// public async Task DossiersUpdateValoreAsync(DossierModel editRec) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); var currRec = await dbCtx .DbSetDossiers .Where(x => x.IdxDossier == editRec.IdxDossier) @@ -104,18 +113,18 @@ namespace MP.Data.Repository.Dossier return await dbCtx.SaveChangesAsync() > 0; } - /// - public async Task> ArticleWithDossierAsync() - { - await using var dbCtx = new MoonPro_FluxContext(_configuration); - return await dbCtx - .DbSetDossiers - .AsNoTracking() - .Select(i => i.CodArticolo) - .Distinct() - .ToListAsync(); - } + #endregion Public Methods - #endregion + #region Protected Fields + + protected readonly IDbContextFactory _ctxFactoryFL; + + #endregion Protected Fields + + #region Private Fields + + private readonly IConfiguration _configuration; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/MP.Data/Repository/FluxLog/FluxLogRepository.cs b/MP.Data/Repository/FluxLog/FluxLogRepository.cs index 2bf4ca5a..e0b2bdf4 100644 --- a/MP.Data/Repository/FluxLog/FluxLogRepository.cs +++ b/MP.Data/Repository/FluxLog/FluxLogRepository.cs @@ -15,21 +15,15 @@ namespace MP.Data.Repository.FluxLog { public class FluxLogRepository : IFluxLogRepository { - #region Private Fields - - private readonly IConfiguration _configuration; - private static NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger(); - - #endregion - #region Public Constructors - public FluxLogRepository(IConfiguration configuration) + public FluxLogRepository(IConfiguration configuration, IDbContextFactory ctxFactoryFL) { _configuration = configuration; + _ctxFactoryFL = ctxFactoryFL; } - #endregion + #endregion Public Constructors #region Public Methods @@ -60,7 +54,7 @@ namespace MP.Data.Repository.FluxLog var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMaccSel); var pOnlyTest = new SqlParameter("@OnlyTest", false); - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); foreach (var item in fluxList) { Log.Info($"FluxLogDataReduxAsync | Flux: {item}"); @@ -149,7 +143,7 @@ namespace MP.Data.Repository.FluxLog /// public async Task> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); return await dbCtx .DbSetFluxLog .AsNoTracking() @@ -162,7 +156,7 @@ namespace MP.Data.Repository.FluxLog /// public async Task> FluxLogParetoAsync(string idxMacchina, DateTime dtFrom, DateTime dtTo) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); return await dbCtx .DbSetFluxLog .Where(x => (string.IsNullOrEmpty(idxMacchina) || x.IdxMacchina == idxMacchina) && (dtFrom <= x.dtEvento && x.dtEvento <= dtTo)) @@ -173,6 +167,19 @@ namespace MP.Data.Repository.FluxLog .ToListAsync() ?? new(); } - #endregion + #endregion Public Methods + + #region Protected Fields + + protected readonly IDbContextFactory _ctxFactoryFL; + + #endregion Protected Fields + + #region Private Fields + + private static NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger(); + private readonly IConfiguration _configuration; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/MP.Data/Repository/MpLand/MpLandRepository.cs b/MP.Data/Repository/MpLand/MpLandRepository.cs index c40c9299..83b60fff 100644 --- a/MP.Data/Repository/MpLand/MpLandRepository.cs +++ b/MP.Data/Repository/MpLand/MpLandRepository.cs @@ -13,6 +13,8 @@ namespace MP.Data.Repository.MpLand private readonly IConfiguration _configuration; private readonly IDbContextFactory _ctxFactory; + private readonly IDbContextFactory _ctxFactoryFluxLog; + private readonly IDbContextFactory _ctxFactoryStats; #endregion @@ -61,11 +63,12 @@ namespace MP.Data.Repository.MpLand if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.All"))) { await using var dbCtx = await _ctxFactory.CreateDbContextAsync(); - var singleRes = await dbCtx + var singleRes = dbCtx .DbSetDbSize .FromSqlRaw(stp_DbInfo) .AsNoTracking() - .FirstOrDefaultAsync(); + .AsEnumerable() + .FirstOrDefault(); if (singleRes != null) { dbResult.Add(singleRes); @@ -73,12 +76,13 @@ namespace MP.Data.Repository.MpLand } if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Flux"))) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); - var singleRes = await dbCtx + await using var dbCtx = await _ctxFactoryFluxLog.CreateDbContextAsync(); + var singleRes = dbCtx .DbSetDbSize .FromSqlRaw(stp_DbInfo) .AsNoTracking() - .FirstOrDefaultAsync(); + .AsEnumerable() + .FirstOrDefault(); if (singleRes != null) { dbResult.Add(singleRes); @@ -86,12 +90,13 @@ namespace MP.Data.Repository.MpLand } if (!string.IsNullOrEmpty(_configuration.GetConnectionString("MP.Stats"))) { - await using var dbCtx = new MoonPro_STATSContext(_configuration); - var singleRes = await dbCtx + await using var dbCtx = await _ctxFactoryStats.CreateDbContextAsync(); + var singleRes = dbCtx .DbSetDbSize .FromSqlRaw(stp_DbInfo) .AsNoTracking() - .FirstOrDefaultAsync(); + .AsEnumerable() + .FirstOrDefault(); if (singleRes != null) { dbResult.Add(singleRes); diff --git a/MP.Data/Repository/MpVoc/IMpVocRepository.cs b/MP.Data/Repository/MpVoc/IMpVocRepository.cs index 845d07ef..733574c1 100644 --- a/MP.Data/Repository/MpVoc/IMpVocRepository.cs +++ b/MP.Data/Repository/MpVoc/IMpVocRepository.cs @@ -6,10 +6,35 @@ namespace MP.Data.Repository.MpVoc { public interface IMpVocRepository { - Task> ConfigGetAllAsync(); + #region Public Methods +#if false + /// + /// Recupero elenco config + /// + /// + Task> ConfigGetAllAsync(); +#endif + + /// + /// recupero elenco lingue + /// + /// Task> LingueGetAllAsync(); + /// + /// Recupero tutte le voci dizionario, async + /// + /// Task> VocabolarioGetAllAsync(); + + /// + /// Recupero dizionario traduzioni x singola lingua + /// + /// Codice lingua + /// Dizionario di traduzioni + Dictionary VocabolarioGetLang(string lingua); + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/MP.Data/Repository/MpVoc/MpVocRepository.cs b/MP.Data/Repository/MpVoc/MpVocRepository.cs index 9afe2146..ae887011 100644 --- a/MP.Data/Repository/MpVoc/MpVocRepository.cs +++ b/MP.Data/Repository/MpVoc/MpVocRepository.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using MP.Data.DbModels; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -8,12 +9,6 @@ namespace MP.Data.Repository.MpVoc { public class MpVocRepository : IMpVocRepository { - #region Private Fields - - private readonly IDbContextFactory _ctxFactory; - - #endregion - #region Public Constructors public MpVocRepository(IDbContextFactory ctxFactory) @@ -21,10 +16,11 @@ namespace MP.Data.Repository.MpVoc _ctxFactory = ctxFactory; } - #endregion + #endregion Public Constructors #region Public Methods +#if false /// public async Task> ConfigGetAllAsync() { @@ -34,7 +30,8 @@ namespace MP.Data.Repository.MpVoc .AsNoTracking() .OrderBy(x => x.Chiave) .ToListAsync() ?? new(); - } + } +#endif /// public async Task> LingueGetAllAsync() @@ -58,6 +55,28 @@ namespace MP.Data.Repository.MpVoc .ToListAsync() ?? new(); } - #endregion + /// + public Dictionary VocabolarioGetLang(string lingua) + { + using var dbCtx = _ctxFactory.CreateDbContextAsync().GetAwaiter().GetResult(); + var rawList = dbCtx + .DbSetVocabolario + .AsNoTracking() + .Where(x => x.Lingua.ToLower() == lingua.ToLower()) + .OrderBy(x => x.Lemma) + .ToList(); + // Proietto in dizionario + return rawList + .DistinctBy(t => t.Lemma, StringComparer.OrdinalIgnoreCase) + .ToDictionary(t => t.Lemma, t => t.Traduzione, StringComparer.OrdinalIgnoreCase); + } + + #endregion Public Methods + + #region Private Fields + + private readonly IDbContextFactory _ctxFactory; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/MP.Data/Repository/Production/IProductionRepository.cs b/MP.Data/Repository/Production/IProductionRepository.cs index 8a2cd94a..7089a4de 100644 --- a/MP.Data/Repository/Production/IProductionRepository.cs +++ b/MP.Data/Repository/Production/IProductionRepository.cs @@ -106,6 +106,7 @@ namespace MP.Data.Repository.Production Task> ListGiacenzeAsync(int IdxOdl); Task> OperatoriGetFiltAsync(string codGruppo); + Task OperatoriUpsertAsync(AnagOperatoriModel updRec); Task> ParametriGetFiltAsync(string IdxMacchina); diff --git a/MP.Data/Repository/Production/ProductionRepository.cs b/MP.Data/Repository/Production/ProductionRepository.cs index 7905e7af..ec051504 100644 --- a/MP.Data/Repository/Production/ProductionRepository.cs +++ b/MP.Data/Repository/Production/ProductionRepository.cs @@ -19,10 +19,15 @@ namespace MP.Data.Repository.Production #endregion #region Public Constructors + protected readonly IDbContextFactory _ctxFactoryFL; - public ProductionRepository(IDbContextFactory ctxFactory, IConfiguration configuration) + public ProductionRepository( + IConfiguration configuration, + IDbContextFactory ctxFactory, + IDbContextFactory ctxFactoryFL) { _ctxFactory = ctxFactory; + _ctxFactoryFL = ctxFactoryFL; _configuration = configuration; } @@ -686,7 +691,7 @@ namespace MP.Data.Repository.Production /// public async Task> MacchineWithFluxAsync(DateTime dtStart, DateTime dtEnd) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); return await dbCtx .DbSetFluxLog .AsNoTracking() @@ -841,10 +846,23 @@ namespace MP.Data.Repository.Production return dbResult; } + public async Task OperatoriUpsertAsync(AnagOperatoriModel updRec) + { + await using var dbCtx = await GetMoonProContextAsync(); + var dbRec = await dbCtx + .DbOperatori + .FindAsync(updRec.MatrOpr); + if (dbRec != null) + { + dbCtx.Entry(dbRec).CurrentValues.SetValues(updRec); + } + return await dbCtx.SaveChangesAsync() > 0; + } + /// public async Task> ParametriGetFiltAsync(string IdxMacchina) { - await using var dbCtx = new MoonPro_FluxContext(_configuration); + await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync(); return await dbCtx .DbSetFluxLog .AsNoTracking() diff --git a/MP.Data/Services/BaseServ.cs b/MP.Data/Services/BaseServ.cs index 770df68e..0a6dbf7e 100644 --- a/MP.Data/Services/BaseServ.cs +++ b/MP.Data/Services/BaseServ.cs @@ -9,6 +9,8 @@ using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; +using static Org.BouncyCastle.Asn1.Cmp.Challenge; namespace MP.Data.Services { @@ -19,10 +21,12 @@ namespace MP.Data.Services { #region Public Constructors - public BaseServ(IConfiguration configuration, IConnectionMultiplexer redConn) + public BaseServ(IConfiguration configuration, IFusionCache cache, IConnectionMultiplexer redConn) { _configuration = configuration; + _cache = cache; + slowLogThresh = _configuration.GetValue("ServerConf:slowLogThresh", 1); // Verifica conf trace... _traceEnabled = _configuration.GetValue("Otel:EnableTracing", false); @@ -161,13 +165,23 @@ namespace MP.Data.Services /// protected static readonly ActivitySource ActivitySource = new ActivitySource("MP.IOC"); - protected IConfiguration _configuration = null!; + /// + /// Oggetto gestione FusionCache + /// + protected readonly IFusionCache _cache; + + /// + /// Path base chiavi REDIS + /// + protected readonly string _redisBaseKey = "MP:IOC"; /// /// Abilitazione operazioni tracing generiche /// protected readonly bool _traceEnabled = false; + protected IConfiguration _configuration = null!; + /// /// Oggetto per connessione a REDIS /// @@ -180,8 +194,19 @@ namespace MP.Data.Services protected IDatabase _redisDb = null!; protected JsonSerializerSettings? JSSettings; + protected string MpIoNS = ""; + /// + /// Durata cache Lunga standard (300 sec) + /// + protected int redisLongTimeCache = 300; + + /// + /// Durata cache Breve standard (5 sec) + /// + protected int redisShortTimeCache = 5; + #endregion Protected Fields #region Protected Properties @@ -281,6 +306,75 @@ namespace MP.Data.Services } } + /// + /// Implementa gestione FusionCache+ tracking attività + /// - recupero cache da memoria o da obj esterno + cache memoria + /// - recupero da fetchFunc se mancasse + store in cache L1/L2 + /// + /// + /// + /// + /// + /// + protected async Task GetOrFetchAsync(string operationName, string cacheKey, Func> fetchFunc, TimeSpan expiration, params string[] tagList) + { + using var activity = ActivitySource.StartActivity(operationName); + string source; + var tryGet = await _cache.TryGetAsync(cacheKey); + if (tryGet.HasValue) + { + source = "MEMORY"; + var result = tryGet.Value!; + + activity?.SetTag("data.source", source); + activity?.Stop(); + // se supero la soglia loggo... + if (activity?.Duration.TotalMilliseconds > slowLogThresh) + { + LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms"); + } + return result; + } + bool fromDb = false; + // cache in redis + var cacheOptions = new FusionCacheEntryOptions() + .SetDuration(expiration) + .SetFailSafe(true); + // cache in RAM per 1/3 del tempo x risparmiare risorse + cacheOptions.MemoryCacheDuration = expiration / 3; + + var final = await _cache.GetOrSetAsync( + cacheKey, + async _ => + { + fromDb = true; + return await fetchFunc(); + }, + options: cacheOptions, + tags: tagList + ); + + source = fromDb ? "DB" : "REDIS"; + activity?.SetTag("data.source", source); + activity?.Stop(); + // switch log in base a source.. + switch (source) + { + case "DB": + LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Info); + break; + + case "REDIS": + LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Debug); + break; + + default: + LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms"); + break; + } + return final!; + } + /// /// Helper generale di lettura da cache o da funzione (DB) con caching successivo /// @@ -327,6 +421,18 @@ namespace MP.Data.Services return result!; } + /// + /// Restituisce un timeout dal valore secondi richiesti + tempo random +/-3% + /// + /// + /// + protected TimeSpan GetRandTOut(double durationSec) + { + double noise = (rand.NextDouble() * 0.06) - 0.03; + double rValue = durationSec * (1 + noise); + return TimeSpan.FromSeconds(rValue); + } + /// /// Helper trace messaggio log (SE abilitato) /// @@ -396,6 +502,7 @@ namespace MP.Data.Services #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); + private bool _disposed = false; /// @@ -408,12 +515,14 @@ namespace MP.Data.Services /// private int cacheTtlShort = 60 * 1; + private Random rand = new Random(); + private Random rnd = new Random(); /// - /// Path base chiavi REDIS + /// Soglia minima (ms) per log timing in console /// - protected readonly string _redisBaseKey = "MP:IOC"; + private double slowLogThresh = 0; #endregion Private Fields } diff --git a/MP.Data/Services/IOC/IocService.cs b/MP.Data/Services/IOC/IocService.cs index 416ad3e6..0a709a30 100644 --- a/MP.Data/Services/IOC/IocService.cs +++ b/MP.Data/Services/IOC/IocService.cs @@ -23,17 +23,19 @@ namespace MP.Data.Services.IOC public IocService( IConfiguration config, IConnectionMultiplexer redis, + IFusionCache cache, IIocRepository repo, - IServiceScopeFactory scopeFactory, - //Microsoft.Extensions.Caching.Memory.IMemoryCache cache - IFusionCache cache) : base(config, redis) + IServiceScopeFactory scopeFactory + ) : base(config, cache, redis) { _className = "IocServ"; int.TryParse(config.GetValue("ServerConf:redisLongTimeCache"), out redisLongTimeCache); int.TryParse(config.GetValue("ServerConf:redisShortTimeCache"), out redisShortTimeCache); _repo = repo; _scopeFactory = scopeFactory; - _cache = cache; +#if false + _cache = cache; +#endif } #endregion Public Constructors @@ -79,7 +81,7 @@ namespace MP.Data.Services.IOC result = await GetCurrOdlByProdAsync(idxMacchina); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); - _redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); + _redisDb.StringSet(currKey, rawData, GetRandTOut(redisLongTimeCache)); } return result; } @@ -261,16 +263,18 @@ namespace MP.Data.Services.IOC #region Protected Methods +#if false /// /// Restituisce un timeout dai minuti richiesti + tempo random 1..60 sec /// /// /// - protected TimeSpan getRandTOut(double stdMinutes) + protected TimeSpan GetRandTOut(double stdMinutes) { double rndValue = stdMinutes + (double)rand.Next(1, 60) / 60; return TimeSpan.FromMinutes(rndValue); - } + } +#endif #endregion Protected Methods @@ -278,7 +282,9 @@ namespace MP.Data.Services.IOC private static Logger Log = LogManager.GetCurrentClassLogger(); - private readonly IFusionCache _cache; +#if false + private readonly IFusionCache _cache; +#endif private readonly string _className; @@ -295,9 +301,11 @@ namespace MP.Data.Services.IOC /// private string dtFormat = "yyyyMMddHHmmssfff"; +#if false private int redisLongTimeCache = 5; - private int redisShortTimeCache = 2; + private int redisShortTimeCache = 2; +#endif #endregion Private Fields @@ -417,7 +425,7 @@ namespace MP.Data.Services.IOC { result = await _repo.ConfigGetAllAsync(); rawData = JsonConvert.SerializeObject(result); - await _redisDb.StringSetAsync(MP.Data.Utils.redisConfKey, rawData, getRandTOut(redisLongTimeCache)); + await _redisDb.StringSetAsync(MP.Data.Utils.redisConfKey, rawData, GetRandTOut(redisLongTimeCache)); } Log.Debug($"ConfigGetAllAsync Read from {source}"); if (result == null) @@ -544,7 +552,7 @@ namespace MP.Data.Services.IOC var fullList = await Macchine2SlaveGetAllAsync(); result = fullList.Select(x => x.IdxMacchina).ToHashSet(); rawData = JsonConvert.SerializeObject(result); - await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10)); + await _redisDb.StringSetAsync(currKey, rawData, GetRandTOut(redisLongTimeCache * 10)); } return result; }, TimeSpan.FromMinutes(15)); @@ -566,7 +574,7 @@ namespace MP.Data.Services.IOC var fullList = await Macchine2SlaveGetAllAsync(); result = fullList.Select(x => x.IdxMacchinaSlave).Distinct().ToHashSet(); rawData = JsonConvert.SerializeObject(result); - await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10)); + await _redisDb.StringSetAsync(currKey, rawData, GetRandTOut(redisLongTimeCache * 10)); } return result; }, TimeSpan.FromMinutes(15)); @@ -593,7 +601,7 @@ namespace MP.Data.Services.IOC result = await _repo.Macchine2SlaveAsync(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); - await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10)); + await _redisDb.StringSetAsync(currKey, rawData, GetRandTOut(redisLongTimeCache * 10)); } if (result == null) { diff --git a/MP.Data/Services/LandDataService.cs b/MP.Data/Services/LandDataService.cs index a94c0634..1770d3eb 100644 --- a/MP.Data/Services/LandDataService.cs +++ b/MP.Data/Services/LandDataService.cs @@ -14,6 +14,7 @@ using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services { @@ -21,7 +22,12 @@ namespace MP.Data.Services { #region Public Constructors - public LandDataService(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpLand.IMpLandRepository mpLandRepository) : base(configuration, redConn) + public LandDataService( + IConfiguration configuration, + IConnectionMultiplexer redConn, + IFusionCache cache, + Repository.MpLand.IMpLandRepository mpLandRepository + ) : base(configuration, cache, redConn) { _mpLandRepository = mpLandRepository; // conf DB @@ -46,7 +52,7 @@ namespace MP.Data.Services /// Restituisce info dimensione, tabelle e num righe DB /// /// - public List AllDbInfo() + public async Task> AllDbInfoAsync() { // setup parametri costanti string source = "DB"; @@ -55,7 +61,7 @@ namespace MP.Data.Services List result = new List(); // cerco in _redisConn... string currKey = $"{redisBaseKey}:DbInfo:ALL"; - RedisValue rawData = _redisDb.StringGet(currKey); + RedisValue rawData = await _redisDb.StringGetAsync(currKey); if (rawData.HasValue) { result = JsonConvert.DeserializeObject>($"{rawData}"); @@ -63,17 +69,17 @@ namespace MP.Data.Services } else { - result = _mpLandRepository.AllDbInfoAsync().GetAwaiter().GetResult(); + result = await _mpLandRepository.AllDbInfoAsync(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); - _redisDb.StringSet(currKey, rawData, UltraFastCache); + await _redisDb.StringSetAsync(currKey, rawData, UltraFastCache); } if (result == null) { result = new List(); } sw.Stop(); - Log.Debug($"AllDbInfo | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"AllDbInfoAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } diff --git a/MP.Data/Services/ListSelectDataSrv.cs b/MP.Data/Services/ListSelectDataSrv.cs index af6b8aef..c93c8e44 100644 --- a/MP.Data/Services/ListSelectDataSrv.cs +++ b/MP.Data/Services/ListSelectDataSrv.cs @@ -12,6 +12,7 @@ using System.Data; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services { @@ -33,7 +34,14 @@ namespace MP.Data.Services #region Public Constructors - public ListSelectDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn, IAnagRepository anagRepository, IProductionRepository productionRepository, ISystemRepository systemRepository) : base(configuration, redConn) + public ListSelectDataSrv( + IConfiguration configuration, + IConnectionMultiplexer redConn, + IFusionCache cache, + IAnagRepository anagRepository, + IProductionRepository productionRepository, + ISystemRepository systemRepository + ) : base(configuration, cache, redConn) { _anagRepository = anagRepository; _productionRepository = productionRepository; diff --git a/MP.Data/Services/Mtc/MtcSetupService.cs b/MP.Data/Services/Mtc/MtcSetupService.cs index 8ea00bf4..8a003d9f 100644 --- a/MP.Data/Services/Mtc/MtcSetupService.cs +++ b/MP.Data/Services/Mtc/MtcSetupService.cs @@ -5,6 +5,7 @@ using MP.Data.Repository.Mtc; using StackExchange.Redis; using System.Collections.Generic; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services.Mtc { @@ -18,7 +19,8 @@ namespace MP.Data.Services.Mtc public MtcSetupService( IConfiguration config, IConnectionMultiplexer redis, - IMtcSetupRepository repo) : base(config, redis) + IFusionCache cache, + IMtcSetupRepository repo) : base(config, cache, redis) { _className = "MtcSetup"; _repo = repo; diff --git a/MP.Data/Services/OrderDataSrv.cs b/MP.Data/Services/OrderDataSrv.cs index 22140226..0f5ec926 100644 --- a/MP.Data/Services/OrderDataSrv.cs +++ b/MP.Data/Services/OrderDataSrv.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services { @@ -31,7 +32,13 @@ namespace MP.Data.Services #region Public Constructors - public OrderDataSrv(IConfiguration configuration, IConnectionMultiplexer redConn, IProductionRepository productionRepository, ISystemRepository systemRepository) : base(configuration, redConn) + public OrderDataSrv( + IConfiguration configuration, + IConnectionMultiplexer redConn, + IFusionCache cache, + IProductionRepository productionRepository, + ISystemRepository systemRepository + ) : base(configuration, cache, redConn) { _productionRepository = productionRepository; _systemRepository = systemRepository; diff --git a/MP.Data/Services/SchedulerDataService.cs b/MP.Data/Services/SchedulerDataService.cs index 46bb8638..6644187f 100644 --- a/MP.Data/Services/SchedulerDataService.cs +++ b/MP.Data/Services/SchedulerDataService.cs @@ -4,6 +4,7 @@ using StackExchange.Redis; using System; using System.Collections.Generic; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services { @@ -13,7 +14,11 @@ namespace MP.Data.Services /// Init servizio TAB /// /// - public SchedulerDataService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn) + public SchedulerDataService( + IConfiguration configuration, + IConnectionMultiplexer redConn, + IFusionCache cache + ) : base(configuration, cache, redConn) { _configuration = configuration; diff --git a/MP.Data/Services/SharedMemService.cs b/MP.Data/Services/SharedMemService.cs index 6609ecc1..93fd6e28 100644 --- a/MP.Data/Services/SharedMemService.cs +++ b/MP.Data/Services/SharedMemService.cs @@ -4,6 +4,7 @@ using NLog; using StackExchange.Redis; using System.Collections.Generic; using System.Linq; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services { @@ -15,7 +16,11 @@ namespace MP.Data.Services /// Init servizio TAB /// /// - public SharedMemService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn) + public SharedMemService( + IConfiguration configuration, + IConnectionMultiplexer redConn, + IFusionCache cache + ) : base(configuration, cache, redConn) { } diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index 948ee410..0ee1616f 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using MP.Core.DTO; using MP.Core.Objects; +using MP.Data.Controllers; using MP.Data.DbModels; using Newtonsoft.Json; using NLog; @@ -15,6 +16,7 @@ using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services { @@ -26,7 +28,12 @@ namespace MP.Data.Services /// Init servizio TAB /// /// - public TabDataService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn) + public TabDataService( + IConfiguration configuration, + IConnectionMultiplexer redConn, + IFusionCache cache, + MpIocController iocContr + ) : base(configuration, cache, redConn) { _configuration = configuration; @@ -41,7 +48,7 @@ namespace MP.Data.Services StringBuilder sb = new StringBuilder(); dbTabController = new Controllers.MpTabController(configuration); sb.AppendLine($"TabDataService | MpTabController OK"); - dbIocController = new Controllers.MpIocController(configuration); + dbIocController = iocContr;// new Controllers.MpIocController(configuration); sb.AppendLine($"TabDataService | MpIocController OK"); dbInveController = new Controllers.MpInveController(configuration); sb.AppendLine($"TabDataService | MpInveController OK"); diff --git a/MP.Data/Services/TranslateSrv.cs b/MP.Data/Services/TranslateSrv.cs index b29fa641..f3ffdfde 100644 --- a/MP.Data/Services/TranslateSrv.cs +++ b/MP.Data/Services/TranslateSrv.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Configuration; using MP.Core.Conf; using MP.Data.DbModels; +using MP.Data.Repository.FluxLog; using Newtonsoft.Json; using NLog; using StackExchange.Redis; @@ -13,6 +14,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services { @@ -23,30 +25,57 @@ namespace MP.Data.Services { #region Public Constructors - public TranslateSrv(IConfiguration configuration, IConnectionMultiplexer redConn, Repository.MpVoc.IMpVocRepository mpVocRepository) : base(configuration, redConn) + public TranslateSrv( + IConfiguration configuration, + IConnectionMultiplexer redConn, + IFusionCache cache, + Repository.MpVoc.IMpVocRepository mpVocRepository + ) : base(configuration, cache, redConn) { _mpVocRepository = mpVocRepository; - Stopwatch sw = new Stopwatch(); - sw.Start(); - // conf DB - string connStr = _configuration.GetConnectionString("MP.Voc"); - if (string.IsNullOrEmpty(connStr)) - { - Log.Error("MP.Voc: ConnString empty!"); - } - else - { - var _ = _mpVocRepository.ConfigGetAllAsync().GetAwaiter().GetResult(); - InitDict(); - sw.Stop(); - Log.Info($"TranslateSrv | MpVocRepository OK | {sw.Elapsed.TotalMilliseconds} ms"); - } } #endregion Public Constructors #region Public Methods + /// + /// Esegue traduzione dato vocabolario da Lingua + Lemma + /// + /// + /// + /// + public string Traduci(string lemma, string lingua = "IT") + { + if (string.IsNullOrWhiteSpace(lemma)) return string.Empty; + if (string.IsNullOrWhiteSpace(lingua)) return lemma; + + string linguaKey = lingua.ToLowerInvariant().Trim(); + string cacheKey = $"vocab:{linguaKey}"; + + // FusionCache gestisce il lock e recupera l'intero dizionario della lingua. + // Se è in L1 (Memory), restituisce l'oggetto C# istantaneamente. + // Se non c'è, passa a L2 (Redis) o invoca la factory per caricarlo. + var dizionarioLingua = _cache.GetOrSet>( + cacheKey, + _ => _mpVocRepository.VocabolarioGetLang(linguaKey), + options => options + .SetDuration(TimeSpan.FromHours(8)) // Durata logica della cache + .SetFailSafe(true, TimeSpan.FromHours(1)) // Se Redis/DB è giù, usa i vecchi dati L1 + ); + + // Ricerca O(1) nel dizionario in memoria + if (dizionarioLingua != null && dizionarioLingua.TryGetValue(lemma, out var traduzione)) + { + return traduzione; + } + + // Fallback: se la parola non è censita, restituisce il lemma originale (lingua + lemma) + return $"{lingua}_{lemma}"; + } + + +#if false /// /// Recupero elenco config /// @@ -80,7 +109,8 @@ namespace MP.Data.Services sw.Stop(); Log.Debug($"ConfigGetAllAsync | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; - } + } +#endif /// /// Pulizia cache Redis (tutta) @@ -88,12 +118,15 @@ namespace MP.Data.Services /// public async Task FlushCache() { +#if false RedisValue pattern = new RedisValue($"{redisBaseKey}:*"); bool answ = await ExecFlushRedisPattern(pattern); // rileggo vocabolario! var rawData = await VocabolarioGetAll(); DictVocab = rawData.ToDictionary(kvp => $"{kvp.Lingua}_{kvp.Lemma}".ToUpper(), kvp => kvp.Traduzione); - return answ; + return answ; +#endif + return await FlushFusionCacheAsync(); } /// @@ -102,9 +135,51 @@ namespace MP.Data.Services /// public async Task FlushCache(string KeyReq) { +#if false RedisValue pattern = new RedisValue($"{redisBaseKey}:{KeyReq}:*"); bool answ = await ExecFlushRedisPattern(pattern); - return answ; + return answ; +#endif + return await FlushFusionCacheAsync(KeyReq); + } + + /// + /// Cancellazione FusionCache (totale) + /// + /// + private async Task FlushFusionCacheAsync() + { + await _cache.ClearAsync(allowFailSafe: false); + return true; + } + + /// + /// Cancellazione FusionCache dato singolo tag + /// + /// + private async Task FlushFusionCacheAsync(string tag) + { + if (string.IsNullOrWhiteSpace(tag)) return false; + + await _cache.RemoveByTagAsync(tag); + return true; + } + + /// + /// Cancellazione FusionCache dato elenco tags + /// + /// + private async Task FlushFusionCacheAsync(List listTags) + { + if (listTags == null || listTags.Count == 0) return false; + + // Generiamo i Task di rimozione ed eseguiamoli in parallelo su Redis/L1 + var tasks = listTags + .Where(tag => !string.IsNullOrWhiteSpace(tag)) + .Select(tag => _cache.RemoveByTagAsync(tag).AsTask()); + + await Task.WhenAll(tasks); + return true; } /// @@ -113,6 +188,17 @@ namespace MP.Data.Services /// public async Task> LingueGetAll() { + string currKey = $"{redisBaseKey}:Lang"; + + return await GetOrFetchAsync( + operationName: "LingueGetAll", + cacheKey: currKey, + expiration: GetRandTOut(redisShortTimeCache), + fetchFunc: async () => await _mpVocRepository.LingueGetAllAsync() ?? new(), + tagList: [currKey] + ); + +#if false string source = "DB"; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -139,9 +225,11 @@ namespace MP.Data.Services } sw.Stop(); Log.Debug($"LingueGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); - return result; + return result; +#endif } +#if false /// /// Traduzione termine /// @@ -157,7 +245,8 @@ namespace MP.Data.Services answ = DictVocab[key]; } return answ; - } + } +#endif /// /// Recupero elenco config @@ -165,6 +254,18 @@ namespace MP.Data.Services /// public async Task> VocabolarioGetAll() { + string currKey = $"{redisBaseKey}:VocAll"; + + return await GetOrFetchAsync( + operationName: "VocabolarioGetAll", + cacheKey: currKey, + expiration: GetRandTOut(redisShortTimeCache), + fetchFunc: async () => await _mpVocRepository.VocabolarioGetAllAsync() ?? new(), + tagList: [currKey] + ); + + +#if false string source = "DB"; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -191,46 +292,31 @@ namespace MP.Data.Services } sw.Stop(); Log.Debug($"VocabolarioGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); - return result; + return result; +#endif } #endregion Public Methods #region Protected Fields +#if false /// /// Vocabolario x recupero rapido traduzioni /// - protected static Dictionary DictVocab = new Dictionary(); + protected static Dictionary DictVocab = new Dictionary(); +#endif #endregion Protected Fields #region Protected Methods - protected override void Dispose(bool disposing) - { - if (!_disposed) - { - if (disposing) - { - // Free managed resources here - DictVocab.Clear(); - } - - // Free unmanaged resources here - _disposed = true; - } - - // Call base class implementation. - base.Dispose(disposing); - } - #endregion Protected Methods #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); - private bool _disposed = false; + private string redisBaseKey = "MP:Voc:Cache"; private readonly Repository.MpVoc.IMpVocRepository _mpVocRepository; @@ -239,16 +325,8 @@ namespace MP.Data.Services #region Private Methods - /// - /// Inizializzazione dict vari - /// - private void InitDict() - { - // inizializzo dizionario vocabolario - var rawData = _mpVocRepository.VocabolarioGetAllAsync().GetAwaiter().GetResult(); - DictVocab = rawData.ToDictionary(kvp => $"{kvp.Lingua}_{kvp.Lemma}".ToUpper(), kvp => kvp.Traduzione); - } +#if false /// /// Esegue flush memoria _redisConn dato pat2Flush /// @@ -287,26 +365,10 @@ namespace MP.Data.Services } } answ = true; -#if false - var listEndpoints = redisConn.GetEndPoints(); - foreach (var endPoint in listEndpoints) - { - //var server = redisConnAdmin.GetServer(listEndpoints[0]); - var server = redisConn.GetServer(endPoint); - if (server != null) - { - var keyList = server.Keys(redisDb.Database, pattern); - foreach (var item in keyList) - { - await redisDb.KeyDeleteAsync(item); - } - answ = true; - } - } -#endif return answ; - } + } +#endif #endregion Private Methods } diff --git a/MP.Data/Services/Utils/StatsAggrService.cs b/MP.Data/Services/Utils/StatsAggrService.cs index 411b463c..a322b84e 100644 --- a/MP.Data/Services/Utils/StatsAggrService.cs +++ b/MP.Data/Services/Utils/StatsAggrService.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services.Utils { @@ -19,7 +20,8 @@ namespace MP.Data.Services.Utils public StatsAggrService( IConfiguration config, IConnectionMultiplexer redis, - IStatsAggrRepository repo) : base(config, redis) + IFusionCache cache, + IStatsAggrRepository repo) : base(config, cache, redis) { _className = "StatsAggr"; _repo = repo; diff --git a/MP.Data/Services/Utils/StatsCodeService.cs b/MP.Data/Services/Utils/StatsCodeService.cs index 3d2bf4df..8e2b262b 100644 --- a/MP.Data/Services/Utils/StatsCodeService.cs +++ b/MP.Data/Services/Utils/StatsCodeService.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services.Utils { @@ -19,7 +20,9 @@ namespace MP.Data.Services.Utils public StatsCodeService( IConfiguration config, IConnectionMultiplexer redis, - IStatsCodeRepository repo) : base(config, redis) + IFusionCache cache, + IStatsCodeRepository repo + ) : base(config, cache, redis) { _className = "StatsStatusCode"; _repo = repo; diff --git a/MP.Data/Services/Utils/StatsDetailService.cs b/MP.Data/Services/Utils/StatsDetailService.cs index 75738f4d..b637b33d 100644 --- a/MP.Data/Services/Utils/StatsDetailService.cs +++ b/MP.Data/Services/Utils/StatsDetailService.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services.Utils { @@ -19,7 +20,9 @@ namespace MP.Data.Services.Utils public StatsDetailService( IConfiguration config, IConnectionMultiplexer redis, - IStatsDetailRepository repo) : base(config, redis) + IFusionCache cache, + IStatsDetailRepository repo + ) : base(config,cache, redis) { _className = "StatsDetail"; _repo = repo; diff --git a/MP.Data/Services/Utils/StatsErrService.cs b/MP.Data/Services/Utils/StatsErrService.cs index 26e76309..36e5c8e4 100644 --- a/MP.Data/Services/Utils/StatsErrService.cs +++ b/MP.Data/Services/Utils/StatsErrService.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Data.Services.Utils { @@ -19,7 +20,9 @@ namespace MP.Data.Services.Utils public StatsErrService( IConfiguration config, IConnectionMultiplexer redis, - IStatsErrRepository repo) : base(config, redis) + IFusionCache cache, + IStatsErrRepository repo + ) : base(config,cache, redis) { _className = "StatsErr"; _repo = repo; diff --git a/MP.SPEC/Components/AskCloseOdl.razor.cs b/MP.SPEC/Components/AskCloseOdl.razor.cs index 2a78e714..62a98b32 100644 --- a/MP.SPEC/Components/AskCloseOdl.razor.cs +++ b/MP.SPEC/Components/AskCloseOdl.razor.cs @@ -55,8 +55,7 @@ namespace MP.SPEC.Components } // eseguo chiusura finale CurrAction.IsActive = false; - MDService.ActionSetReqAsync(CurrAction); - await Task.Delay(1); + await MDService.ActionSetReqAsync(CurrAction); } protected async Task doConfirm() diff --git a/MP.SPEC/Components/Reparti/ListOperatori.razor b/MP.SPEC/Components/Reparti/ListOperatori.razor index 959835cb..93bfcd3d 100644 --- a/MP.SPEC/Components/Reparti/ListOperatori.razor +++ b/MP.SPEC/Components/Reparti/ListOperatori.razor @@ -5,7 +5,10 @@

                    Operatori

                    - + @if (AddEnabled) + { + + }
                    @@ -33,25 +36,51 @@ + - + @if (DelEnabled) + { + + } + @if (StaChgEnab) + { + + } - @foreach (var record in ListRecords) + @foreach (var item in ListRecords) { - + - - - + @if (DelEnabled) + { + + } + @if (StaChgEnab) + { + + } } diff --git a/MP.SPEC/Components/Reparti/ListOperatori.razor.cs b/MP.SPEC/Components/Reparti/ListOperatori.razor.cs index 2ca7dcab..03bf5bca 100644 --- a/MP.SPEC/Components/Reparti/ListOperatori.razor.cs +++ b/MP.SPEC/Components/Reparti/ListOperatori.razor.cs @@ -9,6 +9,9 @@ namespace MP.SPEC.Components.Reparti { #region Public Properties + [Parameter] + public bool AddEnabled { get; set; } = true; + [Parameter] public List? AllRecords { get; set; } = null; @@ -18,9 +21,18 @@ namespace MP.SPEC.Components.Reparti [Parameter] public List? CurrRecords { get; set; } = null; + [Parameter] + public bool DelEnabled { get; set; } = true; + [Parameter] public EventCallback EC_RecChange { get; set; } + [Parameter] + public EventCallback EC_RecSel { get; set; } + + [Parameter] + public bool StaChgEnab { get; set; } = false; + #endregion Public Properties #region Protected Properties @@ -37,7 +49,7 @@ namespace MP.SPEC.Components.Reparti protected override void OnParametersSet() { - numRecord = 10; + //numRecord = 10; UpdateTable(); } @@ -65,7 +77,9 @@ namespace MP.SPEC.Components.Reparti private bool isLoading = false; private List? ListAvail; + private List? ListRecords; + private int numRecord = 5; private int totalCount = 0; @@ -93,6 +107,18 @@ namespace MP.SPEC.Components.Reparti #region Private Methods + private string cssCol(AnagOperatoriModel currRec) + { + return !currRec.isEnabled ? "opacity-75" : ""; + } + + private string cssRow(AnagOperatoriModel currRec) + { + string answ = selRec != null && currRec.MatrOpr == selRec.MatrOpr ? "table-info " : ""; + answ += !currRec.isEnabled ? "text-secondary disabled text-decoration-line-through" : ""; + return answ; + } + private async Task DoAdd(AnagOperatoriModel currRec) { // eliminazione dal gruppo @@ -120,6 +146,19 @@ namespace MP.SPEC.Components.Reparti await EC_RecChange.InvokeAsync(false); } + private AnagOperatoriModel? selRec = null; + + private async Task DoSelect(AnagOperatoriModel sRec) + { + selRec = sRec; + await EC_RecSel.InvokeAsync(sRec); + } + private async Task DoReset() + { + selRec = null; + await EC_RecSel.InvokeAsync(null); + } + private async Task ReportUpdate(bool force) { AddNewEnabled = false; @@ -131,6 +170,17 @@ namespace MP.SPEC.Components.Reparti AddNewEnabled = !AddNewEnabled; } + private async Task ToggleStatusOpr(AnagOperatoriModel updRec) + { + string azione = updRec.isEnabled ? "disabilitarlo" : "abilitarlo"; + if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler modificare l'operatore per {azione}?")) + return; + + updRec.isEnabled = !updRec.isEnabled; + await MDService.OperatoriUpsertAsync(updRec); + await EC_RecChange.InvokeAsync(true); + } + private void UpdateTable() { ListRecords = new(); diff --git a/MP.SPEC/Components/Reparti/ListReparti.razor b/MP.SPEC/Components/Reparti/ListReparti.razor index 4189ceba..b8a1b5f6 100644 --- a/MP.SPEC/Components/Reparti/ListReparti.razor +++ b/MP.SPEC/Components/Reparti/ListReparti.razor @@ -5,7 +5,7 @@

                    Elenco Reparti

                    - @if (SelRecord == null && IsSuperAdmin) + @if (SelRecord == null && IsSuperAdmin && EditEnabled) { } @@ -95,17 +95,20 @@ {
                    @if (SelRecord == null) @@ -122,13 +125,16 @@ } diff --git a/MP.SPEC/Components/Reparti/ListReparti.razor.cs b/MP.SPEC/Components/Reparti/ListReparti.razor.cs index 1582c6fa..3f65ced9 100644 --- a/MP.SPEC/Components/Reparti/ListReparti.razor.cs +++ b/MP.SPEC/Components/Reparti/ListReparti.razor.cs @@ -17,6 +17,9 @@ namespace MP.SPEC.Components.Reparti [Parameter] public string CodGruppoSel { get; set; } = null!; + [Parameter] + public bool EditEnabled { get; set; } = true; + [Parameter] public EventCallback EC_RecordSel { get; set; } diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 951addc4..f6768500 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -702,6 +702,20 @@ namespace MP.SPEC.Data tagList: [Utils.redisAnagGruppi] ); } + /// + /// Restitusice elenco Reparti + /// + /// + public async Task> GruppiRepartoDtoByOperAsync(int matrOpr) + { + return await GetOrFetchAsync( + operationName: "ElencoRepartiDtoAsync", + cacheKey: $"{Utils.redisAnagGruppiOpr}:{matrOpr}", + expiration: GetRandTOut(redisLongTimeCache), + fetchFunc: async () => await _anagRepository.GruppiRepartoDtoByOperAsync(matrOpr) ?? new(), + tagList: [Utils.redisAnagGruppiOpr] + ); + } /// /// Caricamento asincrono della cache degli articoli (Used/Unused) @@ -1408,6 +1422,25 @@ namespace MP.SPEC.Data ); } + /// + /// Aggiornamento operatori su DB + invalidata cache + /// + /// + /// + public async Task OperatoriUpsertAsync(AnagOperatoriModel updRec) + { + using var activity = ActivitySource.StartActivity("OperatoriUpsertAsync"); + string source = "DB"; + bool fatto = false; + // salvo + fatto = await _productionRepository.OperatoriUpsertAsync(updRec); + await FlushFusionCacheAsync(Utils.redisOprList); + activity?.SetTag("data.source", source); + activity?.Stop(); + LogTrace($"OperatoriUpsertAsync | {source} | {activity?.Duration.TotalMilliseconds}ms"); + return fatto; + } + /// /// Elenco di tutti i parametri filtrati x idxMaccSel /// diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 85941120..0c0a71b8 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 8.16.2606.311 + 8.16.2606.317 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Pages/Operatori.razor b/MP.SPEC/Pages/Operatori.razor new file mode 100644 index 00000000..b1fcb4a3 --- /dev/null +++ b/MP.SPEC/Pages/Operatori.razor @@ -0,0 +1,41 @@ +@page "/operatori" + +
                    +
                    +
                    +
                    +
                    +
                    + Gestione Operatori +
                    +
                    +
                    +
                    + @* Edit Massivo Fermi *@ +
                    +
                    +
                    +
                    + @if (isLoading) + { + + } + else + { +
                    +
                    + +
                    + @if (SelRec != null) + { +
                    + +
                    + } +
                    + + } +
                    +
                    + + diff --git a/MP.SPEC/Pages/Operatori.razor.cs b/MP.SPEC/Pages/Operatori.razor.cs new file mode 100644 index 00000000..75ec7e16 --- /dev/null +++ b/MP.SPEC/Pages/Operatori.razor.cs @@ -0,0 +1,66 @@ +using Microsoft.AspNetCore.Components; +using MP.Core.DTO; +using MP.Data.DbModels; +using MP.SPEC.Data; + +namespace MP.SPEC.Pages +{ + public partial class Operatori + { + #region Protected Properties + + [Inject] + protected MpDataService MDService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected override async Task OnInitializedAsync() + { + await ReloadDataAsync(); + } + + #endregion Protected Methods + + #region Private Fields + + private bool isLoading = false; + private List ListOperatori = new(); + private List ListGruppi = new(); + private AnagOperatoriModel? SelRec = null; + + #endregion Private Fields + + #region Private Properties + + private string cssMain => SelRec == null ? "col-12" : "col-6"; + + #endregion Private Properties + + #region Private Methods + + private async Task ReloadDataAsync() + { + isLoading = true; + ListOperatori = await MDService.OperatoriGetFiltAsync("*"); + isLoading = false; + } + + private async Task ShowDetail(AnagOperatoriModel? newRec) + { + SelRec = newRec; + if (SelRec == null) + { + ListGruppi.Clear(); + } + else + { + // recupero gruppi operatore + ListGruppi = await MDService.GruppiRepartoDtoByOperAsync(SelRec.MatrOpr); + } + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MP.SPEC/Program.cs b/MP.SPEC/Program.cs index 64fd379e..04f79f14 100644 --- a/MP.SPEC/Program.cs +++ b/MP.SPEC/Program.cs @@ -170,7 +170,14 @@ builder.Services.AddDbContextFactory(options => .EnableSensitiveDataLogging(false) // true solo in Sviluppo .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); -// MP.Data Services Utils - Statistiche DB +var connStrFL = builder.Configuration.GetConnectionString("MP.Flux") + ?? throw new InvalidOperationException("ConnString 'MP.Flux' mancante."); +builder.Services.AddDbContextFactory(options => + options.UseSqlServer(connStrFL) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + +// Init centralizzato Repository/Servizi da MP.Data Services builder.Services.AddSpecDataLayer(); // servizi del progetto SPEC diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 40cd97d7..56193a1d 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

                    Versione: 8.16.2606.311

                    +

                    Versione: 8.16.2606.317


                    Note di rilascio:
                    • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index aa5451d0..8c2eaf7f 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.311 +8.16.2606.317 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index c283f196..e67b9b17 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.311 + 8.16.2606.317 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false From fab32124d8f196f918159af67ce33b0e02ce113b Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 3 Jun 2026 18:12:16 +0200 Subject: [PATCH 08/12] RIOC: - fix compilazione con prerequisiti vari - fx init program.cs x dbcontext --- MP.RIOC/MP.RIOC.csproj | 2 +- MP.RIOC/Program.cs | 9 ++++++--- MP.RIOC/Resources/ChangeLog.html | 2 +- MP.RIOC/Resources/VersNum.txt | 2 +- MP.RIOC/Resources/manifest.xml | 2 +- MP.RIOC/appsettings.json | 1 + 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/MP.RIOC/MP.RIOC.csproj b/MP.RIOC/MP.RIOC.csproj index 7bc99308..03533e4f 100644 --- a/MP.RIOC/MP.RIOC.csproj +++ b/MP.RIOC/MP.RIOC.csproj @@ -5,7 +5,7 @@ enable enable MP.RIOC - 8.16.2606.311 + 8.16.2606.318 diff --git a/MP.RIOC/Program.cs b/MP.RIOC/Program.cs index 6ba4f593..489b29dd 100644 --- a/MP.RIOC/Program.cs +++ b/MP.RIOC/Program.cs @@ -37,13 +37,16 @@ logger.Info("RedisScript Provider configured"); // Metodi principali x accesso dati var connStr = builder.Configuration.GetConnectionString("MP.Data") ?? throw new InvalidOperationException("ConnString 'MP.Data' mancante."); - -//builder.Services.AddMemoryCache(); - builder.Services.AddDbContextFactory(options => options.UseSqlServer(connStr) .EnableSensitiveDataLogging(false) // true solo in Sviluppo .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); +var connStrFL = builder.Configuration.GetConnectionString("MP.Flux") + ?? throw new InvalidOperationException("ConnString 'MP.Flux' mancante."); +builder.Services.AddDbContextFactory(options => + options.UseSqlServer(connStrFL) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); // MP.Data DbContext for Stats repositories string utilsConnString = builder.Configuration.GetConnectionString("MP.Utils") ?? "Server=localhost;Database=MoonPro_Utils; integrated security=True; MultipleActiveResultSets=True; App=MP.IOC;"; diff --git a/MP.RIOC/Resources/ChangeLog.html b/MP.RIOC/Resources/ChangeLog.html index 0271b927..c71c5486 100644 --- a/MP.RIOC/Resources/ChangeLog.html +++ b/MP.RIOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-RIOC -

                      Versione: 8.16.2606.311

                      +

                      Versione: 8.16.2606.318


                      Note di rilascio:
                      • diff --git a/MP.RIOC/Resources/VersNum.txt b/MP.RIOC/Resources/VersNum.txt index aa5451d0..ea702b6d 100644 --- a/MP.RIOC/Resources/VersNum.txt +++ b/MP.RIOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.311 +8.16.2606.318 diff --git a/MP.RIOC/Resources/manifest.xml b/MP.RIOC/Resources/manifest.xml index 9fb2ac1c..734be1e1 100644 --- a/MP.RIOC/Resources/manifest.xml +++ b/MP.RIOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.311 + 8.16.2606.318 https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/MP.RIOC.zip https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/ChangeLog.html false diff --git a/MP.RIOC/appsettings.json b/MP.RIOC/appsettings.json index 2c648666..958cb8ba 100644 --- a/MP.RIOC/appsettings.json +++ b/MP.RIOC/appsettings.json @@ -82,6 +82,7 @@ "ConnectionStrings": { "MP.Data": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; App=MP.IOC;", "MP.Utils": "Server=SQL2016DEV;Database=MoonPro_Utils; User ID=sa;Password=keyhammer16; integrated security=False; App=MP.RIOC;", + "MP.Flux": "Server=SQL2016DEV;Database=MoonPro_FluxData; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.RIOC;", "Redis": "redis.ufficio:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false", "RedisAdmin": "redis.ufficio:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true" } From febe1d0132c09bd56aaaaec410fb3fd167e479ae Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 3 Jun 2026 18:23:12 +0200 Subject: [PATCH 09/12] IOC: - completata review program.cs - fix temporaneo init servizi data interni (da rivedere con FusionCache ...) --- MP.Data/DataServiceCollectionExtensions.cs | 1 + MP.IOC/Data/MpDataService.cs | 20 +++++++++++++++----- MP.IOC/MP.IOC.csproj | 2 +- MP.IOC/Program.cs | 16 ++++++++++++---- MP.IOC/Resources/ChangeLog.html | 2 +- MP.IOC/Resources/VersNum.txt | 2 +- MP.IOC/Resources/manifest.xml | 2 +- 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index 2adc1d06..8ed9107a 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -34,6 +34,7 @@ namespace MP.Data { // Repository Singleton services.TryAddSingleton(); + services.TryAddSingleton(); // Repository Scoped services.TryAddScoped(); diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index fed66bf3..87ed22a2 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -7,6 +7,7 @@ using MP.Data.Controllers; using MP.Data.DbModels; using MP.Data.DbModels.Anag; using MP.Data.MgModels; +using MP.Data.Repository.Production; using MP.Data.Services.IOC; using MP.Data.Services.Mtc; using Newtonsoft.Json; @@ -22,17 +23,22 @@ namespace MP.IOC.Data public class MpDataService { #region Public Constructors + private readonly IProductionRepository _productionRepository; public MpDataService( IConfiguration configuration, ILogger logger, IServiceScopeFactory scopeFactory, + IProductionRepository productionRepository, + MpIocController mpIocCtr, IMtcSetupService mtcServ) { _logger = logger; _logger.LogInformation("Starting MpDataService INIT"); _configuration = configuration; _scopeFactory = scopeFactory; + _productionRepository = productionRepository; + IocDbController = mpIocCtr; // setup compoenti REDIS redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis")); @@ -58,8 +64,10 @@ namespace MP.IOC.Data } else { - SpecDbController = new MpSpecController(configuration); +#if false + SpecDbController = new MpSpecController(configuration); IocDbController = new MpIocController(configuration); +#endif Log.Info("DbControllers INIT OK"); } @@ -83,9 +91,11 @@ namespace MP.IOC.Data #region Public Properties - public static MpIocController IocDbController { get; set; } = null!; public static MpMongoController mongoController { get; set; } = null!; - public static MpSpecController SpecDbController { get; set; } = null!; + public static MpIocController IocDbController { get; set; } = null!; +#if false + public static MpSpecController SpecDbController { get; set; } = null!; +#endif public MessagePipe BroadastMsgPipe { get; set; } = null!; /// @@ -1209,7 +1219,7 @@ namespace MP.IOC.Data } else { - result = await SpecDbController.MacchineGetFiltAsync(codGruppo); + result = await _productionRepository.MacchineGetFiltAsync(codGruppo); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); @@ -1622,7 +1632,7 @@ namespace MP.IOC.Data } else { - result = await SpecDbController.PODL_getByKeyAsync(idxPODL); + result = await _productionRepository.PODL_getByKeyAsync(idxPODL); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 88739b41..29e1b914 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 8.16.2606.311 + 8.16.2606.318 diff --git a/MP.IOC/Program.cs b/MP.IOC/Program.cs index 8a3df56f..8945acd4 100644 --- a/MP.IOC/Program.cs +++ b/MP.IOC/Program.cs @@ -42,18 +42,26 @@ logger.Info("RedisScript Provider configured"); // Metodi principali x accesso dati var connStr = builder.Configuration.GetConnectionString("MP.Data") ?? throw new InvalidOperationException("ConnString 'MP.Data' mancante."); - builder.Services.AddMemoryCache(); - builder.Services.AddDbContextFactory(options => options.UseSqlServer(connStr) .EnableSensitiveDataLogging(false) // true solo in Sviluppo .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); // MP.Data DbContext for Stats repositories -string utilsConnString = builder.Configuration.GetConnectionString("MP.Utils") ?? "Server=localhost;Database=MoonPro_Utils; integrated security=True; MultipleActiveResultSets=True; App=MP.IOC;"; +string connStrUtils = builder.Configuration.GetConnectionString("MP.Utils") + ?? throw new InvalidOperationException("ConnString 'MP.Utils' mancante."); +//?? "Server=localhost;Database=MoonPro_Utils; integrated security=True; MultipleActiveResultSets=True; App=MP.IOC;"; builder.Services.AddDbContextFactory(options => - options.UseSqlServer(utilsConnString)); + options.UseSqlServer(connStrUtils).EnableSensitiveDataLogging(false) + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + +var connStrFL = builder.Configuration.GetConnectionString("MP.Flux") + ?? throw new InvalidOperationException("ConnString 'MP.Flux' mancante."); +builder.Services.AddDbContextFactory(options => + options.UseSqlServer(connStrFL) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); // MP.Data Services Utils - Statistiche DB builder.Services.AddIocDataLayer(); diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 55fd6939..0f1cd517 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

                        Versione: 8.16.2606.311

                        +

                        Versione: 8.16.2606.318


                        Note di rilascio:
                        • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index aa5451d0..ea702b6d 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.311 +8.16.2606.318 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 92f155e7..1ddeedf0 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.311 + 8.16.2606.318 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 From 217836099ccea0d1f525e9caba6ed55111fc018f Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 3 Jun 2026 18:32:51 +0200 Subject: [PATCH 10/12] LAND: - fix program.cs startup - fix calcolo dim DB - fix IOB count --- MP.Data/DataServiceCollectionExtensions.cs | 1 + MP.Data/Repository/MpLand/MpLandRepository.cs | 8 ++++- MP.Data/Services/LandDataService.cs | 16 ++++----- MP.Land/Components/DbInfoMan.razor.cs | 10 +++--- MP.Land/MP.Land.csproj | 2 +- MP.Land/Pages/IobList.razor.cs | 6 ++-- MP.Land/Resources/ChangeLog.html | 2 +- MP.Land/Resources/VersNum.txt | 2 +- MP.Land/Resources/manifest.xml | 2 +- MP.Land/Startup.cs | 33 +++++++++++++++++-- 10 files changed, 60 insertions(+), 22 deletions(-) diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index 8ed9107a..826ce9f2 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -67,6 +67,7 @@ namespace MP.Data // Servizi LAND services.TryAddSingleton(); + services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/MP.Data/Repository/MpLand/MpLandRepository.cs b/MP.Data/Repository/MpLand/MpLandRepository.cs index 83b60fff..3eb4f9d8 100644 --- a/MP.Data/Repository/MpLand/MpLandRepository.cs +++ b/MP.Data/Repository/MpLand/MpLandRepository.cs @@ -20,10 +20,16 @@ namespace MP.Data.Repository.MpLand #region Public Constructors - public MpLandRepository(IConfiguration configuration, IDbContextFactory ctxFactory) + public MpLandRepository( + IConfiguration configuration, + IDbContextFactory ctxFactory, + IDbContextFactory ctxFactoryFL, + IDbContextFactory ctxFactorySta) { _configuration = configuration; _ctxFactory = ctxFactory; + _ctxFactoryFluxLog = ctxFactoryFL; + _ctxFactoryStats= ctxFactorySta; } #endregion diff --git a/MP.Data/Services/LandDataService.cs b/MP.Data/Services/LandDataService.cs index 1770d3eb..8351a4b8 100644 --- a/MP.Data/Services/LandDataService.cs +++ b/MP.Data/Services/LandDataService.cs @@ -88,15 +88,15 @@ namespace MP.Data.Services ///
                        /// /// - public List IobListAll() + public async Task> IobListAllAsync() { string source = "DB"; List? dbResult = new List(); string currKey = $"{redisBaseKey}:IobList"; Stopwatch sw = new Stopwatch(); sw.Start(); - string? rawData = _redisDb.StringGet(currKey); - if (!string.IsNullOrEmpty(rawData) && rawData.Length > 2) + var rawData = await _redisDb.StringGetAsync(currKey); + if (rawData.HasValue) { source = "REDIS"; var tempResult = JsonConvert.DeserializeObject>(rawData); @@ -105,10 +105,10 @@ namespace MP.Data.Services else { // recupero RRL missing - var listRRl = _mpLandRepository.RemRebootLogGetLastAsync().GetAwaiter().GetResult(); - var listRRlAdd = _mpLandRepository.RemRebootLogGetLastNoMaccAsync().GetAwaiter().GetResult(); + var listRRl = await _mpLandRepository.RemRebootLogGetLastAsync(); + var listRRlAdd = await _mpLandRepository.RemRebootLogGetLastNoMaccAsync(); // recupero lista macchine - var ListMacch = _mpLandRepository.MacchineGetAllAsync().GetAwaiter().GetResult(); + var ListMacch = await _mpLandRepository.MacchineGetAllAsync(); // ...converto in DTO dbResult = ListMacch .Select(x => new IobDTO(x, IobInfo(x.IdxMacchina), MachIobConf(x.IdxMacchina))) @@ -125,14 +125,14 @@ namespace MP.Data.Services // serializzo in cache _redisConn rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - _redisDb.StringSet(currKey, rawData, UltraLongCache); + await _redisDb.StringSetAsync(currKey, rawData, UltraLongCache); } if (dbResult == null) { dbResult = new List(); } sw.Stop(); - Log.Debug($"IobListAll | {source} | {sw.ElapsedMilliseconds} ms"); + Log.Debug($"IobListAllAsync | {source} | {sw.ElapsedMilliseconds} ms"); return dbResult; } diff --git a/MP.Land/Components/DbInfoMan.razor.cs b/MP.Land/Components/DbInfoMan.razor.cs index aae03d69..6b434c3a 100644 --- a/MP.Land/Components/DbInfoMan.razor.cs +++ b/MP.Land/Components/DbInfoMan.razor.cs @@ -5,6 +5,7 @@ using MP.Data.Services; using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace MP.Land.Components { @@ -21,9 +22,10 @@ namespace MP.Land.Components #region Protected Methods - protected override void OnParametersSet() + + protected override async Task OnParametersSetAsync() { - ReloadData(); + await ReloadDataAsync(); } protected void SortRequested(Sorter.SortCallBack e) @@ -117,9 +119,9 @@ namespace MP.Land.Components } } - private void ReloadData() + private async Task ReloadDataAsync() { - ListRecord = LDService.AllDbInfo(); + ListRecord = await LDService.AllDbInfoAsync(); } #endregion Private Methods diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index 508b0702..d7bc72a6 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net8.0 MP.Land - 8.16.2606.0312 + 8.16.2606.0318 Debug;Release;Debug_LiManDebug en True diff --git a/MP.Land/Pages/IobList.razor.cs b/MP.Land/Pages/IobList.razor.cs index 90157bb1..8984045a 100644 --- a/MP.Land/Pages/IobList.razor.cs +++ b/MP.Land/Pages/IobList.razor.cs @@ -173,11 +173,11 @@ namespace MP.Land.Pages return answ; } - protected void DataInit() + protected async Task DataInitAsync() { isLoading = true; // recupero TUTTI i dati IobList già completi anche on i RemoteRebootLog - AllRecords = LDService.IobListAll(); + AllRecords = await LDService.IobListAllAsync(); #if false @@ -216,7 +216,7 @@ namespace MP.Land.Pages AppMService.PageName = "IobList"; AppMService.PageIcon = "fas fa-computer pe-2"; await SetupRight(); - DataInit(); + await DataInitAsync(); } protected void ResetSearch() diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index a19361ad..5cc46a2e 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo Tablet MAPO - DotNet6 -

                        Versione: 8.16.2606.0312

                        +

                        Versione: 8.16.2606.0318


                        Note di rilascio:
                          diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index b505b6b3..c21e857b 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.0312 +8.16.2606.0318 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index c16761d9..d2e91e50 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.0312 + 8.16.2606.0318 https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html false diff --git a/MP.Land/Startup.cs b/MP.Land/Startup.cs index b8b345a7..d318e61b 100644 --- a/MP.Land/Startup.cs +++ b/MP.Land/Startup.cs @@ -1,4 +1,4 @@ -using Blazored.LocalStorage; +using Blazored.LocalStorage; using Blazored.SessionStorage; using Microsoft.AspNetCore.Authentication.Negotiate; using Microsoft.AspNetCore.Builder; @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Localization; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -17,6 +18,10 @@ using MP.TaskMan.Services; using StackExchange.Redis; using System; using System.Globalization; +using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; +using ZiggyCreatures.Caching.Fusion.Backplane.StackExchangeRedis; +using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson; namespace MP.Land { @@ -121,12 +126,22 @@ namespace MP.Land options.FallbackPolicy = options.DefaultPolicy; }); + + // REDIS setup string connStringRedis = Configuration.GetConnectionString("Redis"); string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":")); // avvio oggetto shared x redis... - var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); + IConnectionMultiplexer redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); + // ✅ FusionCache + services.AddFusionCache() + .WithDistributedCache(sp => sp.GetRequiredService()) + .WithSerializer(new FusionCacheNewtonsoftJsonSerializer()) + .WithBackplane(new RedisBackplane(new RedisBackplaneOptions + { + ConnectionMultiplexerFactory = () => Task.FromResult(redisMultiplexer) + })); services.AddLocalization(); @@ -143,6 +158,20 @@ namespace MP.Land .EnableSensitiveDataLogging(false) // true solo in Sviluppo .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + var connStrFlux = Configuration.GetConnectionString("MP.Flux") + ?? throw new InvalidOperationException("ConnString 'MP.Flux' mancante."); + services.AddDbContextFactory(options => + options.UseSqlServer(connStrFlux) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + + var connStrStats = Configuration.GetConnectionString("MP.Stats") + ?? throw new InvalidOperationException("ConnString 'MP.Stats' mancante."); + services.AddDbContextFactory(options => + options.UseSqlServer(connStrStats) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + //init servizi specifici LAND //services.AddAuthLandDataLayer(); services.AddLandDataLayer(); From 8c6bf075fb517a147248b3a110bfcdb13b248852 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 4 Jun 2026 08:12:05 +0200 Subject: [PATCH 11/12] Completata review di tutti i progetti coi nuovi repository! --- MP-TAB3/MP-TAB3.csproj | 2 +- MP-TAB3/Program.cs | 53 ++++++++++++++----- MP-TAB3/Resources/ChangeLog.html | 2 +- MP-TAB3/Resources/VersNum.txt | 2 +- MP-TAB3/Resources/manifest.xml | 2 +- MP-TAB3/appsettings.json | 8 +-- MP.Data/DataServiceCollectionExtensions.cs | 17 ++++++ MP.INVE/MP.INVE.csproj | 2 +- MP.INVE/Resources/ChangeLog.html | 2 +- MP.INVE/Resources/VersNum.txt | 2 +- MP.INVE/Resources/manifest.xml | 2 +- MP.IOC/MP.IOC.csproj | 2 +- MP.IOC/Resources/ChangeLog.html | 2 +- MP.IOC/Resources/VersNum.txt | 2 +- MP.IOC/Resources/manifest.xml | 2 +- MP.MON/MP.MON.csproj | 2 +- MP.MON/Resources/ChangeLog.html | 2 +- MP.MON/Resources/VersNum.txt | 2 +- MP.MON/Resources/manifest.xml | 2 +- MP.Prog/MP.Prog.csproj | 2 +- MP.Prog/Resources/ChangeLog.html | 2 +- MP.Prog/Resources/VersNum.txt | 2 +- MP.Prog/Resources/manifest.xml | 2 +- MP.Prog/Startup.cs | 11 ---- .../Components/Reparti/ListOperatori.razor.cs | 2 +- MP.SPEC/Data/MpDataService.cs | 10 +++- MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Program.cs | 7 +++ MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- MP.SPEC/appsettings.json | 1 + MP.Stats/Data/MpStatsService.cs | 7 ++- MP.Stats/MP.Stats.csproj | 2 +- MP.Stats/Resources/ChangeLog.html | 2 +- MP.Stats/Resources/VersNum.txt | 2 +- MP.Stats/Resources/manifest.xml | 2 +- MP.Stats/Startup.cs | 40 ++++++++++++-- MP.Stats/appsettings.json | 2 - 39 files changed, 148 insertions(+), 66 deletions(-) diff --git a/MP-TAB3/MP-TAB3.csproj b/MP-TAB3/MP-TAB3.csproj index b3d96ba1..d50f5fb4 100644 --- a/MP-TAB3/MP-TAB3.csproj +++ b/MP-TAB3/MP-TAB3.csproj @@ -3,7 +3,7 @@ net8.0 enable - 8.16.2606.311 + 8.16.2606.407 enable MP_TAB3 diff --git a/MP-TAB3/Program.cs b/MP-TAB3/Program.cs index 178df0d6..f00f0736 100644 --- a/MP-TAB3/Program.cs +++ b/MP-TAB3/Program.cs @@ -2,16 +2,18 @@ using Blazored.LocalStorage; using Blazored.SessionStorage; #endif -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Web; -using Microsoft.AspNetCore.StaticFiles; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.FileProviders; using MP.Data; using MP.Data.Services; using NLog; using NLog.Web; using StackExchange.Redis; -using static Org.BouncyCastle.Math.EC.ECCurve; +using ZiggyCreatures.Caching.Fusion; +using ZiggyCreatures.Caching.Fusion.Backplane.StackExchangeRedis; +using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson; var builder = WebApplication.CreateBuilder(args); @@ -27,15 +29,45 @@ var cString = configuration.GetConnectionString("Redis"); string connStringRedis = cString ?? "localhost:6379, DefaultDatabase=5, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false"; //string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":")); // avvio oggetto shared x redis... -var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); +IConnectionMultiplexer redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); // Add services x accesso dati builder.Services.AddSingleton(redisMultiplexer); +// ✅ FusionCache +builder.Services.AddFusionCache() + .WithDistributedCache(sp => sp.GetRequiredService()) + .WithSerializer(new FusionCacheNewtonsoftJsonSerializer()) + .WithBackplane(new RedisBackplane(new RedisBackplaneOptions + { + ConnectionMultiplexerFactory = () => Task.FromResult(redisMultiplexer) + })); + +// Metodi principali x accesso dati +var connStr = builder.Configuration.GetConnectionString("MP.Data") + ?? throw new InvalidOperationException("ConnString 'MP.Data' mancante."); +// aggiungo il costruttore x i vari DbContextFactory +builder.Services.AddDbContextFactory(options => + options.UseSqlServer(connStr) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + +var connStrFL = builder.Configuration.GetConnectionString("MP.Flux") + ?? throw new InvalidOperationException("ConnString 'MP.Flux' mancante."); +builder.Services.AddDbContextFactory(options => + options.UseSqlServer(connStrFL) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); + +// Init centralizzato Repository/Servizi da MP.Data Services +builder.Services.AddTabDataLayer(); + +#if false builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -43,13 +75,10 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); -#if false -builder.Services.AddBlazoredLocalStorage(); -builder.Services.AddBlazoredSessionStorage(); -#endif // aggiunta helper local/session storage service builder.Services.AddScoped(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); +#endif // gestione email builder.Services.Configure(builder.Configuration.GetSection(nameof(MailKitMailSettings))); @@ -62,7 +91,7 @@ logger.Info("Aggiunti services"); var app = builder.Build(); // aggiunt base URL x routing corretto -var pathBase= configuration.GetValue("SpecialConf:AppUrl") ?? (configuration.GetValue("OptConf:AppUrl") ?? ""); +var pathBase = configuration.GetValue("SpecialConf:AppUrl") ?? (configuration.GetValue("OptConf:AppUrl") ?? ""); app.UsePathBase(pathBase); // Configure the HTTP request pipeline. @@ -78,7 +107,7 @@ app.UseHttpsRedirection(); app.UseStaticFiles(); // gestione static files: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-8.0 -string BasePathDisegni = configuration.GetValue("ServerConf:BasePathDisegni") ?? configuration.GetValue("OptConf:BasePathDisegni")?? ""; +string BasePathDisegni = configuration.GetValue("ServerConf:BasePathDisegni") ?? configuration.GetValue("OptConf:BasePathDisegni") ?? ""; if (!string.IsNullOrEmpty(BasePathDisegni)) { // verifico esista folder disegni diff --git a/MP-TAB3/Resources/ChangeLog.html b/MP-TAB3/Resources/ChangeLog.html index 40cd97d7..8907be06 100644 --- a/MP-TAB3/Resources/ChangeLog.html +++ b/MP-TAB3/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

                          Versione: 8.16.2606.311

                          +

                          Versione: 8.16.2606.407


                          Note di rilascio:
                          • diff --git a/MP-TAB3/Resources/VersNum.txt b/MP-TAB3/Resources/VersNum.txt index aa5451d0..0d17f6bd 100644 --- a/MP-TAB3/Resources/VersNum.txt +++ b/MP-TAB3/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.311 +8.16.2606.407 diff --git a/MP-TAB3/Resources/manifest.xml b/MP-TAB3/Resources/manifest.xml index f12d84a9..ab911600 100644 --- a/MP-TAB3/Resources/manifest.xml +++ b/MP-TAB3/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.311 + 8.16.2606.407 https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/MP-TAB3.zip https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/ChangeLog.html false diff --git a/MP-TAB3/appsettings.json b/MP-TAB3/appsettings.json index 6ef14f69..47c80c14 100644 --- a/MP-TAB3/appsettings.json +++ b/MP-TAB3/appsettings.json @@ -8,16 +8,10 @@ "AllowedHosts": "*", "CodApp": "MP.TAB", "ConnectionStrings": { - //"Redis": "redis.ufficio:26379,serviceName=devel,DefaultDatabase=6,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true", - //"MP.All": "Server=SQL2022PROD;Database=Donati_LAV_MoonPro_prod; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;", - //"MP.Mon": "Server=SQL2022PROD;Database=Donati_LAV_MoonPro_prod; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;", - //"MP.IS": "Server=SQL2022PROD;Database=MoonPro_IS_EdilChim; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.INVE;", - //"MP.Tab": "Server=SQL2022PROD;Database=Donati_LAV_MoonPro_prod; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;", - //"MP.Mag": "Server=SQL2022PROD;Database=MoonPro_MAG; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;" - "Redis": "redis.ufficio:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true", "MP.All": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;", "MP.Data": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;", + "MP.Flux": "Server=SQL2016DEV;Database=MoonPro_FluxData; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;", "MP.Mon": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;", "MP.IS": "Server=SQL2016DEV;Database=MoonPro_IS_EdilChim; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.INVE;", "MP.Tab": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.TAB3;", diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index 826ce9f2..ddc1ef7c 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -148,6 +148,23 @@ namespace MP.Data /// public static IServiceCollection AddTabDataLayer(this IServiceCollection services) { + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + + services.TryAddSingleton(); + + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddScoped(); + // aggiunta helper local/session storage service + services.TryAddScoped(); + services.TryAddScoped(); return services; } diff --git a/MP.INVE/MP.INVE.csproj b/MP.INVE/MP.INVE.csproj index d12186f5..ef7907fa 100644 --- a/MP.INVE/MP.INVE.csproj +++ b/MP.INVE/MP.INVE.csproj @@ -5,7 +5,7 @@ enable enable MP.INVE - 8.16.2606.311 + 8.16.2606.408 diff --git a/MP.INVE/Resources/ChangeLog.html b/MP.INVE/Resources/ChangeLog.html index aff20529..878755a2 100644 --- a/MP.INVE/Resources/ChangeLog.html +++ b/MP.INVE/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOINVE -

                            Versione: 8.16.2606.311

                            +

                            Versione: 8.16.2606.408


                            Note di rilascio:
                            • diff --git a/MP.INVE/Resources/VersNum.txt b/MP.INVE/Resources/VersNum.txt index aa5451d0..988a0006 100644 --- a/MP.INVE/Resources/VersNum.txt +++ b/MP.INVE/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.311 +8.16.2606.408 diff --git a/MP.INVE/Resources/manifest.xml b/MP.INVE/Resources/manifest.xml index 5e64eb24..e69c68e1 100644 --- a/MP.INVE/Resources/manifest.xml +++ b/MP.INVE/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.311 + 8.16.2606.408 https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/MP.INVE.zip https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/ChangeLog.html false diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 29e1b914..5f54a793 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 8.16.2606.318 + 8.16.2606.407 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 0f1cd517..60835c6f 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

                              Versione: 8.16.2606.318

                              +

                              Versione: 8.16.2606.407


                              Note di rilascio:
                              • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index ea702b6d..0d17f6bd 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.318 +8.16.2606.407 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 1ddeedf0..e5620788 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.318 + 8.16.2606.407 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 diff --git a/MP.MON/MP.MON.csproj b/MP.MON/MP.MON.csproj index 1d8ab17b..f0bd44bd 100644 --- a/MP.MON/MP.MON.csproj +++ b/MP.MON/MP.MON.csproj @@ -6,7 +6,7 @@ enable MP.MON $(AssemblyName.Replace(' ', '_')) - 8.16.2606.312 + 8.16.2606.318 diff --git a/MP.MON/Resources/ChangeLog.html b/MP.MON/Resources/ChangeLog.html index 81ed3f86..0e773c8e 100644 --- a/MP.MON/Resources/ChangeLog.html +++ b/MP.MON/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

                                Versione: 8.16.2606.312

                                +

                                Versione: 8.16.2606.318


                                Note di rilascio:
                                • diff --git a/MP.MON/Resources/VersNum.txt b/MP.MON/Resources/VersNum.txt index 1b236191..ea702b6d 100644 --- a/MP.MON/Resources/VersNum.txt +++ b/MP.MON/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.312 +8.16.2606.318 diff --git a/MP.MON/Resources/manifest.xml b/MP.MON/Resources/manifest.xml index ef808f77..f12feb05 100644 --- a/MP.MON/Resources/manifest.xml +++ b/MP.MON/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.312 + 8.16.2606.318 https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/MP.MON.zip https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/ChangeLog.html false diff --git a/MP.Prog/MP.Prog.csproj b/MP.Prog/MP.Prog.csproj index 82cdeb00..add2792d 100644 --- a/MP.Prog/MP.Prog.csproj +++ b/MP.Prog/MP.Prog.csproj @@ -3,7 +3,7 @@ net8.0 MP.Prog - 8.16.2606.0310 + 8.16.2606.0408 True diff --git a/MP.Prog/Resources/ChangeLog.html b/MP.Prog/Resources/ChangeLog.html index 03a88103..ad30d9e0 100644 --- a/MP.Prog/Resources/ChangeLog.html +++ b/MP.Prog/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo gestione Programmi MAPO -

                                  Versione: 8.16.2606.0310

                                  +

                                  Versione: 8.16.2606.0408


                                  Note di rilascio:
                                    diff --git a/MP.Prog/Resources/VersNum.txt b/MP.Prog/Resources/VersNum.txt index 6970c00b..47fe7fc3 100644 --- a/MP.Prog/Resources/VersNum.txt +++ b/MP.Prog/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.0310 +8.16.2606.0408 diff --git a/MP.Prog/Resources/manifest.xml b/MP.Prog/Resources/manifest.xml index 70ae7425..93ee4351 100644 --- a/MP.Prog/Resources/manifest.xml +++ b/MP.Prog/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.0310 + 8.16.2606.0408 https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Prog.zip https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html false diff --git a/MP.Prog/Startup.cs b/MP.Prog/Startup.cs index 8f941fab..0e2707af 100644 --- a/MP.Prog/Startup.cs +++ b/MP.Prog/Startup.cs @@ -88,9 +88,6 @@ namespace MP.Prog }); CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("it-IT"); - //// Registrazione Elmah: - //// https://github.com/ElmahCore/ElmahCore - //app.UseElmah(); // fix forwarders app.UseForwardedHeaders(new ForwardedHeadersOptions @@ -152,14 +149,6 @@ namespace MP.Prog o.SlidingExpiration = true; }); - //// Elmah - //services.AddElmah(); - //string elmaConn = "Data Source=SQL2016DEV;Initial Catalog=Elmah;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=SHERPA.BBM;"; - //services.AddElmah(options => - //{ - // options.ConnectionString = elmaConn; - //}); - #if false services.AddStackExchangeRedisCache(options => { diff --git a/MP.SPEC/Components/Reparti/ListOperatori.razor.cs b/MP.SPEC/Components/Reparti/ListOperatori.razor.cs index 03bf5bca..73f18c0b 100644 --- a/MP.SPEC/Components/Reparti/ListOperatori.razor.cs +++ b/MP.SPEC/Components/Reparti/ListOperatori.razor.cs @@ -155,7 +155,7 @@ namespace MP.SPEC.Components.Reparti } private async Task DoReset() { - selRec = null; + selRec = null; await EC_RecSel.InvokeAsync(null); } diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index f6768500..8ddbce9d 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -31,7 +31,15 @@ namespace MP.SPEC.Data private readonly IFluxLogRepository _fluxLogRepository; private readonly IProductionRepository _productionRepository; - public MpDataService(IConnectionMultiplexer connMPlex, IConfiguration configuration, IFusionCache cache, IAnagRepository anagRepository, ISystemRepository systemRepository, IDossierRepository dossierRepository, IFluxLogRepository fluxLogRepository, IProductionRepository productionRepository) + public MpDataService( + IConnectionMultiplexer connMPlex, + IConfiguration configuration, + IFusionCache cache, + IAnagRepository anagRepository, + ISystemRepository systemRepository, + IDossierRepository dossierRepository, + IFluxLogRepository fluxLogRepository, + IProductionRepository productionRepository) { // salvataggio oggetti _configuration = configuration; diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 0c0a71b8..57e69437 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 8.16.2606.317 + 8.16.2606.407 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Program.cs b/MP.SPEC/Program.cs index 04f79f14..a90fc99b 100644 --- a/MP.SPEC/Program.cs +++ b/MP.SPEC/Program.cs @@ -177,6 +177,13 @@ builder.Services.AddDbContextFactory(options => .EnableSensitiveDataLogging(false) // true solo in Sviluppo .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); +var connStrSta = builder.Configuration.GetConnectionString("MP.Stats") + ?? throw new InvalidOperationException("ConnString 'MP.Stats' mancante."); +builder.Services.AddDbContextFactory(options => + options.UseSqlServer(connStrSta) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + // Init centralizzato Repository/Servizi da MP.Data Services builder.Services.AddSpecDataLayer(); diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 56193a1d..8907be06 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

                                    Versione: 8.16.2606.317

                                    +

                                    Versione: 8.16.2606.407


                                    Note di rilascio:
                                    • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 8c2eaf7f..0d17f6bd 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.317 +8.16.2606.407 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index e67b9b17..3ce53f92 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.317 + 8.16.2606.407 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false diff --git a/MP.SPEC/appsettings.json b/MP.SPEC/appsettings.json index 594aca27..6bda77be 100644 --- a/MP.SPEC/appsettings.json +++ b/MP.SPEC/appsettings.json @@ -63,6 +63,7 @@ "MP.Land": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", "MP.Land.Auth": "Server=SQL2016DEV;Database=MoonPro_Anagrafica; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", "MP.Sched": "Server=SQL2016DEV;Database=MoonPro_ES3; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", + "MP.Stats": "Server=SQL2016DEV;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.SPEC;", "Redis": "redis.ufficio:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true", "RedisAdmin": "redis.ufficio:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true", "mdbConnString": "mongodb://W2019-MONGODB:27017" diff --git a/MP.Stats/Data/MpStatsService.cs b/MP.Stats/Data/MpStatsService.cs index 54e4803b..247fa567 100644 --- a/MP.Stats/Data/MpStatsService.cs +++ b/MP.Stats/Data/MpStatsService.cs @@ -11,6 +11,7 @@ using System.Data; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; namespace MP.Stats.Data { @@ -24,7 +25,11 @@ namespace MP.Stats.Data #region Public Constructors - public MpStatsService(IConfiguration configuration, IConnectionMultiplexer redConn) : base(configuration, redConn) + public MpStatsService( + IConfiguration configuration, + IConnectionMultiplexer redConn, + IFusionCache cache + ) : base(configuration, cache, redConn) { Stopwatch sw = Stopwatch.StartNew(); sw.Start(); diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 73e0c184..6a9935f9 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,7 +4,7 @@ net8.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 8.16.2606.0311 + 8.16.2606.0408 true en diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index 7ee0c500..793e14ba 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

                                      Versione: 8.16.2606.0311

                                      +

                                      Versione: 8.16.2606.0408


                                      Note di rilascio:
                                        diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index 4143bf31..47fe7fc3 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.0311 +8.16.2606.0408 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index 7a375362..0a7e3eaa 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.0311 + 8.16.2606.0408 https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false diff --git a/MP.Stats/Startup.cs b/MP.Stats/Startup.cs index 3511f254..17c36165 100644 --- a/MP.Stats/Startup.cs +++ b/MP.Stats/Startup.cs @@ -1,10 +1,14 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Localization; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; +using MP.Data; using MP.Data.Services; using MP.Stats.Data; using MP.TaskMan.Services; @@ -13,6 +17,10 @@ using System; using System.Globalization; using System.IO; using System.Reflection; +using System.Threading.Tasks; +using ZiggyCreatures.Caching.Fusion; +using ZiggyCreatures.Caching.Fusion.Backplane.StackExchangeRedis; +using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson; namespace MP.Stats { @@ -133,11 +141,35 @@ namespace MP.Stats var cString = Configuration.GetConnectionString("Redis"); string connStringRedis = cString ?? "localhost:6379, DefaultDatabase=5, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false"; // avvio oggetto shared x redis... - var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); + IConnectionMultiplexer redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); + + // ✅ FusionCache + services.AddFusionCache() + .WithDistributedCache(sp => sp.GetRequiredService()) + .WithSerializer(new FusionCacheNewtonsoftJsonSerializer()) + .WithBackplane(new RedisBackplane(new RedisBackplaneOptions + { + ConnectionMultiplexerFactory = () => Task.FromResult(redisMultiplexer) + })); // Add services x accesso dati services.AddSingleton(redisMultiplexer); + // aggiungo il costruttore x i vari DbContextFactory + var connStr = Configuration.GetConnectionString("MP.Stats") + ?? throw new InvalidOperationException("ConnString 'MP.Stats' mancante."); + services.AddDbContextFactory(options => + options.UseSqlServer(connStr) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + + var connStrVoc = Configuration.GetConnectionString("MP.Voc") + ?? throw new InvalidOperationException("ConnString 'MP.Voc' mancante."); + services.AddDbContextFactory(options => + options.UseSqlServer(connStrVoc) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + services.AddLocalization(); @@ -145,9 +177,11 @@ namespace MP.Stats services.AddServerSideBlazor(); services.AddSingleton(Configuration); + services.AddStatsDataLayer(); + //services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); services.AddScoped(); } diff --git a/MP.Stats/appsettings.json b/MP.Stats/appsettings.json index 0dc6bccb..56b81552 100644 --- a/MP.Stats/appsettings.json +++ b/MP.Stats/appsettings.json @@ -53,8 +53,6 @@ "ConnectionStrings": { "DefaultConnection": "Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;MultipleActiveResultSets=true", "MP.Stats": "Server=SQL2016DEV;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;", - //"DefaultConnection": "Server=SQL2016DEV;Database=Jetco_MoonPro_STATS_Prod;Trusted_Connection=True;MultipleActiveResultSets=true", - //"MP.Stats": "Server=SQL2022PROD;Database=Jetco_MoonPro_STATS_Prod;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;", "MP.Voc": "Server=SQL2016DEV;Database=MoonPro;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;", "Redis": "redis.ufficio:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true" }, From 561c073489344d9801eb7013105dcb49737d4595 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 4 Jun 2026 08:13:10 +0200 Subject: [PATCH 12/12] Refresh compilazione --- MP-TAB3/MP-TAB3.csproj | 2 +- MP-TAB3/Resources/ChangeLog.html | 2 +- MP-TAB3/Resources/VersNum.txt | 2 +- MP-TAB3/Resources/manifest.xml | 2 +- MP.IOC/MP.IOC.csproj | 2 +- MP.IOC/Resources/ChangeLog.html | 2 +- MP.IOC/Resources/VersNum.txt | 2 +- MP.IOC/Resources/manifest.xml | 2 +- MP.Land/MP.Land.csproj | 2 +- MP.Land/Resources/ChangeLog.html | 2 +- MP.Land/Resources/VersNum.txt | 2 +- MP.Land/Resources/manifest.xml | 2 +- MP.MON/MP.MON.csproj | 2 +- MP.MON/Resources/ChangeLog.html | 2 +- MP.MON/Resources/VersNum.txt | 2 +- MP.MON/Resources/manifest.xml | 2 +- MP.RIOC/MP.RIOC.csproj | 2 +- MP.RIOC/Resources/ChangeLog.html | 2 +- MP.RIOC/Resources/VersNum.txt | 2 +- MP.RIOC/Resources/manifest.xml | 2 +- MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/MP-TAB3/MP-TAB3.csproj b/MP-TAB3/MP-TAB3.csproj index d50f5fb4..f073261a 100644 --- a/MP-TAB3/MP-TAB3.csproj +++ b/MP-TAB3/MP-TAB3.csproj @@ -3,7 +3,7 @@ net8.0 enable - 8.16.2606.407 + 8.16.2606.408 enable MP_TAB3 diff --git a/MP-TAB3/Resources/ChangeLog.html b/MP-TAB3/Resources/ChangeLog.html index 8907be06..6e774415 100644 --- a/MP-TAB3/Resources/ChangeLog.html +++ b/MP-TAB3/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

                                        Versione: 8.16.2606.407

                                        +

                                        Versione: 8.16.2606.408


                                        Note di rilascio:
                                        • diff --git a/MP-TAB3/Resources/VersNum.txt b/MP-TAB3/Resources/VersNum.txt index 0d17f6bd..988a0006 100644 --- a/MP-TAB3/Resources/VersNum.txt +++ b/MP-TAB3/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.407 +8.16.2606.408 diff --git a/MP-TAB3/Resources/manifest.xml b/MP-TAB3/Resources/manifest.xml index ab911600..1c9cc682 100644 --- a/MP-TAB3/Resources/manifest.xml +++ b/MP-TAB3/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.407 + 8.16.2606.408 https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/MP-TAB3.zip https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/ChangeLog.html false diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 5f54a793..96e0e3b4 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 8.16.2606.407 + 8.16.2606.408 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 60835c6f..421f226c 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

                                          Versione: 8.16.2606.407

                                          +

                                          Versione: 8.16.2606.408


                                          Note di rilascio:
                                          • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index 0d17f6bd..988a0006 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.407 +8.16.2606.408 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index e5620788..c0b40892 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.407 + 8.16.2606.408 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 diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index d7bc72a6..0bbf51c6 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net8.0 MP.Land - 8.16.2606.0318 + 8.16.2606.0408 Debug;Release;Debug_LiManDebug en True diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index 5cc46a2e..72c86f08 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo Tablet MAPO - DotNet6 -

                                            Versione: 8.16.2606.0318

                                            +

                                            Versione: 8.16.2606.0408


                                            Note di rilascio:
                                              diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index c21e857b..47fe7fc3 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.0318 +8.16.2606.0408 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index d2e91e50..1b36f10a 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.0318 + 8.16.2606.0408 https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html false diff --git a/MP.MON/MP.MON.csproj b/MP.MON/MP.MON.csproj index f0bd44bd..1af13f40 100644 --- a/MP.MON/MP.MON.csproj +++ b/MP.MON/MP.MON.csproj @@ -6,7 +6,7 @@ enable MP.MON $(AssemblyName.Replace(' ', '_')) - 8.16.2606.318 + 8.16.2606.408 diff --git a/MP.MON/Resources/ChangeLog.html b/MP.MON/Resources/ChangeLog.html index 0e773c8e..6e774415 100644 --- a/MP.MON/Resources/ChangeLog.html +++ b/MP.MON/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

                                              Versione: 8.16.2606.318

                                              +

                                              Versione: 8.16.2606.408


                                              Note di rilascio:
                                              • diff --git a/MP.MON/Resources/VersNum.txt b/MP.MON/Resources/VersNum.txt index ea702b6d..988a0006 100644 --- a/MP.MON/Resources/VersNum.txt +++ b/MP.MON/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.318 +8.16.2606.408 diff --git a/MP.MON/Resources/manifest.xml b/MP.MON/Resources/manifest.xml index f12feb05..39fe57dc 100644 --- a/MP.MON/Resources/manifest.xml +++ b/MP.MON/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.318 + 8.16.2606.408 https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/MP.MON.zip https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/ChangeLog.html false diff --git a/MP.RIOC/MP.RIOC.csproj b/MP.RIOC/MP.RIOC.csproj index 03533e4f..a506ab6c 100644 --- a/MP.RIOC/MP.RIOC.csproj +++ b/MP.RIOC/MP.RIOC.csproj @@ -5,7 +5,7 @@ enable enable MP.RIOC - 8.16.2606.318 + 8.16.2606.408 diff --git a/MP.RIOC/Resources/ChangeLog.html b/MP.RIOC/Resources/ChangeLog.html index c71c5486..e25fa8ef 100644 --- a/MP.RIOC/Resources/ChangeLog.html +++ b/MP.RIOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-RIOC -

                                                Versione: 8.16.2606.318

                                                +

                                                Versione: 8.16.2606.408


                                                Note di rilascio:
                                                • diff --git a/MP.RIOC/Resources/VersNum.txt b/MP.RIOC/Resources/VersNum.txt index ea702b6d..988a0006 100644 --- a/MP.RIOC/Resources/VersNum.txt +++ b/MP.RIOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.318 +8.16.2606.408 diff --git a/MP.RIOC/Resources/manifest.xml b/MP.RIOC/Resources/manifest.xml index 734be1e1..ceddb51b 100644 --- a/MP.RIOC/Resources/manifest.xml +++ b/MP.RIOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.318 + 8.16.2606.408 https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/MP.RIOC.zip https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/ChangeLog.html false diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 57e69437..2ab421b2 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 8.16.2606.407 + 8.16.2606.408 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 8907be06..6e774415 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

                                                  Versione: 8.16.2606.407

                                                  +

                                                  Versione: 8.16.2606.408


                                                  Note di rilascio:
                                                  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 0d17f6bd..988a0006 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.407 +8.16.2606.408 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index 3ce53f92..c43a43f3 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.407 + 8.16.2606.408 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false
                    Matr. Anagr.
                    -
                    @record.MatrOpr
                    +
                    -
                    @record.Cognome @record.Nome
                    +
                    +
                    @item.MatrOpr
                    - + +
                    @item.Cognome @item.Nome
                    + + + @if (item.isEnabled) + { + + } + else + { + + } +
                    - @if (EditRec == null) + @if (EditEnabled) { - - } - else - { - - } - @if (SelRecord == null) - { - + if (EditRec == null) + { + + } + else + { + + } + if (SelRecord == null) + { + + } } @record.CountMacc @record.CountOpr - @if (DelEnabled(record)) + @if (EditEnabled) { - - } - else - { - + if (DelEnabled(record)) + { + + } + else + { + + } }