Fix preliminare metodi getTC
This commit is contained in:
+115
-13
@@ -1476,6 +1476,53 @@ namespace MP.IOC.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il contapezzi salvato per la macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> pzCounter(string idxMacchina)
|
||||
{
|
||||
int answ = -1;
|
||||
try
|
||||
{
|
||||
string currKey = $"{Utils.redisPzCount}:{idxMacchina}";
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
int.TryParse(rawData, out answ);
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = await pzCounterTC(idxMacchina);
|
||||
// salvo in _redisConn...
|
||||
await redisDb.StringSetAsync(currKey, answ.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in pzCounter{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il contapezzi come CONTEGGIO da TCRilevati per la macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> pzCounterTC(string idxMacchina)
|
||||
{
|
||||
int answ = -1;
|
||||
DateTime dataRif = DateTime.Now;
|
||||
var datiProd = await StatoProdMacchinaAsync(idxMacchina, dataRif);
|
||||
if (datiProd != null)
|
||||
{
|
||||
answ = datiProd.PzTotODL;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ricerca ricetta su MongoDB dato PODL
|
||||
/// </summary>
|
||||
@@ -1738,18 +1785,6 @@ namespace MP.IOC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
public bool RedisSetKey(string valKey, string redVal)
|
||||
{
|
||||
bool answ = redisDb.StringSet(Utils.RedKeyHash(valKey), redVal);
|
||||
return answ;
|
||||
}
|
||||
|
||||
public bool RedisSetKey(RedisKey valKey, string redVal, int TTL_sec)
|
||||
{
|
||||
bool answ = redisDb.StringSet(Utils.RedKeyHash(valKey), redVal, TimeSpan.FromSeconds(TTL_sec));
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato
|
||||
/// </summary>
|
||||
@@ -1878,7 +1913,7 @@ namespace MP.IOC.Data
|
||||
// se NON presente salvo in REDIS con TTL 10 sec e sul DB...
|
||||
if (!keyPresent)
|
||||
{
|
||||
RedisSetKey(currKey, adesso.ToString("s"), 10);
|
||||
redisDb.StringSet(currKey, adesso.ToString("s"), TimeSpan.FromSeconds(10));
|
||||
try
|
||||
{
|
||||
Log.Trace($"Scrittura keep alive! IdxMacchina: {IdxMacchina}");
|
||||
@@ -2121,6 +2156,7 @@ namespace MP.IOC.Data
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
|
||||
private static ILogger<MpDataService> _logger = null!;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
@@ -2146,8 +2182,14 @@ namespace MP.IOC.Data
|
||||
private IDatabase redisDb = null!;
|
||||
|
||||
private int redisLongTimeCache = 5;
|
||||
|
||||
private int redisShortTimeCache = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Generatore random classe
|
||||
/// </summary>
|
||||
private Random rnd = new Random();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
@@ -2175,6 +2217,66 @@ namespace MP.IOC.Data
|
||||
await RedisFlushPatternAsync(pattern);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stato prod macchina (completo)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="dtReq"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<StatoProdModel> StatoProdMacchinaAsync(string idxMacchina, DateTime dtReq)
|
||||
{
|
||||
int rndWait = rnd.Next(0, 2);
|
||||
await Task.Delay(rndWait);
|
||||
// setup parametri costanti
|
||||
string source = "DB";
|
||||
StatoProdModel? result = new StatoProdModel();
|
||||
// cerco in _redisConn...
|
||||
string currKey = $"{Utils.redisStatoProd}:{idxMacchina}:{dtReq:HHmm}";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
//if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<StatoProdModel>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = IocDbController.StatoProdMacchina(idxMacchina, dtReq);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromSeconds(5));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new StatoProdModel();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#if false
|
||||
public bool RedisSetKey(string valKey, string redVal)
|
||||
{
|
||||
bool answ = redisDb.StringSet(Utils.RedKeyHash(valKey), redVal);
|
||||
return answ;
|
||||
}
|
||||
public async Task<bool> RedisSetKeyAsync(string valKey, string redVal)
|
||||
{
|
||||
bool answ = await redisDb.StringSetAsync(Utils.RedKeyHash(valKey), redVal);
|
||||
return answ;
|
||||
}
|
||||
|
||||
public bool RedisSetKey(RedisKey valKey, string redVal, int TTL_sec)
|
||||
{
|
||||
bool answ = redisDb.StringSet(Utils.RedKeyHash(valKey), redVal, TimeSpan.FromSeconds(TTL_sec));
|
||||
return answ;
|
||||
}
|
||||
public async Task<bool> RedisSetKeyAsync(RedisKey valKey, string redVal, int TTL_sec)
|
||||
{
|
||||
bool answ = await redisDb.StringSetAsync(Utils.RedKeyHash(valKey), redVal, TimeSpan.FromSeconds(TTL_sec));
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user