Ok x importare maggioranza tags
This commit is contained in:
@@ -37,9 +37,14 @@ namespace MP.FileData.Controllers
|
||||
/// <summary>
|
||||
/// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck e Changed (se cambiati)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina">cod macchina</param>
|
||||
/// <param name="path">path ricerca x macchina</param>
|
||||
/// <param name="searchPattern">pattern di ricerca (*.*)</param>
|
||||
/// <param name="excludePattern">pattern esclusione (separato da spazi</param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
/// <returns></returns>
|
||||
public bool FileInsert(string idxMacchina, List<FileInfo> 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<string> excludeTags = new List<string>() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" };
|
||||
var currTags = TagGetAll();
|
||||
List<TagModel> 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<string> Tags = new List<string>();
|
||||
List<TagModel> Tag2ins = new List<TagModel>();
|
||||
List<TagModel> Tag4File = new List<TagModel>();
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user