diff --git a/MP.SPEC/Components/ListPODL.razor.cs b/MP.SPEC/Components/ListPODL.razor.cs index 66b07d13..3217b076 100644 --- a/MP.SPEC/Components/ListPODL.razor.cs +++ b/MP.SPEC/Components/ListPODL.razor.cs @@ -216,6 +216,7 @@ namespace MP.SPEC.Components .Select(x => x.IdxMacchina) .ToHashSet(); + ListStati = await MDService.AnagStatiComm(); ListArtKit = MDService.ArticoliGetByTipo("KIT", "*"); string strMachRecipe = await MDService.ConfigTryGetAsync("MachineWithRecipe"); @@ -354,6 +355,8 @@ namespace MP.SPEC.Components #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); + private HashSet _machinesWithArch = new(); + private HashSet _machinesWithConf = new(); private string currRecipeArchPath = ""; /// @@ -585,14 +588,8 @@ namespace MP.SPEC.Components private bool machineHasRecipeArch(string idxMacchina) { return _machinesWithArch.Contains(idxMacchina); - //var recipeArchive = MDService.MacchineRecipeArchive(idxMacchina); - //return !string.IsNullOrEmpty(recipeArchive); } - - private HashSet _machinesWithConf = new(); - private HashSet _machinesWithArch = new(); - /// /// Verifica se la idxMaccSel abbia associata una ricetta (template) /// @@ -601,8 +598,6 @@ namespace MP.SPEC.Components private bool machineHasRecipeConf(string idxMacchina) { return _machinesWithConf.Contains(idxMacchina); - //var recipePath = MDService.MacchineRecipeConf(idxMacchina); - //return !string.IsNullOrEmpty(recipePath); } /// diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 89945777..46079cca 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -68,22 +68,6 @@ namespace MP.SPEC.Data Log.Info("MpDataService | INIT completed"); } - /// - /// Helper trace messaggio log (SE abilitato) - /// - /// - private void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null) - { - if (!traceEnabled) - return; - - reqLevel ??= NLog.LogLevel.Debug; - - // Loggo! - Log.Log(reqLevel, traceMsg); - } - private bool traceEnabled = false; - #endregion Public Constructors #region Public Events @@ -98,6 +82,7 @@ namespace MP.SPEC.Data #region Public Properties public static MpSpecController dbController { get; set; } = null!; + public static MpMongoController mongoController { get; set; } = null!; public MessagePipe BroadastMsgPipe { get; set; } = null!; @@ -688,6 +673,20 @@ namespace MP.SPEC.Data /// public string ConfigTryGet(string keyName) { + using var activity = ActivitySource.StartActivity("ConfigTryGet"); + string source = "MEMORY"; + + EnsureConfigLoaded(); + + _configData.TryGetValue(keyName, out var value); + + activity?.SetTag("data.source", source); + activity?.Stop(); + + LogTrace($"ConfigTryGet Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); + return value ?? ""; + +#if false string answ = ""; using var activity = ActivitySource.StartActivity("ConfigTryGet"); string source = "DB+REDIS"; @@ -712,7 +711,8 @@ namespace MP.SPEC.Data activity?.SetTag("data.source", source); activity?.Stop(); LogTrace($"ConfigTryGet Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); - return answ; + return answ; +#endif } /// @@ -722,6 +722,20 @@ namespace MP.SPEC.Data /// public async Task ConfigTryGetAsync(string keyName) { + using var activity = ActivitySource.StartActivity("ConfigTryGetAsync"); + string source = "MEMORY"; + + await EnsureConfigLoadedAsync(); + + _configData.TryGetValue(keyName, out var value); + + activity?.SetTag("data.source", source); + activity?.Stop(); + + LogTrace($"ConfigTryGetAsync Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); + return value ?? ""; + +#if false string answ = ""; using var activity = ActivitySource.StartActivity("ConfigTryGetAsync"); string source = "DB+REDIS"; @@ -747,6 +761,7 @@ namespace MP.SPEC.Data activity?.Stop(); LogTrace($"ConfigTryGetAsync Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); return answ; +#endif } /// @@ -1728,6 +1743,7 @@ namespace MP.SPEC.Data LogTrace($"MacchineGetFilt | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); return result; } + /// /// Elenco di tutte le macchine filtrate x gruppo /// @@ -2037,6 +2053,24 @@ namespace MP.SPEC.Data using var activity = ActivitySource.StartActivity("ODLClose"); string source = "DB"; bool fatto = false; + + await EnsureConfigLoadedAsync(); + bool confRett = false; + _configData.TryGetValue("confRett", out var value); + if (!string.IsNullOrEmpty(value)) + { + bool.TryParse(value, out confRett); + } + int modoConfProd = 0; + _configData.TryGetValue("modoConfProd", out var vModo); + if (!string.IsNullOrEmpty(value)) + { + int.TryParse(vModo, out modoConfProd); + } + // chiamo metodo conferma! + fatto = await dbController.ODLClose(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd); + +#if false // recupero dati x conf modalità conferma var configData = await ConfigGetAllAsync(); if (configData != null) @@ -2055,7 +2089,8 @@ namespace MP.SPEC.Data } // chiamo metodo conferma! fatto = await dbController.ODLClose(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd); - } + } +#endif activity?.SetTag("data.source", source); activity?.Stop(); LogTrace($"ODLClose | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); @@ -2760,6 +2795,21 @@ namespace MP.SPEC.Data LogTrace($"ResetMicrostatoMacchina | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); } + /// + /// Statistiche ODL calcolate (da stored stp_STAT_ODL) + /// + /// + public Task> StatOdl(int IdxOdl) + { + using var activity = ActivitySource.StartActivity("StatOdl"); + string source = "DB"; + var result = dbController.OdlStart(IdxOdl); + activity?.SetTag("data.source", source); + activity?.Stop(); + LogTrace($"StatOdl | {source} | {activity?.Duration.TotalMilliseconds}ms"); + return result; + } + /// /// Stato macchina /// @@ -2796,21 +2846,6 @@ namespace MP.SPEC.Data return result; } - /// - /// Statistiche ODL calcolate (da stored stp_STAT_ODL) - /// - /// - public Task> StatOdl(int IdxOdl) - { - using var activity = ActivitySource.StartActivity("StatOdl"); - string source = "DB"; - var result = dbController.OdlStart(IdxOdl); - activity?.SetTag("data.source", source); - activity?.Stop(); - LogTrace($"StatOdl | {source} | {activity?.Duration.TotalMilliseconds}ms"); - return result; - } - /// /// Restituisce il valore da REDIS associato al tag richiesto /// @@ -2982,7 +3017,7 @@ namespace MP.SPEC.Data } /// - /// Update valore Dossier + /// Update valore Dossier /// /// /// @@ -3277,6 +3312,8 @@ namespace MP.SPEC.Data private static Logger Log = LogManager.GetCurrentClassLogger(); + private Dictionary _configData = new(); + private string MpIoNS = ""; /// @@ -3303,14 +3340,18 @@ namespace MP.SPEC.Data private int redisShortTimeCache = 2; + private bool traceEnabled = false; + #endregion Private Fields #region Private Properties +#if false /// /// Cache dati config /// - private List configData { get; set; } = new List(); + private List configData { get; set; } = new List(); +#endif #endregion Private Properties @@ -3327,6 +3368,43 @@ namespace MP.SPEC.Data ExecFlushRedisPattern(pattern); } } + private void EnsureConfigLoaded() + { + if (_configData.Count == 0) + { + var list = ConfigGetAll(); + + _configData = list + .GroupBy(x => x.Chiave) + .ToDictionary(g => g.Key, g => g.First().Valore); + } + } + private async Task EnsureConfigLoadedAsync() + { + if (_configData.Count == 0) + { + var list = await ConfigGetAllAsync(); + + _configData = list + .GroupBy(x => x.Chiave) + .ToDictionary(g => g.Key, g => g.First().Valore); + } + } + + /// + /// Helper trace messaggio log (SE abilitato) + /// + /// + private void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null) + { + if (!traceEnabled) + return; + + reqLevel ??= NLog.LogLevel.Trace; + + // Loggo! + Log.Log(reqLevel, traceMsg); + } private async Task POdlFlushCache() {