Inizio update x gestione override dati in MON

This commit is contained in:
Samuele E. Locatelli
2022-06-03 19:01:00 +02:00
parent 458d788a13
commit 5135987f1b
8 changed files with 165 additions and 4 deletions
+20
View File
@@ -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";
}
}
+31
View File
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MP.Data.DTO
{
/// <summary>
/// Item da mostrare nei blocchi MON degli impianti come override ai dati MSE
/// </summary>
public class TagDataDTO
{
/// <summary>
/// Indice della colonna (ordine) del dato
/// </summary>
public int ColNum { get; set; } = 0;
/// <summary>
/// Indice della riga del dato
/// </summary>
public int RowNum { get; set; } = 0;
/// <summary>
/// Etichetta da mostrare
/// </summary>
public string TagName { get; set; } = "";
/// <summary>
/// Indicazione della chiave REDIS dove recuperare il tag indicato (già in formato string)
/// </summary>
public string TagLocation{ get; set; } = "";
}
}
+28
View File
@@ -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"
}
]
}
+82
View File
@@ -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<MpDataService> _logger;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
/// <summary>
/// Oggetto per connessione a REDIS
/// </summary>
private ConnectionMultiplexer redisConn = null!;
//ISubscriber sub = redis.GetSubscriber();
/// <summary>
/// Oggetto DB redis da impiegare x chiamate R/W
/// </summary>
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);
}
/// <summary>
/// Configurazione (REDIS) dei tag in override
/// </summary>
/// <param name="CodIOB">IOB di cui cercare la conf</param>
/// <returns></returns>
public async Task<List<TagDataDTO>> getTagConf(string CodIOB)
{
List<TagDataDTO>? currResult = new List<TagDataDTO>();
// 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<List<TagDataDTO>>(rawData);
}
// altrimenti in conf file, se presente, e salvo
if (currResult == null)
{
currResult = tryLoadConf(CodIOB);
}
// altrimenti vuoto!
if (currResult == null)
{
currResult = new List<TagDataDTO>();
}
return await Task.FromResult(currResult);
}
/// <summary>
/// Prova a caricare da file la conf dell'IOB richiesto salvando su REDIS
/// </summary>
/// <param name="codIOB"></param>
/// <exception cref="NotImplementedException"></exception>
private List<TagDataDTO> tryLoadConf(string codIOB)
{
List<TagDataDTO> currConf = new List<TagDataDTO>();
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<List<TagDataDTO>>(rawData);
// salvo in redis!
redisDb.StringSet($"{Constants.CONF_MON_KEY}:{codIOB}", rawData);
}
}
if (currConf == null)
{
currConf = new List<TagDataDTO>();
}
// rendo!
return currConf;
}
#endregion Public Methods
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>6.15.2205.219</Version>
<Version>6.15.2206.319</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MON MAPO</i>
<h4>Versione: 6.15.2205.219</h4>
<h4>Versione: 6.15.2206.319</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
6.15.2205.219
6.15.2206.319
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.15.2205.219</version>
<version>6.15.2206.319</version>
<url>https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/MP.Mon.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>