1376 lines
48 KiB
C#
1376 lines
48 KiB
C#
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using SHERPA.Data.Controllers;
|
|
using SHERPA.Data.DbModels;
|
|
using StackExchange.Redis;
|
|
using System.Diagnostics;
|
|
|
|
namespace SHERPA.Data.Services
|
|
{
|
|
public class SADDataService : IDisposable
|
|
{
|
|
#region Public Constructors
|
|
|
|
public SADDataService(IConfiguration configuration, IConnectionMultiplexer redisConnMult, IEmailSender emailSender)
|
|
{
|
|
Log.Info("Inizio setup classe SADDataService");
|
|
_configuration = configuration;
|
|
_emailSender = emailSender;
|
|
LogDurationLimitMs = _configuration.GetValue<int>("RuntimeOpt:LogDurationLimitMs");
|
|
// Conf cache
|
|
redisConn = redisConnMult;
|
|
redisDb = this.redisConn.GetDatabase();
|
|
|
|
// json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/
|
|
JSSettings = new JsonSerializerSettings()
|
|
{
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
|
};
|
|
|
|
// cod app
|
|
CodApp = _configuration["CodApp"];
|
|
Modulo = _configuration["Modulo"];
|
|
// Conf DB
|
|
string connStr = _configuration.GetConnectionString("Sherpa.Fatt");
|
|
if (string.IsNullOrEmpty(connStr))
|
|
{
|
|
LogError("ConnString Sherpa.Fatt empty!");
|
|
}
|
|
else
|
|
{
|
|
dbController = new SAcDoController(configuration);
|
|
}
|
|
// Conf DB
|
|
string connStrUser = _configuration.GetConnectionString("Sherpa.Anagr");
|
|
if (string.IsNullOrEmpty(connStrUser))
|
|
{
|
|
LogError("ConnString Sherpa.Anagr empty!");
|
|
}
|
|
else
|
|
{
|
|
dbUserController = new SUserController(configuration);
|
|
}
|
|
// registro avvio
|
|
Log.Info("Avviata classe SADDataService");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Aggiorna un record Accounting Document
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AccDocUpdate(AccoDocModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.AccDocUpdate(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in AccDocUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Duplicazione doc selezionato
|
|
/// </summary>
|
|
/// <param name="idxDoc"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AccoDocClone(int idxDoc)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.AccoDocClone(idxDoc);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in AccoDocClone:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione doc selezionato
|
|
/// </summary>
|
|
/// <param name="item2del"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AccoDocDelete(vDocsExplModel item2del)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.AccoDocDelete(item2del.idxDoc);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in AccoDocDelete:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera AccoDoc (Accounting Document) da Key
|
|
/// </summary>
|
|
/// <param name="DocId"></param>
|
|
/// <returns></returns>
|
|
public async Task<AccoDocModel> AccoDocGetByKey(int DocId)
|
|
{
|
|
string source = "DB";
|
|
AccoDocModel? dbResult = new AccoDocModel();
|
|
string currKey = $"{rKeyDoc}:{DocId}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<AccoDocModel>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new AccoDocModel();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.AccoDocGetByKey(DocId);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new AccoDocModel();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"AccoDocGetByKey | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista configurazione
|
|
/// </summary>
|
|
/// <param name="dtStart"></param>
|
|
/// <param name="dtEnd"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<ConfigModel>> ConfigGetAll()
|
|
{
|
|
string source = "DB";
|
|
List<ConfigModel>? dbResult = new List<ConfigModel>();
|
|
string currKey = $"{rKeyConfig}:Table";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<ConfigModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<ConfigModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.ConfigGetAll();
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<ConfigModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"ConfigGetAll | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera una singola chaive di config da cache/DB
|
|
/// </summary>
|
|
/// <param name="chiave"></param>
|
|
/// <returns></returns>
|
|
public async Task<ConfigModel?> ConfigGetKey(string chiave)
|
|
{
|
|
string source = "DB";
|
|
// cerco in cache direttamente la chiave... altrimenti da redis/db
|
|
ConfigModel? keyResult = null;
|
|
string currKey = $"{rKeyConfig}:Dict:{chiave}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<ConfigModel>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
keyResult = new ConfigModel();
|
|
}
|
|
else
|
|
{
|
|
keyResult = tempResult;
|
|
}
|
|
keyResult = JsonConvert.DeserializeObject<ConfigModel>(rawData);
|
|
}
|
|
else
|
|
{
|
|
var listConfig = await ConfigGetAll();
|
|
keyResult = listConfig.FirstOrDefault(x => x.Chiave == chiave);
|
|
rawData = JsonConvert.SerializeObject(keyResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"ConfigGetKey | {chiave} | {source}", sw.Elapsed);
|
|
return await Task.FromResult(keyResult);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Crea scadenze da elenco fatture
|
|
/// </summary>
|
|
/// <param name="idxDoc"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> CreaScadenze()
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.CreaScadenze();
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in CreaScadenze:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clona un item Customer
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> CustomerClona(CustomerModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.CustomerClona(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in CustomerClona:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elimina un item Customer
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> CustomerDelete(CustomerModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.CustomerDelete(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in CustomerDelete:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Customers eliminabili
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<CustomerModel>> CustomersDeletable()
|
|
{
|
|
string source = "DB";
|
|
List<CustomerModel>? dbResult = new List<CustomerModel>();
|
|
string currKey = $"{rKeyCustDel}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<CustomerModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<CustomerModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.CustomersDeletable();
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<CustomerModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"CustomersDeletable | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Customers
|
|
/// </summary>
|
|
/// <param name="searchVal"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<CustomerModel>> CustomersGetAll(string searchVal)
|
|
{
|
|
string source = "DB";
|
|
List<CustomerModel>? dbResult = new List<CustomerModel>();
|
|
string currKey = $"{rKeyCust}:ALL:{searchVal}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<CustomerModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<CustomerModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.CustomersGetAll(searchVal);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<CustomerModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"CustomersGetAll | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricerca Customer da idx
|
|
/// </summary>
|
|
/// <param name="idxCli"></param>
|
|
/// <returns></returns>
|
|
public async Task<CustomerModel> CustomersGetByKey(int idxCli)
|
|
{
|
|
string source = "DB";
|
|
CustomerModel? dbResult = new CustomerModel();
|
|
string currKey = $"{rKeyCust}:{idxCli}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<CustomerModel>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new CustomerModel();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.CustomersGetByKey(idxCli);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new CustomerModel();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"CustomersGetByKey | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Customers che richiedono sync tramite stored
|
|
/// </summary>
|
|
/// <param name="idxTipoDoc">Tipo doc, 0: tutti</param>
|
|
/// <param name="anno">Anno doc, 0: tutti</param>
|
|
/// <param name="notUpl">Indica se solo non caricati (1 = NON caricati)</param>
|
|
/// <returns></returns>
|
|
public async Task<List<CustomerModel>> CustomersToSync(int idxTipoDoc, int anno, bool notUpl)
|
|
{
|
|
string source = "DB";
|
|
List<CustomerModel>? dbResult = new List<CustomerModel>();
|
|
string currKey = $"{rKeySyncCust}:{anno}:{idxTipoDoc}:{notUpl}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<CustomerModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<CustomerModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.CustomersToSync(idxTipoDoc, anno, notUpl);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<CustomerModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"CustomersToSync | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorna un record Cliente
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> CustomerUpdate(CustomerModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.CustomerUpdate(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in CustomerUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce prossimo indice libero documenti x criterio tipo
|
|
/// </summary>
|
|
/// <param name="anno"></param>
|
|
/// <param name="idxTipoDoc"></param>
|
|
/// <returns></returns>
|
|
public int DocsGetNextNum(int anno, int idxTipoDoc)
|
|
{
|
|
return dbController.DocsGetNextNum(anno, idxTipoDoc);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database controller
|
|
dbController.Dispose();
|
|
GC.Collect();
|
|
}
|
|
|
|
public async Task<bool> FlushRedisCache()
|
|
{
|
|
await Task.Delay(1);
|
|
RedisValue pattern = new RedisValue($"{redisBaseAddr}:*");
|
|
bool answ = await ExecFlushRedisPattern(pattern);
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Pagamenti dato doc (fattura)
|
|
/// </summary>
|
|
/// <param name="IdxDoc">IdxDoc</param>
|
|
/// <returns></returns>
|
|
public async Task<List<PagamentiModel>> PagamByDoc(int IdxDoc)
|
|
{
|
|
string source = "DB";
|
|
List<PagamentiModel>? dbResult = new List<PagamentiModel>();
|
|
string currKey = $"{rKeyPagam}:{IdxDoc}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<PagamentiModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<PagamentiModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.PagamByDoc(IdxDoc);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<PagamentiModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"CustomersToSync | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Pagamenti dato doc (fattura)
|
|
/// </summary>
|
|
/// <param name="updItem">recorda da eliminare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PagamDelete(PagamentiModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.PagamDelete(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"PagamDelete in PagamDelete:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorna un pagamento
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PagamUpdate(PagamentiModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.PagamUpdate(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in PagamUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco permessi dato elenco funzioni
|
|
/// </summary>
|
|
/// <param name="ListCodFun"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<PermessiModel>> PermessiGetByUser(string UserName)
|
|
{
|
|
string source = "DB";
|
|
List<PermessiModel>? dbResult = new List<PermessiModel>();
|
|
string currKey = $"{rKeyPermUser}:{UserName}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<PermessiModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<PermessiModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// recupero diritti utente
|
|
var userRightList = dbUserController.DirittiUtente(UserName, Modulo);
|
|
// proietto come funzioni...
|
|
var ListFunc = userRightList.Select(x => x.Funzione).ToList();
|
|
// trasformo i permessi utente
|
|
if (ListFunc == null)
|
|
{
|
|
ListFunc = new List<string>();
|
|
}
|
|
dbResult = dbController.PermessiGetByFunc(ListFunc);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<PermessiModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"PermessiGetByUser | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clona un record Riga Doc
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RigaDocClona(RigheFattModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.RigaDocClona(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RigaDocClona:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elimina una riga Doc
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RigaDocDelete(RigheFattModel item2Del)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.RigaDocDelete(item2Del.Id);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RigaDocDelete:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorna un item RigaDoc cambiando solamente il numero di riga (e spostando un eventuale
|
|
/// altro elemento al suo posto)
|
|
/// </summary>
|
|
/// <param name="delta"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RigaDocMove(RigheFattModel updItem, int delta)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.RigaDocMove(updItem, delta);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RigaDocUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorna un record Riga Doc
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RigaDocUpdate(RigheFattModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.RigaDocUpdate(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RigaDocUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tipo documenti
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<AnagTipoDocModel>> TipoDocGetAll()
|
|
{
|
|
string source = "DB";
|
|
List<AnagTipoDocModel>? dbResult = new List<AnagTipoDocModel>();
|
|
string currKey = $"{rKeySelTipoDoc}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<AnagTipoDocModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<AnagTipoDocModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.TipoDocGetAll();
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<AnagTipoDocModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"TipoDocGetAll | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clona un item VAT
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> VATClona(VatModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.VATClona(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in VATClona:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco VAT eliminabili
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<VatModel>> VATDeletable()
|
|
{
|
|
string source = "DB";
|
|
List<VatModel>? dbResult = new List<VatModel>();
|
|
string currKey = $"{rKeyVatDel}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<VatModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<VatModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.VATDeletable();
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<VatModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"VATDeletable | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elimina un item VAT
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> VATDelete(VatModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.VATDelete(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in VATDelete:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco VAT / CIva (tutti)
|
|
/// </summary>
|
|
/// <param name="tipoDoc">Tipo doc, * = tutti</param>
|
|
/// <param name="anno">Anno doc, 0=tutti</param>
|
|
/// <param name="notUpl">Indica se solo non caricati (1 = NON caricati)</param>
|
|
/// <returns></returns>
|
|
public async Task<List<VatModel>> VATGetAll()
|
|
{
|
|
string source = "DB";
|
|
List<VatModel>? dbResult = new List<VatModel>();
|
|
string currKey = $"{rKeyVatAll}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<VatModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<VatModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.VATGetAll();
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<VatModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"VATGetAll | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricerca VAT / CIva da idx
|
|
/// </summary>
|
|
/// <param name="idxVat"></param>
|
|
/// <returns></returns>
|
|
public async Task<VatModel> VATGetByKey(int idxVat)
|
|
{
|
|
string source = "DB";
|
|
VatModel? dbResult = new VatModel();
|
|
string currKey = $"{rKeyVat}:{idxVat}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<VatModel>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new VatModel();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.VATGetByKey(idxVat);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new VatModel();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"VATGetAll | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco VAT / CIva che richiedono sync tramite stored
|
|
/// </summary>
|
|
/// <param name="idxTipoDoc">Tipo doc, 0: tutti</param>
|
|
/// <param name="anno">Anno doc, 0: tutti</param>
|
|
/// <param name="notUpl">Indica se solo non caricati (1 = NON caricati)</param>
|
|
/// <returns></returns>
|
|
public async Task<List<VatModel>> VATToSync(int idxTipoDoc, int anno, bool notUpl)
|
|
{
|
|
string source = "DB";
|
|
List<VatModel>? dbResult = new List<VatModel>();
|
|
string currKey = $"{rKeySyncVat}:{anno}:{idxTipoDoc}:{notUpl}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<VatModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<VatModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.VATToSync(idxTipoDoc, anno, notUpl);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<VatModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"VATToSync | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorna un record VAT / CIva
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> VATUpdate(VatModel updItem)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = dbController.VATUpdate(updItem);
|
|
// invalido la cache...
|
|
await FlushRedisCache();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in VATUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco AccoDoc (Accounting Document) filtrati
|
|
/// </summary>
|
|
/// <param name="cFilt">Filtro complessivo di selezione</param>
|
|
/// <returns></returns>
|
|
public async Task<List<vDocsExplModel>> VDocExplGetFilt(SelectDocExp cFilt)
|
|
{
|
|
string source = "DB";
|
|
List<vDocsExplModel>? dbResult = new List<vDocsExplModel>();
|
|
string currKey = $"{rKeyDocExp}:{cFilt.Anno}:{cFilt.IdxCli}:{cFilt.IdxTipo}:{cFilt.IdxGruppo}:{cFilt.RagSoc}:{cFilt.Aperta}:{cFilt.Inizio:yyyyMMdd}:{cFilt.Fine:yyyyMMdd}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<vDocsExplModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<vDocsExplModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.VDocExplGetFilt(cFilt.Anno, cFilt.IdxCli, cFilt.IdxTipo, cFilt.IdxGruppo, cFilt.RagSoc, cFilt.Inizio, cFilt.Fine, cFilt.Aperta);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<vDocsExplModel>();
|
|
}
|
|
// eventuale filtro in memoria x searchVal...
|
|
if (dbResult.Count > 0 && !(string.IsNullOrEmpty(cFilt.SearchVal) || cFilt.SearchVal == "*"))
|
|
{
|
|
dbResult = dbResult
|
|
.Where(x => x.Descrizione.Contains(cFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"VDocExplGetFilt | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Fatture Aperte
|
|
/// </summary>
|
|
/// <param name="cFilt">Filtro complessivo di selezione</param>
|
|
/// <param name="IdxDoc">IDX specifico (0=tutti)</param>
|
|
/// <returns></returns>
|
|
public async Task<List<vFattAperteModel>> VFattAperteGetFilt(SelectDocExp cFilt, int IdxDoc)
|
|
{
|
|
string source = "DB";
|
|
List<vFattAperteModel>? dbResult = new List<vFattAperteModel>();
|
|
string currKey = $"{rKeyFattAper}:{cFilt.Anno}:{cFilt.IdxCli}:{cFilt.IdxTipo}:{cFilt.IdxGruppo}:{cFilt.Inizio:yyyyMMdd}:{cFilt.Fine:yyyyMMdd}:{cFilt.Aperta}:{IdxDoc}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<vFattAperteModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<vFattAperteModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.VFattAperteGetFilt(true, cFilt.IdxCli, cFilt.IdxGruppo, IdxDoc, cFilt.IdxTipo);
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<vFattAperteModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"VFattAperteGetFilt | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
public async Task<List<vSelCliModel>> VSelCliGetAll()
|
|
{
|
|
string source = "DB";
|
|
List<vSelCliModel>? dbResult = new List<vSelCliModel>();
|
|
string currKey = $"{rKeySelCli}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<vSelCliModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<vSelCliModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.VSelCliGetAll();
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<vSelCliModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"VSelCliGetAll | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
public async Task<List<vSelGruppiModel>> VSelGruppiGetAll()
|
|
{
|
|
string source = "DB";
|
|
List<vSelGruppiModel>? dbResult = new List<vSelGruppiModel>();
|
|
string currKey = $"{rKeySelGruppi}";
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
string? rawData = await redisDb.StringGetAsync(currKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
source = "REDIS";
|
|
var tempResult = JsonConvert.DeserializeObject<List<vSelGruppiModel>>(rawData);
|
|
if (tempResult == null)
|
|
{
|
|
dbResult = new List<vSelGruppiModel>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = tempResult;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbController.VSelGruppiGetAll();
|
|
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
|
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<vSelGruppiModel>();
|
|
}
|
|
sw.Stop();
|
|
LogDebug($"VSelGruppiGetAll | {source}", sw.Elapsed);
|
|
return dbResult;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private const string passPhrase = "322DBEDA-E470-421C-B4BB-B04EE3384A6B";
|
|
private const string redisBaseAddr = "SHERPA:Data";
|
|
private const string rKeyAKV = $"{redisBaseAddr}:Cache:AKV";
|
|
private const string rKeyConfig = $"{redisBaseAddr}:Cache:Config";
|
|
private const string rKeyCust = $"{redisBaseAddr}:Cache:Cust:List";
|
|
private const string rKeyCustDel = $"{redisBaseAddr}:Cache:Cust:Del";
|
|
private const string rKeyDoc = $"{redisBaseAddr}:Cache:Doc";
|
|
private const string rKeyDocExp = $"{redisBaseAddr}:Cache:DocExpFilt";
|
|
private const string rKeyFattAper = $"{redisBaseAddr}:Cache:FattAperte";
|
|
private const string rKeyPagam = $"{redisBaseAddr}:Cache:Pagamenti";
|
|
private const string rKeyPermUser = $"{redisBaseAddr}:Cache:PermUser";
|
|
private const string rKeySelCli = $"{redisBaseAddr}:Cache:vSel:Cli";
|
|
private const string rKeySelGruppi = $"{redisBaseAddr}:Cache:vSel:Gruppi";
|
|
private const string rKeySelTipoDoc = $"{redisBaseAddr}:Cache:TipoDoc";
|
|
private const string rKeySelTipoV = $"{redisBaseAddr}:Cache:vSel:Tipo";
|
|
private const string rKeySyncCust = $"{redisBaseAddr}:Cache:Cust:CloudSync";
|
|
private const string rKeySyncVat = $"{redisBaseAddr}:Cache:VAT:CloudSync";
|
|
private const string rKeyVat = $"{redisBaseAddr}:Cache:VAT:List";
|
|
private const string rKeyVatAll = $"{redisBaseAddr}:Cache:VAT:ALL";
|
|
private const string rKeyVatDel = $"{redisBaseAddr}:Cache:VAT:Del";
|
|
private static IConfiguration _configuration = null!;
|
|
private static SAcDoController dbController = null!;
|
|
private static SUserController dbUserController = null!;
|
|
private static JsonSerializerSettings? JSSettings;
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private static string Modulo = "";
|
|
private readonly IEmailSender _emailSender;
|
|
|
|
/// <summary>
|
|
/// Durata cache lunga IN SECONDI
|
|
/// </summary>
|
|
private int cacheTtlLong = 60 * 5;
|
|
|
|
/// <summary>
|
|
/// Durata cache breve IN SECONDI
|
|
/// </summary>
|
|
private int cacheTtlShort = 60 * 1;
|
|
|
|
private int LogDurationLimitMs = 1000;
|
|
|
|
/// <summary>
|
|
/// Oggetto per connessione a REDIS
|
|
/// </summary>
|
|
private IConnectionMultiplexer redisConn;
|
|
|
|
//ISubscriber sub = redis.GetSubscriber();
|
|
/// <summary>
|
|
/// Oggetto DB redis da impiegare x chiamate R/W
|
|
/// </summary>
|
|
private IDatabase redisDb = null!;
|
|
|
|
private Random rnd = new Random();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string CodApp { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
|
/// </summary>
|
|
private TimeSpan FastCache
|
|
{
|
|
get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
|
/// </summary>
|
|
private TimeSpan LongCache
|
|
{
|
|
get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Durata cache lunga (+ perturbazione percentuale +/-10%)
|
|
/// </summary>
|
|
private TimeSpan UltraLongCache
|
|
{
|
|
get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000);
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#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 = redisConn.GetEndPoints();
|
|
foreach (var endPoint in listEndpoints)
|
|
{
|
|
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
|
var server = redisConn.GetServer(endPoint);
|
|
if (server != null)
|
|
{
|
|
var keyList = server.Keys(redisDb.Database, pattern);
|
|
foreach (var item in keyList)
|
|
{
|
|
await redisDb.KeyDeleteAsync(item);
|
|
}
|
|
answ = true;
|
|
}
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua Log tipo Debug
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="ts"></param>
|
|
private void LogDebug(string message, TimeSpan ts)
|
|
{
|
|
// Se superato limite --> invio a INFO
|
|
if (ts.TotalMilliseconds > LogDurationLimitMs)
|
|
{
|
|
LogInfo($"{message} | [DEBUG] DurationLimit Exceeded", ts);
|
|
}
|
|
else
|
|
{
|
|
Log.Debug($"{message} | {ts.TotalMilliseconds} ms");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua Log tipo ERROR
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="exc">Eventuale exxeczione da traccaire</param>
|
|
private void LogError(string message)
|
|
{
|
|
Log.Error(message);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua Log tipo ERROR
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="exc">Eventuale eccezione da tracciare</param>
|
|
private void LogException(string message, Exception exc)
|
|
{
|
|
Log.Error(exc, $"{message}{Environment.NewLine}{exc}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua Log tipo TRACE
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="ts"></param>
|
|
private void LogInfo(string message, TimeSpan ts)
|
|
{
|
|
Log.Info($"{message} | {ts.TotalMilliseconds} ms");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua Log tipo TRACE
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="ts"></param>
|
|
private void LogTrace(string message, TimeSpan ts)
|
|
{
|
|
// Se superato limite --> invio a INFO
|
|
if (ts.TotalMilliseconds > LogDurationLimitMs)
|
|
{
|
|
LogInfo($"{message} | [TRACE] DurationLimit Exceeded", ts);
|
|
}
|
|
else
|
|
{
|
|
Log.Trace($"{message} | {ts.TotalMilliseconds} ms");
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |