diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index ac190761..97a3930e 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -244,11 +244,29 @@ namespace MP.FileData.Controllers FileContent = File.ReadAllBytes(o.FullName) }).ToList(); - // calcolo MD5 + List excludeTags = new List() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" }; + + // calcolo MD5 e tags foreach (var item in newRec) { var hash = md5.ComputeHash(item.FileContent); item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + + List Tags = new List(); + // cerco codice tag come nome file(TAG) nei primi 500 char + string code2search = ""; + if (item.FileStringContent.Length > 200) + { + code2search = item.FileStringContent.Substring(0, 200); + } + else + { + code2search = item.FileStringContent; + } + Tags = TagsUtils.searchProgComment(item.Name, code2search, excludeTags); + + //// aggiungo i tags SE non ci fossero + //item.Tags = Tags; } // aggiungo in blocco diff --git a/MP.FileData/TagsUtils.cs b/MP.FileData/TagsUtils.cs new file mode 100644 index 00000000..1c1fdbdc --- /dev/null +++ b/MP.FileData/TagsUtils.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace MP.FileData +{ + /// + /// Helper estrazione tag x programmi + /// + public class TagsUtils + { + #region Protected Fields + + protected static List ExcludeTags = new List(); + + #endregion Protected Fields + + #region Public Methods + + /// + /// Cerca tag di commento inseriti nel formato + /// NOME_PROG(commento) + /// + /// es: O00123(172L D20.5) --> estrae 172L D20.5 + /// + /// + /// + /// + public static List searchProgComment(string fileName, string fileContent, List excludeTags) + { + // bonifico: a capo --> spazi + fileContent = fileContent.Replace(Environment.NewLine, " "); + List answ = new List(); + if (fileContent.Length > 0) + { + // uso regexp + string pattern = $"\\b{fileName}" + @".{0,2}\([\w\d\s]+\)"; + MatchCollection matchTags = Regex.Matches(fileContent, pattern); + if (matchTags.Count > 0) + { + for (int count = 0; count < matchTags.Count; count++) + { + // pulizia: elimino nome programma e parentesi + string currMatch = matchTags[count].Value + .Replace(fileName, "") + .Replace("(", " ") + .Replace(")", " ").Trim(); + // split con spazi + var splitTags = currMatch.Split(" "); + foreach (var item in splitTags) + { + if (!excludeTags.Contains(item) && !string.IsNullOrEmpty(item)) + { + // esclusione valori ignorati + answ.Add(item); + } + } + } + } + } + return answ; + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index e119936d..8490d541 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -65,7 +65,7 @@
@if (currRecord != null) { - + } @if (ListRecords == null) {