149 lines
4.8 KiB
C#
149 lines
4.8 KiB
C#
using MP.Data;
|
|
using MP.Data.Conf;
|
|
using MP.Data.DatabaseModels;
|
|
using MP.Data.DTO;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using StackExchange.Redis;
|
|
using System.Diagnostics;
|
|
|
|
namespace MP.INVE.Data
|
|
{
|
|
public class MiDataService : IDisposable
|
|
{
|
|
#region Public Constructors
|
|
|
|
public MiDataService(IConfiguration configuration, ILogger<MpDataService> logger)
|
|
{
|
|
_logger = logger;
|
|
_logger.LogInformation("Starting MpDataService INIT");
|
|
_configuration = configuration;
|
|
|
|
// setup compoenti REDIS
|
|
redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis"));
|
|
redisConnAdmin = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("RedisAdmin"));
|
|
redisDb = redisConn.GetDatabase();
|
|
|
|
// leggo cache lungo periodo
|
|
int.TryParse(_configuration.GetValue<string>("ServerConf:redisLongTimeCache"), out redisLongTimeCache);
|
|
|
|
_logger.LogInformation("Redis INIT");
|
|
|
|
// conf DB
|
|
string connStr = _configuration.GetConnectionString("Mp.Data");
|
|
if (string.IsNullOrEmpty(connStr))
|
|
{
|
|
_logger.LogError("DbController: ConnString empty!");
|
|
}
|
|
else
|
|
{
|
|
dbController = new MP.Data.Controllers.MpInveController(configuration);
|
|
_logger.LogInformation("DbController OK");
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
public static MP.Data.Controllers.MpInveController dbController { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Dizionario dei tag configurati per IOB
|
|
/// </summary>
|
|
public Dictionary<string, List<TagData>> currTagConf { get; set; } = new Dictionary<string, List<TagData>>();
|
|
|
|
#endregion Public Properties
|
|
|
|
|
|
|
|
#region Protected Fields
|
|
|
|
protected Random rand = new Random();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Restituisce un timeout dai minuti richiesti + tempo random 1..60 sec
|
|
/// </summary>
|
|
/// <param name="stdMinutes"></param>
|
|
/// <returns></returns>
|
|
protected TimeSpan getRandTOut(int stdMinutes)
|
|
{
|
|
double rndValue = (double)stdMinutes + (double)rand.Next(1, 60) / 60;
|
|
return TimeSpan.FromMinutes(rndValue);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private const string redisArtByDossier = redisBaseAddr + "SPEC:Cache:ArtByDossier";
|
|
|
|
private const string redisArtList = redisBaseAddr + "SPEC:Cache:ArtList";
|
|
|
|
private const string redisBaseAddr = "MP:";
|
|
|
|
private const string redisConfKey = redisBaseAddr + "SPEC:Cache:Config";
|
|
|
|
private const string redisDossByMac = redisBaseAddr + "SPEC:Cache:DossByMac";
|
|
|
|
private const string redisFluxByMac = redisBaseAddr + "SPEC:Cache:FluxByMac";
|
|
|
|
private const string redisFluxLogFilt = redisBaseAddr + "SPEC:Cache:FluxLogFilt";
|
|
|
|
private const string redisMacByFlux = redisBaseAddr + "SPEC:Cache:MacByFlux";
|
|
|
|
private const string redisMacList = redisBaseAddr + "SPEC:Cache:MacList";
|
|
|
|
private const string redisOdlCurrByMac = redisBaseAddr + "SPEC:Cache:OdlByMac";
|
|
|
|
private const string redisPOdlList = redisBaseAddr + "SPEC:Cache:POdlList";
|
|
|
|
private const string redisPOdlByPOdl = redisBaseAddr + "SPEC:Cache:POdlByPOdl";
|
|
|
|
private const string redisPOdlByOdl = redisBaseAddr + "SPEC:Cache:POdlByOdl";
|
|
|
|
private const string redisStatoCom = redisBaseAddr + "SPEC:Cache:StatoCom";
|
|
|
|
private const string redisTipoArt = redisBaseAddr + "SPEC:Cache:TipoArt";
|
|
|
|
private const string redisVocabolario = redisBaseAddr + "SPEC:Cache:Vocabolario";
|
|
|
|
private static IConfiguration _configuration = null!;
|
|
|
|
private static ILogger<MiDataService> _logger = null!;
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
/// <summary>
|
|
/// Oggetto vocabolario x uso continuo traduzione
|
|
/// </summary>
|
|
private List<VocabolarioModel> ObjVocabolario = new List<VocabolarioModel>();
|
|
|
|
/// <summary>
|
|
/// Oggetto per connessione a REDIS
|
|
/// </summary>
|
|
private ConnectionMultiplexer redisConn = null!;
|
|
|
|
/// <summary>
|
|
/// Oggetto per connessione a REDIS modalità admin (ex flux dati)
|
|
/// </summary>
|
|
private ConnectionMultiplexer redisConnAdmin = null!;
|
|
|
|
/// <summary>
|
|
/// Oggetto DB redis da impiegare x chiamate R/W
|
|
/// </summary>
|
|
private IDatabase redisDb = null!;
|
|
|
|
private int redisLongTimeCache = 5;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |