139 lines
4.3 KiB
C#
139 lines
4.3 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<MiDataService> logger)
|
|
{
|
|
_logger = logger;
|
|
_logger.LogInformation("Starting MiDataService 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 connStrData = _configuration.GetConnectionString("Mp.Data");
|
|
string connStrInve = _configuration.GetConnectionString("Mp.Inve");
|
|
if (string.IsNullOrEmpty(connStrData) || string.IsNullOrEmpty(connStrInve))
|
|
{
|
|
_logger.LogError($"DbController: ConnString empty! connStrData: {connStrData} | connStrInve: {connStrInve}");
|
|
}
|
|
else
|
|
{
|
|
dbController = new MP.Data.Controllers.MpInveController(configuration);
|
|
_logger.LogInformation("DbController OK");
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
#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 Public Methods
|
|
|
|
public List<AnagOperatoriModel> ElencoOperatori(int matrOpr, string authkey)
|
|
{
|
|
List<AnagOperatoriModel>? result = new List<AnagOperatoriModel>();
|
|
result = dbController.ElencoOperatori(matrOpr, authkey);
|
|
return result;
|
|
}
|
|
|
|
public List<InventorySessionModel> InventSessCurrList()
|
|
{
|
|
List<InventorySessionModel> result = new List<InventorySessionModel>();
|
|
result = dbController.InventSessCurrList();
|
|
return result;
|
|
}
|
|
|
|
|
|
#endregion Public Methods
|
|
|
|
#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 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
|
|
}
|
|
} |