diff --git a/MP.Mon/Data/MpDataService.cs b/MP.Mon/Data/MpDataService.cs index 327f4b53..ab191f88 100644 --- a/MP.Mon/Data/MpDataService.cs +++ b/MP.Mon/Data/MpDataService.cs @@ -3,38 +3,13 @@ using MP.Data.DatabaseModels; using Newtonsoft.Json; using NLog; using StackExchange.Redis; +using System.Diagnostics; using System.Text; namespace MP.Mon.Data { public class MpDataService : IDisposable { - #region Public Fields - - public static MP.Data.Controllers.MpMonController dbController { get; set; } = null!; - - #endregion Public Fields - - #region Private Fields - - private static IConfiguration _configuration = null!; - private static ILogger _logger = null!; - - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - - /// - /// Oggetto per connessione a REDIS - /// - private ConnectionMultiplexer redisConn = null!; - - //ISubscriber sub = redis.GetSubscriber(); - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - private IDatabase redisDb = null!; - - #endregion Private Fields - #region Public Constructors public MpDataService(IConfiguration configuration, ILogger logger) @@ -71,6 +46,8 @@ namespace MP.Mon.Data #region Public Properties + public static MP.Data.Controllers.MpMonController dbController { get; set; } = null!; + /// /// Dizionario dei tag configurati per IOB /// @@ -91,6 +68,15 @@ namespace MP.Mon.Data dbController.Dispose(); } + /// + /// Elenco setup dei tag conf correnti + /// + /// + public Task>> getAllTags() + { + return Task.FromResult(currTagConf); + } + /// /// restituisce il valore da REDIS associato al tag richeisto /// @@ -108,8 +94,6 @@ namespace MP.Mon.Data return outVal; } - private string redisMseKey = "MP:MON:Cache:MSE"; - public Task> MacchineGetAll() { return Task.FromResult(dbController.MacchineGetAll()); @@ -117,29 +101,27 @@ namespace MP.Mon.Data public async Task> MseGetAll() { -#if false - var dbResult = dbController.MseGetAll(); - if (dbResult == null) - { - dbResult = new List(); - } - return Task.FromResult(dbResult); -#endif + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); List result = new List(); // cerco in redis... var rawData = await redisDb.StringGetAsync(redisMseKey); if (!string.IsNullOrEmpty(rawData)) { - Log.Trace("Read from REDIS"); result = JsonConvert.DeserializeObject>(rawData); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Read from REDIS: {ts.TotalMilliseconds}ms"); } else { - Log.Trace("Read from DB"); result = await Task.FromResult(dbController.MseGetAll()); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); await redisDb.StringSetAsync(redisMseKey, rawData, TimeSpan.FromSeconds(2)); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Read from DB: {ts.TotalMilliseconds}ms"); } if (result == null) { @@ -150,6 +132,28 @@ namespace MP.Mon.Data #endregion Public Methods + #region Private Fields + + private static IConfiguration _configuration = null!; + private static ILogger _logger = null!; + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + /// + /// Oggetto per connessione a REDIS + /// + private ConnectionMultiplexer redisConn = null!; + + //ISubscriber sub = redis.GetSubscriber(); + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + private IDatabase redisDb = null!; + + private string redisMseKey = "MP:MON:Cache:MSE"; + + #endregion Private Fields + #region Private Methods /// @@ -173,7 +177,8 @@ namespace MP.Mon.Data var fileConfData = JsonConvert.DeserializeObject(rawData); if (fileConfData != null) { - // effettuo esplosione conf SE contenesse il valore "***" = tutti gli IOB + // effettuo esplosione conf SE contenesse il valore "***" = tutti + // gli IOB if (fileConfData.IobSetup.ContainsKey("***")) { // recupero elenco macchine... @@ -184,8 +189,8 @@ namespace MP.Mon.Data { if (!string.IsNullOrEmpty(item.IdxMacchina)) { - // converto i valori x la macchina corrente... - // clono in nuovo oggetto + // converto i valori x la macchina corrente... clono in + // nuovo oggetto var specVal = baseConf.Value.Select(i => i.Clone()).ToList(); // sostituisco segnaposto foreach (var singleVal in specVal) @@ -217,7 +222,6 @@ namespace MP.Mon.Data currConf.Add(item.IdxMacchina, specVal); } } - } // altrimenti copio ed ho finito else diff --git a/MP.Mon/MP.Mon.csproj b/MP.Mon/MP.Mon.csproj index 94287724..553800c1 100644 --- a/MP.Mon/MP.Mon.csproj +++ b/MP.Mon/MP.Mon.csproj @@ -4,7 +4,7 @@ net6.0 enable enable - 6.15.2207.819 + 6.15.2207.909 diff --git a/MP.Mon/Resources/ChangeLog.html b/MP.Mon/Resources/ChangeLog.html index 5c4ba563..870e3194 100644 --- a/MP.Mon/Resources/ChangeLog.html +++ b/MP.Mon/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MON MAPO -

Versione: 6.15.2207.819

+

Versione: 6.15.2207.909


Note di rilascio:
  • diff --git a/MP.Mon/Resources/VersNum.txt b/MP.Mon/Resources/VersNum.txt index 6ac420a2..f1cbf975 100644 --- a/MP.Mon/Resources/VersNum.txt +++ b/MP.Mon/Resources/VersNum.txt @@ -1 +1 @@ -6.15.2207.819 +6.15.2207.909 diff --git a/MP.Mon/Resources/manifest.xml b/MP.Mon/Resources/manifest.xml index 6ecd8b05..3266ea92 100644 --- a/MP.Mon/Resources/manifest.xml +++ b/MP.Mon/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.15.2207.819 + 6.15.2207.909 https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/MP.Mon.zip https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/ChangeLog.html false diff --git a/MP.WASM.Mon/Server/Controllers/MSEController.cs b/MP.WASM.Mon/Server/Controllers/MSEController.cs index 55cc8b9e..57c72a2e 100644 --- a/MP.WASM.Mon/Server/Controllers/MSEController.cs +++ b/MP.WASM.Mon/Server/Controllers/MSEController.cs @@ -24,14 +24,10 @@ namespace MP.WASM.Mon.Server.Controllers /// Avvio controller dei dati MSE ///
/// - public MSEController(MpDataService DataService, IConfiguration configuration, ILogger logger) + public MSEController(MpDataService DataService) { - _logger = logger; - _configuration = configuration; _DataService = DataService; Log.Info("Avviata classe MSEController"); - // setup conf IOB da dizionario - tryLoadIobTags(); } #endregion Public Constructors @@ -70,6 +66,12 @@ namespace MP.WASM.Mon.Server.Controllers return _DataService.MacchineGetAll(); } + [HttpGet("getAllTagConf")] + public Task>> getAllTags() + { + return _DataService.getAllTags(); + } + /// /// Metodo principale x ricevere tutte i dati MSE di tutti gli impianti /// @@ -84,108 +86,14 @@ namespace MP.WASM.Mon.Server.Controllers #region Private Fields - private static IConfiguration _configuration = null!; private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - //private static ILogger _logger = null!; - private readonly ILogger _logger; - - /// - /// Oggetto per connessione a REDIS - /// - private ConnectionMultiplexer redisConn = null!; - - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - private IDatabase redisDb = null!; #endregion Private Fields #region Private Methods - /// - /// Prova a caricare da file la conf degli IOB se presente - /// - private void tryLoadIobTags() - { - Dictionary> currConf = new Dictionary>(); - string strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location; - if (!string.IsNullOrEmpty(strExeFilePath)) - { - string? strWorkPath = Path.GetDirectoryName(strExeFilePath); - if (!string.IsNullOrEmpty(strWorkPath)) - { - string filePath = $"{strWorkPath}/Conf/iobTagsConf.json"; - if (System.IO.File.Exists(filePath)) - { - string rawData = System.IO.File.ReadAllText(filePath); - if (!string.IsNullOrEmpty(rawData)) - { - var fileConfData = JsonConvert.DeserializeObject(rawData); - if (fileConfData != null) - { - // effettuo esplosione conf SE contenesse il valore "***" = tutti - // gli IOB - if (fileConfData.IobSetup.ContainsKey("***")) - { - // recupero elenco macchine... - var elencoMacc = _DataService.MacchineGetAll().Result; - // x ogni macchina creo le righe standard da conf... - var baseConf = fileConfData.IobSetup.Where(x => x.Key == "***").FirstOrDefault(); - foreach (var item in elencoMacc) - { - if (!string.IsNullOrEmpty(item.IdxMacchina)) - { - // converto i valori x la macchina corrente... clono in - // nuovo oggetto - var specVal = baseConf.Value.Select(i => i.Clone()).ToList(); - // sostituisco segnaposto - foreach (var singleVal in specVal) - { - singleVal.TagLocation = singleVal.TagLocation.Replace("***", item.IdxMacchina); - } - // ora aggiungo eventuali valori in override... - if (fileConfData.IobSetup.ContainsKey(item.IdxMacchina)) - { - var otConf = fileConfData.IobSetup.Where(x => x.Key == item.IdxMacchina).FirstOrDefault(); - //verifico x ogni valore other... - foreach (var otTag in otConf.Value) - { - var ovrTag = specVal.Where(x => x.ColNum == otTag.ColNum && x.RowNum == otTag.RowNum).FirstOrDefault(); - // se contiene --> sovrascrivo - if (ovrTag != null) - { - //ovrTag = otTag.Clone(); - specVal.Remove(ovrTag); - specVal.Add(otTag.Clone()); - } - // se non contiene --> aggiungo - else - { - specVal.Add(otTag); - } - } - } - currConf.Add(item.IdxMacchina, specVal); - } - } - } - // altrimenti copio ed ho finito - else - { - currConf = fileConfData.IobSetup; - } - } - } - } - if (currConf != null) - { - currTagConf = currConf; - } - } - } - } + #endregion Private Methods } diff --git a/MP.WASM.Mon/Server/Data/MpDataService.cs b/MP.WASM.Mon/Server/Data/MpDataService.cs index 6037d307..6609d9f0 100644 --- a/MP.WASM.Mon/Server/Data/MpDataService.cs +++ b/MP.WASM.Mon/Server/Data/MpDataService.cs @@ -3,38 +3,13 @@ using MP.Data.DatabaseModels; using Newtonsoft.Json; using NLog; using StackExchange.Redis; +using System.Diagnostics; using System.Text; namespace MP.WASM.Mon.Data { public class MpDataService : IDisposable { - #region Public Fields - - public static MP.Data.Controllers.MpMonController dbController { get; set; } = null!; - - #endregion Public Fields - - #region Private Fields - - private static IConfiguration _configuration = null!; - private static ILogger _logger = null!; - - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - - /// - /// Oggetto per connessione a REDIS - /// - private ConnectionMultiplexer redisConn = null!; - - //ISubscriber sub = redis.GetSubscriber(); - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - private IDatabase redisDb = null!; - - #endregion Private Fields - #region Public Constructors public MpDataService(IConfiguration configuration, ILogger logger) @@ -71,6 +46,8 @@ namespace MP.WASM.Mon.Data #region Public Properties + public static MP.Data.Controllers.MpMonController dbController { get; set; } = null!; + /// /// Dizionario dei tag configurati per IOB /// @@ -91,6 +68,15 @@ namespace MP.WASM.Mon.Data dbController.Dispose(); } + /// + /// Elenco setup dei tag conf correnti + /// + /// + public Task>> getAllTags() + { + return Task.FromResult(currTagConf); + } + /// /// restituisce il valore da REDIS associato al tag richeisto /// @@ -110,21 +96,64 @@ namespace MP.WASM.Mon.Data public Task> MacchineGetAll() { - return Task.FromResult(dbController.MacchineGetAll().ToList()); + return Task.FromResult(dbController.MacchineGetAll()); } - public Task> MseGetAll() + public async Task> MseGetAll() { - var dbResult = dbController.MseGetAll(); - if (dbResult == null) + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + List result = new List(); + // cerco in redis... + var rawData = await redisDb.StringGetAsync(redisMseKey); + if (!string.IsNullOrEmpty(rawData)) { - dbResult = new List(); + result = JsonConvert.DeserializeObject>(rawData); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Read from REDIS: {ts.TotalMilliseconds}ms"); } - return Task.FromResult(dbResult); + else + { + result = await Task.FromResult(dbController.MseGetAll()); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(redisMseKey, rawData, TimeSpan.FromSeconds(2)); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Read from DB: {ts.TotalMilliseconds}ms"); + } + if (result == null) + { + result = new List(); + } + return result; } #endregion Public Methods + #region Private Fields + + private static IConfiguration _configuration = null!; + private static ILogger _logger = null!; + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + /// + /// Oggetto per connessione a REDIS + /// + private ConnectionMultiplexer redisConn = null!; + + //ISubscriber sub = redis.GetSubscriber(); + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + private IDatabase redisDb = null!; + + private string redisMseKey = "MP:MON:Cache:MSE"; + + #endregion Private Fields + #region Private Methods /// @@ -148,7 +177,8 @@ namespace MP.WASM.Mon.Data var fileConfData = JsonConvert.DeserializeObject(rawData); if (fileConfData != null) { - // effettuo esplosione conf SE contenesse il valore "***" = tutti gli IOB + // effettuo esplosione conf SE contenesse il valore "***" = tutti + // gli IOB if (fileConfData.IobSetup.ContainsKey("***")) { // recupero elenco macchine... @@ -159,8 +189,8 @@ namespace MP.WASM.Mon.Data { if (!string.IsNullOrEmpty(item.IdxMacchina)) { - // converto i valori x la macchina corrente... - // clono in nuovo oggetto + // converto i valori x la macchina corrente... clono in + // nuovo oggetto var specVal = baseConf.Value.Select(i => i.Clone()).ToList(); // sostituisco segnaposto foreach (var singleVal in specVal) @@ -192,7 +222,6 @@ namespace MP.WASM.Mon.Data currConf.Add(item.IdxMacchina, specVal); } } - } // altrimenti copio ed ho finito else diff --git a/MP.WASM.Mon/Server/NLog.config b/MP.WASM.Mon/Server/NLog.config new file mode 100644 index 00000000..b32ba10a --- /dev/null +++ b/MP.WASM.Mon/Server/NLog.config @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file