Update: spostao da DTO a conf la parte setup IOB + metodi ad avvio class MpDataService
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Conf
|
||||
{
|
||||
/// <summary>
|
||||
/// Struttura conf del file conf TAG x IOB
|
||||
/// </summary>
|
||||
public class IobTags
|
||||
{
|
||||
/// <summary>
|
||||
/// Oggetto dizionario di configurazione x IOB
|
||||
/// </summary>
|
||||
public Dictionary<string, List<TagData>> IobSetup = new Dictionary<string, List<TagData>>();
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.DTO
|
||||
namespace MP.Data.Conf
|
||||
{
|
||||
/// <summary>
|
||||
/// Item da mostrare nei blocchi MON degli impianti come override ai dati MSE
|
||||
/// </summary>
|
||||
public class TagDataDTO
|
||||
public class TagData
|
||||
{
|
||||
/// <summary>
|
||||
/// Indice della colonna (ordine) del dato
|
||||
@@ -26,6 +26,6 @@ namespace MP.Data.DTO
|
||||
/// <summary>
|
||||
/// Indicazione della chiave REDIS dove recuperare il tag indicato (già in formato string)
|
||||
/// </summary>
|
||||
public string TagLocation{ get; set; } = "";
|
||||
public string TagLocation { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
[
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"IobSetup": {
|
||||
"GIACO_ICOEL_001": [
|
||||
{
|
||||
"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"
|
||||
}
|
||||
],
|
||||
"GIACO_ICOEL_002": [
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using NLog;
|
||||
using MP.Data.DTO;
|
||||
using Newtonsoft.Json;
|
||||
using MP.Data;
|
||||
using MP.Data.Conf;
|
||||
|
||||
namespace MP.Mon.Data
|
||||
{
|
||||
@@ -17,6 +18,11 @@ namespace MP.Mon.Data
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario dei tag configurati per IOB
|
||||
/// </summary>
|
||||
protected Dictionary<string, List<TagData>> currTagConf { get; set; } = new Dictionary<string, List<TagData>>();
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS
|
||||
/// </summary>
|
||||
@@ -36,6 +42,57 @@ namespace MP.Mon.Data
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// restituisce il valore da REDIS associato al tag richeisto
|
||||
/// </summary>
|
||||
/// <param name="redKey">Chiave in cui cercare il valore</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> getTagConf(string redKey)
|
||||
{
|
||||
string outVal = "";
|
||||
// cerco in REDIS la conf x l'IOB
|
||||
string rawData = await redisDb.StringGetAsync(redKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
outVal = rawData;
|
||||
}
|
||||
return await Task.FromResult(outVal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prova a caricare da file la conf degli IOB se presente
|
||||
/// </summary>
|
||||
private void tryLoadIobTags()
|
||||
{
|
||||
Dictionary<string, List<TagData>> currConf = new Dictionary<string, List<TagData>>();
|
||||
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 (File.Exists(filePath))
|
||||
{
|
||||
string rawData = File.ReadAllText(filePath);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
var fileConfData = JsonConvert.DeserializeObject<IobTags>(rawData);
|
||||
if (fileConfData != null)
|
||||
{
|
||||
currConf = fileConfData.IobSetup;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currConf != null)
|
||||
{
|
||||
currTagConf = currConf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MpDataService(IConfiguration configuration, ILogger<MpDataService> logger)
|
||||
@@ -43,6 +100,9 @@ namespace MP.Mon.Data
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
|
||||
// setup conf IOB da dizionario
|
||||
tryLoadIobTags();
|
||||
|
||||
// setup compoenti REDIS
|
||||
this.redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis"));
|
||||
this.redisDb = this.redisConn.GetDatabase();
|
||||
@@ -95,62 +155,6 @@ 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
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"))
|
||||
// avvio oggetto shared x redis...
|
||||
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
||||
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddServerSideBlazor();
|
||||
|
||||
Reference in New Issue
Block a user