From a18d91fabbf016543525f3de85df56b47cb54628 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Fri, 7 Mar 2025 21:42:52 +0100 Subject: [PATCH] Fix MessageService --- MP.Data/Services/MessageService.cs | 145 +++++++++++++++++------------ 1 file changed, 88 insertions(+), 57 deletions(-) diff --git a/MP.Data/Services/MessageService.cs b/MP.Data/Services/MessageService.cs index 2ebba5c2..77eae03f 100644 --- a/MP.Data/Services/MessageService.cs +++ b/MP.Data/Services/MessageService.cs @@ -1,6 +1,7 @@ using Blazored.LocalStorage; using Blazored.SessionStorage; using EgwCoreLib.Utils; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal; using Microsoft.Extensions.Configuration; using MP.Data.Controllers; using MP.Data.DatabaseModels; @@ -27,6 +28,54 @@ namespace MP.Data.Services #endregion Public Fields + #region Protected Fields + + protected const string KeyDevIp4 = "DevIpv4"; + + protected const string KeyDevSec = "DevSec"; + + protected const string KeyMacDict = "MachineDict"; + + protected static IConfiguration _configuration = null!; + + /// + /// Oggetto per connessione a REDIS + /// + protected ConnectionMultiplexer redisConn = null!; + + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + protected IDatabase redisDb = null!; + + #endregion Protected Fields + + #region Private Fields + + private AnagOperatoriModel? _rigaOper; + + /// + /// Durata cache lunga IN SECONDI + /// + private int cacheTtlLong = 60 * 5; + + /// + /// Durata cache breve IN SECONDI + /// + private int cacheTtlShort = 60 * 1; + + private string lastIdxMacc = ""; + + private DateTime lastUserUpd = DateTime.Now; + + private Logger Log = LogManager.GetCurrentClassLogger(); + + private string redisBaseKey = "MP:TAB:User"; + + private Random rnd = new Random(); + + #endregion Private Fields + #region Public Constructors public MessageService(IConfiguration configuration, ILocalStorageService genLocalStorage, ISessionStorageService sessStore, TabDataService tdService, SharedMemService smServ) @@ -98,7 +147,6 @@ namespace MP.Data.Services } public DateTime dtLastAction { get; set; } = DateTime.Now; - public DateTime dtLastSave { get; set; } = DateTime.Now; public string LastIdxMacchina @@ -115,6 +163,28 @@ namespace MP.Data.Services } } + /// + /// Cache elenco macchine abilitate all'utente, vuoto se scaduto reload + /// + public List? ListMachineEnabled + { + get + { + List? answ = userListMachine; + if (DateTime.Now.Subtract(lastUserUpd).TotalSeconds > 30) + { + answ = new List(); + Log.Debug("ListMachineEnabled unvalidated"); + } + return answ; + } + set + { + lastUserUpd = DateTime.Now; + userListMachine = value; + } + } + public int MatrOpr { get @@ -184,6 +254,23 @@ namespace MP.Data.Services #endregion Public Properties + #region Protected Properties + + protected int expDays { get; set; } = 0; + protected ILocalStorageService localStorage { get; set; } = null!; + protected ISessionStorageService sessionStore { get; set; } = null!; + protected SharedMemService SMService { get; set; } = null!; + protected TabDataService TDService { get; set; } = null!; + + #endregion Protected Properties + + #region Private Properties + + private List? userListMachine { get; set; } = null; + private Dictionary UserPrefs { get; set; } = new Dictionary(); + + #endregion Private Properties + #region Public Methods public async Task ClearLocalStor() @@ -612,62 +699,6 @@ namespace MP.Data.Services #endregion Public Methods - #region Protected Fields - - protected const string KeyDevIp4 = "DevIpv4"; - protected const string KeyDevSec = "DevSec"; - protected const string KeyMacDict = "MachineDict"; - protected static IConfiguration _configuration = null!; - - /// - /// Oggetto per connessione a REDIS - /// - protected ConnectionMultiplexer redisConn = null!; - - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - protected IDatabase redisDb = null!; - - #endregion Protected Fields - - #region Protected Properties - - protected int expDays { get; set; } = 0; - protected ILocalStorageService localStorage { get; set; } = null!; - protected ISessionStorageService sessionStore { get; set; } = null!; - protected SharedMemService SMService { get; set; } = null!; - protected TabDataService TDService { get; set; } = null!; - - #endregion Protected Properties - - #region Private Fields - - private AnagOperatoriModel? _rigaOper; - - /// - /// Durata cache lunga IN SECONDI - /// - private int cacheTtlLong = 60 * 5; - - /// - /// Durata cache breve IN SECONDI - /// - private int cacheTtlShort = 60 * 1; - - private string lastIdxMacc = ""; - private Logger Log = LogManager.GetCurrentClassLogger(); - private string redisBaseKey = "MP:TAB:User"; - private Random rnd = new Random(); - - #endregion Private Fields - - #region Private Properties - - private Dictionary UserPrefs { get; set; } = new Dictionary(); - - #endregion Private Properties - #region Private Methods private string machineMse(string idxMacc)