Continua revisione codice assisted

This commit is contained in:
Samuele E. Locatelli (W11-AI)
2026-06-02 20:02:38 +02:00
parent 0a6133a0c9
commit 843435ad3b
7 changed files with 99 additions and 94 deletions
@@ -78,6 +78,7 @@ namespace MP.Data
// ---------- Start Altro ----------
// Singleton
services.TryAddSingleton<AppAuthService>();
services.TryAddScoped<OrderDataSrv>();
services.TryAddSingleton<ListSelectDataSrv>();
services.TryAddSingleton<SharedMemService>();
services.TryAddSingleton<TabDataService>();
+3 -4
View File
@@ -431,14 +431,13 @@ namespace MP.Data.Repository.Anag
}
/// <summary>
/// Recupero dizionario traduzioni da cache o DB
/// Recupero dizionario traduzioni
/// </summary>
/// <param name="lingua">Codice lingua</param>
/// <returns>Dizionario di traduzioni</returns>
public async Task<Dictionary<string, string>> VocabolarioGetLangAsync(string lingua)
public Dictionary<string, string> VocabolarioGetLang(string lingua)
{
await using var dbCtx = await CreateContextAsync();
using var dbCtx = _ctxFactory.CreateDbContextAsync().GetAwaiter().GetResult();
var rawList = dbCtx
.DbSetVocabolario
.AsNoTracking()
+2 -2
View File
@@ -191,11 +191,11 @@ namespace MP.Data.Repository.Anag
Task<Dictionary<int, int>> PODL_getDictOdlPodlAsync(List<int> missingIds);
/// <summary>
/// Recupero dizionario traduzioni da cache o DB
/// Recupero dizionario traduzioni
/// </summary>
/// <param name="lingua">Codice lingua</param>
/// <returns>Dizionario di traduzioni</returns>
Task<Dictionary<string, string>> VocabolarioGetLangAsync(string lingua);
Dictionary<string, string> VocabolarioGetLang(string lingua);
#endregion Public Methods
}
@@ -104,6 +104,18 @@ namespace MP.Data.Repository.Dossier
return await dbCtx.SaveChangesAsync() > 0;
}
/// <inheritdoc />
public async Task<List<string>> ArticleWithDossierAsync()
{
await using var dbCtx = new MoonPro_FluxContext(_configuration);
return await dbCtx
.DbSetDossiers
.AsNoTracking()
.Select(i => i.CodArticolo)
.Distinct()
.ToListAsync();
}
#endregion
}
}
@@ -19,6 +19,8 @@ namespace MP.Data.Repository.Dossier
Task<bool> DossiersUpdateValoreAsync(DossierModel editRec);
Task<List<string>> ArticleWithDossierAsync();
#endregion
}
}
+2 -2
View File
@@ -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
+77 -86
View File
@@ -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<bool>("Otel:EnableTracing", false);
slowLogThresh = _configuration.GetValue<double>("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<string>("ServerConf:redisShortTimeCache"), out redisShortTimeCache);
int.TryParse(_configuration.GetValue<string>("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<string>("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
/// <summary>
/// Elenco Codice articolo con dati dossier gestiti
/// Elenco codice articoli che abbiano dati Dossier
/// </summary>
/// <returns></returns>
public async Task<List<string>> ArticleWithDossierAsync()
@@ -256,10 +246,11 @@ namespace MP.SPEC.Data
operationName: "ArticleWithDossierAsync",
cacheKey: Utils.redisArtByDossier,
expiration: GetRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.ArticleWithDossierAsync() ?? new List<string>(),
fetchFunc: async () => await _dossierRepository.ArticleWithDossierAsync() ?? new List<string>(),
tagList: [Utils.redisArtByDossier]
);
}
#endif
/// <summary>
/// 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<ConfigModel>(),
fetchFunc: async () => await _systemRepository.ConfigGetAllAsync() ?? new List<ConfigModel>(),
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<DossierModel>(),
fetchFunc: async () => await _dossierRepository.DossiersGetLastFiltAsync(IdxMacchina, CodArticolo, DtStart, DtEnd, MaxRec) ?? new List<DossierModel>(),
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<LinkMenuModel>(),
fetchFunc: async () => await _systemRepository.ElencoLinkAsync() ?? new List<LinkMenuModel>(),
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<StatDedupDTO> procStats = await dbController.FluxLogDataReduxAsync(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem);
List<StatDedupDTO> 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<FluxLogModel>(),
fetchFunc: async () => await _fluxLogRepository.FluxLogGetLastFiltAsync(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec) ?? new List<FluxLogModel>(),
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<ParetoFluxLogDTO>(),
fetchFunc: async () => await _fluxLogRepository.FluxLogParetoAsync(idxMacchina, dtFrom, dtTo) ?? new List<ParetoFluxLogDTO>(),
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<IstanzeKitModel>(),
fetchFunc: async () => await _productionRepository.IstKitFiltAsync(keyKit, keyExtOrd) ?? new List<IstanzeKitModel>(),
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<AnagGiacenzeModel>(),
fetchFunc: async () => await _productionRepository.ListGiacenzeAsync(IdxOdl) ?? new List<AnagGiacenzeModel>(),
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<MacchineModel>(),
fetchFunc: async () =>
await _productionRepository.MacchineGetFiltAsync(codGruppo)
?? new List<MacchineModel>(),
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<string>(),
fetchFunc: async () => await _productionRepository.MacchineWithFluxAsync(dtStart, dtEnd) ?? new List<string>(),
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<AnagOperatoriModel>(),
fetchFunc: async () => await _productionRepository.OperatoriGetFiltAsync(codGruppo) ?? new List<AnagOperatoriModel>(),
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<int, int> ottimizzato da EF Core
Dictionary<int, int> dbResults = await dbController.PODL_getDictOdlPodlAsync(missingIds);
Dictionary<int, int> 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<PODLExpModel>(),
fetchFunc: async () => await _productionRepository.ListPODLFiltAsync(lanciato, keyRichPart, idxMacchina, codGruppo, startDate, endDate) ?? new List<PODLExpModel>(),
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<TemplateKitModel>(),
fetchFunc: async () => await _productionRepository.TemplateKitFiltAsync(codParent, codChild) ?? new List<TemplateKitModel>(),
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<TksScoreModel>();
var result = await _productionRepository.TksScoreAsync(KeyFilt, MaxResult) ?? new List<TksScoreModel>();
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<TksScoreModel>(),
fetchFunc: async () => await _productionRepository.TksScoreAsync(KeyFilt, MaxResult) ?? new List<TksScoreModel>(),
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<Dictionary<string, string>>(
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<WipSetupKitModel>(),
fetchFunc: async () => await _productionRepository.WipKitFiltAsync(KeyFilt) ?? new List<WipSetupKitModel>(),
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);