diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index ddc1ef7c..03a1f181 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -35,9 +35,11 @@ namespace MP.Data // Repository Singleton services.TryAddSingleton(); services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); - // Repository Scoped - services.TryAddScoped(); + // Repository Scoped (non usate da MpDataService) services.TryAddScoped(); services.TryAddScoped(); diff --git a/MP.Data/Repository/Anag/AnagRepository.cs b/MP.Data/Repository/Anag/AnagRepository.cs index 03721446..5b3f7eb5 100644 --- a/MP.Data/Repository/Anag/AnagRepository.cs +++ b/MP.Data/Repository/Anag/AnagRepository.cs @@ -27,55 +27,25 @@ namespace MP.Data.Repository.Anag { AnagCountersModel answ = new AnagCountersModel(); await using var dbCtx = await CreateContextAsync(); - bool outTable = true; - if (outTable) - { - var pCntType = new SqlParameter("@CntType", cntType); - var pLastNum = new SqlParameter - { - ParameterName = "@LastNum", - SqlDbType = SqlDbType.Int, - Direction = ParameterDirection.Output - }; - var dbResult = await dbCtx - .DbSetAnagCount - .FromSqlRaw("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT", pCntType, pLastNum) - .AsNoTracking() - .FirstOrDefaultAsync(); - if (dbResult != null) - { - answ = dbResult; - } - } - else + var pCntType = new SqlParameter("@CntType", cntType); + var pLastNum = new SqlParameter { - // se si volessero impiegare parametri OUTPUT (qui ne mancherebbe 1 nella stored x CntCode...) - var pCntType = new SqlParameter("@CntType", cntType); - var pLastNum = new SqlParameter - { - ParameterName = "@LastNum", - SqlDbType = SqlDbType.Int, - Direction = ParameterDirection.Output - }; - var pCntCode = new SqlParameter - { - ParameterName = "@CntCode", - SqlDbType = SqlDbType.NVarChar, - Direction = ParameterDirection.Output - }; - var dbResult = await dbCtx - .Database - .ExecuteSqlRawAsync("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT, @CntCode OUTPUT", pCntType, pLastNum, pCntCode); - if (dbResult != 0) - { - answ.CntType = cntType; - answ.CntCode = $"{pCntCode.Value}"; - int lNum = 0; - int.TryParse($"{pLastNum.Value}", out lNum); - answ.LastNum = lNum; - } + ParameterName = "@LastNum", + SqlDbType = SqlDbType.Int, + Direction = ParameterDirection.Output + }; + + var dbResult = (await dbCtx + .DbSetAnagCount + .FromSqlRaw("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT", pCntType, pLastNum) + .AsNoTracking() + .ToListAsync()).FirstOrDefault(); + if (dbResult != null) + { + answ = dbResult; } + return answ; } diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index fc850daf..e8cde00d 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -16,6 +16,9 @@ using StackExchange.Redis; using System.Data; using System.Diagnostics; using System.Globalization; +using MP.Data.Repository.IOC; +using MP.Data.Repository.Anag; +using MP.Data.Repository.System; using ZiggyCreatures.Caching.Fusion; using static MP.Core.Objects.Enums; @@ -25,6 +28,9 @@ namespace MP.IOC.Data { #region Public Constructors private readonly IProductionRepository _productionRepository; + private readonly IIocRepository _iocRepository; + private readonly IAnagRepository _anagRepository; + private readonly ISystemRepository _systemRepository; public MpDataService( IConfiguration configuration, @@ -33,13 +39,19 @@ namespace MP.IOC.Data IProductionRepository productionRepository, IFusionCache cache, MpIocController mpIocCtr, - IMtcSetupService mtcServ) + IMtcSetupService mtcServ, + IIocRepository iocRepository, + IAnagRepository anagRepository, + ISystemRepository systemRepository) { _logger = logger; _logger.LogInformation("Starting MpDataService INIT"); _configuration = configuration; _scopeFactory = scopeFactory; _productionRepository = productionRepository; + _iocRepository = iocRepository; + _anagRepository = anagRepository; + _systemRepository = systemRepository; _cache = cache; IocDbController = mpIocCtr; @@ -440,7 +452,7 @@ namespace MP.IOC.Data List slaveList = new(); if (isMachMaster) { - List allSlaveList = await IocDbController.Macchine2SlaveAsync(); + List allSlaveList = await _iocRepository.Macchine2SlaveAsync(); slaveList = allSlaveList.Where(x => x.IdxMacchina == idxMacchina).ToList(); } @@ -685,7 +697,7 @@ namespace MP.IOC.Data string CodArticolo = datiMacc["CodArticolo"]; if (string.IsNullOrEmpty(CodArticolo)) { - var allDatiMacch = await IocDbController.DatiMacchineGetAllAsync(); + var allDatiMacch = await _iocRepository.DatiMacchineGetAllAsync(); var recMacc = allDatiMacch.FirstOrDefault(x => x.IdxMacchina == idxMacchina); if (recMacc != null) { @@ -747,18 +759,8 @@ namespace MP.IOC.Data } else { - if (useFactory) - { - await using var scope = _scopeFactory.CreateAsyncScope(); - var iocService = scope.ServiceProvider.GetRequiredService(); - // solo microstato - await iocService.MicroStatoMacchinaUpsertAsync(newRecMsm); - } - else - { - // solo microstato - await IocDbController.MicroStatoMacchinaUpsertAsync(newRecMsm); - } + // solo microstato → IIocRepository + await _iocRepository.MicroStatoMacchinaUpsertAsync(newRecMsm); } return answ; } @@ -769,7 +771,7 @@ namespace MP.IOC.Data operationName: "ConfigGetAllAsync", cacheKey: Utils.redisConfKey, expiration: getRandTOut(redisLongTimeCache), - fetchFunc: async () => (await IocDbController.ConfigGetAllAsync()) ?? new List(), + fetchFunc: async () => (await _systemRepository.ConfigGetAllAsync()) ?? new List(), tagList: [Utils.redisConfKey] ); } @@ -1068,7 +1070,7 @@ namespace MP.IOC.Data } else { - resultList = await IocDbController.ListValuesFiltAsync(tabName, fieldName); + resultList = await _anagRepository.ListValuesFiltAsync(tabName, fieldName); // serializzo e salvo... rawData = JsonConvert.SerializeObject(resultList); await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache)); @@ -1090,19 +1092,7 @@ namespace MP.IOC.Data operationName: "Macchine2SlaveGetAllAsync", cacheKey: $"{Utils.redisBaseAddr}:M2STab", expiration: getRandTOut(redisLongTimeCache * 10), - fetchFunc: async () => - { - if (useFactory) - { - await using var scope = _scopeFactory.CreateAsyncScope(); - var mtcService = scope.ServiceProvider.GetRequiredService(); - return await mtcService.Macchine2SlaveAsync() ?? new List(); - } - else - { - return await IocDbController.Macchine2SlaveAsync() ?? new List(); - } - }, + fetchFunc: async () => await _iocRepository.Macchine2SlaveAsync() ?? new List(), tagList: [Utils.redisBaseAddr] ); } @@ -1328,13 +1318,13 @@ namespace MP.IOC.Data { if (forceDb) { - return (await IocDbController.MseGetAllAsync(maxAge)) ?? new List(); + return (await _productionRepository.MseGetAllAsync(maxAge)) ?? new List(); } return await GetOrFetchAsync( operationName: "MseGetAllAsync", cacheKey: Constants.redisMseKey, expiration: getRandTOut(redisShortTimeCache / 2), - fetchFunc: async () => (await IocDbController.MseGetAllAsync(maxAge)) ?? new List(), + fetchFunc: async () => (await _productionRepository.MseGetAllAsync(maxAge)) ?? new List(), tagList: [Constants.redisMseKey] ); } @@ -2113,7 +2103,7 @@ namespace MP.IOC.Data { var currHash = Utils.RedKeyMsmi(idxMacchina); // recupero records - var tabMSMI = await IocDbController.VMSFDGetMultiByMaccAsync(idxMacchina); + var tabMSMI = await _iocRepository.VMSFDGetMultiByMaccAsync(idxMacchina); KeyValuePair[] answ = new KeyValuePair[tabMSMI.Count]; // salvo tutti i valori StateMachineIngressi... @@ -2256,7 +2246,7 @@ namespace MP.IOC.Data Contatore = contatore, Valore = valore }; - return await IocDbController.SignalLogInsertAsync(newRec); + return await _iocRepository.SignalLogInsertAsync(newRec); } /// @@ -2276,7 +2266,7 @@ namespace MP.IOC.Data DateTime adesso = DateTime.Now; await redisDb.StringSetAsync(currKey, adesso.ToString("s"), TimeSpan.FromSeconds(30)); // effettuo scrittura sul DB - await IocDbController.KeepAliveUpsertAsync(IdxMacchina, DateTime.Now, oraMacchina); + await _iocRepository.KeepAliveUpsertAsync(IdxMacchina, DateTime.Now, oraMacchina); } } @@ -2621,7 +2611,7 @@ namespace MP.IOC.Data private async Task CheckCambiaStatoBatchAsync(tipoInputEvento tipoInput, string IdxMacchina, DateTime InizioStato, int IdxTipo, string CodArt, string Value, int MatrOpr, string pallet) { - await IocDbController.CheckCambiaStatoBatchAsync(tipoInput, IdxMacchina, InizioStato, IdxTipo, CodArt, Value, MatrOpr, pallet); + await _iocRepository.CheckCambiaStatoBatchAsync(tipoInput, IdxMacchina, InizioStato, IdxTipo, CodArt, Value, MatrOpr, pallet); #if false List listTransit = new List(); TransizioneStatiModel? rigaTrans = null; @@ -2928,7 +2918,7 @@ namespace MP.IOC.Data } else { - dbResult = await IocDbController.VMSFDGetByMaccAsync(idxMacc); + dbResult = await _iocRepository.VMSFDGetByMaccAsync(idxMacc); } if (dbResult == null) return new Dictionary(); @@ -3009,7 +2999,7 @@ namespace MP.IOC.Data { var currHash = Utils.GetHashSMI(idxFamIn); // leggo da DB... - var tabSMI = await IocDbController.StateMachineIngressiAsync(idxFamIn); + var tabSMI = await _iocRepository.StateMachineIngressiAsync(idxFamIn); KeyValuePair[] answ = new KeyValuePair[tabSMI.Count]; // salvo tutti i valori StateMachineIngressi... @@ -3074,7 +3064,7 @@ namespace MP.IOC.Data try { // inserisco evento - inserito = await IocDbController.EvListInsertAsync(newRec); + inserito = await _systemRepository.EvListInsertAsync(newRec); // faccio controllo per eventuale cambio stato da tab transizioni... await CheckCambiaStatoBatchAsync(tipoInputEvento.hw, newRec.IdxMacchina, newRec.InizioStato ?? DateTime.Now, newRec.IdxTipo, newRec.CodArticolo, newRec.Value, newRec.MatrOpr, newRec.pallet); } @@ -3115,7 +3105,7 @@ namespace MP.IOC.Data try { // inserisco evento - inserito = await IocDbController.EvListMicroStatoInsertAsync(newRecMsm, newRecEv); + inserito = await _iocRepository.EvListMicroStatoInsertAsync(newRecMsm, newRecEv); // faccio controllo per eventuale cambio stato da tab transizioni... await CheckCambiaStatoBatchAsync(tipoInputEvento.hw, newRecEv.IdxMacchina, newRecEv.InizioStato ?? DateTime.Now, newRecEv.IdxTipo, newRecEv.CodArticolo, newRecEv.Value, newRecEv.MatrOpr, newRecEv.pallet); } @@ -3144,7 +3134,7 @@ namespace MP.IOC.Data try { // inserisco evento - inserito = await IocDbController.EvListInsertAsync(newRec); + inserito = await _systemRepository.EvListInsertAsync(newRec); // faccio controllo per eventuale cambio stato da tab transizioni... await CheckCambiaStatoBatchAsync(tipoInputEvento.barcode, newRec.IdxMacchina, newRec.InizioStato ?? DateTime.Now, newRec.IdxTipo, newRec.CodArticolo, newRec.Value, newRec.MatrOpr, newRec.pallet); } @@ -3180,7 +3170,7 @@ namespace MP.IOC.Data } else { - result = await IocDbController.StatoProdMacchinaAsync(idxMacchina, dtReq); + result = await _iocRepository.StatoProdMacchinaAsync(idxMacchina, dtReq); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromSeconds(60)); @@ -3247,7 +3237,7 @@ namespace MP.IOC.Data if (needDB) { // verifico se esiste su DB - var dbRec = await IocDbController.MacchineGetByIdxAsync(IdxMacchina); + var dbRec = await _iocRepository.MacchineGetByIdxAsync(IdxMacchina); if (dbRec == null) { MacchineModel newRec = new MacchineModel() @@ -3261,10 +3251,10 @@ namespace MP.IOC.Data RecipeArchivePath = "", RecipePath = "" }; - await IocDbController.MacchineUpsertAsync(newRec); + await _iocRepository.MacchineUpsertAsync(newRec); - // verifico ci sia un microstato macchina... - var recMSM = await IocDbController.MicroStatoMacchinaGetByIdxMaccAsync(IdxMacchina); + // verifica se ci sia un microstato macchina... + var recMSM = await _iocRepository.MicroStatoMacchinaGetByIdxMaccAsync(IdxMacchina); if (recMSM.Count == 0) { // inserisco nuovo stato... @@ -3275,7 +3265,7 @@ namespace MP.IOC.Data InizioStato = DateTime.Now, Value = "00" }; - await IocDbController.MicroStatoMacchinaUpsertAsync(msRec); + await _iocRepository.MicroStatoMacchinaUpsertAsync(msRec); } } } diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index a43a160b..96043f0a 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 8.16.2606.414 + 8.16.2606.811 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 988f5d0e..38cd6371 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 8.16.2606.414

+

Versione: 8.16.2606.811


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index b698ae9b..1ee643ed 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.414 +8.16.2606.811 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index 1cb2501a..27714b35 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.414 + 8.16.2606.811 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