Ancora fix procedura decodifica tags
This commit is contained in:
@@ -48,9 +48,10 @@ namespace MP.FileData.Controllers
|
||||
/// <param name="path">path ricerca x macchina</param>
|
||||
/// <param name="numDayPre">Numero giorni x ricerca all'indietro da data corrente / 0 = nessun limite</param>
|
||||
/// <param name="searchPattern">pattern di ricerca (*.*)</param>
|
||||
/// <param name="forceTag">Forza il controllo dei Tags</param>
|
||||
/// <param name="SearchRules">Regole di ricerca applicate</param>
|
||||
/// <returns></returns>
|
||||
public int CheckFileArchived(string idxMacchina, string path, int numDayPre, string searchPattern, SearchRules currRule)
|
||||
public int CheckFileArchived(string idxMacchina, string path, int numDayPre, string searchPattern, bool forceTag, SearchRules currRule)
|
||||
{
|
||||
Log.Info($"CheckFileArchived S00 | macchina: {idxMacchina} | path: {path} | pattern: {searchPattern} | # ExcludedFileExt: {currRule.ExcludedFileExt.Count()}");
|
||||
int checkDone = 0;
|
||||
@@ -92,7 +93,6 @@ namespace MP.FileData.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
checkDone++;
|
||||
// cerca nel DB...
|
||||
FileModel currRecord = archivedFile
|
||||
.Where(x => x.Active && x.Path == file.FullName)
|
||||
@@ -133,19 +133,22 @@ namespace MP.FileData.Controllers
|
||||
// salvo i NUOVI file
|
||||
if (fileNew != null && fileNew.Count > 0)
|
||||
{
|
||||
checkDone += fileNew.Count;
|
||||
FileInsert(idxMacchina, path, fileNew, 0, currRule);
|
||||
Log.Info($"CheckFileArchived S03 | insert {fileNew.Count} files");
|
||||
}
|
||||
// aggiorno i file modificati
|
||||
if (fileMod != null && fileMod.Count > 0)
|
||||
{
|
||||
checkDone += fileMod.Count;
|
||||
FileSetUpdated(fileMod);
|
||||
Log.Info($"CheckFileArchived S04 | update {fileMod.Count} files");
|
||||
}
|
||||
// segno data-ora ultimo controllo x file invariati
|
||||
if (fileChecked != null && fileChecked.Count > 0)
|
||||
{
|
||||
FileSetChecked(fileChecked);
|
||||
checkDone += fileChecked.Count;
|
||||
FileSetChecked(fileChecked, path, currRule, forceTag);
|
||||
Log.Info($"CheckFileArchived S05 | refreshed {fileChecked.Count} files");
|
||||
}
|
||||
|
||||
@@ -272,9 +275,11 @@ namespace MP.FileData.Controllers
|
||||
/// <summary>
|
||||
/// Effettua inserimento di un elenco di record in archivio come NUOVO documento tracciato
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="newFiles"></param>
|
||||
/// <param name="rev"></param>
|
||||
/// <param name="idxMacchina">Macchina</param>
|
||||
/// <param name="basePath">Path base macchina</param>
|
||||
/// <param name="newFiles">Elenco files</param>
|
||||
/// <param name="rev">rev da usare x creazione</param>
|
||||
/// <param name="currRule">Configuraizone ricerca</param>
|
||||
/// <returns></returns>
|
||||
public bool FileInsert(string idxMacchina, string basePath, List<FileInfo> newFiles, int rev, SearchRules currRule)
|
||||
{
|
||||
@@ -330,7 +335,7 @@ namespace MP.FileData.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
Tags = TagsUtils.searchPathName(fileName, basePath, currRule);
|
||||
Tags = TagsUtils.searchPathName(item.Path, basePath, currRule);
|
||||
}
|
||||
|
||||
foreach (var tag in Tags)
|
||||
@@ -448,23 +453,93 @@ namespace MP.FileData.Controllers
|
||||
/// <summary>
|
||||
/// Effettua update di un record in archivio da lista (SOLO STATUS)
|
||||
/// </summary>
|
||||
/// <param name="updFiles"></param>
|
||||
/// <param name="updFiles">Elenco file controllati</param>
|
||||
/// <param name="basePath">Path base macchina</param>
|
||||
/// <param name="currRule">Configuraizone ricerca</param>
|
||||
/// <param name="forceTag">Indica se fare COMUNQUE verifica del TAG</param>
|
||||
/// <returns></returns>
|
||||
public bool FileSetChecked(List<FileModel> updFiles)
|
||||
public bool FileSetChecked(List<FileModel> updFiles, string basePath, SearchRules currRule, bool forceTag)
|
||||
{
|
||||
bool answ = false;
|
||||
DateTime adesso = DateTime.Now;
|
||||
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
// SOLO SE richiesto forzatura tags
|
||||
if (forceTag)
|
||||
{
|
||||
// elenco Tags
|
||||
List<TagModel> currTags = localDbCtx.DbSetTags.ToList();
|
||||
foreach (var item in updFiles)
|
||||
{
|
||||
// rimuovo tags vecchi
|
||||
if (item.Tags != null)
|
||||
{
|
||||
item.Tags.Clear();
|
||||
localDbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
List<string> Tags = new List<string>();
|
||||
List<TagModel> Tag4File = new List<TagModel>();
|
||||
// se necessario bonifico filename...
|
||||
string fileName = item.Name;
|
||||
if (currRule.FileNameExtReplace.Count > 0)
|
||||
{
|
||||
foreach (var fReplace in currRule.FileNameExtReplace)
|
||||
{
|
||||
fileName = fileName.Replace(fReplace.Key, fReplace.Value).Trim();
|
||||
}
|
||||
}
|
||||
// cerco codice tag da configurazione
|
||||
if (currRule.Mode == SearchMode.StringOnFile)
|
||||
{
|
||||
Tags = TagsUtils.searchProgComment(fileName, item.FileStringContent, currRule);
|
||||
}
|
||||
else
|
||||
{
|
||||
Tags = TagsUtils.searchPathName(item.Path, basePath, currRule);
|
||||
}
|
||||
|
||||
foreach (var tag in Tags)
|
||||
{
|
||||
var foundTag = currTags.SingleOrDefault(x => x.TagId == tag);
|
||||
// aggiungo i tags SE non ci fossero
|
||||
if (foundTag == null)
|
||||
{
|
||||
var newTag = new TagModel() { TagId = tag };
|
||||
currTags.Add(newTag);
|
||||
Tag4File.Add(newTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
// al file aggiungo comunque
|
||||
Tag4File.Add(foundTag);
|
||||
}
|
||||
}
|
||||
// aggiungo ai file
|
||||
if (Tag4File.Count > 0)
|
||||
{
|
||||
// salvo i tags relativi ai files
|
||||
item.Tags = Tag4File;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
// salvo
|
||||
localDbCtx.SaveChanges();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in salvataggio FileSetChecked{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
// update comunque data-ora
|
||||
foreach (var item in updFiles)
|
||||
{
|
||||
// salvo update file
|
||||
item.LastCheck = adesso;
|
||||
localDbCtx.Entry(item).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
// salvo
|
||||
localDbCtx.SaveChanges();
|
||||
answ = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user