72f579f151
- Fix editing parametro in dossier - fix cache refresh live params
1193 lines
45 KiB
C#
1193 lines
45 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.SPEC.Data
|
|
{
|
|
public class MpDataService : IDisposable
|
|
{
|
|
#region Public Constructors
|
|
|
|
public MpDataService(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.MpSpecController(configuration);
|
|
_logger.LogInformation("DbController OK");
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
public static MP.Data.Controllers.MpSpecController 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 async Task<List<ListValues>> AnagStatiComm()
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
List<ListValues>? result = new List<ListValues>();
|
|
// cerco in redis...
|
|
RedisValue rawData = await redisDb.StringGetAsync(redisStatoCom);
|
|
if (!string.IsNullOrEmpty($"{rawData}"))
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ListValues>>($"{rawData}");
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"AnagStatiComm Read from REDIS: {ts.TotalMilliseconds}ms");
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.AnagStatiComm());
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(redisStatoCom, rawData, getRandTOut(redisLongTimeCache));
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"AnagStatiComm Read from DB: {ts.TotalMilliseconds}ms");
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ListValues>();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public async Task<List<ListValues>> AnagTipoArtLV()
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string source = "DB";
|
|
List<ListValues>? result = new List<ListValues>();
|
|
// cerco in redis...
|
|
RedisValue rawData = await redisDb.StringGetAsync(redisTipoArt);
|
|
if (!string.IsNullOrEmpty($"{rawData}"))
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ListValues>>($"{rawData}");
|
|
source = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.AnagTipoArtLV());
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(redisTipoArt, rawData, getRandTOut(redisLongTimeCache));
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"AnagTipoArtLV Read from {source}: {ts.TotalMilliseconds}ms");
|
|
if (result == null)
|
|
{
|
|
result = new List<ListValues>();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Codice articolo con dati dossier gestiti
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<string>> ArticleWithDossier()
|
|
{
|
|
List<string>? result = new List<string>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = redisArtByDossier;
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<string>>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.ArticleWithDossier());
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<string>();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"ArticleWithDossier | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione record selezionato
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ArticoliDeleteRecord(AnagArticoli currRec)
|
|
{
|
|
bool fatto = await dbController.ArticoliDeleteRecord(currRec);
|
|
await resetCacheArticoli();
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restitusice elenco articoli cercati
|
|
/// </summary>
|
|
/// <param name="numRecord"></param>
|
|
/// <param name="searchVal"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<AnagArticoli>> ArticoliGetSearch(int numRecord, string azienda, string searchVal)
|
|
{
|
|
List<AnagArticoli>? result = new List<AnagArticoli>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = $"{redisArtList}:{azienda}";
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<AnagArticoli>>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.ArticoliGetSearch(numRecord, azienda, searchVal));
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache / 5));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<AnagArticoli>();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"ArticoliGetSearch | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiornamento record selezionato
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ArticoliUpdateRecord(AnagArticoli currRec)
|
|
{
|
|
bool fatto = await dbController.ArticoliUpdateRecord(currRec);
|
|
await resetCacheArticoli();
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica se sia possiubile cancellare articolo dato suo CodArt cercando su redis o su
|
|
/// tab veto da DB
|
|
/// </summary>
|
|
/// <param name="CodArt"></param>
|
|
/// <returns></returns>
|
|
public bool ArticoloDelEnabled(object CodArt)
|
|
{
|
|
bool answ = false;
|
|
string codArticolo = $"{CodArt}";
|
|
int cacheCheckArtUsato = 1;
|
|
int.TryParse(_configuration.GetValue<string>("ServerConf:cacheCheckArtUsato"), out cacheCheckArtUsato);
|
|
TimeSpan TTLCache = getRandTOut(cacheCheckArtUsato);
|
|
// cerco in cache redis...
|
|
string redKeyArtUsed = $"{Utils.redKeyArtUsed}:{codArticolo}";
|
|
string redKeyTabCheckArt = Utils.redKeyTabCheckArt;
|
|
string rawData = redisDb.StringGet(redKeyArtUsed);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
bool.TryParse(rawData, out answ);
|
|
}
|
|
else
|
|
{
|
|
// controllo non sia stato mai prodotto sennò non posso cancellare...
|
|
try
|
|
{
|
|
// cerco in cache se ci sia la tabella con gli articoli impiegati...
|
|
string rawTable = redisDb.StringGet(redKeyTabCheckArt);
|
|
List<string>? artList = new List<string>();
|
|
if (!string.IsNullOrEmpty(rawTable))
|
|
{
|
|
artList = JsonConvert.DeserializeObject<List<string>>(rawTable);
|
|
}
|
|
// rileggo...
|
|
if (artList == null || artList.Count == 0)
|
|
{
|
|
artList = new List<string>();
|
|
var tabArticoli = dbController.ArticoliGetUsed();
|
|
var codList = tabArticoli.Select(x => x.CodArticolo);
|
|
foreach (string cod in codList)
|
|
{
|
|
artList.Add(cod);
|
|
}
|
|
// SE fosse vuoto aggiungo comunque il cado "ND"...
|
|
if (artList.Count == 0)
|
|
{
|
|
artList.Add("ND");
|
|
}
|
|
// salvo
|
|
rawTable = JsonConvert.SerializeObject(artList);
|
|
redisDb.StringSet(redKeyTabCheckArt, rawTable, TTLCache);
|
|
}
|
|
// cerco nella tabella: se ci fosse --> disabilitato delete
|
|
bool usato = false;
|
|
if (artList != null && artList.Count > 0)
|
|
{
|
|
usato = artList.Contains(codArticolo);
|
|
}
|
|
answ = !usato;
|
|
redisDb.StringSet(redKeyArtUsed, $"{answ}", TTLCache);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public async Task<List<ConfigModel>> ConfigGetAll()
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
List<ConfigModel>? result = new List<ConfigModel>();
|
|
// cerco in redis...
|
|
RedisValue rawData = await redisDb.StringGetAsync(redisConfKey);
|
|
if (!string.IsNullOrEmpty($"{rawData}"))
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<ConfigModel>>($"{rawData}");
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"ConfigGetAll Read from REDIS: {ts.TotalMilliseconds}ms");
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.ConfigGetAll());
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
await redisDb.StringSetAsync(redisConfKey, rawData, getRandTOut(redisLongTimeCache));
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"ConfigGetAll Read from DB: {ts.TotalMilliseconds}ms");
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<ConfigModel>();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset dati cache config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task ConfigResetCache()
|
|
{
|
|
await redisDb.StringSetAsync(redisConfKey, "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update chiave config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> ConfigUpdate(ConfigModel updRec)
|
|
{
|
|
return await Task.FromResult(dbController.ConfigUpdate(updRec));
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database controller
|
|
dbController.Dispose();
|
|
redisConn.Dispose();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione di un dossier
|
|
/// </summary>
|
|
/// <param name="selRecord">record dossier da eliminare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DossiersDeleteRecord(DossierModel selRecord)
|
|
{
|
|
bool result = false;
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
result = await dbController.DossiersDeleteRecord(selRecord);
|
|
// elimino cache redis...
|
|
RedisValue pattern = new RedisValue($"{redisDossByMac}:*");
|
|
bool answ = await ExecFlushRedisPattern(pattern);
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"DossiersDeleteRecord | IdxMacchina {selRecord.IdxMacchina} | DtRif {selRecord.DtRif} | IdxODL {selRecord.IdxODL} | {ts.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco ultimi n record DOssiers (che contengono ad esempio "salvataggi" di FLuxLog) dato
|
|
/// macchina (ordinato x data registrazione)
|
|
/// </summary>
|
|
/// <param name="IdxMacchina">* = tutte, altrimenti solo x una data macchina</param>
|
|
/// <param name="DtStart">Data minima per estrazione records</param>
|
|
/// <param name="DtEnd">Data Massima per estrazione records</param>
|
|
/// <returns></returns>
|
|
public async Task<List<DossierModel>> DossiersGetLastFilt(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd)
|
|
{
|
|
List<DossierModel>? result = new List<DossierModel>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = $"{redisDossByMac}:{IdxMacchina}:{CodArticolo}:{DtStart:yyyyMMddHHmm}:{DtEnd:yyyyMMddHHmm}";
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<DossierModel>>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.DossiersGetLastFilt(IdxMacchina, CodArticolo, DtStart, DtEnd));
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache / 5));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<DossierModel>();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"DossiersGetLastFilt | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento nuovo record dossier
|
|
/// </summary>
|
|
/// <param name="currDoss"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DossiersInsert(DossierModel currDoss)
|
|
{
|
|
// aggiorno record sul DB
|
|
bool answ = await dbController.DossiersInsert(currDoss);
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua salvataggio snapshot parametri (con stored) + svuota eventuale cache redis
|
|
/// </summary>
|
|
/// <param name="IdxMacchina">macchina</param>
|
|
/// <param name="MaxSec">NUm massimo secondi per recuperare dati correnti</param>
|
|
/// <param name="DtRif">DataOra riferimento x cui prendere valori antecedenti</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DossiersTakeParamsSnapshot(string IdxMacchina, int MaxSec, DateTime DtRif)
|
|
{
|
|
bool answ = false;
|
|
await Task.Delay(1);
|
|
// chiamo stored x salvare parametri
|
|
dbController.DossiersTakeParamsSnapshot(IdxMacchina, MaxSec, DtRif);
|
|
// elimino cache redis...
|
|
RedisValue pattern = new RedisValue($"{redisDossByMac}:*");
|
|
answ = await ExecFlushRedisPattern(pattern);
|
|
Log.Info($"Svuotata cache dossier | {pattern}");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua salvataggio snapshot parametri (con stored) + svuota eventuale cache redis
|
|
/// </summary>
|
|
/// <param name="IdxMacchina">macchina</param>
|
|
/// <param name="MaxSec">NUm massimo secondi per recuperare dati correnti</param>
|
|
/// <param name="DtRif">DataOra riferimento x cui prendere valori antecedenti</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DossiersTakeParamsSnapshotLast(string IdxMacchina, DateTime dtMin, DateTime dtMax)
|
|
{
|
|
bool answ = false;
|
|
await Task.Delay(1);
|
|
Log.Info($"Richiesta snapshot per macchina {IdxMacchina} | periodo {dtMin} --> {dtMax}");
|
|
// chiamo stored x salvare parametri
|
|
dbController.DossiersTakeParamsSnapshotLast(IdxMacchina, dtMin, dtMax);
|
|
// elimino cache redis...
|
|
RedisValue pattern = new RedisValue($"{redisDossByMac}:*");
|
|
answ = await ExecFlushRedisPattern(pattern);
|
|
Log.Info($"Svuotata cache dossier | {pattern}");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update valore dossier
|
|
/// </summary>
|
|
/// <param name="currDoss"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DossiersUpdateValore(DossierModel currDoss)
|
|
{
|
|
// aggiorno record sul DB
|
|
bool answ = await dbController.DossiersUpdateValore(currDoss);
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restitusice elenco aziende
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Task<List<AnagGruppi>> ElencoAziende()
|
|
{
|
|
return Task.FromResult(dbController.AnagGruppiAziende());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restitusice elenco fasi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Task<List<AnagGruppi>> ElencoGruppiFase()
|
|
{
|
|
return Task.FromResult(dbController.AnagGruppiFase());
|
|
}
|
|
|
|
public Task<List<LinkMenu>> ElencoLink()
|
|
{
|
|
return Task.FromResult(dbController.ElencoLink());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record EventList
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> EvListInsert(EventListModel newRec)
|
|
{
|
|
return await dbController.EvListInsert(newRec);
|
|
}
|
|
|
|
public async Task<bool> FlushRedisCache()
|
|
{
|
|
await Task.Delay(1);
|
|
RedisValue pattern = new RedisValue($"{redisBaseAddr}*");
|
|
bool answ = await ExecFlushRedisPattern(pattern);
|
|
// rileggo vocabolario.,..
|
|
ObjVocabolario = VocabolarioGetAll();
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco ultimi n record flux log dato macchina e flusso (ordinato x data registrazione)
|
|
/// </summary>
|
|
/// <param name="DtMax">Data massima x eventi</param>
|
|
/// <param name="DtMin">Data minima x eventi</param>
|
|
/// <param name="IdxMacchina">* = tutte, altrimenti solo x una data macchina</param>
|
|
/// <param name="CodFlux">*=tutti, altrimenti solo selezionato</param>
|
|
/// <param name="MaxRec">numero massimo record da restituire</param>
|
|
/// <returns></returns>
|
|
public async Task<List<FluxLog>> FluxLogGetLastFilt(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec, int redisCacheSec)
|
|
{
|
|
List<FluxLog>? result = new List<FluxLog>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = $"{redisFluxLogFilt}:{IdxMacchina}:{CodFlux}:{MaxRec}:{DtMax:yyyyMMddHHmm}:{DtMin:yyyyMMddHHmm}";
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<FluxLog>>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.FluxLogGetLastFilt(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec));
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(redisCacheSec / 2));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<FluxLog>();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"FluxLogGetLastFilt | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco setup dei tag conf correnti
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Task<Dictionary<string, List<TagData>>> getAllTags()
|
|
{
|
|
return Task.FromResult(currTagConf);
|
|
}
|
|
|
|
public List<FluxLogDTO> getFluxLog(string Valore)
|
|
{
|
|
List<FluxLogDTO> answ = new List<FluxLogDTO>();
|
|
DossierFluxLogDTO? result = JsonConvert.DeserializeObject<DossierFluxLogDTO>(Valore);
|
|
if (result != null)
|
|
{
|
|
if (result.ODL != null)
|
|
{
|
|
answ = result
|
|
.ODL
|
|
.OrderBy(x => x.CodFlux)
|
|
.ToList();
|
|
// inizializzo SE necessario
|
|
foreach (var item in answ)
|
|
{
|
|
item.ValoreEdit = String.IsNullOrEmpty(item.ValoreEdit) ? item.Valore : item.ValoreEdit;
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce il valore da REDIS associato al tag richeisto
|
|
/// </summary>
|
|
/// <param name="redKey">Chiave in cui cercare il valore</param>
|
|
/// <returns></returns>
|
|
public string getTagConf(string redKey)
|
|
{
|
|
string outVal = "";
|
|
// cerco in REDIS la conf x l'IOB
|
|
var rawData = redisDb.StringGet(redKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
outVal = $"{rawData}";
|
|
}
|
|
return outVal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco ODL filtrati x stato, articolo, KeyRich (che contiene stato)
|
|
/// </summary>
|
|
/// <param name="inCorso">Stato ODL: true=in corso/completato</param>
|
|
/// <param name="codArt">Cod articolo</param>
|
|
/// <param name="keyRichPart">KeyRich (parziale) da cercare (es cod stato x yacht)</param>
|
|
/// <param name="IdxMacchina">id macchina da cercare</param>
|
|
/// <returns></returns>
|
|
public async Task<List<ODLModel>> ListODLFilt(bool inCorso, string codArt, string keyRichPart, string IdxMacchina, DateTime startDate, DateTime endDate)
|
|
{
|
|
return await Task.FromResult(dbController.ListODLFilt(inCorso, codArt, keyRichPart, IdxMacchina, startDate, endDate));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco PODL non avviati filtrati x articolo, KeyRich (che contiene stato)
|
|
/// </summary>
|
|
/// <param name="codArt">Cod articolo</param>
|
|
/// <param name="keyRichPart">KeyRich (parziale) da cercare (es cod stato x yacht)</param>
|
|
/// <returns></returns>
|
|
public async Task<List<PODLModel>> ListPODLFilt(string codArt, string keyRichPart)
|
|
{
|
|
List<PODLModel>? result = new List<PODLModel>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = $"{redisPOdlList}:{codArt}:{keyRichPart}";
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<PODLModel>>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.ListPODLFilt(codArt, keyRichPart));
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(3));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<PODLModel>();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"ListPODLFilt | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco di tutte le macchine gestite
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<Macchine>> MacchineGetAll()
|
|
{
|
|
List<Macchine>? result = new List<Macchine>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = redisMacList;
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<Macchine>>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.MacchineGetAll());
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<Macchine>();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"MacchineGetAll | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco id Macchine che abbiano dati FLuxLog, nel periodo indicato
|
|
/// </summary>
|
|
/// <param name="dtStart"></param>
|
|
/// <param name="dtEnd"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<string>> MacchineWithFlux(DateTime dtStart, DateTime dtEnd)
|
|
{
|
|
List<string>? result = new List<string>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = $"{redisMacByFlux}:{dtStart:yyyyMMddHHmm}:{dtEnd:yyyyMMddHHmm}";
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<string>>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.MacchineWithFlux(dtStart, dtEnd);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<string>();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"MacchineWithFlux | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua chiusura dell'ODL indicato, andand
|
|
/// </summary>
|
|
/// <param name="idxOdl">idx odl da chiudere</param>
|
|
/// <param name="idxMacchina">idx macchina</param>
|
|
/// <param name="matrOpr">matricola operatore</param>
|
|
/// <param name="confPezzi">indica se confermare i pezzi priam di chiudere ODL</param>
|
|
public async Task<bool> ODLClose(int idxOdl, string idxMacchina, int matrOpr, bool confPezzi)
|
|
{
|
|
bool fatto = false;
|
|
await Task.Delay(1);
|
|
// recupero dati x conf modalità conferma
|
|
var configData = await ConfigGetAll();
|
|
if (configData != null)
|
|
{
|
|
bool confRett = false;
|
|
var currRec = configData.FirstOrDefault(x => x.Chiave == "confRett");
|
|
if (currRec != null)
|
|
{
|
|
bool.TryParse(currRec.Valore, out confRett);
|
|
}
|
|
int modoConfProd = 0;
|
|
currRec = configData.FirstOrDefault(x => x.Chiave == "modoConfProd");
|
|
if (currRec != null)
|
|
{
|
|
int.TryParse(currRec.Valore, out modoConfProd);
|
|
}
|
|
// chiamo metodo conferma!
|
|
fatto = await dbController.ODLClose(idxOdl, idxMacchina, matrOpr, confPezzi, confRett, modoConfProd);
|
|
}
|
|
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Record ODL da chaive
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<ODLModel> OdlGetByKey(int IdxOdl)
|
|
{
|
|
await Task.Delay(1);
|
|
var dbResult = dbController.OdlGetByKey(IdxOdl);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// ODL correnti (tutti)
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public List<string> OdlGetCurrent()
|
|
{
|
|
List<string>? dbResult = new List<string>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = $"{redisOdlCurrByMac}";
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
try
|
|
{
|
|
dbResult = JsonConvert.DeserializeObject<List<string>>($"{rawData}");
|
|
}
|
|
catch
|
|
{ }
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.OdlGetCurrent().Select(x => x.IdxMacchina).Distinct().ToList();
|
|
rawData = JsonConvert.SerializeObject(dbResult);
|
|
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(3));
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<string>();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"OdlGetCurrent | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco di tutti i parametri filtrati x macchina
|
|
/// </summary>
|
|
/// <param name="IdxMacchina">* = tutte, altrimenti solo x una data macchina</param>
|
|
/// <returns></returns>
|
|
public async Task<List<string>> ParametriGetFilt(string IdxMacchina)
|
|
{
|
|
List<string>? result = new List<string>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = $"{redisFluxByMac}:{IdxMacchina}";
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<string>>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await Task.FromResult(dbController.ParametriGetFilt(IdxMacchina));
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new List<string>();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"ParametriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero PODL da chiave
|
|
/// </summary>
|
|
/// <param name="idxPODL"></param>
|
|
/// <returns></returns>
|
|
public async Task<PODLModel> PODL_getByKey(int idxPODL)
|
|
{
|
|
PODLModel result = new PODLModel();
|
|
if (idxPODL != 0)
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = $"{redisPOdlByPOdl}:{idxPODL}";
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<PODLModel>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = await dbController.PODL_getByKey(idxPODL);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new PODLModel();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"PODL_getByKey | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
}
|
|
else
|
|
{
|
|
Log.Debug("Errore IdxPODL = 0");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero PODL da IdxODL
|
|
/// </summary>
|
|
/// <param name="idxODL"></param>
|
|
/// <returns></returns>
|
|
public PODLModel PODL_getByOdl(int idxODL)
|
|
{
|
|
PODLModel result = new PODLModel();
|
|
if (idxODL != 0)
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
string readType = "DB";
|
|
string currKey = $"{redisPOdlByOdl}:{idxODL}";
|
|
// cerco in redis dato valore sel macchina...
|
|
RedisValue rawData = redisDb.StringGet(currKey);
|
|
if (rawData.HasValue)
|
|
{
|
|
result = JsonConvert.DeserializeObject<PODLModel>($"{rawData}");
|
|
readType = "REDIS";
|
|
}
|
|
else
|
|
{
|
|
result = dbController.PODL_getByOdl(idxODL);
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
|
|
}
|
|
if (result == null)
|
|
{
|
|
result = new PODLModel();
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"PODL_getByOdl | Read from {readType}: {ts.TotalMilliseconds}ms");
|
|
}
|
|
else
|
|
{
|
|
Log.Debug("Errore IdxODL = 0");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione record selezionato
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PODLDeleteRecord(PODLModel currRec)
|
|
{
|
|
return await dbController.PODLDeleteRecord(currRec);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Avvio fase setup per il record selezionato
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> POdlDoSetup(PODLModel currRec)
|
|
{
|
|
return await dbController.PODL_startSetup(currRec, 0, 1, 1, "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiornamento record selezionato
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> POdlUpdateRecord(PODLModel currRec)
|
|
{
|
|
var dbResult = await dbController.PODLUpdateRecord(currRec);
|
|
// elimino cache redis...
|
|
RedisValue pattern = new RedisValue($"{redisPOdlList}:*");
|
|
bool answ = await ExecFlushRedisPattern(pattern);
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Statistiche ODL calcolate (da stored stp_STAT_ODL)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Task<List<StatODLModel>> StatOdl(int IdxOdl)
|
|
{
|
|
return dbController.OdlStart(IdxOdl);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue traduzione dato vocabolario da Lingua + Lemma
|
|
/// </summary>
|
|
/// <param name="lemma"></param>
|
|
/// <param name="lingua"></param>
|
|
/// <returns></returns>
|
|
public string Traduci(string lemma, string lingua)
|
|
{
|
|
string answ = $"[{lemma}]";
|
|
// verifico se ho qualcosa nell'obj vocabolario...
|
|
if (ObjVocabolario == null || ObjVocabolario.Count == 0)
|
|
{
|
|
// inizializzo il vocabolario...
|
|
ObjVocabolario = VocabolarioGetAll();
|
|
}
|
|
var record = ObjVocabolario.Where(x => x.Lingua == lingua && x.Lemma == lemma).FirstOrDefault();
|
|
if (record != null)
|
|
{
|
|
answ = record.Traduzione;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public async Task<bool> updateDossierValue(DossierModel currDoss, FluxLogDTO editFL)
|
|
{
|
|
bool answ = false;
|
|
// recupero intero set valori dossier deserializzando...
|
|
var fluxLogList = getFluxLog(currDoss.Valore);
|
|
await Task.Delay(1);
|
|
|
|
// se tutto ok
|
|
if (fluxLogList != null)
|
|
{
|
|
// da provare...!!!!
|
|
|
|
// elimino vecchio record
|
|
var currRec = fluxLogList.FirstOrDefault(x => x.CodFlux == editFL.CodFlux && x.dtEvento == editFL.dtEvento);
|
|
if (currRec != null)
|
|
{
|
|
fluxLogList.Remove(currRec);
|
|
// aggiungo nuovo
|
|
fluxLogList.Add(editFL);
|
|
}
|
|
|
|
// serializzo nuovamente valore
|
|
DossierFluxLogDTO? result = new DossierFluxLogDTO();
|
|
var ODLflux = result.ODL.ToList();
|
|
foreach (var item in fluxLogList)
|
|
{
|
|
ODLflux.Add(item);
|
|
}
|
|
|
|
DossierFluxLogDTO updatedResult = new DossierFluxLogDTO() { ODL = ODLflux };
|
|
|
|
string rawVal = JsonConvert.SerializeObject(updatedResult);
|
|
currDoss.Valore = rawVal;
|
|
// aggiorno record sul DB
|
|
await dbController.DossiersUpdateValore(currDoss);
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo tabella Vocabolario
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<VocabolarioModel> VocabolarioGetAll()
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
List<VocabolarioModel>? result = new List<VocabolarioModel>();
|
|
string source = "REDIS";
|
|
// cerco in redis...
|
|
RedisValue rawData = redisDb.StringGet(redisVocabolario);
|
|
if (!string.IsNullOrEmpty($"{rawData}"))
|
|
{
|
|
result = JsonConvert.DeserializeObject<List<VocabolarioModel>>($"{rawData}");
|
|
}
|
|
else
|
|
{
|
|
result = dbController.VocabolarioGetAll();
|
|
// serializzo e salvo...
|
|
rawData = JsonConvert.SerializeObject(result);
|
|
redisDb.StringSet(redisVocabolario, rawData, getRandTOut(redisLongTimeCache / 5));
|
|
source = "DB";
|
|
}
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Debug($"VocabolarioGetAll Read from {source}: {ts.TotalMilliseconds}ms");
|
|
if (result == null)
|
|
{
|
|
result = new List<VocabolarioModel>();
|
|
}
|
|
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 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 redisPOdlByOdl = redisBaseAddr + "SPEC:Cache:POdlByOdl";
|
|
private const string redisPOdlByPOdl = redisBaseAddr + "SPEC:Cache:POdlByPOdl";
|
|
private const string redisPOdlList = redisBaseAddr + "SPEC:Cache:POdlList";
|
|
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<MpDataService> _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
|
|
|
|
/// <summary>
|
|
/// Esegue flush memoria redis dato pattern
|
|
/// </summary>
|
|
/// <param name="pattern"></param>
|
|
/// <returns></returns>
|
|
private async Task<bool> ExecFlushRedisPattern(RedisValue pattern)
|
|
{
|
|
bool answ = false;
|
|
var listEndpoints = redisConnAdmin.GetEndPoints();
|
|
foreach (var endPoint in listEndpoints)
|
|
{
|
|
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
|
var server = redisConnAdmin.GetServer(endPoint);
|
|
if (server != null)
|
|
{
|
|
var keyList = server.Keys(redisDb.Database, pattern);
|
|
foreach (var item in keyList)
|
|
{
|
|
await redisDb.KeyDeleteAsync(item);
|
|
}
|
|
// brutalmente rimuovo intero contenuto DB... DANGER
|
|
//await server.FlushDatabaseAsync();
|
|
answ = true;
|
|
}
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
private async Task resetCacheArticoli()
|
|
{
|
|
RedisValue pattern = new RedisValue($"{redisArtByDossier}:*");
|
|
await ExecFlushRedisPattern(pattern);
|
|
pattern = new RedisValue($"{redisArtList}:*");
|
|
await ExecFlushRedisPattern(pattern);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |