120 lines
4.7 KiB
C#
120 lines
4.7 KiB
C#
using Egw.Window.Data;
|
|
using EgwCoreLib.Lux.Data.DbModel.Config;
|
|
using EgwMultiEngineManager.Data;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using StackExchange.Redis;
|
|
|
|
namespace EgwCoreLib.Lux.Data.Services.General
|
|
{
|
|
public class ConfigDataService : BaseServ, IConfigDataService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ConfigDataService(IConfiguration configuration, IConnectionMultiplexer RedisConn) : base(configuration, RedisConn)
|
|
{
|
|
// init implicito
|
|
_redisBaseKey = configuration.GetValue<string>("ServerConf:RedisBaseKey") ?? "Lux";
|
|
Log.Info($"ConfigDataService | Init OK");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Restituisce l'elenco dell'HW valido da cache REDIS
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<HardwareModel>> HwModelListAsync(Constants.EXECENVIRONMENTS execEnvironment, string HwReq = "HW.AGB")
|
|
{
|
|
List<HardwareModel> result = new List<HardwareModel>();
|
|
// leggo obj da redis cache
|
|
var currKey = $"{_redisBaseKey}:{execEnvironment}:HML:{HwReq}";
|
|
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
|
// prendo solo i valori validi (Name <> FamilyName)
|
|
if (rawData.HasValue)
|
|
{
|
|
var currList = JsonConvert.DeserializeObject<List<HardwareModel>>($"{rawData}");
|
|
result = currList ?? new List<HardwareModel>();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce l'elenco dei profili da cache REDIS
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<string>> ProfileListAsync(Constants.EXECENVIRONMENTS execEnvironment, string ProfReq = "Default")
|
|
{
|
|
List<string> result = new List<string>();
|
|
// leggo obj da redis cache
|
|
var currKey = $"{_redisBaseKey}:{execEnvironment}:PROF:LIST:{ProfReq}";
|
|
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
|
// prendo solo i valori validi (Name <> FamilyName)
|
|
if (rawData.HasValue)
|
|
{
|
|
var currList = JsonConvert.DeserializeObject<List<string>>($"{rawData}");
|
|
result = currList ?? new List<string>();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce l'elenco dei profili da cache REDIS
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<string>> ProfileThreshListAsync(Constants.EXECENVIRONMENTS execEnvironment, string ProfReq = "Default")
|
|
{
|
|
List<string> result = new List<string>();
|
|
// leggo obj da redis cache
|
|
var currKey = $"{_redisBaseKey}:{execEnvironment}:PROF:THRESH:{ProfReq}";
|
|
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
|
// prendo solo i valori validi (Name <> FamilyName)
|
|
if (rawData.HasValue)
|
|
{
|
|
var currList = JsonConvert.DeserializeObject<List<string>>($"{rawData}");
|
|
result = currList ?? new List<string>();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce il dizionario dei profili + relativa lista soglie da cache REDIS
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<Dictionary<string, List<Threshold>>> ProfileThreshDictAsync(Constants.EXECENVIRONMENTS execEnvironment)
|
|
{
|
|
Dictionary<string, List<Threshold>> result = new Dictionary<string, List<Threshold>>();
|
|
// recupero profili per ciclare...
|
|
List<string> profList = await ProfileListAsync(execEnvironment);
|
|
foreach (var prof in profList)
|
|
{
|
|
// leggo obj da redis cache
|
|
var currKey = $"{_redisBaseKey}:{execEnvironment}:PROF:THRESH:{prof}";
|
|
RedisValue rawData = _redisDb.StringGet(currKey);
|
|
// prendo solo i valori validi (Name <> FamilyName)
|
|
if (rawData.HasValue)
|
|
{
|
|
var currList = JsonConvert.DeserializeObject<List<Threshold>>($"{rawData}") ?? new List<Threshold>();
|
|
if (currList.Any())
|
|
{
|
|
result.Add(prof, currList);
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private string _redisBaseKey = "Lux";
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |