- correzione tag extraction
- correzione indentazione json
This commit is contained in:
Samuele Locatelli
2024-10-21 20:09:28 +02:00
parent 3623e0059f
commit 9fad86eb17
16 changed files with 137 additions and 98 deletions
+26 -12
View File
@@ -138,13 +138,27 @@ namespace MP.FileData.Controllers
{
fileList = fileListRaw.ToList();
}
Log.Trace($"CheckFileArchived S01 | file trovati: {fileList.Count()}");
Log.Debug($"CheckFileArchived S01 | file trovati: {fileList.Count()}");
List<FileInfo> fileNew = new List<FileInfo>();
List<FileModel> fileChecked = new List<FileModel>();
List<FileModel> fileMod = new List<FileModel>();
// recupera elenco file nel DB
var archivedFile = FileGetByPath(path, true);
List<FileModel> archivedFile = new List<FileModel>();
List<FileModel> foundFile = FileGetByPath(path, true);
// rimuovo eventuali file con estensioni escluse...
foreach (var fRec in foundFile)
{
if (!string.IsNullOrEmpty(fRec.Extension) && currRule.ExcludedFileExt.Contains(fRec.Extension))
{
Log.Trace($"CheckFileArchived S01.B: escluso {fRec.Name} | estensione {fRec.Extension}");
}
else
{
archivedFile.Add(fRec);
}
}
Log.Debug($"CheckFileArchived S01.C | Recuperati {archivedFile.Count()} da DB per confronto");
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
// verifica i file
@@ -159,9 +173,9 @@ namespace MP.FileData.Controllers
{
// cerca nel DB...
FileModel currRecord = archivedFile
.Where(x => x.Active && x.Path == file.FullName)
.OrderByDescending(y => y.Rev)
.FirstOrDefault();
.Where(x => x.Active && x.Path == file.FullName)
.OrderByDescending(y => y.Rev)
.FirstOrDefault();
// se NON trova lo crea
if (currRecord == null)
{
@@ -389,7 +403,7 @@ namespace MP.FileData.Controllers
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
// converto
List<DatabaseModels.FileModel> newRec = newFiles.Select(o => new DatabaseModels.FileModel()
List<FileModel> newRec = newFiles.Select(o => new FileModel()
{
Active = true,
DiskStatus = FileState.Ok,
@@ -427,15 +441,15 @@ namespace MP.FileData.Controllers
// cerco codice tag da configurazione
if (currRule.Mode == SearchMode.StringOnFile)
{
Tags = TagsUtils.searchProgComment(fileName, item.FileStringContent, currRule);
Tags = TagsUtils.SearchProgComment(fileName, item.FileStringContent, currRule);
}
else if (currRule.Mode == SearchMode.TagListed)
{
Tags = TagsUtils.searchTagListed(fileName, item.FileStringContent, currRule);
Tags = TagsUtils.SearchTagListed(fileName, item.FileStringContent, currRule);
}
else
{
Tags = TagsUtils.searchPathName(item.Path, basePath, currRule);
Tags = TagsUtils.SearchPathName(item.Path, basePath, currRule);
}
foreach (var tag in Tags)
@@ -594,15 +608,15 @@ namespace MP.FileData.Controllers
// cerco codice tag da configurazione
if (currRule.Mode == SearchMode.StringOnFile)
{
Tags = TagsUtils.searchProgComment(fileName, item.FileStringContent, currRule);
Tags = TagsUtils.SearchProgComment(fileName, item.FileStringContent, currRule);
}
else if (currRule.Mode == SearchMode.TagListed)
{
Tags = TagsUtils.searchTagListed(fileName, item.FileStringContent, currRule);
Tags = TagsUtils.SearchTagListed(fileName, item.FileStringContent, currRule);
}
else
{
Tags = TagsUtils.searchPathName(item.Path, basePath, currRule);
Tags = TagsUtils.SearchPathName(item.Path, basePath, currRule);
}
foreach (var tag in Tags)
+16 -1
View File
@@ -48,7 +48,22 @@ namespace MP.FileData.DatabaseModels
set
{
// serializzo a byte
FileContent = Encoding.ASCII.GetBytes(value);
//FileContent = Encoding.ASCII.GetBytes(value);
FileContent = Encoding.UTF8.GetBytes(value);
}
}
[NotMapped]
public string Extension
{
get
{
string answ = "";
if(!string.IsNullOrEmpty(Name))
{
int sPos = Name.LastIndexOf('.');
answ = Name.Substring(sPos);
}
return answ;
}
}
+7 -8
View File
@@ -36,7 +36,7 @@ namespace MP.FileData
/// <param name="filePath">Nome del file (path completo)</param>
/// <param name="currRule">Parametri analisi</param>
/// <returns></returns>
public static List<string> searchPathName(string filePath, string basePath, SearchRules currRule)
public static List<string> SearchPathName(string filePath, string basePath, SearchRules currRule)
{
List<string> answ = new List<string>();
string fileName = Path.GetFileName(filePath);
@@ -74,7 +74,7 @@ namespace MP.FileData
// se nullo --> segnalo!
if (answ.Count == 0)
{
Log.Warn($"searchPathName Attenzione Tag non trovati | {filePath} | basePath: {basePath}");
Log.Warn($"SearchPathName Attenzione Tag non trovati | {filePath} | basePath: {basePath}");
}
return answ;
}
@@ -89,7 +89,7 @@ namespace MP.FileData
/// <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, SearchRules currRule)
public static List<string> SearchProgComment(string fileName, string fileContent, SearchRules currRule)
{
// verifico se trimmare contenuto file
if (fileContent.Length > currRule.MaxChar2Search && currRule.MaxChar2Search > 0)
@@ -148,7 +148,7 @@ namespace MP.FileData
// se nullo --> segnalo!
if (answ.Count == 0)
{
Log.Warn($"searchProgComment Attenzione Tag non trovati | {fileName} | pattern: {pattern}");
Log.Warn($"SearchProgComment Attenzione Tag non trovati | {fileName} | pattern: {pattern}");
//Log.Trace($"{fileName}:{Environment.NewLine}{fileContent}");
}
return answ;
@@ -164,7 +164,7 @@ namespace MP.FileData
/// <param name="fileContent">Contenuto del file da analizzare</param>
/// <param name="currRule">Parametri analisi</param>
/// <returns></returns>
public static List<string> searchTagListed(string fileName, string fileContent, SearchRules currRule)
public static List<string> SearchTagListed(string fileName, string fileContent, SearchRules currRule)
{
// verifico se trimmare contenuto file
if (fileContent.Length > currRule.MaxChar2Search && currRule.MaxChar2Search > 0)
@@ -183,7 +183,7 @@ namespace MP.FileData
{
foreach (var row in fileRows)
{
if (row.StartsWith(tag2check))
if (row.StartsWith(tag2check) || row.Contains(tag2check))
{
answ.Add(row.Trim());
break;
@@ -195,8 +195,7 @@ namespace MP.FileData
// se nullo --> segnalo!
if (answ.Count == 0)
{
Log.Warn($"searchTagListed Attenzione Tag non trovati | {fileName} | tags cercati: {currRule.Tag2Collect.Count}");
//Log.Trace($"{Environment.NewLine}{fileContent}");
Log.Warn($"SearchTagListed Attenzione Tag non trovati | {fileName} | tags cercati: {currRule.Tag2Collect.Count}");
}
return answ;
}