Inizio migrazione redis cache
This commit is contained in:
@@ -186,7 +186,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbTabController.AlarmLogListFilt(idxMacchina, dtFrom, dtTo, showMulti));
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
@@ -246,7 +246,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.AnagEventiGetAll();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -283,7 +283,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.AnagEventiGetByMacc(IdxMacch);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -318,7 +318,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.AnagTagsOrd();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -356,7 +356,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.AnagStatiGetAll();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -395,7 +395,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.CommentiGetLastByMacc(idxMacchina, numDays);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
@@ -469,7 +469,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.ConfigGetAll();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -751,7 +751,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = await dbTabController.EvListGetLastBySearch(idxMacchina, dtLimit, idxTipo, maxRec);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -831,7 +831,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.FermiNonQualificatiFilt(idxMacchina, gg, durataMin);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
@@ -935,7 +935,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbTabController.ListPODLByMacc(idxMacchina, onlyFree, onlyDirect));
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
@@ -973,7 +973,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbInveController.LottoEsterno(codArt, codLotto, codMagazzino);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -1021,7 +1021,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.Macchine2Slave();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
@@ -1206,7 +1206,7 @@ namespace MP.Data.Services
|
||||
{
|
||||
result = rawResult.FirstOrDefault();
|
||||
}
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, UltraLongCache);
|
||||
stopWatch.Stop();
|
||||
@@ -1244,7 +1244,7 @@ namespace MP.Data.Services
|
||||
{
|
||||
var listRes = await Task.FromResult(dbTabController.OdlByIdx(idxOdl, onlyUnused));
|
||||
result = listRes.FirstOrDefault();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
@@ -1303,7 +1303,7 @@ namespace MP.Data.Services
|
||||
{
|
||||
var listRes = await Task.FromResult(dbTabController.OdlCurrByMacc(idxMacchina));
|
||||
result = listRes.FirstOrDefault();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
@@ -1439,7 +1439,7 @@ namespace MP.Data.Services
|
||||
var results = dbTabController.OdlLastByMacc(idxMacchina);
|
||||
// riordino
|
||||
result = results.FirstOrDefault();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -1478,7 +1478,7 @@ namespace MP.Data.Services
|
||||
result = await Task.FromResult(dbTabController.OdlListByMaccPeriodo(idxMacchina, dtStart, dtEnd));
|
||||
// riordino
|
||||
result = result.OrderByDescending(x => x.DataInizio).ToList();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
@@ -1782,7 +1782,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.PezziProdMacchina(idxMacchina);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
@@ -1843,7 +1843,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbTabController.PODLExp_getByKey(idxPODL));
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
@@ -1980,7 +1980,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.RegControlliFilt(idxMacchina, idxODL, dataFrom, dataTo, showMulti);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -2042,7 +2042,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.RegControlliLast(idxMacchina);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -2082,7 +2082,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.RegDichiarGetFilt(idxMacchina, tagCode, matrOpr, idxODL, dataFrom, dataTo);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -2168,7 +2168,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.RegScartiGetFilt(idxMacchina, idxODL, dataFrom, dataTo, showMulti);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -2252,7 +2252,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.RegScartiKitGetFilt(ParentRec);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
@@ -2563,7 +2563,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.ST_AnagGruppiList();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -2674,7 +2674,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.STAR_byGrpOdl(codGruppo, idxODL);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -2713,7 +2713,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.STAR_byGrpOdlLbl(codGruppo, label, idxODL);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -2749,7 +2749,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.STAR_pendByOdl(idxODL);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(5));
|
||||
}
|
||||
@@ -2785,7 +2785,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.StatoMacchina(idxMacchina);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(2));
|
||||
}
|
||||
@@ -2823,7 +2823,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.StatoProdMacchina(idxMacchina, dtReq);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
@@ -2858,7 +2858,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbTabController.TurnoMacchinaGet(idxMacchina));
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -2892,7 +2892,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbTabController.TurnoMacchinaGetAll());
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -2952,7 +2952,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbIocController.VMSFDGetAll();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
@@ -2989,7 +2989,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbIocController.VMSFDGetByMacc(idxMacc);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraFastCache);
|
||||
}
|
||||
@@ -3026,7 +3026,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbIocController.VMSFDGetByMacc(idxMacc);
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -3057,7 +3057,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = dbTabController.VocabolarioGetAll();
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
redisDb.StringSet(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
@@ -3091,7 +3091,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbTabController.VSCS_getAll());
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -3127,7 +3127,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbTabController.VSOdlGetLastByMacc(idxMacchina, numRec));
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
@@ -3164,7 +3164,7 @@ namespace MP.Data.Services
|
||||
else
|
||||
{
|
||||
result = await Task.FromResult(dbTabController.VSOdlGetUnused(idxMacchina, showAll, numDayAdd));
|
||||
// serializzp e salvo...
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,13 @@
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MP.Data.Controllers;
|
||||
using MP.Data.DatabaseModels;
|
||||
using MP.Data.Services;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NLog.Fluent;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
@@ -15,20 +20,34 @@ using static MP.Data.Objects.Enums;
|
||||
|
||||
namespace MP.Stats.Data
|
||||
{
|
||||
public class MpStatsService : IDisposable
|
||||
public class MpStatsService : BaseServ, IDisposable
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
public static MP.Data.Controllers.MpStatsController dbController;
|
||||
|
||||
#endregion Public Fields
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS
|
||||
/// </summary>
|
||||
protected ConnectionMultiplexer redisConn = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto DB redis da impiegare x chiamate R/W
|
||||
/// </summary>
|
||||
protected IDatabase redisDb = null!;
|
||||
#region Public Constructors
|
||||
|
||||
public MpStatsService(IConfiguration configuration, ILogger<MpStatsService> logger, IMemoryCache memoryCache, IDistributedCache distributedCache)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
|
||||
// setup compoenti REDIS
|
||||
redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis"));
|
||||
redisDb = redisConn.GetDatabase();
|
||||
|
||||
|
||||
// conf cache
|
||||
this.memoryCache = memoryCache;
|
||||
this.distributedCache = distributedCache;
|
||||
@@ -136,6 +155,54 @@ namespace MP.Stats.Data
|
||||
{
|
||||
// Clear database controller
|
||||
dbController.Dispose();
|
||||
// redis dispose
|
||||
redisConn = null;
|
||||
redisDb = null;
|
||||
}
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
// notifico update ai client in ascolto x reset cache
|
||||
NotifyReloadRequest($"FlushRedisCache | {pattern}");
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Evento richiesta rilettura dati pagina (x refresh pagine aperte)
|
||||
/// </summary>
|
||||
public event EventHandler ReloadRequest = delegate { };
|
||||
|
||||
/// <summary>
|
||||
/// Invio notifica rilettura (con parametro)
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public void NotifyReloadRequest(string message)
|
||||
{
|
||||
if (ReloadRequest != null)
|
||||
{
|
||||
// messaggio
|
||||
ReloadEventArgs rea = new ReloadEventArgs(message);
|
||||
ReloadRequest.Invoke(this, rea);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,10 +214,14 @@ namespace MP.Stats.Data
|
||||
{
|
||||
TaskResultModel dbResult = dbController.ExecuteTask(TaskId);
|
||||
// svuoto cache!
|
||||
await FlushCache("TaskList");
|
||||
await FlushCache("TaskExecList");
|
||||
#if false
|
||||
string cacheKey = $"MP:STATS:TaskList";
|
||||
await distributedCache.RemoveAsync(cacheKey);
|
||||
cacheKey = $"MP:STATS:TaskExecList";
|
||||
await distributedCache.RemoveAsync(cacheKey);
|
||||
await distributedCache.RemoveAsync(cacheKey);
|
||||
#endif
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
|
||||
@@ -443,6 +514,8 @@ namespace MP.Stats.Data
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
|
||||
private string redisBaseKey = "MP:STATS";
|
||||
|
||||
/// <summary>
|
||||
/// Ricerca task dato tipo + num max (desc)
|
||||
/// </summary>
|
||||
@@ -450,6 +523,35 @@ namespace MP.Stats.Data
|
||||
/// <returns></returns>
|
||||
public async Task<List<TaskExecModel>> TaskExecGetFilt(int TaskId, int maxRec, string searchVal)
|
||||
{
|
||||
// setup parametri costanti
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<TaskExecModel> result = new List<TaskExecModel>();
|
||||
// cerco in redis...
|
||||
DateTime adesso = DateTime.Now;
|
||||
string currKey = $"{redisBaseKey}:TaskExecList:{TaskId}:{adesso:yyMMdd}:{adesso:HHmm}:{maxRec}";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<TaskExecModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.TaskExecGetFilt(TaskId, maxRec);
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<TaskExecModel>();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"TaskExecGetFilt | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
#if false
|
||||
List<TaskExecModel> dbResult = new List<TaskExecModel>();
|
||||
DateTime adesso = DateTime.Now;
|
||||
string cacheKey = $"MP:STATS:TaskExecList:{TaskId}:{adesso:yyMMdd}:{adesso:HHmm}:{maxRec}";
|
||||
@@ -479,7 +581,8 @@ namespace MP.Stats.Data
|
||||
.Where(x => x.Result.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return await Task.FromResult(dbResult);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -490,6 +593,45 @@ namespace MP.Stats.Data
|
||||
/// <returns></returns>
|
||||
public async Task<List<TaskListModel>> TaskListAll(Task2ExeType TType, string searchVal = "")
|
||||
{
|
||||
|
||||
// setup parametri costanti
|
||||
string source = "DB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<TaskListModel> result = new List<TaskListModel>();
|
||||
// cerco in redis...
|
||||
DateTime adesso = DateTime.Now;
|
||||
string currKey = $"{redisBaseKey}:TaskList:{TType}";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<TaskListModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = dbController.TaskListGetAll(TType);
|
||||
// serializzp e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<TaskListModel>();
|
||||
}
|
||||
// se necessario filtro..
|
||||
if (!string.IsNullOrEmpty(searchVal))
|
||||
{
|
||||
result = result
|
||||
.Where(x => x.Name.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|
||||
|| x.Descript.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"TaskListAll | {source} | {sw.Elapsed.TotalMilliseconds}ms");
|
||||
return result;
|
||||
|
||||
#if false
|
||||
List<TaskListModel> dbResult = new List<TaskListModel>();
|
||||
string cacheKey = $"MP:STATS:TaskList:{TType}";
|
||||
string rawData;
|
||||
@@ -519,9 +661,30 @@ namespace MP.Stats.Data
|
||||
|| x.Descript.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
return await Task.FromResult(dbResult);
|
||||
return await Task.FromResult(dbResult);
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// Pulizia cache Redis (tutta)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FlushCache()
|
||||
{
|
||||
RedisValue pattern = new RedisValue($"{redisBaseKey}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pulizia cache Redis per chiave specifica (da redisBaseKey...)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FlushCache(string KeyReq)
|
||||
{
|
||||
RedisValue pattern = new RedisValue($"{redisBaseKey}:{KeyReq}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Update/Insert record TaskList
|
||||
/// </summary>
|
||||
@@ -531,10 +694,13 @@ namespace MP.Stats.Data
|
||||
{
|
||||
bool dbResult = dbController.TaskListUpsert(rec2upd);
|
||||
// svuoto cache!
|
||||
await FlushCache("TaskList");
|
||||
#if false
|
||||
string cacheKey = $"MP:STATS:TaskList:{rec2upd.TType}";
|
||||
await distributedCache.RemoveAsync(cacheKey);
|
||||
cacheKey = $"MP:STATS:TaskList:ND";
|
||||
await distributedCache.RemoveAsync(cacheKey);
|
||||
await distributedCache.RemoveAsync(cacheKey);
|
||||
#endif
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>MP.Stats</RootNamespace>
|
||||
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
|
||||
<Version>6.16.2404.0308</Version>
|
||||
<Version>6.16.2404.0308</Version>
|
||||
<Version>6.16.2404.0309</Version>
|
||||
<Version>6.16.2404.0309</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<div class="card-body py-0 px-1">
|
||||
@if (isLoading)
|
||||
{
|
||||
@* <ProgressDisplay DisplaySize="ProgressDisplay.ModalSize.Medium" ExpTimeMSec="@lastExeTime" CurrVal="0" NextVal="1" MaxVal="1" Title="Task Processing" RefreshInterval="200"></ProgressDisplay> *@
|
||||
<ProgressDisplay DisplaySize="ProgressDisplay.ModalSize.Medium" ExpTimeMSec="@expTimeMsec" CurrVal="@currVal" NextVal="@nextVal" MaxVal="@MaxVal" Title="Task Processing" RefreshInterval="200"></ProgressDisplay>
|
||||
<LoadingData Title="Elaborazione..." DisplayMode="LoadingData.SpinMode.BounceLine" DisplaySize="LoadingData.CtrlSize.Large"></LoadingData>
|
||||
}
|
||||
else if (ListRecords == null)
|
||||
|
||||
@@ -135,6 +135,19 @@ namespace MP.Stats.Pages
|
||||
await StatService.FlushAll();
|
||||
await ReloadData();
|
||||
}
|
||||
private double currVal = 0;
|
||||
private double nextVal = 0;
|
||||
private int MaxVal = 10;
|
||||
/// <summary>
|
||||
/// Gestione display avanzamento step
|
||||
/// </summary>
|
||||
/// <param name="currStep"></param>
|
||||
protected async Task advStep(int currStep)
|
||||
{
|
||||
currVal = currStep;
|
||||
nextVal = currVal + 1;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
protected async Task doRun(TaskListModel selRec)
|
||||
{
|
||||
@@ -143,14 +156,21 @@ namespace MP.Stats.Pages
|
||||
return;
|
||||
|
||||
// imposto tempo atteso esecuzione da ultimo...
|
||||
lastExeTime = (int)(1000 * selRec.LastDuration);
|
||||
isLoading = true;
|
||||
MaxVal = 4;
|
||||
int currStep = 0;
|
||||
await advStep(currStep);
|
||||
expTimeMsec = (int)(1000 * selRec.LastDuration) / 4;
|
||||
detRecord = null;
|
||||
await advStep(currStep++);
|
||||
await Task.Delay(100);
|
||||
await advStep(currStep++);
|
||||
// chiama esecuzione task
|
||||
var result = await StatService.ExecuteTask(selRec.TaskId);
|
||||
await advStep(currStep++);
|
||||
isLoading = false;
|
||||
await Task.Delay(100);
|
||||
await advStep(currStep++);
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
@@ -286,7 +306,7 @@ namespace MP.Stats.Pages
|
||||
|
||||
private bool isLoading { get; set; } = false;
|
||||
|
||||
private int lastExeTime { get; set; } = 30000;
|
||||
private int expTimeMsec { get; set; } = 30000;
|
||||
|
||||
private int numRecord { get; set; } = 10;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo statistiche MAPO</i>
|
||||
<h4>Versione: 6.16.2404.0308</h4>
|
||||
<h4>Versione: 6.16.2404.0309</h4>
|
||||
<br />
|
||||
Note di rilascio:
|
||||
<ul>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2404.0308
|
||||
6.16.2404.0309
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2404.0308</version>
|
||||
<version>6.16.2404.0309</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -6,6 +6,7 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using MP.Stats.Data;
|
||||
using StackExchange.Redis;
|
||||
using System.Globalization;
|
||||
|
||||
namespace MP.Stats
|
||||
@@ -90,6 +91,16 @@ namespace MP.Stats
|
||||
options.InstanceName = "MP:Stats";
|
||||
});
|
||||
|
||||
// REDIS setup
|
||||
var cString = Configuration.GetConnectionString("Redis");
|
||||
string connStringRedis = cString ?? "localhost:6379, DefaultDatabase=5, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false";
|
||||
// avvio oggetto shared x redis...
|
||||
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
||||
|
||||
// Add services x accesso dati
|
||||
services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
||||
|
||||
|
||||
services.AddLocalization();
|
||||
|
||||
services.AddRazorPages();
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;MultipleActiveResultSets=true",
|
||||
"MP.Stats": "Server=SQL2016DEV;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"Redis": "localhost:6379,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true",
|
||||
//"Redis": "localhost:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true",
|
||||
"DefaultConnection": "Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;MultipleActiveResultSets=true",
|
||||
"MP.Stats": "Server=SQL2016DEV;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;"
|
||||
},
|
||||
"FormatDur": "HH:mm.ss.ff"
|
||||
}
|
||||
Reference in New Issue
Block a user