- correzione tag extraction
- correzione indentazione json
This commit is contained in:
Samuele Locatelli
2024-10-21 20:09:28 +02:00
parent 3623e0059f
commit 9fad86eb17
16 changed files with 137 additions and 98 deletions
+26 -12
View File
@@ -138,13 +138,27 @@ namespace MP.FileData.Controllers
{
fileList = fileListRaw.ToList();
}
Log.Trace($"CheckFileArchived S01 | file trovati: {fileList.Count()}");
Log.Debug($"CheckFileArchived S01 | file trovati: {fileList.Count()}");
List<FileInfo> fileNew = new List<FileInfo>();
List<FileModel> fileChecked = new List<FileModel>();
List<FileModel> fileMod = new List<FileModel>();
// recupera elenco file nel DB
var archivedFile = FileGetByPath(path, true);
List<FileModel> archivedFile = new List<FileModel>();
List<FileModel> foundFile = FileGetByPath(path, true);
// rimuovo eventuali file con estensioni escluse...
foreach (var fRec in foundFile)
{
if (!string.IsNullOrEmpty(fRec.Extension) && currRule.ExcludedFileExt.Contains(fRec.Extension))
{
Log.Trace($"CheckFileArchived S01.B: escluso {fRec.Name} | estensione {fRec.Extension}");
}
else
{
archivedFile.Add(fRec);
}
}
Log.Debug($"CheckFileArchived S01.C | Recuperati {archivedFile.Count()} da DB per confronto");
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
// verifica i file
@@ -159,9 +173,9 @@ namespace MP.FileData.Controllers
{
// cerca nel DB...
FileModel currRecord = archivedFile
.Where(x => x.Active && x.Path == file.FullName)
.OrderByDescending(y => y.Rev)
.FirstOrDefault();
.Where(x => x.Active && x.Path == file.FullName)
.OrderByDescending(y => y.Rev)
.FirstOrDefault();
// se NON trova lo crea
if (currRecord == null)
{
@@ -389,7 +403,7 @@ namespace MP.FileData.Controllers
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
// converto
List<DatabaseModels.FileModel> newRec = newFiles.Select(o => new DatabaseModels.FileModel()
List<FileModel> newRec = newFiles.Select(o => new FileModel()
{
Active = true,
DiskStatus = FileState.Ok,
@@ -427,15 +441,15 @@ namespace MP.FileData.Controllers
// cerco codice tag da configurazione
if (currRule.Mode == SearchMode.StringOnFile)
{
Tags = TagsUtils.searchProgComment(fileName, item.FileStringContent, currRule);
Tags = TagsUtils.SearchProgComment(fileName, item.FileStringContent, currRule);
}
else if (currRule.Mode == SearchMode.TagListed)
{
Tags = TagsUtils.searchTagListed(fileName, item.FileStringContent, currRule);
Tags = TagsUtils.SearchTagListed(fileName, item.FileStringContent, currRule);
}
else
{
Tags = TagsUtils.searchPathName(item.Path, basePath, currRule);
Tags = TagsUtils.SearchPathName(item.Path, basePath, currRule);
}
foreach (var tag in Tags)
@@ -594,15 +608,15 @@ namespace MP.FileData.Controllers
// cerco codice tag da configurazione
if (currRule.Mode == SearchMode.StringOnFile)
{
Tags = TagsUtils.searchProgComment(fileName, item.FileStringContent, currRule);
Tags = TagsUtils.SearchProgComment(fileName, item.FileStringContent, currRule);
}
else if (currRule.Mode == SearchMode.TagListed)
{
Tags = TagsUtils.searchTagListed(fileName, item.FileStringContent, currRule);
Tags = TagsUtils.SearchTagListed(fileName, item.FileStringContent, currRule);
}
else
{
Tags = TagsUtils.searchPathName(item.Path, basePath, currRule);
Tags = TagsUtils.SearchPathName(item.Path, basePath, currRule);
}
foreach (var tag in Tags)
+16 -1
View File
@@ -48,7 +48,22 @@ namespace MP.FileData.DatabaseModels
set
{
// serializzo a byte
FileContent = Encoding.ASCII.GetBytes(value);
//FileContent = Encoding.ASCII.GetBytes(value);
FileContent = Encoding.UTF8.GetBytes(value);
}
}
[NotMapped]
public string Extension
{
get
{
string answ = "";
if(!string.IsNullOrEmpty(Name))
{
int sPos = Name.LastIndexOf('.');
answ = Name.Substring(sPos);
}
return answ;
}
}
+7 -8
View File
@@ -36,7 +36,7 @@ namespace MP.FileData
/// <param name="filePath">Nome del file (path completo)</param>
/// <param name="currRule">Parametri analisi</param>
/// <returns></returns>
public static List<string> searchPathName(string filePath, string basePath, SearchRules currRule)
public static List<string> SearchPathName(string filePath, string basePath, SearchRules currRule)
{
List<string> answ = new List<string>();
string fileName = Path.GetFileName(filePath);
@@ -74,7 +74,7 @@ namespace MP.FileData
// se nullo --> segnalo!
if (answ.Count == 0)
{
Log.Warn($"searchPathName Attenzione Tag non trovati | {filePath} | basePath: {basePath}");
Log.Warn($"SearchPathName Attenzione Tag non trovati | {filePath} | basePath: {basePath}");
}
return answ;
}
@@ -89,7 +89,7 @@ namespace MP.FileData
/// <param name="fileContent">Contenuto del file da analizzare</param>
/// <param name="currRule">Parametri analisi</param>
/// <returns></returns>
public static List<string> searchProgComment(string fileName, string fileContent, SearchRules currRule)
public static List<string> SearchProgComment(string fileName, string fileContent, SearchRules currRule)
{
// verifico se trimmare contenuto file
if (fileContent.Length > currRule.MaxChar2Search && currRule.MaxChar2Search > 0)
@@ -148,7 +148,7 @@ namespace MP.FileData
// se nullo --> segnalo!
if (answ.Count == 0)
{
Log.Warn($"searchProgComment Attenzione Tag non trovati | {fileName} | pattern: {pattern}");
Log.Warn($"SearchProgComment Attenzione Tag non trovati | {fileName} | pattern: {pattern}");
//Log.Trace($"{fileName}:{Environment.NewLine}{fileContent}");
}
return answ;
@@ -164,7 +164,7 @@ namespace MP.FileData
/// <param name="fileContent">Contenuto del file da analizzare</param>
/// <param name="currRule">Parametri analisi</param>
/// <returns></returns>
public static List<string> searchTagListed(string fileName, string fileContent, SearchRules currRule)
public static List<string> SearchTagListed(string fileName, string fileContent, SearchRules currRule)
{
// verifico se trimmare contenuto file
if (fileContent.Length > currRule.MaxChar2Search && currRule.MaxChar2Search > 0)
@@ -183,7 +183,7 @@ namespace MP.FileData
{
foreach (var row in fileRows)
{
if (row.StartsWith(tag2check))
if (row.StartsWith(tag2check) || row.Contains(tag2check))
{
answ.Add(row.Trim());
break;
@@ -195,8 +195,7 @@ namespace MP.FileData
// se nullo --> segnalo!
if (answ.Count == 0)
{
Log.Warn($"searchTagListed Attenzione Tag non trovati | {fileName} | tags cercati: {currRule.Tag2Collect.Count}");
//Log.Trace($"{Environment.NewLine}{fileContent}");
Log.Warn($"SearchTagListed Attenzione Tag non trovati | {fileName} | tags cercati: {currRule.Tag2Collect.Count}");
}
return answ;
}
+52 -53
View File
@@ -27,10 +27,10 @@ namespace MP.Prog.Components
#region Protected Properties
[Inject]
protected FileArchDataService FDService { get; set; }
protected IConfiguration Configuration { get; set; }
[Inject]
protected IConfiguration Configuration { get; set; }
protected FileArchDataService FDService { get; set; }
protected int percLoading { get; set; } = 0;
protected bool showProgress { get; set; } = false;
@@ -39,42 +39,6 @@ namespace MP.Prog.Components
#region Protected Methods
protected async Task ArchiveCheck(int maxHour)
{
showProgress = true;
percLoading = 0;
await verificaTutte(maxHour);
setupMessages.Add($"Effettuata verifica e rilettura di {numChecks} files!");
}
protected async Task ArchiveSingleCheck(string idxMacchina, int maxHour)
{
showProgress = true;
percLoading = 0;
await verificaSingola(idxMacchina, maxHour, 2);
setupMessages.Add($"Effettuata verifica e rilettura di {numChecks} files!");
}
protected async Task ClearMessage()
{
await Task.Delay(10);
setupMessages = new List<string>();
}
protected async Task SelEdit(string idxMacc)
{
// recupero macchina e mando a edit!
SelRecord = await FDService.ArchMaccGetByKey(idxMacc);
}
protected async void ResetSel()
{
SelRecord = null;
await ReloadData();
}
protected void AddNew()
{
DateTime adesso = DateTime.Now;
@@ -89,25 +53,51 @@ namespace MP.Prog.Components
Note = ""
};
}
protected async Task ArchiveCheck(int maxHour)
{
showProgress = true;
percLoading = 0;
await VerificaTutte(maxHour);
setupMessages.Add($"Effettuata verifica e rilettura di {numChecks} files!");
}
protected async Task ArchiveSingleCheck(string idxMacchina, int maxHour)
{
showProgress = true;
percLoading = 0;
await VerificaSingola(idxMacchina, maxHour, 2);
setupMessages.Add($"Effettuata verifica e rilettura di {numChecks} files!");
}
protected void ClearMessage()
{
setupMessages = new List<string>();
}
protected async Task ForceCheck(int maxHour)
{
ListRecords = null;
await InvokeAsync(StateHasChanged);
setupMessages.Add("Inizio Analisi Archivio...");
await InvokeAsync(StateHasChanged);
ListRecords = null;
await Task.Delay(1);
await ArchiveCheck(maxHour);
await ClearMessage();
await Task.Delay(400);
ClearMessage();
await ReloadData();
}
protected async Task ForceCheckMacchina(string idxMacchina)
{
ListRecords = null;
await InvokeAsync(StateHasChanged);
setupMessages.Add($"Inizio Analisi Archivio | Archivio {idxMacchina}");
await InvokeAsync(StateHasChanged);
ListRecords = null;
await Task.Delay(1);
await ArchiveSingleCheck(idxMacchina, 0);
await ClearMessage();
await Task.Delay(400);
ClearMessage();
await ReloadData();
}
@@ -131,16 +121,25 @@ namespace MP.Prog.Components
await InvokeAsync(StateHasChanged);
}
protected async void ResetSel()
{
SelRecord = null;
await ReloadData();
}
protected async Task SelEdit(string idxMacc)
{
// recupero macchina e mando a edit!
SelRecord = await FDService.ArchMaccGetByKey(idxMacc);
}
#endregion Protected Methods
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private List<ArchiveStatusDTO> ListRecords;
private ArchMaccModel? SelRecord { get; set; } = null;
private int numChecks = 0;
private Stopwatch sw = new Stopwatch();
private int totalCount = 0;
@@ -148,35 +147,35 @@ namespace MP.Prog.Components
#region Private Properties
private ArchMaccModel? SelRecord { get; set; } = null;
private List<string> setupMessages { get; set; } = new List<string>();
#endregion Private Properties
#region Private Methods
private async Task verificaSingola(string idxMacchina, int numDays, int numMacchine)
private async Task VerificaSingola(string idxMacchina, int numDays, int numMacchine)
{
sw.Restart();
// recupero elenco macchine
percLoading += 100 / numMacchine;
numChecks = await FDService.updateMachineArchive(idxMacchina, numDays, true, false);
numChecks = await FDService.UpdateMachineArchive(idxMacchina, numDays, true, false);
await Task.Delay(1);
setupMessages.Add($"{idxMacchina}: {numChecks} files");
await InvokeAsync(StateHasChanged);
await Task.Delay(1);
sw.Stop();
var elapsTime = sw.Elapsed;
Log.Trace($"verificaSingola | idxMacchina: {idxMacchina} | {elapsTime.TotalMilliseconds}ms");
Log.Info($"VerificaSingola | idxMacchina: {idxMacchina} | {sw.ElapsedMilliseconds:N0}ms");
}
private async Task verificaTutte(int numDays)
private async Task VerificaTutte(int numDays)
{
// recupero elenco macchine
var listaMacchine = await FDService.ArchMaccGetAll();
int numMacchine = listaMacchine.Count();
foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList())
{
await verificaSingola(item.IdxMacchina, numDays, numMacchine);
await VerificaSingola(item.IdxMacchina, numDays, numMacchine);
}
}
+2 -2
View File
@@ -75,7 +75,7 @@
{
get
{
return _oldText.Replace(Environment.NewLine, sepDest).Replace("\n", sepDest).Replace("\r", sepDest);
return _oldText.Replace(" ", "&nbsp;").Replace(Environment.NewLine, sepDest).Replace("\n", sepDest).Replace("\r", sepDest);
}
}
@@ -83,7 +83,7 @@
{
get
{
return _newText.Replace(Environment.NewLine, sepDest).Replace("\n", sepDest).Replace("\r", sepDest);
return _newText.Replace(" ", "&nbsp;").Replace(Environment.NewLine, sepDest).Replace("\n", sepDest).Replace("\r", sepDest);
}
}
[Parameter]
+1 -1
View File
@@ -116,7 +116,7 @@ namespace MP.Prog.Components
await DataReset.InvokeAsync(0);
await DataService.FileExport(_currItem);
await DataReset.InvokeAsync(0);
await DataService.updateMachineArchive(_currItem.IdxMacchina, 1, false, false);
await DataService.UpdateMachineArchive(_currItem.IdxMacchina, 1, false, false);
await DataUpdated.InvokeAsync(1);
}
else
+2 -1
View File
@@ -2,7 +2,8 @@
"ExcludedTags": [ ],
"ExcludedFileExt": [
".bak",
".bck"
".bck",
".file"
],
"FileNameExtReplace": {
},
+18 -7
View File
@@ -69,9 +69,17 @@ namespace MP.Prog.Data
public async Task<bool> ArchivioMaccUpsert(ArchMaccModel currRec)
{
bool fatto = await dbController.ArchMaccUpsert(currRec);
await ResetArchiveCache();
return fatto;
}
/// <summary>
/// Reset della cache dati ArchivioMacchine in redis
/// </summary>
/// <returns></returns>
private async Task ResetArchiveCache()
{
await ExecFlushRedisPattern($"{redisBaseAddr}:ArchMacc:*");
await ExecFlushRedisPattern($"{redisBaseAddr}:ArchStatus:*");
return fatto;
}
public async Task<List<ArchMaccModel>> ArchMaccGetAll()
@@ -263,13 +271,13 @@ namespace MP.Prog.Data
/// Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite
/// </param>
/// <returns></returns>
public async Task<int> updateAllArchive(int numDayPre, bool forceTag)
public async Task<int> UpdateAllArchive(int numDayPre, bool forceTag)
{
int checkDone = 0;
var listaMacchine = await ArchMaccGetAll();
foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList())
{
checkDone += await updateMachineArchive(item.IdxMacchina, numDayPre, forceTag, false);
checkDone += await UpdateMachineArchive(item.IdxMacchina, numDayPre, forceTag, false);
}
return await Task.FromResult(checkDone);
@@ -285,7 +293,7 @@ namespace MP.Prog.Data
/// <param name="forceTag">Forza la riverifica dei tags (x update da setup)</param>
/// <param name="fullLog">Scrittura log verboso macchina</param>
/// <returns></returns>
public async Task<int> updateMachineArchive(string idxMacchina, int numDayPre, bool forceTag, bool fullLog)
public async Task<int> UpdateMachineArchive(string idxMacchina, int numDayPre, bool forceTag, bool fullLog)
{
int checkDone = 0;
Stopwatch stopWatch = new Stopwatch();
@@ -293,7 +301,7 @@ namespace MP.Prog.Data
string ruleName = "Rule00.json";
try
{
var macchina = ArchMaccGetByKey(idxMacchina).Result;
ArchMaccModel macchina = await ArchMaccGetByKey(idxMacchina);
if (macchina != null && !string.IsNullOrEmpty(macchina.BasePath))
{
if (!string.IsNullOrEmpty(macchina.RuleName))
@@ -351,13 +359,16 @@ namespace MP.Prog.Data
}
catch (Exception exc)
{
Log.Error($"Eccezione in updateMachineArchive{Environment.NewLine}{exc}{Environment.NewLine}{exc.InnerException}");
Log.Error($"Eccezione in UpdateMachineArchive{Environment.NewLine}{exc}{Environment.NewLine}{exc.InnerException}");
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Info($"Effettuato update archivio file MACCHINA | last {numDayPre} days | {checkDone} checked | {ts.TotalMilliseconds} ms");
return await Task.FromResult(checkDone);
// svuoto cache!
await ResetArchiveCache();
// restituisco conteggio
return checkDone;
}
#endregion Public Methods
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>MP.Prog</RootNamespace>
<Version>6.16.2410.2116</Version>
<Version>6.16.2410.2120</Version>
</PropertyGroup>
<ItemGroup>
+1 -3
View File
@@ -1,7 +1,5 @@
@page "/Archive"
@using MP.Prog.Components
<div class="card shadow">
<div class="card-header table-primary">
<div class="d-flex justify-content-between">
@@ -83,7 +81,7 @@
</div>
@if (DeleteDialogOpen)
{
<MP.Prog.Components.TagSearch Title="Ricerca Tag" OnClose="@OnDialogClose"></MP.Prog.Components.TagSearch>
<TagSearch Title="Ricerca Tag" OnClose="@OnDialogClose"></TagSearch>
}
</div>
</div>
+3 -4
View File
@@ -5,10 +5,9 @@ using MP.Prog.Data;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MP.Prog.Pages
{
public partial class Archive : ComponentBase, IDisposable
@@ -371,7 +370,7 @@ namespace MP.Prog.Pages
{
SelTag = searchVal;
currPage = 1;
await ReloadAllData();
await ReloadData();
isLoading = false;
}
@@ -382,7 +381,7 @@ namespace MP.Prog.Pages
// importante altrimenti NON mostra update UI
await Task.Delay(1);
//AppMService.File_Filter = SelectData.Init(5, 10);
var numCheck = await DataService.updateAllArchive(numDays, false);
var numCheck = await DataService.UpdateAllArchive(numDays, false);
await ReloadAllData();
await Task.Delay(1);
await RefreshDisplayLoading();
+4 -1
View File
@@ -23,10 +23,13 @@ namespace MP.Prog
})
.ConfigureLogging(logging =>
{
// impostante per non perdere le regole di log
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Error);
})
.UseNLog();
// importante per eseguire la conf regike logging
.UseNLog(new NLogAspNetCoreOptions() { RemoveLoggerFactoryFilter = false });
//.UseNLog();
public static void Main(string[] args)
{
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo gestione Programmi MAPO</i>
<h4>Versione: 6.16.2410.2116</h4>
<h4>Versione: 6.16.2410.2120</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
6.16.2410.2116
6.16.2410.2120
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.16.2410.2116</version>
<version>6.16.2410.2120</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": "Info",
"minLevel": "Trace",
"writeTo": "logconsole"
},
{