diff --git a/MP.Data/Constants.cs b/MP.Data/Constants.cs new file mode 100644 index 00000000..da0fdf49 --- /dev/null +++ b/MP.Data/Constants.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.Data +{ + public class Constants + { + + // dati conf REDIS Cache + public static readonly string BASE_HASH = "MAPO"; + + // REDIS KEY Dati correnti + public static readonly string CONF_MON_KEY = $"{BASE_HASH}:Conf:MonDispData"; + public static readonly string ACT_FLUX_DATA_KEY = $"{BASE_HASH}:Current:FluxData"; + + } +} diff --git a/MP.Data/DTO/TagDataDTO.cs b/MP.Data/DTO/TagDataDTO.cs new file mode 100644 index 00000000..da341069 --- /dev/null +++ b/MP.Data/DTO/TagDataDTO.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.Data.DTO +{ + /// + /// Item da mostrare nei blocchi MON degli impianti come override ai dati MSE + /// + public class TagDataDTO + { + /// + /// Indice della colonna (ordine) del dato + /// + public int ColNum { get; set; } = 0; + /// + /// Indice della riga del dato + /// + public int RowNum { get; set; } = 0; + /// + /// Etichetta da mostrare + /// + public string TagName { get; set; } = ""; + /// + /// Indicazione della chiave REDIS dove recuperare il tag indicato (già in formato string) + /// + public string TagLocation{ get; set; } = ""; + } +} diff --git a/MP.Mon/Conf/ICOEL.json b/MP.Mon/Conf/ICOEL.json new file mode 100644 index 00000000..7a762740 --- /dev/null +++ b/MP.Mon/Conf/ICOEL.json @@ -0,0 +1,28 @@ +{ + [ + { + "ColNum": 1, + "RowNum": 1, + "TagName": "Vel", + "TagLocation": "FluxData:TonnOra" + }, + { + "ColNum": 2, + "RowNum": 1, + "TagName": "Vel", + "TagLocation": "FluxData:PezziMin" + }, + { + "ColNum": 1, + "RowNum": 2, + "TagName": "Batch SX", + "TagLocation": "FluxData:BatchL1" + }, + { + "ColNum": 2, + "RowNum": 2, + "TagName": "Batch DX", + "TagLocation": "FluxData:BatchL2" + } + ] +} \ No newline at end of file diff --git a/MP.Mon/Data/MpDataService.cs b/MP.Mon/Data/MpDataService.cs index f29f056b..2d9bed3d 100644 --- a/MP.Mon/Data/MpDataService.cs +++ b/MP.Mon/Data/MpDataService.cs @@ -1,5 +1,10 @@ using MP.Data.DatabaseModels; using System.Text; +using StackExchange.Redis; +using NLog; +using MP.Data.DTO; +using Newtonsoft.Json; +using MP.Data; namespace MP.Mon.Data { @@ -10,6 +15,19 @@ namespace MP.Mon.Data private static IConfiguration _configuration; private static ILogger _logger; + 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 Fields @@ -24,6 +42,13 @@ namespace MP.Mon.Data { _logger = logger; _configuration = configuration; + + // setup compoenti REDIS + this.redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis")); + this.redisDb = this.redisConn.GetDatabase(); + //// setup canali pub/sub + //actLogPipe = new MessagePipe(redisConn, Constants.ACT_LOG_M_QUEUE); + // conf DB string connStr = _configuration.GetConnectionString("Mp.Mon"); if (string.IsNullOrEmpty(connStr)) @@ -70,6 +95,63 @@ namespace MP.Mon.Data return Task.FromResult(dbResult); } + /// + /// Configurazione (REDIS) dei tag in override + /// + /// IOB di cui cercare la conf + /// + public async Task> getTagConf(string CodIOB) + { + List? currResult = new List(); + // cerco in REDIS la conf x l'IOB + string rawData = await redisDb.StringGetAsync($"{Constants.CONF_MON_KEY}:{CodIOB}"); + if (!string.IsNullOrEmpty(rawData)) + { + currResult = JsonConvert.DeserializeObject>(rawData); + } + // altrimenti in conf file, se presente, e salvo + if (currResult == null) + { + currResult = tryLoadConf(CodIOB); + } + // altrimenti vuoto! + if (currResult == null) + { + currResult = new List(); + } + return await Task.FromResult(currResult); + } + + /// + /// Prova a caricare da file la conf dell'IOB richiesto salvando su REDIS + /// + /// + /// + private List tryLoadConf(string codIOB) + { + List currConf = new List(); + string strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location; + string strWorkPath = Path.GetDirectoryName(strExeFilePath); + + string filePath = $"{strWorkPath}/Conf/{codIOB}"; + if (File.Exists(filePath)) + { + string rawData = File.ReadAllText(filePath); + if (!string.IsNullOrEmpty(rawData)) + { + currConf = JsonConvert.DeserializeObject>(rawData); + // salvo in redis! + redisDb.StringSet($"{Constants.CONF_MON_KEY}:{codIOB}", rawData); + } + } + if (currConf == null) + { + currConf = new List(); + } + // rendo! + return currConf; + } + #endregion Public Methods } } \ No newline at end of file diff --git a/MP.Mon/MP.Mon.csproj b/MP.Mon/MP.Mon.csproj index 49875696..c0261946 100644 --- a/MP.Mon/MP.Mon.csproj +++ b/MP.Mon/MP.Mon.csproj @@ -4,7 +4,7 @@ net6.0 enable enable - 6.15.2205.219 + 6.15.2206.319 diff --git a/MP.Mon/Resources/ChangeLog.html b/MP.Mon/Resources/ChangeLog.html index 6ddccf16..b1225424 100644 --- a/MP.Mon/Resources/ChangeLog.html +++ b/MP.Mon/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MON MAPO -

Versione: 6.15.2205.219

+

Versione: 6.15.2206.319


Note di rilascio:
  • diff --git a/MP.Mon/Resources/VersNum.txt b/MP.Mon/Resources/VersNum.txt index 4644d6d0..9b5b893d 100644 --- a/MP.Mon/Resources/VersNum.txt +++ b/MP.Mon/Resources/VersNum.txt @@ -1 +1 @@ -6.15.2205.219 +6.15.2206.319 diff --git a/MP.Mon/Resources/manifest.xml b/MP.Mon/Resources/manifest.xml index 9291d5f2..b1bfe0eb 100644 --- a/MP.Mon/Resources/manifest.xml +++ b/MP.Mon/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.15.2205.219 + 6.15.2206.319 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