diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index d6a78f6c..c1286693 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using MP.FileData.DatabaseModels; +using Newtonsoft.Json; namespace MP.FileData.Controllers { @@ -112,6 +113,9 @@ namespace MP.FileData.Controllers 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() { @@ -119,13 +123,19 @@ namespace MP.FileData.Controllers Mode = SearchMode.StringOnFile, MaxChar2Search = 100, ReplaceCR = true, - RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s.]+\)", + RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s./]+\)", RegExRepFileName = true, - ExcludedTags = ".xls .xlsx", + 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) { @@ -284,7 +294,6 @@ namespace MP.FileData.Controllers }).ToList(); // gestione Tags (da migliorare...) - List excludeTags = new List() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" }; List currTags = TagGetAll(); // calcolo MD5 e tags @@ -295,18 +304,17 @@ namespace MP.FileData.Controllers List Tags = new List(); List Tag4File = new List(); - // cerco codice tag come nome file(TAG) nei primi 100 char - int maxChar = 100; - string code2search = ""; - if (item.FileStringContent.Length > maxChar) + // se necessario bonifico filename... + string fileName = item.Name; + if (currRule.FileNameExtReplace.Count > 0) { - code2search = item.FileStringContent.Substring(0, maxChar); + foreach (var fReplace in currRule.FileNameExtReplace) + { + fileName = fileName.Replace(fReplace.Key, fReplace.Value).Trim(); + } } - else - { - code2search = item.FileStringContent; - } - Tags = TagsUtils.searchProgComment(item.Name, code2search, currRule); + // cerco codice tag da configurazione + Tags = TagsUtils.searchProgComment(fileName, item.FileStringContent, currRule); foreach (var tag in Tags) { @@ -366,6 +374,10 @@ namespace MP.FileData.Controllers 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() { @@ -375,7 +387,8 @@ namespace MP.FileData.Controllers ReplaceCR = true, RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s.]+\)", RegExRepFileName = true, - ExcludedTags = ".xls .xlsx", + ExcludedTags = new List() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" }, + FileNameExtReplace = fileExtReplace, OutReplace = confReplace, OutExcludeFileName = true }; diff --git a/MP.FileData/ModelBuilderExtensions.cs b/MP.FileData/ModelBuilderExtensions.cs index b3415b80..354ccc88 100644 --- a/MP.FileData/ModelBuilderExtensions.cs +++ b/MP.FileData/ModelBuilderExtensions.cs @@ -20,7 +20,7 @@ namespace MP.FileData { // inizializzazione dei valori di default x MACCHINA modelBuilder.Entity().HasData( - new MacchinaModel { IdxMacchina = "0", CodMacchina = "0", Descrizione = "--- Tutte ---", Nome = "--- Tutte ---", BasePath = "", ImgUrl = "", Note = "", ShowOrder = 0 } + new MacchinaModel { IdxMacchina = "0", RuleName = "0", Descrizione = "--- Tutte ---", Nome = "--- Tutte ---", BasePath = "", ImgUrl = "", Note = "", ShowOrder = 0 } ); } diff --git a/MP.FileData/SearchRules.cs b/MP.FileData/SearchRules.cs index 41b7af27..2a1580e7 100644 --- a/MP.FileData/SearchRules.cs +++ b/MP.FileData/SearchRules.cs @@ -26,7 +26,12 @@ namespace MP.FileData /// /// Pattern esclusione Tags (stop-words) /// - public string ExcludedTags { get; set; } = ""; + public List ExcludedTags { get; set; } = new List(); + + /// + /// Pattern in formato RegExp + /// + public Dictionary FileNameExtReplace { get; set; } = new Dictionary(); /// /// Quantità massima di caratteri da analizzare, 0 = tutti diff --git a/MP.FileData/TagsUtils.cs b/MP.FileData/TagsUtils.cs index 54147e2e..1023812b 100644 --- a/MP.FileData/TagsUtils.cs +++ b/MP.FileData/TagsUtils.cs @@ -42,7 +42,7 @@ namespace MP.FileData // verifico se trimmare contenuto file if (fileContent.Length > currRule.MaxChar2Search && currRule.MaxChar2Search > 0) { - fileContent.Substring(0, currRule.MaxChar2Search); + fileContent = fileContent.Substring(0, currRule.MaxChar2Search); } // bonifico: a capo --> spazi fileContent = fileContent.Replace(Environment.NewLine, " "); @@ -65,7 +65,7 @@ namespace MP.FileData // bonifica preliminare (se richiesta) if (currRule.OutExcludeFileName) { - currMatch.Replace(fileName, ""); + currMatch = currMatch.Replace(fileName, ""); } if (currRule.OutReplace.Count > 0) { @@ -74,13 +74,6 @@ namespace MP.FileData currMatch = currMatch.Replace(item.Key, item.Value); } } -#if false - // pulizia: elimino nome programma e parentesi - string currMatch = matchTags[count].Value - .Replace(fileName, "") - .Replace("(", " ") - .Replace(")", " ").Trim(); -#endif // trim finale currMatch = currMatch.Trim(); @@ -88,23 +81,22 @@ namespace MP.FileData var splitTags = currMatch.Split(" "); foreach (var item in splitTags) { - if (!currRule.ExcludedTags.Contains(item) && !string.IsNullOrEmpty(item)) + if (!string.IsNullOrEmpty(item)) { - // esclusione valori ignorati - answ.Add(item); + if (!currRule.ExcludedTags.Contains(item) && item != fileName) + { + // esclusione valori ignorati + answ.Add(item); + } } } } } - else - { - Log.Warn($"searchProgComment Attenzione Match non trovato | {fileName} | pattern: {currRule.RegExPattern}"); - } } // se nullo --> segnalo! if (answ.Count == 0) { - Log.Warn($"searchProgComment Attenzione Tag non trovati | {fileName} | pattern: {currRule.RegExPattern}{Environment.NewLine}{fileContent}"); + Log.Warn($"searchProgComment Attenzione Tag non trovati | {fileName} | pattern: {pattern}{Environment.NewLine}{fileContent}"); } return answ; } diff --git a/MP.Prog/Conf/Rule01.json b/MP.Prog/Conf/Rule01.json index 5f282702..4771d118 100644 --- a/MP.Prog/Conf/Rule01.json +++ b/MP.Prog/Conf/Rule01.json @@ -1 +1,24 @@ - \ No newline at end of file +{ + "ExcludedTags": [ + "M4", + "M5", + "M4+A", + "M4+B", + "M5+A", + "M5+B" + ], + "FileNameExtReplace": { + ".P-2": "" + }, + "MaxChar2Search": 100, + "Mode": 0, + "Name": "Commento Filename", + "OutExcludeFileName": true, + "OutReplace": { + "(": " ", + ")": " " + }, + "RegExPattern": "\\b{{fileName}}.{0,2}\\([\\w\\d\\s./]+\\)", + "RegExRepFileName": true, + "ReplaceCR": true +} \ No newline at end of file diff --git a/MP.Prog/MP.Prog.csproj b/MP.Prog/MP.Prog.csproj index 6dcb148c..fc16b061 100644 --- a/MP.Prog/MP.Prog.csproj +++ b/MP.Prog/MP.Prog.csproj @@ -21,6 +21,7 @@ + diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index 8490d541..590a6d4c 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -47,7 +47,7 @@ { foreach (var item in MacList) { - + } } @@ -132,7 +132,7 @@ -
@record.Macchina.CodMacchina
+
@record.Macchina.RuleName
@record.Macchina.Descrizione