674 lines
27 KiB
C#
674 lines
27 KiB
C#
using Microsoft.Extensions.Caching.Distributed;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
using Core;
|
|
using Core.DTO;
|
|
using LiMan.DB.DBModels;
|
|
|
|
namespace LiMan.UI.Data
|
|
{
|
|
public class LiManDataService : IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
private static ILogger<LiManDataService> _logger;
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
private readonly IEmailSender _emailSender;
|
|
private readonly IDistributedCache distributedCache;
|
|
private readonly IMemoryCache memoryCache;
|
|
|
|
/// <summary>
|
|
/// Durata assoluta massima della cache IN SECONDI
|
|
/// </summary>
|
|
private int chAbsExp = 60 * 5;
|
|
|
|
/// <summary>
|
|
/// Durata della cache IN SECONDI in modalità inattiva (non acceduta) prima di venire rimossa
|
|
/// NON estende oltre il tempo massimo di validità della cache (chAbsExp)
|
|
/// </summary>
|
|
private int chSliExp = 60 * 1;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Protected Fields
|
|
|
|
protected static string connStringBBM = "";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Public Fields
|
|
|
|
public static GLS.Controllers.LicManController dbControllerGLS;
|
|
|
|
public static DB.Controllers.DbController dbControllerNext;
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public LiManDataService(IConfiguration configuration, ILogger<LiManDataService> logger, IMemoryCache memoryCache, IDistributedCache distributedCache, IEmailSender emailSender)
|
|
{
|
|
_logger = logger;
|
|
_configuration = configuration;
|
|
_emailSender = emailSender;
|
|
// conf cache
|
|
this.memoryCache = memoryCache;
|
|
this.distributedCache = distributedCache;
|
|
// conf DB
|
|
string connStrGLS = _configuration.GetConnectionString("LiMan.GLS");
|
|
string connStrDB = _configuration.GetConnectionString("LiMan.DB");
|
|
if (string.IsNullOrEmpty(connStrDB) || string.IsNullOrEmpty(connStrGLS))
|
|
{
|
|
_logger.LogError("Almost one ConnString empty!");
|
|
}
|
|
else
|
|
{
|
|
dbControllerGLS = new LiMan.GLS.Controllers.LicManController(configuration);
|
|
dbControllerNext = new LiMan.DB.Controllers.DbController(configuration);
|
|
_logger.LogInformation("DbControllers OK");
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Private Methods
|
|
|
|
private DistributedCacheEntryOptions cacheOpt(bool fastCache)
|
|
{
|
|
var numSecAbsExp = fastCache ? chAbsExp : chAbsExp * 10;
|
|
var numSecSliExp = fastCache ? chSliExp : chSliExp * 10;
|
|
return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp));
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected string getCacheKey(string TableName, SelectData CurrFilter)
|
|
{
|
|
string answ = $"{TableName}:D_{CurrFilter.DateStart:yyyyMMddHHmm}_{CurrFilter.DateEnd:yyyyMMddHHmm}";
|
|
return answ;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Internal Methods
|
|
|
|
/// <summary>
|
|
/// Effettua sblocco di una licenza impostando data veto a oggi
|
|
/// </summary>
|
|
/// <param name="idxSubLic"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AttivazioneUnlock(int idxSubLic)
|
|
{
|
|
bool fatto = dbControllerNext.AttivazioniUnlock(idxSubLic);
|
|
await Task.Delay(1);
|
|
return fatto;
|
|
}
|
|
/// <summary>
|
|
/// Effettua sblocco di una licenza impostando data veto a oggi
|
|
/// </summary>
|
|
/// <param name="idxSubLic"></param>
|
|
/// <returns></returns>
|
|
internal async Task<bool> AttivazioneDelete(int idxSubLic)
|
|
{
|
|
bool fatto = dbControllerNext.AttivazioniDelete(idxSubLic);
|
|
await Task.Delay(1);
|
|
return fatto;
|
|
}
|
|
|
|
#endregion Internal Methods
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Hash Redis contenente i dati MP di una specifico TYPE (es StatusMacchina, StateMachineIngressi, ...)
|
|
/// </summary>
|
|
/// <param name="dataType"></param>
|
|
/// <returns></returns>
|
|
public static string mHash(string dataType)
|
|
{
|
|
return $"DATA:{dataType}";
|
|
}
|
|
|
|
public async Task<List<GLS.DatabaseModels.AnagApplicazioni>> ApplicazioniGLSGetAll()
|
|
{
|
|
List<GLS.DatabaseModels.AnagApplicazioni> dbResult = new List<GLS.DatabaseModels.AnagApplicazioni>();
|
|
string cacheKey = mHash("GLS:Applicazioni");
|
|
string rawData;
|
|
var redisDataList = await distributedCache.GetAsync(cacheKey);
|
|
if (redisDataList != null)
|
|
{
|
|
rawData = Encoding.UTF8.GetString(redisDataList);
|
|
dbResult = JsonConvert.DeserializeObject<List<GLS.DatabaseModels.AnagApplicazioni>>(rawData);
|
|
}
|
|
else
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerGLS.GetApplicazioni();
|
|
rawData = JsonConvert.SerializeObject(dbResult);
|
|
redisDataList = Encoding.UTF8.GetBytes(rawData);
|
|
await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(true));
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB + caching per ApplicazioniGLSGetAll: {ts.TotalMilliseconds} ms");
|
|
}
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
public async Task<bool> ApplicazioniGLSUpdate(GLS.DatabaseModels.AnagApplicazioni currItem)
|
|
{
|
|
bool done = false;
|
|
try
|
|
{
|
|
done = dbControllerGLS.UpdateApplicazioni(currItem);
|
|
await InvalidateAllCache();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in ApplicazioniGLSUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return await Task.FromResult(done);
|
|
}
|
|
|
|
public async Task<List<DB.DBModels.ApplicativoModel>> ApplicazioniNextGetAll()
|
|
{
|
|
List<DB.DBModels.ApplicativoModel> dbResult = new List<DB.DBModels.ApplicativoModel>();
|
|
string cacheKey = mHash("Next:Applicazioni");
|
|
string rawData;
|
|
var redisDataList = await distributedCache.GetAsync(cacheKey);
|
|
if (redisDataList != null)
|
|
{
|
|
rawData = Encoding.UTF8.GetString(redisDataList);
|
|
dbResult = JsonConvert.DeserializeObject<List<DB.DBModels.ApplicativoModel>>(rawData);
|
|
}
|
|
else
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerNext.GetApplicazioni();
|
|
rawData = JsonConvert.SerializeObject(dbResult);
|
|
redisDataList = Encoding.UTF8.GetBytes(rawData);
|
|
await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(true));
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB + caching per ApplicazioniNextGetAll: {ts.TotalMilliseconds} ms");
|
|
}
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
public async Task<bool> ApplicazioniNextUpdate(DB.DBModels.ApplicativoModel currItem)
|
|
{
|
|
bool done = false;
|
|
try
|
|
{
|
|
done = dbControllerNext.UpsertApplicazione(currItem);
|
|
await InvalidateAllCache();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in ApplicazioniNextUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return await Task.FromResult(done);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera attivazioni data licenza
|
|
/// </summary>
|
|
/// <param name="CurrFilter"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<DB.DBModels.SubLicenzaModel>> AttivazioniGetByLic(int IdxLic)
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
List<DB.DBModels.SubLicenzaModel> dbResult = new List<DB.DBModels.SubLicenzaModel>();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerNext.AttivazioniGetByLic(IdxLic);
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB per AttivazioniGetByLic: {ts.TotalMilliseconds} ms");
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
public async Task<bool> DbForceMigrate()
|
|
{
|
|
return await Task.FromResult(dbControllerGLS.DbForceMigrate());
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database controller
|
|
dbControllerGLS.Dispose();
|
|
}
|
|
|
|
public async Task<List<GLS.DatabaseModels.AnagInstallazioni>> InstallazioniGLSGetAll()
|
|
{
|
|
List<GLS.DatabaseModels.AnagInstallazioni> dbResult = new List<GLS.DatabaseModels.AnagInstallazioni>();
|
|
string cacheKey = mHash("GLS:Installazioni");
|
|
string rawData;
|
|
var redisDataList = await distributedCache.GetAsync(cacheKey);
|
|
if (redisDataList != null)
|
|
{
|
|
rawData = Encoding.UTF8.GetString(redisDataList);
|
|
dbResult = JsonConvert.DeserializeObject<List<GLS.DatabaseModels.AnagInstallazioni>>(rawData);
|
|
}
|
|
else
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerGLS.GetInstallazioni();
|
|
rawData = JsonConvert.SerializeObject(dbResult);
|
|
redisDataList = Encoding.UTF8.GetBytes(rawData);
|
|
await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(true));
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB + caching per InstallazioniGLSGetAll: {ts.TotalMilliseconds} ms");
|
|
}
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
public async Task<bool> InstallazioniGLSUpdate(GLS.DatabaseModels.AnagInstallazioni currItem)
|
|
{
|
|
bool done = false;
|
|
try
|
|
{
|
|
done = dbControllerGLS.UpdateInstallazioni(currItem);
|
|
await InvalidateAllCache();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in InstallazioniGLSUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return await Task.FromResult(done);
|
|
}
|
|
|
|
public async Task<List<DB.DBModels.InstallazioneModel>> InstallazioniNextGetAll()
|
|
{
|
|
List<DB.DBModels.InstallazioneModel> dbResult = new List<DB.DBModels.InstallazioneModel>();
|
|
string cacheKey = mHash("Next:Installazioni");
|
|
string rawData;
|
|
var redisDataList = await distributedCache.GetAsync(cacheKey);
|
|
if (redisDataList != null)
|
|
{
|
|
rawData = Encoding.UTF8.GetString(redisDataList);
|
|
dbResult = JsonConvert.DeserializeObject<List<DB.DBModels.InstallazioneModel>>(rawData);
|
|
}
|
|
else
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerNext.GetInstallazioni();
|
|
rawData = JsonConvert.SerializeObject(dbResult);
|
|
redisDataList = Encoding.UTF8.GetBytes(rawData);
|
|
await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(true));
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB + caching per InstallazioniNextGetAll: {ts.TotalMilliseconds} ms");
|
|
}
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
public async Task<bool> InstallazioniNextUpdate(DB.DBModels.InstallazioneModel currItem)
|
|
{
|
|
bool done = false;
|
|
try
|
|
{
|
|
done = dbControllerNext.UpsertInstallazione(currItem);
|
|
await InvalidateAllCache();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in InstallazioniNextUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return await Task.FromResult(done);
|
|
}
|
|
|
|
/// <summary>
|
|
/// invalida tutta la cache in caso di update
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task InvalidateAllCache()
|
|
{
|
|
await distributedCache.RemoveAsync(mHash("GLS:Applicazioni"));
|
|
await distributedCache.RemoveAsync(mHash("Next:Applicazioni"));
|
|
await distributedCache.RemoveAsync(mHash("GLS:Installazioni"));
|
|
await distributedCache.RemoveAsync(mHash("Next:Installazioni"));
|
|
await distributedCache.RemoveAsync(mHash("GLS:Licenze"));
|
|
await distributedCache.RemoveAsync(mHash("Next:Licenze"));
|
|
//await distributedCache.RemoveAsync(mHash("SUPPL:List"));
|
|
//await distributedCache.RemoveAsync(mHash("TRANSP:List"));
|
|
//await distributedCache.RemoveAsync(mHash("WEEKPLAN:List"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Trasferisce una licenza da GLS a Next come LOG di una licenza scaduta
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> LicenzaLogGlsNext(GLS.DatabaseModels.LicenzeAttive currItem, int IdxLicNext)
|
|
{
|
|
bool done = false;
|
|
|
|
var currLicenza = dbControllerNext.GetLicenza(IdxLicNext);
|
|
// step 1: converto licenza, faccio upsert
|
|
var logLicNext = new DB.DBModels.LogLicenzaModel()
|
|
{
|
|
CodApp = currItem.ApplicativoNavigation.Applicativo,
|
|
CodInst = currItem.InstallazioneNavigation.Installazione,
|
|
Chiave = currItem.Licenza,
|
|
NumLicenze = currItem.NumLicenze,
|
|
Scadenza = currItem.Scadenza,
|
|
Descrizione = currItem.ApplicativoNavigation.Descrizione,
|
|
Tipo = TipoLicenza.GLS,
|
|
IdxLic = IdxLicNext,
|
|
Locked = true
|
|
};
|
|
bool step1 = dbControllerNext.UpsertLogLic(logLicNext);
|
|
|
|
if (currLicenza != null && step1)
|
|
{
|
|
// step 2: disattivo vecchia licenza
|
|
currItem.Locked = true;
|
|
done = dbControllerGLS.UpdateLicenze(currItem);
|
|
}
|
|
return await Task.FromResult(done);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Trasferisce una licenza da GLS a Next
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> LicenzaTransferGlsNext(GLS.DatabaseModels.LicenzeAttive currItem)
|
|
{
|
|
bool done = false;
|
|
// step 1: controllo applicazione esistente
|
|
DB.DBModels.ApplicativoModel appNext = new DB.DBModels.ApplicativoModel()
|
|
{
|
|
CodApp = currItem.ApplicativoNavigation.Applicativo,
|
|
Descrizione = currItem.ApplicativoNavigation.Descrizione
|
|
};
|
|
bool step1 = dbControllerNext.UpsertApplicazione(appNext);
|
|
|
|
// step 2: controllo installazione esistente
|
|
var instNext = new DB.DBModels.InstallazioneModel()
|
|
{
|
|
Cliente = currItem.InstallazioneNavigation.Installazione,
|
|
CodInst = currItem.InstallazioneNavigation.Installazione,
|
|
Contatto = currItem.InstallazioneNavigation.Contatto,
|
|
Email = currItem.InstallazioneNavigation.Email,
|
|
Descrizione = currItem.ApplicativoNavigation.Descrizione
|
|
};
|
|
bool step2 = dbControllerNext.UpsertInstallazione(instNext);
|
|
|
|
// step 3: converto licenza, faccio upsert
|
|
var licNext = new DB.DBModels.LicenzaModel()
|
|
{
|
|
CodApp = currItem.ApplicativoNavigation.Applicativo,
|
|
CodInst = currItem.InstallazioneNavigation.Installazione,
|
|
Chiave = currItem.Licenza,
|
|
NumLicenze = currItem.NumLicenze,
|
|
Scadenza = currItem.Scadenza,
|
|
Descrizione = currItem.ApplicativoNavigation.Descrizione,
|
|
Tipo = TipoLicenza.GLS,
|
|
Enigma = "",
|
|
Payload = "",
|
|
DataEnigma = DateTime.Now
|
|
};
|
|
bool step3 = dbControllerNext.UpsertLicenza(licNext);
|
|
|
|
if (step1 && step2 && step3)
|
|
{
|
|
// step 4: disattivo vecchia licenza
|
|
currItem.Locked = true;
|
|
done = dbControllerGLS.UpdateLicenze(currItem);
|
|
}
|
|
return await Task.FromResult(done);
|
|
}
|
|
|
|
public async Task<List<GLS.DatabaseModels.LicenzeAttive>> LicenzeGLSGetAll()
|
|
{
|
|
List<GLS.DatabaseModels.LicenzeAttive> dbResult = new List<GLS.DatabaseModels.LicenzeAttive>();
|
|
string cacheKey = mHash("GLS:Licenze");
|
|
string rawData;
|
|
var redisDataList = await distributedCache.GetAsync(cacheKey);
|
|
if (redisDataList != null)
|
|
{
|
|
rawData = Encoding.UTF8.GetString(redisDataList);
|
|
dbResult = JsonConvert.DeserializeObject<List<GLS.DatabaseModels.LicenzeAttive>>(rawData);
|
|
}
|
|
else
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerGLS.GetLicenze();
|
|
rawData = JsonConvert.SerializeObject(dbResult);
|
|
redisDataList = Encoding.UTF8.GetBytes(rawData);
|
|
await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(true));
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB + caching per LicenzeGLSGetAll: {ts.TotalMilliseconds} ms");
|
|
}
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera licenze SENZA cache
|
|
/// </summary>
|
|
/// <param name="CurrFilter"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<GLS.DatabaseModels.LicenzeAttive>> LicenzeGLSGetFilt(SelectGLS CurrFilter)
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
List<GLS.DatabaseModels.LicenzeAttive> dbResult = new List<GLS.DatabaseModels.LicenzeAttive>();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerGLS.GetLicenzeFilt(CurrFilter.OnlyActive, CurrFilter.OnlyUnlock, CurrFilter.ApplicazioneSel, CurrFilter.InstallazioneSel);
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB per LicenzeGLSGetFilt: {ts.TotalMilliseconds} ms");
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
public async Task<bool> LicenzeGLSUpdate(GLS.DatabaseModels.LicenzeAttive currItem)
|
|
{
|
|
bool done = false;
|
|
#if false
|
|
try
|
|
{
|
|
done = dbControllerGLS.UpdateApplicazioni(currItem);
|
|
await InvalidateAllCache();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in ApplicazioniUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
#endif
|
|
return await Task.FromResult(done);
|
|
}
|
|
|
|
public async Task<List<DB.DBModels.LicenzaModel>> LicenzeNextGetAll()
|
|
{
|
|
List<DB.DBModels.LicenzaModel> dbResult = new List<DB.DBModels.LicenzaModel>();
|
|
string cacheKey = mHash("Next:Licenze");
|
|
string rawData;
|
|
var redisDataList = await distributedCache.GetAsync(cacheKey);
|
|
if (redisDataList != null)
|
|
{
|
|
rawData = Encoding.UTF8.GetString(redisDataList);
|
|
dbResult = JsonConvert.DeserializeObject<List<DB.DBModels.LicenzaModel>>(rawData);
|
|
}
|
|
else
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerNext.GetLicenze();
|
|
rawData = JsonConvert.SerializeObject(dbResult);
|
|
redisDataList = Encoding.UTF8.GetBytes(rawData);
|
|
await distributedCache.SetAsync(cacheKey, redisDataList, cacheOpt(true));
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB + caching per LicenzeNextGetAll: {ts.TotalMilliseconds} ms");
|
|
}
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera licenze SENZA cache
|
|
/// </summary>
|
|
/// <param name="CurrFilter"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<DB.DBModels.LicenzaModel>> LicenzeNextGetFilt(SelectNext CurrFilter)
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
List<DB.DBModels.LicenzaModel> dbResult = new List<DB.DBModels.LicenzaModel>();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerNext.GetLicenzeFilt(CurrFilter.OnlyActive, CurrFilter.ApplicazioneSel, CurrFilter.InstallazioneSel);
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB per LicenzeNextGetFilt: {ts.TotalMilliseconds} ms");
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco file registrati dato ticket id
|
|
/// </summary>
|
|
/// <param name="idxTicket">Identificativo del ticket</param>
|
|
/// <returns></returns>
|
|
public async Task<List<FileAttachModel>> FileGetFilt(int idxTicket)
|
|
{
|
|
List<FileAttachModel> dbResult = new List<FileAttachModel>();
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerNext.FileGetFilt(idxTicket);
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB per FileGetFilt: {ts.TotalMilliseconds} ms");
|
|
return await Task.FromResult(dbResult);
|
|
|
|
}
|
|
|
|
public async Task<bool> LicenzeNextUpdate(DB.DBModels.LicenzaModel currItem)
|
|
{
|
|
bool done = false;
|
|
|
|
// chiamo Log licenza + update insieme
|
|
try
|
|
{
|
|
done = dbControllerNext.UpsertLicenza(currItem);
|
|
await InvalidateAllCache();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in ApplicazioniUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
return await Task.FromResult(done);
|
|
}
|
|
|
|
public void rollBackEditGLS(object item)
|
|
{
|
|
dbControllerGLS.rollBackEntity(item);
|
|
}
|
|
|
|
public async Task<bool> SendEmail(string destEmail, string oggetto, string corpo)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
await _emailSender.SendEmailAsync(destEmail, oggetto, corpo);
|
|
answ = true;
|
|
}
|
|
catch
|
|
{ }
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiornamentos tato ticket
|
|
/// </summary>
|
|
/// <param name="IdxTicket"></param>
|
|
/// <param name="NewStatus"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> TicketUpdateState(int IdxTicket, StatoRichiesta NewStatus)
|
|
{
|
|
bool fatto = false;
|
|
// inserimento!
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
stopWatch.Start();
|
|
fatto = dbControllerNext.TicketUpdateState(IdxTicket, NewStatus);
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata update con TicketUpdateState: {ts.TotalMilliseconds} ms");
|
|
|
|
// restituisce elenco
|
|
return await Task.FromResult(fatto);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Recupera elenco Tickets filtrato
|
|
/// </summary>
|
|
/// <param name="CurrFilter"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<TicketDTO>> TicketsGetFilt(SelectNext CurrFilter)
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
List<TicketDTO> dbResult = new List<TicketDTO>();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerNext.TicketGetFiltAllLic(CurrFilter.OnlyActive, Core.TipologiaTicket.ND, CurrFilter.ApplicazioneSel, CurrFilter.InstallazioneSel, 1000);
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB per TicketsGetFilt: {ts.TotalMilliseconds} ms");
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco Tickets filtrato
|
|
/// </summary>
|
|
/// <param name="CurrFilter"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<TicketDTO>> TicketsGetAll()
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
List<TicketDTO> dbResult = new List<TicketDTO>();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerNext.TicketGetAll(false, 1000);
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB per TicketsGetAll: {ts.TotalMilliseconds} ms");
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricerca ticket filtrati
|
|
/// </summary>
|
|
/// <param name="onlyOpen"></param>
|
|
/// <param name="CodApp"></param>
|
|
/// <param name="CodInst"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<TicketDTO>> TicketsGetFilt(bool onlyOpen,string CodApp, string CodInst)
|
|
{
|
|
Stopwatch stopWatch = new Stopwatch();
|
|
List<TicketDTO> dbResult = new List<TicketDTO>();
|
|
stopWatch.Start();
|
|
dbResult = dbControllerNext.TicketGetFilt(onlyOpen,CodApp,CodInst);
|
|
stopWatch.Stop();
|
|
TimeSpan ts = stopWatch.Elapsed;
|
|
Log.Trace($"Effettuata lettura da DB per TicketsGetFilt: {ts.TotalMilliseconds} ms");
|
|
return await Task.FromResult(dbResult);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |