Completato fix setup page + cache redis

This commit is contained in:
Samuele Locatelli
2024-10-21 12:05:23 +02:00
parent ea2f942f94
commit 60f983df9b
17 changed files with 264 additions and 107 deletions
+86 -48
View File
@@ -15,14 +15,6 @@ namespace MP.FileData.Controllers
{
public class FileController : IDisposable
{
#region Private Fields
private static IConfiguration _configuration;
private static MoonPro_ProgContext dbCtx;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Public Constructors
public FileController(IConfiguration configuration)
@@ -42,11 +34,83 @@ namespace MP.FileData.Controllers
}
/// <summary>
/// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck e Changed (se cambiati)
/// Elenco tabella Macchine
/// </summary>
/// <returns></returns>
public List<DatabaseModels.ArchMaccModel> ArchMaccGetAll()
{
List<DatabaseModels.ArchMaccModel> dbResult = new List<DatabaseModels.ArchMaccModel>();
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
dbResult = localDbCtx
.DbSetArchMacc
.OrderBy(x => x.IdxMacchina)
.ToList();
}
return dbResult;
}
/// <summary>
/// Recupera singola macchina
/// </summary>
/// <returns></returns>
public ArchMaccModel ArchMaccGetByKey(string idxMacchina)
{
ArchMaccModel dbResult = new ArchMaccModel();
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
dbResult = localDbCtx
.DbSetArchMacc
.Where(x => x.IdxMacchina == idxMacchina)
.SingleOrDefault();
}
return dbResult;
}
/// <summary>
/// Elenco tabella Macchine
/// </summary>
/// <returns></returns>
public async Task<bool> ArchMaccUpsert(ArchMaccModel upsRec)
{
bool fatto = false;
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
var currRec = localDbCtx
.DbSetArchMacc
.Where(x => x.IdxMacchina == upsRec.IdxMacchina)
.FirstOrDefault();
if (currRec != null)
{
currRec.BasePath = upsRec.BasePath;
currRec.Descrizione = upsRec.Descrizione;
currRec.RuleName = upsRec.RuleName;
currRec.ShowOrder = upsRec.ShowOrder;
currRec.ImgUrl = upsRec.ImgUrl;
currRec.Nome = upsRec.Nome;
currRec.Note = upsRec.Note;
// segno modificato
localDbCtx.Entry(currRec).State = EntityState.Modified;
}
else
{
localDbCtx.DbSetArchMacc.Add(upsRec);
}
int numDone = await localDbCtx.SaveChangesAsync();
fatto = numDone != 0;
}
return fatto;
}
/// <summary>
/// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck
/// e Changed (se cambiati)
/// </summary>
/// <param name="idxMacchina">cod macchina</param>
/// <param name="path">path ricerca x macchina</param>
/// <param name="numDayPre">Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite</param>
/// <param name="numDayPre">
/// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite
/// </param>
/// <param name="searchPattern">pattern di ricerca (*.*)</param>
/// <param name="forceTag">Forza il controllo dei Tags</param>
/// <param name="currRule">Regole di ricerca applicate</param>
@@ -428,7 +492,7 @@ namespace MP.FileData.Controllers
listUpdate.Add(newFileInfo);
var currMacchina = localDbCtx
.DbSetMacchine
.DbSetArchMacc
.Where(x => x.IdxMacchina == currFile.IdxMacchina)
.SingleOrDefault();
if (currMacchina != null)
@@ -505,7 +569,7 @@ namespace MP.FileData.Controllers
if (forceTag)
{
// elenco Tags
List <TagModel> currTags = localDbCtx.DbSetTags.ToList();
List<TagModel> currTags = localDbCtx.DbSetTags.ToList();
FileModel currItem = null;
foreach (var item in updFiles)
{
@@ -586,7 +650,7 @@ namespace MP.FileData.Controllers
// salvo update file
item.LastCheck = adesso;
localDbCtx.Entry(item).State = EntityState.Modified;
}
}
#endif
answ = true;
@@ -673,7 +737,7 @@ namespace MP.FileData.Controllers
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
ArchiveList = localDbCtx
.DbSetMacchine
.DbSetArchMacc
.Select(x => new ArchiveStatusDTO()
{
IdxMacchina = x.IdxMacchina,
@@ -709,40 +773,6 @@ namespace MP.FileData.Controllers
return ArchiveList;
}
/// <summary>
/// Recupera singola macchina
/// </summary>
/// <returns></returns>
public MacchinaModel MacchinaGetByKey(string idxMacchina)
{
MacchinaModel dbResult = new MacchinaModel();
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
dbResult = localDbCtx
.DbSetMacchine
.Where(x => x.IdxMacchina == idxMacchina)
.SingleOrDefault();
}
return dbResult;
}
/// <summary>
/// Elenco tabella Macchine
/// </summary>
/// <returns></returns>
public List<DatabaseModels.MacchinaModel> MacchineGetAll()
{
List<DatabaseModels.MacchinaModel> dbResult = new List<DatabaseModels.MacchinaModel>();
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
dbResult = localDbCtx
.DbSetMacchine
.OrderBy(x => x.IdxMacchina)
.ToList();
}
return dbResult;
}
public void ResetController()
{
dbCtx = new MoonPro_ProgContext(_configuration);
@@ -871,6 +901,14 @@ namespace MP.FileData.Controllers
#endregion Public Methods
#region Private Fields
private static IConfiguration _configuration;
private static MoonPro_ProgContext dbCtx;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#if false
/// <summary>
/// Elenco Azioni (decodifica)
@@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace MP.FileData.DatabaseModels
{
[Table("Macchine")]
public partial class MacchinaModel
public partial class ArchMaccModel
{
#region Public Properties
+1 -1
View File
@@ -53,7 +53,7 @@ namespace MP.FileData.DatabaseModels
}
[ForeignKey("IdxMacchina")]
public virtual MacchinaModel Macchina { get; set; }
public virtual ArchMaccModel Macchina { get; set; }
#endregion Public Properties
}
+2 -2
View File
@@ -19,8 +19,8 @@ namespace MP.FileData
public static void Seed(this ModelBuilder modelBuilder)
{
// inizializzazione dei valori di default x MACCHINA
modelBuilder.Entity<MacchinaModel>().HasData(
new MacchinaModel { IdxMacchina = "0", RuleName = "0", Descrizione = "--- Tutte ---", Nome = "--- Tutte ---", BasePath = "", ImgUrl = "", Note = "", ShowOrder = 0 }
modelBuilder.Entity<ArchMaccModel>().HasData(
new ArchMaccModel { IdxMacchina = "0", RuleName = "0", Descrizione = "--- Tutte ---", Nome = "--- Tutte ---", BasePath = "", ImgUrl = "", Note = "", ShowOrder = 0 }
);
}
+1 -1
View File
@@ -59,7 +59,7 @@ namespace MP.FileData
#region Public Properties
public virtual DbSet<MacchinaModel> DbSetMacchine { get; set; }
public virtual DbSet<ArchMaccModel> DbSetArchMacc { get; set; }
public virtual DbSet<FileModel> DbSetProgFile { get; set; }
public virtual DbSet<TagModel> DbSetTags { get; set; }
+18 -7
View File
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Components;
using MP.FileData.DatabaseModels;
using MP.Prog.Data;
using System.Threading.Tasks;
namespace MP.Prog.Components
@@ -8,17 +9,27 @@ namespace MP.Prog.Components
{
[Parameter]
public MacchinaModel CurrRec { get; set; }
public ArchMaccModel CurrRec { get; set; }
[Parameter]
public EventCallback<bool> EC_update { get; set; }
protected async void DoCancel()
[Inject]
protected FileArchDataService FDService { get; set; }
protected async Task DoSave()
{
await Task.Delay(1);
}
protected async void DoSave()
{
await Task.Delay(1);
bool fatto = false;
if (CurrRec != null)
{
fatto = await FDService.ArchivioMaccUpsert(CurrRec);
}
await EC_update.InvokeAsync(fatto);
}
protected async Task DoCancel()
{
await EC_update.InvokeAsync(true);
}
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
<div class="row">
@if (SelRecord != null)
{
<ArchiveEdit CurrRec="SelRecord"></ArchiveEdit>
<ArchiveEdit CurrRec="SelRecord" EC_update="ResetSel"></ArchiveEdit>
}
else
{
+9 -7
View File
@@ -66,23 +66,24 @@ namespace MP.Prog.Components
protected async Task SelEdit(string idxMacc)
{
// recupero macchina e mando a edit!
SelRecord = await FDService.MacchinaGetByKey(idxMacc);
SelRecord = await FDService.ArchMaccGetByKey(idxMacc);
}
protected void ResetSel()
protected async void ResetSel()
{
SelRecord = null;
await ReloadData();
}
protected void AddNew()
{
DateTime adesso = DateTime.Now;
SelRecord = new MacchinaModel()
SelRecord = new ArchMaccModel()
{
IdxMacchina = $"ID_{adesso:yyMMd_HHmmss}",
RuleName = "Rule05.json",
Nome = "Nuova Folder",
Descrizione = "Nuova folder",
Descrizione = "Backup folder",
BasePath = Configuration.GetValue<string>("ServerConf:FolderBasePath"),
ImgUrl = "Steamware.png",
Note = ""
@@ -116,7 +117,7 @@ namespace MP.Prog.Components
protected async Task ReloadData()
{
//sw.Restart();
ListRecords = null;
await Task.Delay(1);
numChecks = 0;
ListRecords = await FDService.GetArchiveStatus();
@@ -125,6 +126,7 @@ namespace MP.Prog.Components
setupMessages = new List<string>();
showProgress = false;
percLoading = 0;
await InvokeAsync(StateHasChanged);
}
#endregion Protected Methods
@@ -133,7 +135,7 @@ namespace MP.Prog.Components
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private List<ArchiveStatusDTO> ListRecords;
private MacchinaModel? SelRecord { get; set; } = null;
private ArchMaccModel? SelRecord { get; set; } = null;
private int numChecks = 0;
@@ -168,7 +170,7 @@ namespace MP.Prog.Components
private async Task verificaTutte(int numDays)
{
// recupero elenco macchine
var listaMacchine = await FDService.MacchineGetAll();
var listaMacchine = await FDService.ArchMaccGetAll();
int numMacchine = listaMacchine.Count();
foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList())
{
+1 -1
View File
@@ -56,7 +56,7 @@ namespace MP.Prog.Components
public EventCallback<int> DataUpdated { get; set; }
[Parameter]
public List<MacchinaModel> MacList { get; set; }
public List<ArchMaccModel> MacList { get; set; }
[Parameter]
public List<TagModel> TagList { get; set; }
+136 -30
View File
@@ -15,6 +15,7 @@ using System.Diagnostics;
using MP.FileData.Controllers;
using MP.FileData.DTO;
using StackExchange.Redis;
using MP.FileData.DatabaseModels;
namespace MP.Prog.Data
{
@@ -37,6 +38,12 @@ namespace MP.Prog.Data
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
};
// conf DB
string connStr = _configuration.GetConnectionString("MP.Prog");
if (string.IsNullOrEmpty(connStr))
@@ -54,6 +61,93 @@ namespace MP.Prog.Data
#region Public Methods
/// <summary>
/// Esegue Upsert record ArchivioMacchina
/// </summary>
/// <param name="currRec"></param>
/// <returns></returns>
public async Task<bool> ArchivioMaccUpsert(ArchMaccModel currRec)
{
bool fatto = await dbController.ArchMaccUpsert(currRec);
await ExecFlushRedisPattern($"{redisBaseAddr}:ArchMacc:*");
await ExecFlushRedisPattern($"{redisBaseAddr}:ArchStatus:*");
return fatto;
}
public async Task<List<ArchMaccModel>> ArchMaccGetAll()
{
string source = "DB";
List<ArchMaccModel> dbResult = new List<ArchMaccModel>();
string currKey = $"{redisBaseAddr}:ArchMacc:ALL";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<ArchMaccModel>>(rawData);
if (tempResult == null)
{
dbResult = new List<ArchMaccModel>();
}
else
{
dbResult = tempResult;
}
}
else
{
dbResult = dbController.ArchMaccGetAll();
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
if (dbResult == null)
{
dbResult = new List<ArchMaccModel>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Info($"ArchMaccGetAll | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task<ArchMaccModel> ArchMaccGetByKey(string idxMacchina)
{
string source = "DB";
ArchMaccModel dbResult = new ArchMaccModel();
string currKey = $"{redisBaseAddr}:ArchMacc:{idxMacchina}";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<ArchMaccModel>(rawData);
if (tempResult == null)
{
dbResult = new ArchMaccModel();
}
else
{
dbResult = tempResult;
}
}
else
{
dbResult = dbController.ArchMaccGetByKey(idxMacchina);
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
if (dbResult == null)
{
dbResult = new ArchMaccModel();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Info($"ArchMaccGetByKey | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public void Dispose()
{
// Clear database controller
@@ -72,14 +166,14 @@ namespace MP.Prog.Data
return await Task.FromResult(numCount);
}
public Task<FileData.DatabaseModels.FileModel> FileGetByKey(int FileId)
public Task<FileModel> FileGetByKey(int FileId)
{
return Task.FromResult(dbController.FileGetByKey(FileId));
}
public async Task<List<FileData.DatabaseModels.FileModel>> FileGetFilt(SelectData CurrFilter)
public async Task<List<FileModel>> FileGetFilt(SelectData CurrFilter)
{
List<FileData.DatabaseModels.FileModel> dbResult = new List<FileData.DatabaseModels.FileModel>();
List<FileModel> dbResult = new List<FileModel>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = dbController.FileGetFilt(CurrFilter.IdxMacchina, CurrFilter.OnlyActive, CurrFilter.OnlyMod, CurrFilter.OnlyNoTag, CurrFilter.FileName, CurrFilter.Tag, CurrFilter.SearchVal, CurrFilter.NumSkip, CurrFilter.PageSize).ToList();
@@ -98,31 +192,46 @@ namespace MP.Prog.Data
public async Task<List<ArchiveStatusDTO>> GetArchiveStatus()
{
string source = "DB";
List<ArchiveStatusDTO> dbResult = new List<ArchiveStatusDTO>();
string currKey = $"{redisBaseAddr}:ArchStatus:ALL";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
dbResult = dbController.GetArchiveStatus();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<ArchiveStatusDTO>>(rawData);
if (tempResult == null)
{
dbResult = new List<ArchiveStatusDTO>();
}
else
{
dbResult = tempResult;
}
}
else
{
dbResult = dbController.GetArchiveStatus();
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
if (dbResult == null)
{
dbResult = new List<ArchiveStatusDTO>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB per GetArchiveStatus: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
public Task<FileData.DatabaseModels.MacchinaModel> MacchinaGetByKey(string idxMacchina)
{
return Task.FromResult(dbController.MacchinaGetByKey(idxMacchina));
}
public Task<List<FileData.DatabaseModels.MacchinaModel>> MacchineGetAll()
{
return Task.FromResult(dbController.MacchineGetAll().ToList());
Log.Info($"GetArchiveStatus | {source} in: {ts.TotalMilliseconds} ms");
return dbResult;
}
public async Task<List<AutocompleteModel>> MachineList()
{
List<AutocompleteModel> answ = new List<AutocompleteModel>();
answ.Add(new AutocompleteModel { LabelField = "--- TUTTE ---", ValueField = "*" });
answ.AddRange(dbController.MacchineGetAll().Select(x => new AutocompleteModel { LabelField = $"{x.IdxMacchina} | {x.Nome} {x.Descrizione} ", ValueField = x.IdxMacchina }).ToList());
answ.AddRange(dbController.ArchMaccGetAll().Select(x => new AutocompleteModel { LabelField = $"{x.IdxMacchina} | {x.Nome} {x.Descrizione} ", ValueField = x.IdxMacchina }).ToList());
return await Task.FromResult(answ);
}
@@ -131,7 +240,7 @@ namespace MP.Prog.Data
dbController.RollBackEntity(item);
}
public async Task<List<FileData.DatabaseModels.TagModel>> TagGetFilt(string SearchVal)
public async Task<List<TagModel>> TagGetFilt(string SearchVal)
{
return await Task.FromResult(dbController.TagGetFilt(SearchVal, 200).ToList());
}
@@ -157,7 +266,7 @@ namespace MP.Prog.Data
public async Task<int> updateAllArchive(int numDayPre, bool forceTag)
{
int checkDone = 0;
var listaMacchine = await MacchineGetAll();
var listaMacchine = await ArchMaccGetAll();
foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList())
{
checkDone += await updateMachineArchive(item.IdxMacchina, numDayPre, forceTag, false);
@@ -184,7 +293,7 @@ namespace MP.Prog.Data
string ruleName = "Rule00.json";
try
{
var macchina = MacchinaGetByKey(idxMacchina).Result;
var macchina = ArchMaccGetByKey(idxMacchina).Result;
if (macchina != null && !string.IsNullOrEmpty(macchina.BasePath))
{
if (!string.IsNullOrEmpty(macchina.RuleName))
@@ -255,27 +364,27 @@ namespace MP.Prog.Data
#region Internal Methods
internal Task FileApprove(FileData.DatabaseModels.FileModel currItem)
internal Task FileApprove(FileModel currItem)
{
return Task.FromResult(dbController.FileModApprove(currItem));
}
internal Task FileDelete(FileData.DatabaseModels.FileModel currItem)
internal Task FileDelete(FileModel currItem)
{
return Task.FromResult(dbController.FileDelete(currItem));
}
internal Task FileExport(FileData.DatabaseModels.FileModel currItem)
internal Task FileExport(FileModel currItem)
{
return Task.FromResult(dbController.FileExport(currItem));
}
internal Task FileReject(FileData.DatabaseModels.FileModel currItem)
internal Task FileReject(FileModel currItem)
{
return Task.FromResult(dbController.FileModReject(currItem));
}
internal Task FileUpdate(FileData.DatabaseModels.FileModel updItem)
internal Task FileUpdate(FileModel updItem)
{
return Task.FromResult(dbController.FileUpdate(updItem));
}
@@ -290,7 +399,6 @@ namespace MP.Prog.Data
#region Protected Fields
protected static string connStringBBM = "";
protected static string connStringFatt = "";
#endregion Protected Fields
@@ -303,11 +411,9 @@ namespace MP.Prog.Data
private const string redisBaseAddr = "MP:PROG";
private static IConfiguration _configuration;
private static ILogger<FileArchDataService> _logger;
private static List<FileData.DatabaseModels.MacchinaModel> ElencoMacchine = new List<FileData.DatabaseModels.MacchinaModel>();
private static List<ArchMaccModel> ElencoMacchine = new List<ArchMaccModel>();
private static JsonSerializerSettings? JSSettings;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
/// <summary>
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>MP.Prog</RootNamespace>
<Version>6.16.2410.2109</Version>
<Version>6.16.2410.2112</Version>
</PropertyGroup>
<ItemGroup>
+2 -2
View File
@@ -18,7 +18,7 @@ namespace MP.Prog.Pages
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private FileModel currRecord = null;
private List<FileModel> ListRecords;
private List<MacchinaModel> MacList;
private List<ArchMaccModel> MacList;
private List<TagModel> TagList;
#endregion Private Fields
@@ -423,7 +423,7 @@ namespace MP.Prog.Pages
protected async Task ReloadAllData()
{
isLoading = true;
MacList = await DataService.MacchineGetAll();
MacList = await DataService.ArchMaccGetAll();
SelIdxMacc = "0";
SearchTag = defTag;
TagList = await DataService.TagGetFilt(SearchTag);
+1 -1
View File
@@ -24,7 +24,7 @@ namespace MP.Prog
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Error);
})
.UseNLog();
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo gestione Programmi MAPO</i>
<h4>Versione: 6.16.2410.2109</h4>
<h4>Versione: 6.16.2410.2112</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
6.16.2410.2109
6.16.2410.2112
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.16.2410.2109</version>
<version>6.16.2410.2112</version>
<url>https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Prog.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1 -1
View File
@@ -39,7 +39,7 @@
"rules": [
{
"logger": "*",
"minLevel": "Trace",
"minLevel": "Info",
"writeTo": "logconsole"
},
{