diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index c1286693..2f0baaa7 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -43,12 +43,13 @@ namespace MP.FileData.Controllers /// pattern di ricerca (*.*) /// pattern esclusione (separato da spazi /// - public bool CheckFileArchived(string idxMacchina, string path, string searchPattern, string excludePattern) + public bool CheckFileArchived(string idxMacchina, string path, string searchPattern, SearchRules currRule) { - Log.Info($"CheckFileArchived S01 | macchina: {idxMacchina} | path: {path} | pattern: {searchPattern} | excludePattern: {excludePattern}"); + Log.Info($"CheckFileArchived S00 | macchina: {idxMacchina} | path: {path} | pattern: {searchPattern} | # ExcludedFileExt: {currRule.ExcludedFileExt.Count()}"); bool answ = false; DirectoryInfo dirInfo = new DirectoryInfo(path); FileInfo[] fileList = dirInfo.GetFiles(searchPattern); + Log.Info($"CheckFileArchived S01 | file trovati: {fileList.Count()}"); List fileNew = new List(); List fileChecked = new List(); List fileMod = new List(); @@ -62,7 +63,7 @@ namespace MP.FileData.Controllers foreach (var file in fileList) { // escludo i file con desinenza da escludere... - if (excludePattern.Contains(file.Extension) && !string.IsNullOrEmpty(file.Extension)) + if (!string.IsNullOrEmpty(file.Extension) && currRule.ExcludedFileExt.Contains(file.Extension)) { Log.Info($"CheckFileArchived S02: escluso {file.Name} | estensione {file.Extension}"); } @@ -105,37 +106,6 @@ namespace MP.FileData.Controllers } } - // fixme todo !!! fix da conf file - - // fare: lettura conf rule x recupero tag x singola macchina - //$"\\b{fileName}" + @".{0,2}\([\w\d\s.]+\)"; - - Dictionary confReplace = new Dictionary(); - confReplace.Add("(", " "); - confReplace.Add(")", " "); - - Dictionary fileExtReplace = new Dictionary(); - fileExtReplace.Add(".P-2", ""); - // hard coded + salvataggio conf x creare json - SearchRules currRule = new SearchRules() - { - Name = "Commento Filename", - Mode = SearchMode.StringOnFile, - MaxChar2Search = 100, - ReplaceCR = true, - RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s./]+\)", - RegExRepFileName = true, - FileNameExtReplace = fileExtReplace, - ExcludedTags = new List() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" }, - OutReplace = confReplace, - OutExcludeFileName = true - }; - - // serializzo - - string rawRule = JsonConvert.SerializeObject(currRule, Formatting.Indented); - Log.Info($"Conf rule:{Environment.NewLine}{rawRule}"); - // salvo i NUOVI file if (fileNew != null && fileNew.Count > 0) { @@ -294,7 +264,8 @@ namespace MP.FileData.Controllers }).ToList(); // gestione Tags (da migliorare...) - List currTags = TagGetAll(); + List currTags = localDbCtx.DbSetTags.ToList(); + //List currTags = TagGetAll(); // calcolo MD5 e tags foreach (var item in newRec) @@ -318,7 +289,7 @@ namespace MP.FileData.Controllers foreach (var tag in Tags) { - var foundTag = currTags.Where(x => x.TagId == tag).FirstOrDefault(); + var foundTag = currTags.SingleOrDefault(x => x.TagId == tag); // aggiungo i tags SE non ci fossero if (foundTag == null) { @@ -340,9 +311,9 @@ namespace MP.FileData.Controllers } } - localDbCtx - .DbSetTags - .AddRange(currTags); + //localDbCtx + //.DbSetTags + //.AddRange(newTags); // aggiungo in blocco localDbCtx diff --git a/MP.FileData/SearchRules.cs b/MP.FileData/SearchRules.cs index 2a1580e7..d928d5a2 100644 --- a/MP.FileData/SearchRules.cs +++ b/MP.FileData/SearchRules.cs @@ -23,6 +23,11 @@ namespace MP.FileData { #region Public Properties + /// + /// Estensioni file esclusi + /// + public List ExcludedFileExt { get; set; } = new List(); + /// /// Pattern esclusione Tags (stop-words) /// @@ -46,7 +51,7 @@ namespace MP.FileData /// /// Nome della regola di ricerca /// - public string Name { get; set; } + public string Name { get; set; } = "ND"; /// /// Configurazione opzionale x rimozione filename da output finali diff --git a/MP.FileData/TagsUtils.cs b/MP.FileData/TagsUtils.cs index 1023812b..15dfb70c 100644 --- a/MP.FileData/TagsUtils.cs +++ b/MP.FileData/TagsUtils.cs @@ -45,7 +45,7 @@ namespace MP.FileData fileContent = fileContent.Substring(0, currRule.MaxChar2Search); } // bonifico: a capo --> spazi - fileContent = fileContent.Replace(Environment.NewLine, " "); + fileContent = fileContent.Replace(Environment.NewLine, " ").ToUpper(); //string pattern = $"\\b{fileName}" + @".{0,2}\([\w\d\s.]+\)"; string pattern = currRule.RegExPattern; if (currRule.RegExRepFileName) diff --git a/MP.Prog/Conf/Rule01.json b/MP.Prog/Conf/Rule01.json index 4771d118..1ee93dff 100644 --- a/MP.Prog/Conf/Rule01.json +++ b/MP.Prog/Conf/Rule01.json @@ -7,18 +7,23 @@ "M5+A", "M5+B" ], + "ExcludedFileExt": [ + ".xls", + ".xls#", + ".xlsx" + ], "FileNameExtReplace": { ".P-2": "" }, "MaxChar2Search": 100, "Mode": 0, - "Name": "Commento Filename", + "Name": "Tag da Commento Filename", "OutExcludeFileName": true, "OutReplace": { "(": " ", ")": " " }, - "RegExPattern": "\\b{{fileName}}.{0,2}\\([\\w\\d\\s./]+\\)", + "RegExPattern": "\\b{{fileName}}.{0,2}\\([\\w\\d\\s./\\-=]+\\)", "RegExRepFileName": true, "ReplaceCR": true } \ No newline at end of file diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index 7f04f4e8..7d53343c 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -2,9 +2,12 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using MP.FileData; +using Newtonsoft.Json; using NLog; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -100,6 +103,15 @@ namespace MP.Prog.Data #endregion Private Properties + #region Protected Methods + + protected string rulePath(string ruleName) + { + return string.Format($"Conf/{ruleName}"); + } + + #endregion Protected Methods + #region Internal Methods internal Task FileApprove(FileData.DatabaseModels.FileModel currItem) @@ -250,17 +262,66 @@ namespace MP.Prog.Data /// public async Task updateAllArchive() { + string ruleName = "Rule01.json"; try { var listaMacchine = await MacchineGetAll(); foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList()) { - dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, "*.*", ".xlsx .xls"); + if (!string.IsNullOrEmpty(item.RuleName)) + { } + // gestione confRule... + SearchRules currRule = new SearchRules(); + try + { + string rawData = File.ReadAllText(rulePath(ruleName)); + currRule = JsonConvert.DeserializeObject(rawData); + Log.Info($"Conf rule acquisito da file {ruleName}:{Environment.NewLine}{rawData}"); + } + catch (Exception exc) + { + Log.Error($"Eccezione in deserializzazione conf rule{Environment.NewLine}{exc}"); + } + + // se NON deserializzato inizializzo hard-coded + if (currRule.Name == "ND") + { + // fare: lettura conf rule x recupero tag x singola macchina + //$"\\b{fileName}" + @".{0,2}\([\w\d\s.]+\)"; + + Dictionary confReplace = new Dictionary(); + confReplace.Add("(", " "); + confReplace.Add(")", " "); + + Dictionary fileExtReplace = new Dictionary(); + fileExtReplace.Add(".P-2", ""); + // hard coded + salvataggio conf x creare json + currRule = new SearchRules() + { + Name = "Commento Filename", + Mode = SearchMode.StringOnFile, + MaxChar2Search = 100, + ReplaceCR = true, + RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s./]+\)", + RegExRepFileName = true, + FileNameExtReplace = fileExtReplace, + ExcludedTags = new List() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" }, + OutReplace = confReplace, + OutExcludeFileName = true + }; + + // serializzo + + string rawRule = JsonConvert.SerializeObject(currRule, Formatting.Indented); + Log.Info($"Conf rule generato:{Environment.NewLine}{rawRule}"); + } + + dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, "*.*", currRule); } } catch (Exception exc) { - Log.Error($"Eccezione in updateAllArchive{Environment.NewLine}{exc}"); + Log.Error($"Eccezione in updateAllArchive{Environment.NewLine}{exc}{Environment.NewLine}{exc.InnerException}"); } } diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index 590a6d4c..cd593b00 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -132,7 +132,7 @@ -
@record.Macchina.RuleName
+
@record.Macchina.Nome
@record.Macchina.Descrizione