Creato classe x parametrizzare gest TAGS
This commit is contained in:
@@ -104,10 +104,32 @@ 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<string, string> confReplace = new Dictionary<string, string>();
|
||||
confReplace.Add("(", " ");
|
||||
confReplace.Add(")", " ");
|
||||
// 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,
|
||||
ExcludedTags = ".xls .xlsx",
|
||||
OutReplace = confReplace,
|
||||
OutExcludeFileName = true
|
||||
};
|
||||
|
||||
// salvo i NUOVI file
|
||||
if (fileNew != null && fileNew.Count > 0)
|
||||
{
|
||||
FileInsert(idxMacchina, fileNew, 0);
|
||||
FileInsert(idxMacchina, fileNew, 0, currRule);
|
||||
Log.Info($"CheckFileArchived S03 | insert {fileNew.Count} files");
|
||||
}
|
||||
// aggiorno i file modificati
|
||||
@@ -234,8 +256,9 @@ namespace MP.FileData.Controllers
|
||||
/// <param name="newFiles"></param>
|
||||
/// <param name="rev"></param>
|
||||
/// <returns></returns>
|
||||
public bool FileInsert(string idxMacchina, List<FileInfo> newFiles, int rev)
|
||||
public bool FileInsert(string idxMacchina, List<FileInfo> newFiles, int rev, SearchRules currRule)
|
||||
{
|
||||
// fare: lettura conf x macchina
|
||||
Log.Info($"FileInsert S01 per macchina {idxMacchina}: {newFiles.Count} files da valutare");
|
||||
bool answ = false;
|
||||
DateTime adesso = DateTime.Now;
|
||||
@@ -283,7 +306,7 @@ namespace MP.FileData.Controllers
|
||||
{
|
||||
code2search = item.FileStringContent;
|
||||
}
|
||||
Tags = TagsUtils.searchProgComment(item.Name, code2search, excludeTags);
|
||||
Tags = TagsUtils.searchProgComment(item.Name, code2search, currRule);
|
||||
|
||||
foreach (var tag in Tags)
|
||||
{
|
||||
@@ -339,8 +362,26 @@ namespace MP.FileData.Controllers
|
||||
var newFileInfo = new FileInfo(currFile.Path);
|
||||
listUpdate.Add(newFileInfo);
|
||||
|
||||
// fixme todo !!! fix da conf file
|
||||
Dictionary<string, string> confReplace = new Dictionary<string, string>();
|
||||
confReplace.Add("(", " ");
|
||||
confReplace.Add(")", " ");
|
||||
// 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,
|
||||
ExcludedTags = ".xls .xlsx",
|
||||
OutReplace = confReplace,
|
||||
OutExcludeFileName = true
|
||||
};
|
||||
|
||||
// inserisco come REVISIONE
|
||||
FileInsert(currFile.IdxMacchina, listUpdate, currFile.Rev + 1);
|
||||
FileInsert(currFile.IdxMacchina, listUpdate, currFile.Rev + 1, currRule);
|
||||
|
||||
// archivio vecchio file
|
||||
currFile.Active = false;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.FileData
|
||||
{
|
||||
public enum SearchMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Ricerca occorrenze di una RegExp dentro il contenuto del file
|
||||
/// </summary>
|
||||
StringOnFile,
|
||||
|
||||
/// <summary>
|
||||
/// Cerca da path relativo + nume file
|
||||
/// </summary>
|
||||
PathAndName
|
||||
}
|
||||
|
||||
public class SearchRules
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Pattern esclusione Tags (stop-words)
|
||||
/// </summary>
|
||||
public string ExcludedTags { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Quantità massima di caratteri da analizzare, 0 = tutti
|
||||
/// </summary>
|
||||
public int MaxChar2Search { get; set; } = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Modalità ricerca
|
||||
/// </summary>
|
||||
public SearchMode Mode { get; set; } = SearchMode.StringOnFile;
|
||||
|
||||
/// <summary>
|
||||
/// Nome della regola di ricerca
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Configurazione opzionale x rimozione filename da output finali
|
||||
/// </summary>
|
||||
public bool OutExcludeFileName { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Replace in uscita per "bonificare" il tag
|
||||
/// </summary>
|
||||
public Dictionary<string, string> OutReplace { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// Pattern in formato RegExp
|
||||
/// </summary>
|
||||
public string RegExPattern { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Configurazione opzionale x sostituzione placeholder {{fileName}} in RegExp con il VERO nome file
|
||||
/// </summary>
|
||||
public bool RegExRepFileName { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Configurazione opzionale x sostituzione carriage return --> spazi
|
||||
/// </summary>
|
||||
public bool ReplaceCR { get; set; } = true;
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -31,16 +31,27 @@ namespace MP.FileData
|
||||
/// Cerca tag di commento inseriti nel formato
|
||||
/// NOME_PROG(commento)
|
||||
///
|
||||
/// es: O00123(172L D20.5) --> estrae 172L D20.5
|
||||
/// es: O00123(172L D20.5) --> estrae 172L, D20.5
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="fileContent"></param>
|
||||
/// <param name="fileName">Nome del file (da cercare per contenuto)</param>
|
||||
/// <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, List<string> excludeTags)
|
||||
public static List<string> searchProgComment(string fileName, string fileContent, SearchRules currRule)
|
||||
{
|
||||
// verifico se trimmare contenuto file
|
||||
if (fileContent.Length > currRule.MaxChar2Search && currRule.MaxChar2Search > 0)
|
||||
{
|
||||
fileContent.Substring(0, currRule.MaxChar2Search);
|
||||
}
|
||||
// bonifico: a capo --> spazi
|
||||
fileContent = fileContent.Replace(Environment.NewLine, " ");
|
||||
string pattern = $"\\b{fileName}" + @".{0,2}\([\w\d\s.]+\)";
|
||||
//string pattern = $"\\b{fileName}" + @".{0,2}\([\w\d\s.]+\)";
|
||||
string pattern = currRule.RegExPattern;
|
||||
if (currRule.RegExRepFileName)
|
||||
{
|
||||
pattern = pattern.Replace("{{fileName}}", fileName);
|
||||
}
|
||||
List<string> answ = new List<string>();
|
||||
if (fileContent.Length > 0)
|
||||
{
|
||||
@@ -50,16 +61,34 @@ namespace MP.FileData
|
||||
{
|
||||
for (int count = 0; count < matchTags.Count; count++)
|
||||
{
|
||||
string currMatch = matchTags[count].Value;
|
||||
// bonifica preliminare (se richiesta)
|
||||
if (currRule.OutExcludeFileName)
|
||||
{
|
||||
currMatch.Replace(fileName, "");
|
||||
}
|
||||
if (currRule.OutReplace.Count > 0)
|
||||
{
|
||||
foreach (var item in currRule.OutReplace)
|
||||
{
|
||||
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();
|
||||
|
||||
// split con spazi
|
||||
var splitTags = currMatch.Split(" ");
|
||||
foreach (var item in splitTags)
|
||||
{
|
||||
if (!excludeTags.Contains(item) && !string.IsNullOrEmpty(item))
|
||||
if (!currRule.ExcludedTags.Contains(item) && !string.IsNullOrEmpty(item))
|
||||
{
|
||||
// esclusione valori ignorati
|
||||
answ.Add(item);
|
||||
@@ -69,13 +98,13 @@ namespace MP.FileData
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn($"searchProgComment Attenzione Match non trovato | {fileName} | pattern: {pattern}");
|
||||
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: {pattern}{Environment.NewLine}{fileContent}");
|
||||
Log.Warn($"searchProgComment Attenzione Tag non trovati | {fileName} | pattern: {currRule.RegExPattern}{Environment.NewLine}{fileContent}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user