126 lines
4.6 KiB
C#
126 lines
4.6 KiB
C#
using Egw.Window.Data;
|
|
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data.Controllers;
|
|
using EgwCoreLib.Lux.Data.DbModel.Config;
|
|
using EgwMultiEngineManager.Data;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EgwCoreLib.Lux.Data.Services
|
|
{
|
|
public class ConfigDataService : BaseServ
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ConfigDataService(IConfiguration configuration, IConnectionMultiplexer RedisConn) : base(configuration, RedisConn)
|
|
{
|
|
// init implicito
|
|
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 List<HardwareModel> HwModelList(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 = redisDb.StringGet(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 List<string> ProfileList(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 = redisDb.StringGet(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 List<string> ProfileThreshList(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 = redisDb.StringGet(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 Dictionary<string, List<Threshold>> ProfileThreshDict(Constants.EXECENVIRONMENTS execEnvironment)
|
|
{
|
|
Dictionary<string, List<Threshold>> result = new Dictionary<string, List<Threshold>>();
|
|
// recupero profili per ciclare...
|
|
List<string> profList = ProfileList(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
|
|
}
|
|
} |