diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs
index f008f7ee..4242dd44 100644
--- a/MP.FileData/Controllers/FileController.cs
+++ b/MP.FileData/Controllers/FileController.cs
@@ -37,9 +37,14 @@ namespace MP.FileData.Controllers
///
/// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck e Changed (se cambiati)
///
+ /// cod macchina
+ /// path ricerca x macchina
+ /// pattern di ricerca (*.*)
+ /// pattern esclusione (separato da spazi
///
- public bool CheckFileArchived(string idxMacchina, string path, string searchPattern)
+ public bool CheckFileArchived(string idxMacchina, string path, string searchPattern, string excludePattern)
{
+ Log.Info($"CheckFileArchived S01 | macchina: {idxMacchina} | path: {path} | pattern: {searchPattern} | excludePattern: {excludePattern}");
bool answ = false;
DirectoryInfo dirInfo = new DirectoryInfo(path);
FileInfo[] fileList = dirInfo.GetFiles(searchPattern);
@@ -55,38 +60,46 @@ namespace MP.FileData.Controllers
// verifica i file
foreach (var file in fileList)
{
- // cerca nel DB...
- FileModel currRecord = archivedFile
- .Where(x => x.Active && x.Path == file.FullName)
- .OrderByDescending(y => y.Rev)
- .FirstOrDefault();
- // se NON trova lo crea
- if (currRecord == null)
+ // escludo i file con desinenza da escludere...
+ if (excludePattern.Contains(file.Extension) && !string.IsNullOrEmpty(file.Extension))
{
- fileNew.Add(file);
+ Log.Info($"CheckFileArchived S02: escluso {file.Name} | estensione {file.Extension}");
}
else
{
- // verifico se data modifica sia cambiata...
- if (currRecord.LastMod != file.LastWriteTime)
+ // cerca nel DB...
+ FileModel currRecord = archivedFile
+ .Where(x => x.Active && x.Path == file.FullName)
+ .OrderByDescending(y => y.Rev)
+ .FirstOrDefault();
+ // se NON trova lo crea
+ if (currRecord == null)
{
- // calcolo e verifico MD5
- var fileContent = File.ReadAllBytes(file.FullName);
- var hash = md5.ComputeHash(fileContent);
- var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
- if (newMD5 != currRecord.MD5)
+ fileNew.Add(file);
+ }
+ else
+ {
+ // verifico se data modifica sia cambiata...
+ if (currRecord.LastMod != file.LastWriteTime)
{
- fileMod.Add(currRecord);
+ // calcolo e verifico MD5
+ var fileContent = File.ReadAllBytes(file.FullName);
+ var hash = md5.ComputeHash(fileContent);
+ var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
+ if (newMD5 != currRecord.MD5)
+ {
+ fileMod.Add(currRecord);
+ }
+ else
+ {
+ fileChecked.Add(currRecord);
+ }
}
else
{
fileChecked.Add(currRecord);
}
}
- else
- {
- fileChecked.Add(currRecord);
- }
}
}
}
@@ -95,11 +108,13 @@ namespace MP.FileData.Controllers
if (fileNew != null && fileNew.Count > 0)
{
FileInsert(idxMacchina, fileNew, 0);
+ Log.Info($"CheckFileArchived S03 | insert {fileNew.Count} files");
}
// aggiorno i file modificati
if (fileMod != null && fileMod.Count > 0)
{
FileSetUpdated(fileMod);
+ Log.Info($"CheckFileArchived S04 | update {fileMod.Count} files");
}
// segno data-ora ultimo controllo x file invariati
if (fileChecked != null && fileChecked.Count > 0)
@@ -221,6 +236,7 @@ namespace MP.FileData.Controllers
///
public bool FileInsert(string idxMacchina, List newFiles, int rev)
{
+ Log.Info($"FileInsert S01 per macchina {idxMacchina}: {newFiles.Count} files da valutare");
bool answ = false;
DateTime adesso = DateTime.Now;
// MD5 hash
@@ -246,7 +262,7 @@ namespace MP.FileData.Controllers
// gestione Tags (da migliorare...)
List excludeTags = new List() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" };
- var currTags = TagGetAll();
+ List currTags = TagGetAll();
// calcolo MD5 e tags
foreach (var item in newRec)
@@ -255,7 +271,7 @@ namespace MP.FileData.Controllers
item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
List Tags = new List();
- List Tag2ins = new List();
+ List Tag4File = new List();
// cerco codice tag come nome file(TAG) nei primi 100 char
int maxChar = 100;
string code2search = "";
@@ -271,31 +287,45 @@ namespace MP.FileData.Controllers
foreach (var tag in Tags)
{
- var foundTag = currTags.Where(x => x.TagId == tag).ToList();
+ var foundTag = currTags.Where(x => x.TagId == tag).FirstOrDefault();
// aggiungo i tags SE non ci fossero
- if (foundTag.Count == 0)
+ if (foundTag == null)
{
- Tag2ins.Add(new TagModel() { TagId = tag });
+ var newTag = new TagModel() { TagId = tag };
+ currTags.Add(newTag);
+ Tag4File.Add(newTag);
+ }
+ else
+ {
+ // al file aggiungo comunque
+ Tag4File.Add(foundTag);
}
}
-
- // salvo i tags
- TagInsert(Tag2ins);
-
- // salvo i tags relativi ai files
- item.Tags = Tag2ins;
+ // aggiungo ai file
+ if (Tag4File.Count > 0)
+ {
+ // salvo i tags relativi ai files
+ item.Tags = Tag4File;
+ }
}
+ localDbCtx
+ .DbSetTags
+ .AddRange(currTags);
+
// aggiungo in blocco
localDbCtx
.DbSetProgFile
.AddRange(newRec);
+ Log.Info($"FileInsert S02 per macchina {idxMacchina}: {newRec.Count} files da aggiungere EFCore");
+
// salvo
localDbCtx.SaveChanges();
answ = true;
}
}
+ Log.Info($"FileInsert S03 per macchina {idxMacchina}");
return answ;
}
diff --git a/MP.FileData/TagsUtils.cs b/MP.FileData/TagsUtils.cs
index 1c1fdbdc..07f31807 100644
--- a/MP.FileData/TagsUtils.cs
+++ b/MP.FileData/TagsUtils.cs
@@ -1,4 +1,5 @@
-using System;
+using NLog;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -12,6 +13,12 @@ namespace MP.FileData
///
public class TagsUtils
{
+ #region Private Fields
+
+ private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
+
+ #endregion Private Fields
+
#region Protected Fields
protected static List ExcludeTags = new List();
@@ -33,11 +40,11 @@ namespace MP.FileData
{
// bonifico: a capo --> spazi
fileContent = fileContent.Replace(Environment.NewLine, " ");
+ string pattern = $"\\b{fileName}" + @".{0,2}\([\w\d\s.]+\)";
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)
{
@@ -60,6 +67,15 @@ namespace MP.FileData
}
}
}
+ else
+ {
+ Log.Warn($"searchProgComment Attenzione Match non trovato | {fileName} | pattern: {pattern}");
+ }
+ }
+ // se nullo --> segnalo!
+ if (answ.Count == 0)
+ {
+ Log.Warn($"searchProgComment Attenzione Tag non trovati | {fileName} | pattern: {pattern}{Environment.NewLine}{fileContent}");
}
return answ;
}
diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs
index d8ea5784..7f04f4e8 100644
--- a/MP.Prog/Data/FileArchDataService.cs
+++ b/MP.Prog/Data/FileArchDataService.cs
@@ -242,7 +242,6 @@ namespace MP.Prog.Data
public Task> TagGetFilt(string SearchVal)
{
return Task.FromResult(dbController.TagGetFilt(SearchVal, 200).ToList());
- //return Task.FromResult(dbController.ArtGetFilt(SearchVal, 20).ToList());
}
///
@@ -256,11 +255,13 @@ namespace MP.Prog.Data
var listaMacchine = await MacchineGetAll();
foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList())
{
- dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, "*.*");
+ dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, "*.*", ".xlsx .xls");
}
}
- catch
- { }
+ catch (Exception exc)
+ {
+ Log.Error($"Eccezione in updateAllArchive{Environment.NewLine}{exc}");
+ }
}
#endregion Public Methods