diff --git a/MP.INVE/Components/CmpTop.razor.cs b/MP.INVE/Components/CmpTop.razor.cs index 3eb00344..17e6d5fd 100644 --- a/MP.INVE/Components/CmpTop.razor.cs +++ b/MP.INVE/Components/CmpTop.razor.cs @@ -22,7 +22,7 @@ namespace MP.INVE.Components public async Task LogOut() { - await localStorage.ClearAsync(); + await MIDataService.clearLocalStorageAsync(); // rimando a pagina login NavManager.NavigateTo("OperatoreLogin", true); } @@ -33,6 +33,7 @@ namespace MP.INVE.Components [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; + [Inject] protected MiDataService MIDataService { get; set; } = null!; @@ -44,8 +45,11 @@ namespace MP.INVE.Components protected async Task getId() { +#if false OperatoreDTO answ = new OperatoreDTO(); answ = await localStorage.GetItemAsync("MatrOpr"); +#endif + OperatoreDTO answ = await MIDataService.getCurrOperDtoAsync(); if (!NavManager.Uri.Contains("Jumper?")) { if (answ != null) @@ -89,10 +93,14 @@ namespace MP.INVE.Components [Inject] private NavigationManager NavManager { get; set; } = null!; + [Inject] private ISessionStorageService sessionStorage { get; set; } = null!; + +#if false [Inject] private ILocalStorageService localStorage { get; set; } = null!; +#endif #endregion Private Properties } diff --git a/MP.INVE/Data/MiDataService.cs b/MP.INVE/Data/MiDataService.cs index 94cffed8..e35261d3 100644 --- a/MP.INVE/Data/MiDataService.cs +++ b/MP.INVE/Data/MiDataService.cs @@ -1,7 +1,9 @@ -using Egw.Core; +using Blazored.LocalStorage; +using Egw.Core; using Microsoft.AspNetCore.Mvc.ModelBinding; using MP.Data.Conf; using MP.Data.DatabaseModels; +using MP.Data.DTO; using MP.INVE.Pages; using Newtonsoft.Json; using NLog; @@ -13,13 +15,84 @@ namespace MP.INVE.Data { public class MiDataService : IDisposable { + #region Protected Fields + + protected const string passPhrase = "7871D817-C71F-4DFC-BF12-00A95BE507B5"; + + protected Random rand = new Random(); + + #endregion Protected Fields + + #region Private Fields + + private const string redisBaseAddr = "MP:INVE"; + + private const string redisConfigBaseAddr = ":Config"; + + private const string redisElencoOperatori = redisBaseAddr + redisOperatoriBaseAddr + ":ListOperatori"; + + private const string redisLottiBaseAddr = ":Lotti"; + + private const string redisLottiEsterni = redisBaseAddr + redisLottiBaseAddr + ":LottiEsterni"; + + private const string redisLottiInterni = redisBaseAddr + redisLottiBaseAddr + ":LottiInterni"; + + private const string redisMagList = redisBaseAddr + ":ListMag"; + + private const string redisOperatoreLogged = redisBaseAddr + redisOperatoriBaseAddr + ":OperatoreLogged"; + + private const string redisOperatoriBaseAddr = ":Operatore"; + + private const string redisScanBaseAddr = redisBaseAddr + ":Scan"; + + private const string redisSessionBaseAddr = ":Session"; + + private const string redisSessionCurrList = redisBaseAddr + redisSessionBaseAddr + ":ListSessHist"; + + private const string redisSessionHistList = redisBaseAddr + redisSessionBaseAddr + ":ListSessCurr"; + + private const string redisTotLottoAddr = ":TotaleLotto"; + + private const string redisUdcBaseAddr = ":UDC"; + + private static IConfiguration _configuration = null!; + + private static ILogger _logger = null!; + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + /// + /// Oggetto vocabolario x uso continuo traduzione + /// + private List ObjVocabolario = new List(); + + /// + /// Oggetto per connessione a REDIS + /// + private ConnectionMultiplexer redisConn = null!; + + /// + /// Oggetto per connessione a REDIS modalità admin (ex flux dati) + /// + private ConnectionMultiplexer redisConnAdmin = null!; + + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + private IDatabase redisDb = null!; + + private int redisLongTimeCache = 5; + + #endregion Private Fields + #region Public Constructors - public MiDataService(IConfiguration configuration, ILogger logger) + public MiDataService(IConfiguration configuration, ILogger logger, ILocalStorageService blazLocalStorage) { _logger = logger; _logger.LogInformation("Starting MiDataService INIT"); _configuration = configuration; + localStorage = blazLocalStorage; // setup compoenti REDIS redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis")); @@ -58,17 +131,58 @@ namespace MP.INVE.Data #endregion Public Properties + #region Private Properties + + private static ILocalStorageService localStorage { get; set; } = null!; + + #endregion Private Properties + #region Public Methods - public string DeriptData(string encData) + /// + /// Aggiornamento record selezionato + /// + /// + /// + public async Task artBySearch(string artSearch) { - return SteamCrypto.DecryptString(encData, passPhrase); + var dbResult = dbController.artBySearch(artSearch); + // elimino cache redis... + await Task.Delay(1); + return dbResult; } - public void Dispose() + /// + /// Effettua pulizia localstorage + /// + /// + public async Task clearLocalStorageAsync() { + bool answ = false; + try + { + await localStorage.ClearAsync(); + answ = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in clearLocalStorage{Environment.NewLine}{exc}"); + } + return answ; } + public async Task CloseOpenSessione(int sessID, bool flgClose) + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + bool result = false; + string source = "DB"; + result = await dbController.CloseOpenSessione(sessID, flgClose); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"CloseOpenSessione Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } public async Task> ConfigGetAll() { @@ -101,25 +215,6 @@ namespace MP.INVE.Data return result; } - /// - /// Restituisce valore della stringa (SE disponibile) - /// - /// - /// - public async Task tryGetConfig(string keyName) - { - string answ = ""; - // preselezione valori - var configData = await ConfigGetAll(); - var currRec = configData.FirstOrDefault(x => x.Chiave == keyName); - if (currRec != null) - { - answ = currRec.Valore; - } - - return answ; - } - /// /// Reset dati cache config /// @@ -129,38 +224,35 @@ namespace MP.INVE.Data await redisDb.StringSetAsync(redisConfigBaseAddr, ""); } - - public async Task InsertNewScansione(ScanDataModel newScan) + public async Task DeleteMag(AnagMagModel Mag) { bool result = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - result = await dbController.InsertNewScansione(newScan); + result = await dbController.DeleteMag(Mag); // elimino cache redis... - RedisValue pattern = new RedisValue(redisScanBaseAddr); + RedisValue pattern = new RedisValue($"{redisMagList}:*"); bool answ = await ExecFlushRedisPattern(pattern); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"InsertNewScansione | Id scansione: {newScan.ScanID} | Id sessione: {newScan.InveSessID} | {ts.TotalMilliseconds}ms"); + Log.Debug($"DeleteMag | Codice magazzino: {Mag.CodMag} | Descrizione magazzino: {Mag.DescMag} | {ts.TotalMilliseconds}ms"); return result; - // aggiungo record al DB } - - public async Task InsertNewSessione(InventorySessionModel newSess) + public async Task deleteScansione(ScanDataModel scan) { bool result = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - result = await dbController.InsertNewSessione(newSess); + result = await dbController.deleteScansione(scan); // elimino cache redis... - RedisValue pattern = new RedisValue($"{redisBaseAddr}{redisSessionBaseAddr}*"); + RedisValue pattern = new RedisValue($"{redisScanBaseAddr}*"); bool answ = await ExecFlushRedisPattern(pattern); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"InsertNewSessione | Id sessione: {newSess.InveSessID} | Descrizione sessione: {newSess.Description} | {ts.TotalMilliseconds}ms"); + Log.Debug($"deleteScansione | Id scansione: {scan.ScanID} | Codice scansionato: {scan.ScanValue} | {ts.TotalMilliseconds}ms"); return result; - // aggiungo record al DB + // elimino record dal DB } public async Task deleteSessione(InventorySessionModel session) @@ -178,107 +270,76 @@ namespace MP.INVE.Data return result; // elimino record dal DB } - public async Task deleteScansione(ScanDataModel scan) + + public string DeriptData(string encData) { - bool result = false; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - result = await dbController.deleteScansione(scan); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{redisScanBaseAddr}*"); - bool answ = await ExecFlushRedisPattern(pattern); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"deleteScansione | Id scansione: {scan.ScanID} | Codice scansionato: {scan.ScanValue} | {ts.TotalMilliseconds}ms"); - return result; - // elimino record dal DB + return SteamCrypto.DecryptString(encData, passPhrase); } - public async Task InsertNewMag(AnagMagModel newMag) + public void Dispose() { - bool result = false; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - result = await dbController.InsertNewMag(newMag); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{redisMagList}"); - bool answ = await ExecFlushRedisPattern(pattern); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"InsertNewMag | Codice magazzino: {newMag.CodMag} | Descrizione magazzino: {newMag.DescMag} | {ts.TotalMilliseconds}ms"); - return result; - // aggiungo record al DB - } - public async Task UpdateMag(AnagMagModel Mag) - { - bool result = false; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - result = await dbController.UpdateMag(Mag); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{redisMagList}"); - bool answ = await ExecFlushRedisPattern(pattern); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"UpdateMag | Codice magazzino: {Mag.CodMag} | Descrizione magazzino: {Mag.DescMag} | {ts.TotalMilliseconds}ms"); - return result; - // aggiungo record al DB - } - public async Task DeleteMag(AnagMagModel Mag) - { - bool result = false; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - result = await dbController.DeleteMag(Mag); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{redisMagList}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"DeleteMag | Codice magazzino: {Mag.CodMag} | Descrizione magazzino: {Mag.DescMag} | {ts.TotalMilliseconds}ms"); - return result; } - public bool loginOperatore(int matrOpr, string authkey) + public List ElencoLotti() { string source = ""; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - AnagOperatoriModel? result = new AnagOperatoriModel(); - bool answ = false; + List? result = new List(); // cerco in redis... - RedisValue rawData = redisDb.StringGet($"{redisElencoOperatori}:{matrOpr}:{authkey}"); + RedisValue rawData = redisDb.StringGet(redisLottiInterni); if (!string.IsNullOrEmpty($"{rawData}")) { + result = JsonConvert.DeserializeObject>($"{rawData}"); - result = JsonConvert.DeserializeObject($"{rawData}"); - if (result != null) - { - answ = true; - source = "REDIS"; - } + source = "REDIS"; } else { - answ = dbController.LoginOperatore(matrOpr, authkey); - if (answ) - { - result = ElencoOperatori().Where(x => (x.MatrOpr == matrOpr) && (x.authKey == authkey)).SingleOrDefault(); - } + result = dbController.ElencoLotti(); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); - redisDb.StringSetAsync(redisOperatoreLogged, rawData, getRandTOut(redisLongTimeCache)); + redisDb.StringSetAsync(redisLottiInterni, rawData, getRandTOut(redisLongTimeCache)); source = "DB"; - } if (result == null) { - result = new AnagOperatoriModel(); + result = new List(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"loginOperatore Read from {source}: {ts.TotalMilliseconds}ms"); - return answ; + Log.Debug($"ElencoLotti Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + + public List ElencoMagazzini() + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + List result = new List(); + string source = "DB"; + // cerco in redis... + RedisValue rawData = redisDb.StringGet(redisMagList); + if (!string.IsNullOrEmpty($"{rawData}")) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.ElencoMagazzini(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSetAsync(redisMagList, rawData, getRandTOut(redisLongTimeCache)); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ElencoMagazzini Read from {source}: {ts.TotalMilliseconds}ms"); + if (result == null) + { + result = new List(); + } + return result; } public List ElencoOperatori() @@ -313,147 +374,6 @@ namespace MP.INVE.Data return result; } - - public List LottoEsterno(string codArt, string codLotto, string codMagazzino) - { - string source = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - List? result = new List(); - // cerco in redis... - result = dbController.LottoEsterno(codArt, codLotto, codMagazzino); - source = "DB"; - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"LottoEsterno Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - - public List ScanList() - { - string source = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - List? result = new List(); - // cerco in redis... - RedisValue rawData = redisDb.StringGet(redisScanBaseAddr); - if (!string.IsNullOrEmpty($"{rawData}")) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - - source = "REDIS"; - } - else - { - result = dbController.ScanList(); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - redisDb.StringSetAsync(redisScanBaseAddr, rawData, getRandTOut(redisLongTimeCache)); - source = "DB"; - } - if (result == null) - { - result = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ScanList Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - public List InveSessTotLotList(int sessID) - { - string source = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - List? result = new List(); - result = dbController.InveSessTotLotList(sessID); - source = "DB"; - if (result == null) - { - result = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"InveSessTotLotList Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - - public ScanDataModel ScanByUdcSession(string udc, int inveSessId) - { - string source = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - ScanDataModel? result = new ScanDataModel(); - result = dbController.ScanByUdcSession(udc, inveSessId); - source = "DB"; - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ScanByUdcSession Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - - public List ScanByValueSessionOpr(string scanData, int inveSessId, string Opr) - { - string source = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - List? result = new List(); - result = dbController.ScanByValueSessionOpr(scanData, inveSessId, Opr); - source = "DB"; - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ScanByValueSessionOpr Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - - public List ScanBySession(int idSessione) - { - string source = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - List? result = new List(); - // cerco in redis... - { - var ListAll = ScanList(); - result = ListAll.Where(x => x.InveSessID == idSessione).ToList(); - if (result == null) - { - result = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ScanBySession Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - } - - /// - /// Aggiornamento record selezionato - /// - /// - /// - public async Task UpdateScan(ScanDataModel currRec) - { - var dbResult = await dbController.updateScan(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue(redisScanBaseAddr); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - /// - /// Aggiornamento record selezionato - /// - /// - /// - public async Task artBySearch(string artSearch) - { - var dbResult = dbController.artBySearch(artSearch); - // elimino cache redis... - await Task.Delay(1); - return dbResult; - } - public List ElencoUDC() { string source = ""; @@ -486,69 +406,95 @@ namespace MP.INVE.Data return result; } - public AnagUdcModel IsUDC(string udc) - { - string source = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - AnagUdcModel? result = new AnagUdcModel(); - result = dbController.IsUDC(udc); - source = "DB"; - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"IsUDC Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - public AnagLottoModel LottoInterno(string lotto) - { - string source = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - AnagLottoModel? result = new AnagLottoModel(); - result = dbController.LottoInterno(lotto); - source = "DB"; - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"LottoInterno Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - public List ElencoLotti() - { - string source = ""; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - List? result = new List(); - // cerco in redis... - RedisValue rawData = redisDb.StringGet(redisLottiInterni); - if (!string.IsNullOrEmpty($"{rawData}")) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - - source = "REDIS"; - } - else - { - result = dbController.ElencoLotti(); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - redisDb.StringSetAsync(redisLottiInterni, rawData, getRandTOut(redisLongTimeCache)); - source = "DB"; - } - if (result == null) - { - result = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ElencoLotti Read from {source}: {ts.TotalMilliseconds}ms"); - return result; - } - public string EncriptData(string rawData) { return SteamCrypto.EncryptString(rawData, passPhrase); } + public async Task FlushRedisCache() + { + await Task.Delay(1); + RedisValue pattern = new RedisValue($"{redisBaseAddr}*"); + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + + /// + /// Restituisce il record OperatoreDTO da localstorage + /// + /// + public async Task getCurrOperDtoAsync() + { + OperatoreDTO answ = new OperatoreDTO(); + answ = await localStorage.GetItemAsync("MatrOpr"); + return answ; + } + + public async Task InsertNewMag(AnagMagModel newMag) + { + bool result = false; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + result = await dbController.InsertNewMag(newMag); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{redisMagList}"); + bool answ = await ExecFlushRedisPattern(pattern); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"InsertNewMag | Codice magazzino: {newMag.CodMag} | Descrizione magazzino: {newMag.DescMag} | {ts.TotalMilliseconds}ms"); + return result; + // aggiungo record al DB + } + + public async Task InsertNewScansione(ScanDataModel newScan) + { + bool result = false; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + result = await dbController.InsertNewScansione(newScan); + // elimino cache redis... + RedisValue pattern = new RedisValue(redisScanBaseAddr); + bool answ = await ExecFlushRedisPattern(pattern); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"InsertNewScansione | Id scansione: {newScan.ScanID} | Id sessione: {newScan.InveSessID} | {ts.TotalMilliseconds}ms"); + return result; + // aggiungo record al DB + } + + public async Task InsertNewSessione(InventorySessionModel newSess) + { + bool result = false; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + result = await dbController.InsertNewSessione(newSess); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{redisBaseAddr}{redisSessionBaseAddr}*"); + bool answ = await ExecFlushRedisPattern(pattern); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"InsertNewSessione | Id sessione: {newSess.InveSessID} | Descrizione sessione: {newSess.Description} | {ts.TotalMilliseconds}ms"); + return result; + // aggiungo record al DB + } + + public InventorySessionModel InventSessByID(int sessID) + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + InventorySessionModel result = new InventorySessionModel(); + string source = "DB"; + result = dbController.InventSessByID(sessID); + if (result == null) + { + result = new InventorySessionModel(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"InventSessByID Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + public List InventSessCurrList() { Stopwatch stopWatch = new Stopwatch(); @@ -579,36 +525,6 @@ namespace MP.INVE.Data return result; } - public List ElencoMagazzini() - { - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - List result = new List(); - string source = "DB"; - // cerco in redis... - RedisValue rawData = redisDb.StringGet(redisMagList); - if (!string.IsNullOrEmpty($"{rawData}")) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = dbController.ElencoMagazzini(); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - redisDb.StringSetAsync(redisMagList, rawData, getRandTOut(redisLongTimeCache)); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ElencoMagazzini Read from {source}: {ts.TotalMilliseconds}ms"); - if (result == null) - { - result = new List(); - } - return result; - } - public List InventSessHistList() { Stopwatch stopWatch = new Stopwatch(); @@ -639,35 +555,188 @@ namespace MP.INVE.Data return result; } - public InventorySessionModel InventSessByID(int sessID) + public List InveSessTotLotList(int sessID) { + string source = ""; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - InventorySessionModel result = new InventorySessionModel(); - string source = "DB"; - result = dbController.InventSessByID(sessID); + List? result = new List(); + result = dbController.InveSessTotLotList(sessID); + source = "DB"; if (result == null) { - result = new InventorySessionModel(); + result = new List(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"InventSessByID Read from {source}: {ts.TotalMilliseconds}ms"); + Log.Debug($"InveSessTotLotList Read from {source}: {ts.TotalMilliseconds}ms"); return result; } - public async Task CloseOpenSessione(int sessID, bool flgClose) + public AnagUdcModel IsUDC(string udc) { + string source = ""; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - bool result = false; - string source = "DB"; - result = await dbController.CloseOpenSessione(sessID, flgClose); + AnagUdcModel? result = new AnagUdcModel(); + result = dbController.IsUDC(udc); + source = "DB"; stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"CloseOpenSessione Read from {source}: {ts.TotalMilliseconds}ms"); + Log.Debug($"IsUDC Read from {source}: {ts.TotalMilliseconds}ms"); return result; } + + public bool loginOperatore(int matrOpr, string authkey) + { + string source = ""; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + AnagOperatoriModel? result = new AnagOperatoriModel(); + bool answ = false; + // cerco in redis... + RedisValue rawData = redisDb.StringGet($"{redisElencoOperatori}:{matrOpr}:{authkey}"); + if (!string.IsNullOrEmpty($"{rawData}")) + { + result = JsonConvert.DeserializeObject($"{rawData}"); + if (result != null) + { + answ = true; + source = "REDIS"; + } + } + else + { + answ = dbController.LoginOperatore(matrOpr, authkey); + if (answ) + { + result = ElencoOperatori().Where(x => (x.MatrOpr == matrOpr) && (x.authKey == authkey)).SingleOrDefault(); + } + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSetAsync(redisOperatoreLogged, rawData, getRandTOut(redisLongTimeCache)); + source = "DB"; + } + if (result == null) + { + result = new AnagOperatoriModel(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"loginOperatore Read from {source}: {ts.TotalMilliseconds}ms"); + return answ; + } + + public List LottoEsterno(string codArt, string codLotto, string codMagazzino) + { + string source = ""; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + List? result = new List(); + // cerco in redis... + result = dbController.LottoEsterno(codArt, codLotto, codMagazzino); + source = "DB"; + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"LottoEsterno Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + + public AnagLottoModel LottoInterno(string lotto) + { + string source = ""; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + AnagLottoModel? result = new AnagLottoModel(); + result = dbController.LottoInterno(lotto); + source = "DB"; + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"LottoInterno Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + + public List ScanBySession(int idSessione) + { + string source = ""; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + List? result = new List(); + // cerco in redis... + { + var ListAll = ScanList(); + result = ListAll.Where(x => x.InveSessID == idSessione).ToList(); + if (result == null) + { + result = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ScanBySession Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + } + + public ScanDataModel ScanByUdcSession(string udc, int inveSessId) + { + string source = ""; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + ScanDataModel? result = new ScanDataModel(); + result = dbController.ScanByUdcSession(udc, inveSessId); + source = "DB"; + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ScanByUdcSession Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + + public List ScanByValueSessionOpr(string scanData, int inveSessId, string Opr) + { + string source = ""; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + List? result = new List(); + result = dbController.ScanByValueSessionOpr(scanData, inveSessId, Opr); + source = "DB"; + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ScanByValueSessionOpr Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + + public List ScanList() + { + string source = ""; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + List? result = new List(); + // cerco in redis... + RedisValue rawData = redisDb.StringGet(redisScanBaseAddr); + if (!string.IsNullOrEmpty($"{rawData}")) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + + source = "REDIS"; + } + else + { + result = dbController.ScanList(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSetAsync(redisScanBaseAddr, rawData, getRandTOut(redisLongTimeCache)); + source = "DB"; + } + if (result == null) + { + result = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ScanList Read from {source}: {ts.TotalMilliseconds}ms"); + return result; + } + public async Task TransferSessione(int sessID) { Stopwatch stopWatch = new Stopwatch(); @@ -680,16 +749,59 @@ namespace MP.INVE.Data Log.Debug($"TransferSessione Read from {source}: {ts.TotalMilliseconds}ms"); return result; } + + /// + /// Restituisce valore della stringa (SE disponibile) + /// + /// + /// + public async Task tryGetConfig(string keyName) + { + string answ = ""; + // preselezione valori + var configData = await ConfigGetAll(); + var currRec = configData.FirstOrDefault(x => x.Chiave == keyName); + if (currRec != null) + { + answ = currRec.Valore; + } + + return answ; + } + + public async Task UpdateMag(AnagMagModel Mag) + { + bool result = false; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + result = await dbController.UpdateMag(Mag); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{redisMagList}"); + bool answ = await ExecFlushRedisPattern(pattern); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"UpdateMag | Codice magazzino: {Mag.CodMag} | Descrizione magazzino: {Mag.DescMag} | {ts.TotalMilliseconds}ms"); + return result; + // aggiungo record al DB + } + + /// + /// Aggiornamento record selezionato + /// + /// + /// + public async Task UpdateScan(ScanDataModel currRec) + { + var dbResult = await dbController.updateScan(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue(redisScanBaseAddr); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } + #endregion Public Methods - #region Protected Fields - - protected const string passPhrase = "7871D817-C71F-4DFC-BF12-00A95BE507B5"; - - protected Random rand = new Random(); - - #endregion Protected Fields - #region Protected Methods /// @@ -702,13 +814,10 @@ namespace MP.INVE.Data double rndValue = (double)stdMinutes + (double)rand.Next(1, 60) / 60; return TimeSpan.FromMinutes(rndValue); } - public async Task FlushRedisCache() - { - await Task.Delay(1); - RedisValue pattern = new RedisValue($"{redisBaseAddr}*"); - bool answ = await ExecFlushRedisPattern(pattern); - return answ; - } + + #endregion Protected Methods + + #region Private Methods /// /// Esegue flush memoria redis dato pattern @@ -739,53 +848,6 @@ namespace MP.INVE.Data return answ; } - #endregion Protected Methods - - #region Private Fields - - private const string redisBaseAddr = "MP:INVE"; - private const string redisSessionBaseAddr = ":Session"; - private const string redisOperatoriBaseAddr = ":Operatore"; - private const string redisLottiBaseAddr = ":Lotti"; - private const string redisUdcBaseAddr = ":UDC"; - private const string redisTotLottoAddr = ":TotaleLotto"; - private const string redisLottiInterni = redisBaseAddr + redisLottiBaseAddr + ":LottiInterni"; - private const string redisLottiEsterni = redisBaseAddr + redisLottiBaseAddr + ":LottiEsterni"; - private const string redisConfigBaseAddr = ":Config"; - private const string redisScanBaseAddr = redisBaseAddr + ":Scan"; - private const string redisElencoOperatori = redisBaseAddr + redisOperatoriBaseAddr + ":ListOperatori"; - private const string redisOperatoreLogged = redisBaseAddr + redisOperatoriBaseAddr + ":OperatoreLogged"; - private const string redisSessionCurrList = redisBaseAddr + redisSessionBaseAddr + ":ListSessHist"; - private const string redisSessionHistList = redisBaseAddr + redisSessionBaseAddr + ":ListSessCurr"; - private const string redisMagList = redisBaseAddr + ":ListMag"; - private static IConfiguration _configuration = null!; - - private static ILogger _logger = null!; - - private static Logger Log = LogManager.GetCurrentClassLogger(); - - /// - /// Oggetto vocabolario x uso continuo traduzione - /// - private List ObjVocabolario = new List(); - - /// - /// Oggetto per connessione a REDIS - /// - private ConnectionMultiplexer redisConn = null!; - - /// - /// Oggetto per connessione a REDIS modalità admin (ex flux dati) - /// - private ConnectionMultiplexer redisConnAdmin = null!; - - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - private IDatabase redisDb = null!; - - private int redisLongTimeCache = 5; - - #endregion Private Fields + #endregion Private Methods } } \ No newline at end of file diff --git a/MP.INVE/MP.INVE.csproj b/MP.INVE/MP.INVE.csproj index efe90c46..dffe99b2 100644 --- a/MP.INVE/MP.INVE.csproj +++ b/MP.INVE/MP.INVE.csproj @@ -5,7 +5,7 @@ enable enable MP.INVE - 6.16.2212.1610 + 6.16.2212.1611 diff --git a/MP.INVE/Resources/ChangeLog.html b/MP.INVE/Resources/ChangeLog.html index caaf0c73..2675e33f 100644 --- a/MP.INVE/Resources/ChangeLog.html +++ b/MP.INVE/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOINVE -

Versione: 6.16.2212.1610

+

Versione: 6.16.2212.1611


Note di rilascio:
  • diff --git a/MP.INVE/Resources/VersNum.txt b/MP.INVE/Resources/VersNum.txt index 31f86dce..b8ebf232 100644 --- a/MP.INVE/Resources/VersNum.txt +++ b/MP.INVE/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2212.1610 +6.16.2212.1611 diff --git a/MP.INVE/Resources/manifest.xml b/MP.INVE/Resources/manifest.xml index 3e35ff8d..72998040 100644 --- a/MP.INVE/Resources/manifest.xml +++ b/MP.INVE/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2212.1610 + 6.16.2212.1611 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