From f3319674179d107f21e4d571beeffe411b8b537a Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 29 Oct 2024 10:41:30 +0100 Subject: [PATCH] PROG - fix esclusione file temp da regexp - fix gestione delete - test update/approve da REST --- MP.FileData/Controllers/FileController.cs | 81 ++++++++++++++++----- MP.FileData/Enum.cs | 2 +- MP.FileData/SearchRules.cs | 10 +++ MP.Prog/Components/ArchiveStatus.razor.cs | 1 - MP.Prog/Components/FileEditor.razor | 6 -- MP.Prog/Components/RevList.razor.cs | 2 +- MP.Prog/Conf/Rule01.json | 56 +++++++------- MP.Prog/Conf/Rule02.json | 44 +++++------ MP.Prog/Conf/Rule03.json | 68 ++++++++--------- MP.Prog/Conf/Rule04.json | 6 +- MP.Prog/Conf/Rule05.json | 6 +- MP.Prog/Controllers/FileChangeController.cs | 12 ++- MP.Prog/MP.Prog.csproj | 2 +- MP.Prog/Pages/Archive.razor.cs | 3 +- MP.Prog/Resources/ChangeLog.html | 2 +- MP.Prog/Resources/VersNum.txt | 2 +- MP.Prog/Resources/manifest.xml | 2 +- 17 files changed, 182 insertions(+), 123 deletions(-) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 578c7b07..3ea65ec5 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using MP.FileData.DatabaseModels; using Newtonsoft.Json; using MP.FileData.DTO; +using System.Text.RegularExpressions; namespace MP.FileData.Controllers { @@ -121,25 +122,10 @@ namespace MP.FileData.Controllers { Log.Info($"CheckFileArchived S00 | macchina: {idxMacchina} | path: {path} | pattern: {searchPattern} | # ExcludedFileExt: {currRule.ExcludedFileExt.Count()}"); int checkDone = 0; - DirectoryInfo dirInfo = new DirectoryInfo(path); - FileInfo[] fileListRaw = dirInfo.GetFiles(searchPattern, SearchOption.AllDirectories); List fileList = new List(); - DateTime adesso = DateTime.Now; - // se ho un limite x giorni indietor x modifiche --> limito! - if (numDayPre > 0) - { - foreach (var item in fileListRaw) - { - if (adesso.Subtract(item.LastWriteTime).TotalDays <= numDayPre) - { - fileList.Add(item); - } - } - } - else - { - fileList = fileListRaw.ToList(); - } + // leggo i files rispettando regole e filtri vari + fileList = GetFiltFileFromDisk(path, numDayPre, searchPattern, currRule, fileList); + Log.Debug($"CheckFileArchived S01 | file trovati: {fileList.Count()}"); List fileNew = new List(); List fileChecked = new List(); @@ -271,6 +257,61 @@ namespace MP.FileData.Controllers // chiudo return checkDone; } + /// + /// Recupera file dal disco saltando eventuali math di esclusione e/o filtro date/nome file + /// + /// + /// + /// + /// + /// + /// + private static List GetFiltFileFromDisk(string path, int numDayPre, string searchPattern, SearchRules currRule, List fileList) + { + DirectoryInfo dirInfo = new DirectoryInfo(path); + var fileListRaw = dirInfo.GetFiles(searchPattern, SearchOption.AllDirectories).ToList(); + List file2Rem = new List(); + // se richiesto filtro i files esclusi da regexp li calcolo... + if (currRule.ExclFileEnabled) + { + foreach (var item in fileListRaw) + { + string pattern = currRule.ExclFileRegExPattern; + // uso regexp + MatchCollection hasMatch = Regex.Matches(item.Name, pattern); + if (hasMatch.Count > 0) + { + file2Rem.Add(item); + } + } + // quindi li rimuovo da elenco raw... + if (file2Rem.Count > 0) + { + foreach (var f2d in file2Rem) + { + fileListRaw.Remove(f2d); + } + } + } + DateTime adesso = DateTime.Now; + // se ho un limite x giorni indietro x modifiche --> limito! + if (numDayPre > 0) + { + foreach (var item in fileListRaw) + { + if (adesso.Subtract(item.LastWriteTime).TotalDays <= numDayPre) + { + fileList.Add(item); + } + } + } + else + { + fileList = fileListRaw.ToList(); + } + + return fileList; + } /// /// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck @@ -1010,7 +1051,7 @@ namespace MP.FileData.Controllers foreach (var item in missFiles) { // salvo update file - item.DiskStatus = FileState.Deleted; + item.DiskStatus = FileState.Missing; item.LastCheck = adesso; localDbCtx.Entry(item).State = EntityState.Modified; } @@ -1163,7 +1204,7 @@ namespace MP.FileData.Controllers .Count(); item.NumMissing = activeRecords - .Where(x => x.DiskStatus == FileState.Deleted) + .Where(x => x.DiskStatus == FileState.Missing) .Count(); item.NoTags = activeRecords diff --git a/MP.FileData/Enum.cs b/MP.FileData/Enum.cs index 5163fd93..a2de0a37 100644 --- a/MP.FileData/Enum.cs +++ b/MP.FileData/Enum.cs @@ -13,7 +13,7 @@ namespace MP.FileData { ND = 0, Changed, - Deleted, + Missing, Ok } } \ No newline at end of file diff --git a/MP.FileData/SearchRules.cs b/MP.FileData/SearchRules.cs index 0f8ee9e3..c3e2589f 100644 --- a/MP.FileData/SearchRules.cs +++ b/MP.FileData/SearchRules.cs @@ -93,6 +93,16 @@ namespace MP.FileData /// public List Tag2Collect { get; set; } = new List(); + /// + /// Configurazione opzionale x escludere files da regexp su filename + /// + public bool ExclFileEnabled { get; set; } = false; + + /// + /// Pattern in formato RegExp x esclusione file da nome + /// + public string ExclFileRegExPattern { get; set; } = ""; + #endregion Public Properties } } \ No newline at end of file diff --git a/MP.Prog/Components/ArchiveStatus.razor.cs b/MP.Prog/Components/ArchiveStatus.razor.cs index 55670bed..9a186f0f 100644 --- a/MP.Prog/Components/ArchiveStatus.razor.cs +++ b/MP.Prog/Components/ArchiveStatus.razor.cs @@ -163,7 +163,6 @@ namespace MP.Prog.Components // recupero elenco macchine percLoading += 100 / numMacchine; numChecks = await FDService.UpdateMachineArchive(idxMacchina, numDays, true, false, "", false); - //numChecks = await FDService.UpdateMachineArchive(idxMacchina, numDays, true, false, MServ.UserName, false); await Task.Delay(1); setupMessages.Add($"{idxMacchina}: {numChecks} files"); await InvokeAsync(StateHasChanged); diff --git a/MP.Prog/Components/FileEditor.razor b/MP.Prog/Components/FileEditor.razor index f6112f6b..f092d35e 100644 --- a/MP.Prog/Components/FileEditor.razor +++ b/MP.Prog/Components/FileEditor.razor @@ -64,13 +64,7 @@ else {
-
-
-
-
-
-
} diff --git a/MP.Prog/Components/RevList.razor.cs b/MP.Prog/Components/RevList.razor.cs index ba0c0d33..c5b44208 100644 --- a/MP.Prog/Components/RevList.razor.cs +++ b/MP.Prog/Components/RevList.razor.cs @@ -132,7 +132,7 @@ namespace MP.Prog.Components answ += " text-bg-warning"; break; - case FileState.Deleted: + case FileState.Missing: answ += " text-bg-danger"; break; diff --git a/MP.Prog/Conf/Rule01.json b/MP.Prog/Conf/Rule01.json index 1ee93dff..dc958695 100644 --- a/MP.Prog/Conf/Rule01.json +++ b/MP.Prog/Conf/Rule01.json @@ -1,29 +1,31 @@ { - "ExcludedTags": [ - "M4", - "M5", - "M4+A", - "M4+B", - "M5+A", - "M5+B" - ], - "ExcludedFileExt": [ - ".xls", - ".xls#", - ".xlsx" - ], - "FileNameExtReplace": { - ".P-2": "" - }, - "MaxChar2Search": 100, - "Mode": 0, - "Name": "Tag da Commento Filename", - "OutExcludeFileName": true, - "OutReplace": { - "(": " ", - ")": " " - }, - "RegExPattern": "\\b{{fileName}}.{0,2}\\([\\w\\d\\s./\\-=]+\\)", - "RegExRepFileName": true, - "ReplaceCR": true + "ExcludedTags": [ + "M4", + "M5", + "M4+A", + "M4+B", + "M5+A", + "M5+B" + ], + "ExcludedFileExt": [ + ".xls", + ".xls#", + ".xlsx" + ], + "FileNameExtReplace": { + ".P-2": "" + }, + "MaxChar2Search": 100, + "Mode": 0, + "Name": "Tag da Commento Filename", + "OutExcludeFileName": true, + "OutReplace": { + "(": " ", + ")": " " + }, + "RegExPattern": "\\b{{fileName}}.{0,2}\\([\\w\\d\\s./\\-=]+\\)", + "RegExRepFileName": true, + "ReplaceCR": true, + "ExclFileEnabled": true, + "ExclFileRegExPattern": "^~\\$" } \ No newline at end of file diff --git a/MP.Prog/Conf/Rule02.json b/MP.Prog/Conf/Rule02.json index b7414dda..6548131f 100644 --- a/MP.Prog/Conf/Rule02.json +++ b/MP.Prog/Conf/Rule02.json @@ -1,23 +1,25 @@ { - "ExcludedTags": [], - "ExcludedFileExt": [ - ".xls", - ".xls#", - ".xlsx" - ], - "FileNameExtReplace": { - ".P-2": "" - }, - "MaxChar2Search": 1, - "Mode": 1, - "Name": "Tag da Directory + Filename", - "OutExcludeFileName": false, - "OutReplace": { - ".WPD": "", - ".MPF": "", - ".SPF": "" - }, - "RegExPattern": "", - "RegExRepFileName": true, - "ReplaceCR": false + "ExcludedTags": [], + "ExcludedFileExt": [ + ".xls", + ".xls#", + ".xlsx" + ], + "FileNameExtReplace": { + ".P-2": "" + }, + "MaxChar2Search": 1, + "Mode": 1, + "Name": "Tag da Directory + Filename", + "OutExcludeFileName": false, + "OutReplace": { + ".WPD": "", + ".MPF": "", + ".SPF": "" + }, + "RegExPattern": "", + "RegExRepFileName": true, + "ReplaceCR": false, + "ExclFileEnabled": true, + "ExclFileRegExPattern": "^~\\$" } \ No newline at end of file diff --git a/MP.Prog/Conf/Rule03.json b/MP.Prog/Conf/Rule03.json index e7cc1892..6f19ccdf 100644 --- a/MP.Prog/Conf/Rule03.json +++ b/MP.Prog/Conf/Rule03.json @@ -1,35 +1,37 @@ { - "ExcludedTags": [ - "M4", - "M5", - "M4+A", - "M4+B", - "M5+A", - "M5+B", - "M6+A", - "M6+B", - "+A" - ], - "ExcludedFileExt": [ - ".xls", - ".xls#", - ".xlsx" - ], - "FileNameExtReplace": { - ".P-2": "", - ".tim": "" - }, - "MaxChar2Search": 100, - "Mode": 0, - "Name": "Tag da Commento Filename Tornoss TISIS", - "OutExcludeFileName": true, - "OutReplace": { - "(": " ", - ")": " ", - "<": " ", - ">": " " - }, - "RegExPattern": "\\b{{fileName}}.{0,2}\\([\\<\\w\\d\\s./\\-=\\+\\>]+\\)", - "RegExRepFileName": true, - "ReplaceCR": true + "ExcludedTags": [ + "M4", + "M5", + "M4+A", + "M4+B", + "M5+A", + "M5+B", + "M6+A", + "M6+B", + "+A" + ], + "ExcludedFileExt": [ + ".xls", + ".xls#", + ".xlsx" + ], + "FileNameExtReplace": { + ".P-2": "", + ".tim": "" + }, + "MaxChar2Search": 100, + "Mode": 0, + "Name": "Tag da Commento Filename Tornoss TISIS", + "OutExcludeFileName": true, + "OutReplace": { + "(": " ", + ")": " ", + "<": " ", + ">": " " + }, + "RegExPattern": "\\b{{fileName}}.{0,2}\\([\\<\\w\\d\\s./\\-=\\+\\>]+\\)", + "RegExRepFileName": true, + "ReplaceCR": true, + "ExclFileEnabled": true, + "ExclFileRegExPattern": "^~\\$" } \ No newline at end of file diff --git a/MP.Prog/Conf/Rule04.json b/MP.Prog/Conf/Rule04.json index c1a5fa19..f0991de1 100644 --- a/MP.Prog/Conf/Rule04.json +++ b/MP.Prog/Conf/Rule04.json @@ -1,5 +1,5 @@ { - "ExcludedTags": [ ], + "ExcludedTags": [], "ExcludedFileExt": [ ".bak", ".bck" @@ -33,5 +33,7 @@ "IP=", "AUTO_CHANGE_ODL=", "AUTO_SNAPSHOT_DOSSIER=" - ] + ], + "ExclFileEnabled": true, + "ExclFileRegExPattern": "^~\\$" } \ No newline at end of file diff --git a/MP.Prog/Conf/Rule05.json b/MP.Prog/Conf/Rule05.json index 8607aced..e77df664 100644 --- a/MP.Prog/Conf/Rule05.json +++ b/MP.Prog/Conf/Rule05.json @@ -1,5 +1,5 @@ { - "ExcludedTags": [ ], + "ExcludedTags": [], "ExcludedFileExt": [ ".bak", ".bck", @@ -39,5 +39,7 @@ "\"QrJumpPath\":", "\"Environment\":", "\"appVers\":" - ] + ], + "ExclFileEnabled": true, + "ExclFileRegExPattern": "^~\\$" } \ No newline at end of file diff --git a/MP.Prog/Controllers/FileChangeController.cs b/MP.Prog/Controllers/FileChangeController.cs index 7e7494da..70446d52 100644 --- a/MP.Prog/Controllers/FileChangeController.cs +++ b/MP.Prog/Controllers/FileChangeController.cs @@ -152,11 +152,15 @@ namespace MP.Prog.Controllers // ciclo ogni file modificato foreach (var cFile in listChanged) { - // approvo il file modificato con utente anonimo (auto-Approve) - bool fatto = await FADService.FileModApprove(cFile, ""); - if (fatto) + // se è modificato... + if (cFile.DiskStatus == FileData.FileState.Changed) { - answ.Add(cFile.Path); + // approvo il file modificato con utente anonimo (auto-Approve) + bool fatto = await FADService.FileModApprove(cFile, ""); + if (fatto) + { + answ.Add(cFile.Path); + } } } return answ; diff --git a/MP.Prog/MP.Prog.csproj b/MP.Prog/MP.Prog.csproj index fc51295a..c5bd87e0 100644 --- a/MP.Prog/MP.Prog.csproj +++ b/MP.Prog/MP.Prog.csproj @@ -3,7 +3,7 @@ net6.0 MP.Prog - 6.16.2410.2909 + 6.16.2410.2910 True diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index 564530c8..649d3801 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -134,6 +134,7 @@ namespace MP.Prog.Pages var numCheck = await FDService.UpdateMachineFilesArchive(CurrRec.IdxMacchina, FileIdList, false, false, "", false); isLoading = true; + currRecord = null; await ReloadData(); isLoading = false; } @@ -678,7 +679,7 @@ namespace MP.Prog.Pages answ += " text-bg-warning"; break; - case FileState.Deleted: + case FileState.Missing: answ += " text-bg-danger"; break; diff --git a/MP.Prog/Resources/ChangeLog.html b/MP.Prog/Resources/ChangeLog.html index 338cd6ab..b88d8894 100644 --- a/MP.Prog/Resources/ChangeLog.html +++ b/MP.Prog/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo gestione Programmi MAPO -

Versione: 6.16.2410.2909

+

Versione: 6.16.2410.2910


Note di rilascio:
    diff --git a/MP.Prog/Resources/VersNum.txt b/MP.Prog/Resources/VersNum.txt index db88b9d2..c04a835b 100644 --- a/MP.Prog/Resources/VersNum.txt +++ b/MP.Prog/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2410.2909 +6.16.2410.2910 diff --git a/MP.Prog/Resources/manifest.xml b/MP.Prog/Resources/manifest.xml index 45021f1f..f245f835 100644 --- a/MP.Prog/Resources/manifest.xml +++ b/MP.Prog/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2410.2909 + 6.16.2410.2910 https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Prog.zip https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html false