Continuo fix gest approvazione
This commit is contained in:
@@ -144,6 +144,7 @@ namespace MP.FileData.Controllers
|
||||
List<FileInfo> fileNew = new List<FileInfo>();
|
||||
List<FileModel> fileChecked = new List<FileModel>();
|
||||
List<FileModel> fileMod = new List<FileModel>();
|
||||
List<FileModel> fileDel = new List<FileModel>();
|
||||
|
||||
// recupera elenco file nel DB
|
||||
List<FileModel> archivedFile = new List<FileModel>();
|
||||
@@ -163,7 +164,7 @@ namespace MP.FileData.Controllers
|
||||
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
|
||||
// verifica i file partendo dal filesystem
|
||||
foreach (var file in fileList)
|
||||
{
|
||||
// escludo i file con desinenza da escludere...
|
||||
@@ -208,6 +209,28 @@ namespace MP.FileData.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ora parto dal DB ed escludo quelli già mappati...
|
||||
foreach (var fileDb in archivedFile)
|
||||
{
|
||||
// escludo i file con desinenza da escludere...
|
||||
if (!string.IsNullOrEmpty(fileDb.Extension) && currRule.ExcludedFileExt.Contains(fileDb.Extension))
|
||||
{
|
||||
Log.Trace($"CheckFileArchived S02: escluso {fileDb.Name} | estensione {fileDb.Extension}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// cerca nel filesystem...
|
||||
var currRecord = fileList
|
||||
.Where(x => fileDb.Path == x.FullName)
|
||||
.FirstOrDefault();
|
||||
// se NON trova lo crea
|
||||
if (currRecord == null)
|
||||
{
|
||||
fileDel.Add(fileDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// salvo i NUOVI file
|
||||
@@ -231,6 +254,13 @@ namespace MP.FileData.Controllers
|
||||
FileSetChecked(fileChecked, path, currRule, forceTag);
|
||||
Log.Trace($"CheckFileArchived S05 | refreshed {fileChecked.Count} files");
|
||||
}
|
||||
// indico infine i file modificati
|
||||
if (fileDel != null && fileDel.Count > 0)
|
||||
{
|
||||
checkDone += fileDel.Count;
|
||||
FileSetMissing(fileDel, path, currRule, false);
|
||||
Log.Trace($"FileArchivedMissing S06 | missing {fileDel.Count} files");
|
||||
}
|
||||
|
||||
Log.Info($"Effettuati {checkDone} controlli");
|
||||
// svuoto
|
||||
@@ -242,6 +272,145 @@ namespace MP.FileData.Controllers
|
||||
return checkDone;
|
||||
}
|
||||
|
||||
/// <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="FileList">Elenco dei files (su DB) da verificare</param>
|
||||
/// <param name="path">path ricerca x macchina</param>
|
||||
/// <param name="searchPattern">pattern di ricerca (*.*)</param>
|
||||
/// <param name="forceTag">Forza il controllo dei Tags</param>
|
||||
/// <param name="currRule">Regole di ricerca applicate</param>
|
||||
/// <param name="UserName">Utente connesso x approvazione</param>
|
||||
/// <param name="DoApprove">indica se vada approvata la modifica o lasciato "in sospeso"</param>
|
||||
/// <returns></returns>
|
||||
public int CheckFileListArchived(string idxMacchina, List<FileModel> FileList, string path, string searchPattern, bool forceTag, SearchRules currRule, string UserName, bool DoApprove)
|
||||
{
|
||||
Log.Info($"CheckFileListArchived S00 | macchina: {idxMacchina} | path: {path} | pattern: {searchPattern} | # ExcludedFileExt: {currRule.ExcludedFileExt.Count()}");
|
||||
int checkDone = 0;
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
FileInfo[] fileListRaw = null;
|
||||
if (FileList.Count == 1)
|
||||
{
|
||||
// leggo il singolo... imposto il search pattern...
|
||||
searchPattern = $"{FileList.FirstOrDefault().Name}";
|
||||
fileListRaw = dirInfo.GetFiles(searchPattern, SearchOption.AllDirectories);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
fileListRaw = dirInfo.GetFiles(searchPattern, SearchOption.AllDirectories);
|
||||
}
|
||||
List<FileInfo> fileList = new List<FileInfo>();
|
||||
DateTime adesso = DateTime.Now;
|
||||
// prendo tutti i files
|
||||
fileList = fileListRaw.ToList();
|
||||
Log.Debug($"CheckFileListArchived S01 | file trovati: {fileList.Count()}");
|
||||
List<FileModel> fileChecked = new List<FileModel>();
|
||||
List<FileModel> fileMod = new List<FileModel>();
|
||||
List<FileModel> fileDel = new List<FileModel>();
|
||||
|
||||
// recupera elenco file nel DB
|
||||
List<FileModel> archivedFile = new List<FileModel>();
|
||||
List<FileModel> dbFileListRaw = FileGetByPath(path, true);
|
||||
// preparo lista di interi
|
||||
List<string> FilePathList = FileList.Select(x => x.Path).ToList();
|
||||
// ora li filtro: prendo solo quelli che sono nell'elenco dei files da controllare...
|
||||
List<FileModel> foundFile = dbFileListRaw.Where(x => FilePathList.Contains(x.Path)).ToList();
|
||||
|
||||
// rimuovo eventuali file con estensioni escluse...
|
||||
foreach (var fRec in foundFile)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(fRec.Extension) && currRule.ExcludedFileExt.Contains(fRec.Extension))
|
||||
{
|
||||
Log.Trace($"CheckFileListArchived S01.B: escluso {fRec.Name} | estensione {fRec.Extension}");
|
||||
}
|
||||
else
|
||||
{
|
||||
archivedFile.Add(fRec);
|
||||
}
|
||||
}
|
||||
Log.Debug($"CheckFileListArchived S01.C | Recuperati {archivedFile.Count()} da DB per confronto");
|
||||
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
|
||||
{
|
||||
// parto dal DB ed escludo quelli già mappati...
|
||||
foreach (var fileDb in archivedFile)
|
||||
{
|
||||
// escludo i file con desinenza da escludere...
|
||||
if (!string.IsNullOrEmpty(fileDb.Extension) && currRule.ExcludedFileExt.Contains(fileDb.Extension))
|
||||
{
|
||||
Log.Trace($"CheckFileListArchived S02: escluso {fileDb.Name} | estensione {fileDb.Extension}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// cerca nel filesystem...
|
||||
var currRecord = fileList
|
||||
.Where(x => fileDb.Path == x.FullName)
|
||||
.FirstOrDefault();
|
||||
// se NON trova lo crea
|
||||
if (currRecord == null)
|
||||
{
|
||||
fileDel.Add(fileDb);
|
||||
}
|
||||
else
|
||||
{
|
||||
// verifico se data modifica sia cambiata...
|
||||
if (fileDb.LastMod != currRecord.LastWriteTime)
|
||||
{
|
||||
// calcolo e verifico MD5
|
||||
var fileContent = File.ReadAllBytes(currRecord.FullName);
|
||||
var hash = md5.ComputeHash(fileContent);
|
||||
var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||
if (newMD5 != fileDb.MD5)
|
||||
{
|
||||
fileMod.Add(fileDb);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileChecked.Add(fileDb);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fileChecked.Add(fileDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// aggiorno i file modificati
|
||||
if (fileMod != null && fileMod.Count > 0)
|
||||
{
|
||||
checkDone += fileMod.Count;
|
||||
FileSetUpdated(fileMod);
|
||||
Log.Trace($"CheckFileListArchived S04 | update {fileMod.Count} files");
|
||||
}
|
||||
// segno data-ora ultimo controllo x file invariati
|
||||
if (fileChecked != null && fileChecked.Count > 0)
|
||||
{
|
||||
checkDone += fileChecked.Count;
|
||||
FileSetChecked(fileChecked, path, currRule, forceTag);
|
||||
Log.Trace($"CheckFileListArchived S05 | refreshed {fileChecked.Count} files");
|
||||
}
|
||||
// indico infine i file modificati
|
||||
if (fileDel != null && fileDel.Count > 0)
|
||||
{
|
||||
checkDone += fileDel.Count;
|
||||
FileSetMissing(fileDel, path, currRule, false);
|
||||
Log.Trace($"FileArchivedMissing S06 | missing {fileDel.Count} files");
|
||||
}
|
||||
|
||||
Log.Info($"Effettuati {checkDone} controlli");
|
||||
// svuoto
|
||||
fileChecked = new List<FileModel>();
|
||||
fileMod = new List<FileModel>();
|
||||
GC.Collect();
|
||||
// chiudo
|
||||
return checkDone;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
@@ -335,6 +504,8 @@ namespace MP.FileData.Controllers
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Cerca il file x chiave ID
|
||||
/// </summary>
|
||||
@@ -353,6 +524,33 @@ namespace MP.FileData.Controllers
|
||||
return thisFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///recupera tutte le revisioni dato un singolo record, ordinate x REV descending
|
||||
/// </summary>
|
||||
/// <param name="FileId"></param>
|
||||
/// <returns></returns>
|
||||
public List<FileModel> FileGetAllRevByKey(int FileId)
|
||||
{
|
||||
List<FileModel> dbResult = new List<FileModel>();
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
var thisRec = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.FileId == FileId)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (thisRec != null)
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.Path == thisRec.Path)
|
||||
.OrderByDescending(x => x.Rev)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cerca un file dato un fice successivo specificando rev richiesta)
|
||||
/// </summary>
|
||||
@@ -378,14 +576,14 @@ namespace MP.FileData.Controllers
|
||||
{
|
||||
tFile = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.Name == oFile.Name && x.IdxMacchina == oFile.IdxMacchina && x.Path == oFile.Path)
|
||||
.Where(x => x.IdxMacchina == oFile.IdxMacchina && x.Path == oFile.Path && x.Rev == Rev)
|
||||
//.Where(x => x.Name == oFile.Name && x.IdxMacchina == oFile.IdxMacchina && x.Path == oFile.Path)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
return tFile;
|
||||
}
|
||||
|
||||
|
||||
public List<FileModel> FileGetByPath(string path, bool onlyActive)
|
||||
{
|
||||
List<FileModel> dbResult = new List<FileModel>();
|
||||
@@ -540,38 +738,6 @@ namespace MP.FileData.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imposta utente approvazione + data modifica File
|
||||
/// </summary>
|
||||
/// <param name="currFile"></param>
|
||||
/// <param name="UserName"></param>
|
||||
/// <returns></returns>
|
||||
public bool FileSetUserApp(FileModel currFile, string UserName)
|
||||
{
|
||||
bool done = false;
|
||||
List<FileInfo> listUpdate = new List<FileInfo>();
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
FileModel currRec = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.FileId == currFile.FileId)
|
||||
.FirstOrDefault();
|
||||
if (currRec != null)
|
||||
{
|
||||
DateTime adesso = DateTime.Now;
|
||||
currRec.UserAppr = UserName;
|
||||
currRec.LastMod = adesso;
|
||||
currRec.LastCheck = adesso;
|
||||
//currFile.DiskStatus = FileState.Ok;
|
||||
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
// salvo DB
|
||||
localDbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Approvazione modifica File
|
||||
/// </summary>
|
||||
@@ -756,6 +922,113 @@ namespace MP.FileData.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua update di un record in archivio da lista (SOLO STATUS)
|
||||
/// </summary>
|
||||
/// <param name="missFiles">Elenco file MISSING</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 FileSetMissing(List<FileModel> missFiles, 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();
|
||||
FileModel currItem = null;
|
||||
foreach (var item in missFiles)
|
||||
{
|
||||
// recupero record da DB...
|
||||
currItem = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.FileId == item.FileId)
|
||||
.Include(x => x.Tags)
|
||||
.FirstOrDefault();
|
||||
|
||||
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 if (currRule.Mode == SearchMode.TagListed)
|
||||
{
|
||||
Tags = TagsUtils.SearchTagListed(fileName, item.FileStringContent, currRule);
|
||||
}
|
||||
else
|
||||
{
|
||||
Tags = TagsUtils.SearchPathName(item.Path, basePath, currRule);
|
||||
}
|
||||
|
||||
foreach (var tag in Tags)
|
||||
{
|
||||
var foundTag = currTags.SingleOrDefault(x => x.TagId.ToLower() == tag.ToLower());
|
||||
//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);
|
||||
//localDbCtx.SaveChanges();
|
||||
Tag4File.Add(newTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
// al file aggiungo comunque
|
||||
Tag4File.Add(foundTag);
|
||||
}
|
||||
}
|
||||
// aggiungo ai file
|
||||
if (Tag4File.Count > 0)
|
||||
{
|
||||
// salvo i tags relativi ai files
|
||||
currItem.Tags.Clear();
|
||||
currItem.Tags = Tag4File;
|
||||
//localDbCtx.Entry(currItem).State = EntityState.Modified;
|
||||
}
|
||||
//localDbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
// update comunque data-ora e stato missing
|
||||
foreach (var item in missFiles)
|
||||
{
|
||||
// salvo update file
|
||||
item.DiskStatus = FileState.Deleted;
|
||||
item.LastCheck = adesso;
|
||||
localDbCtx.Entry(item).State = EntityState.Modified;
|
||||
}
|
||||
try
|
||||
{
|
||||
// salvo
|
||||
localDbCtx.SaveChanges();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Errore in salvataggio FileSetChecked{Environment.NewLine}{exc}");
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
GC.Collect();
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua update di un record in archivio da lista (solo status, da approvare)
|
||||
/// </summary>
|
||||
@@ -783,6 +1056,37 @@ namespace MP.FileData.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imposta utente approvazione + data modifica File
|
||||
/// </summary>
|
||||
/// <param name="currFile"></param>
|
||||
/// <param name="UserName"></param>
|
||||
/// <returns></returns>
|
||||
public bool FileSetUserApp(FileModel currFile, string UserName)
|
||||
{
|
||||
bool done = false;
|
||||
List<FileInfo> listUpdate = new List<FileInfo>();
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
FileModel currRec = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.FileId == currFile.FileId)
|
||||
.FirstOrDefault();
|
||||
if (currRec != null)
|
||||
{
|
||||
DateTime adesso = DateTime.Now;
|
||||
currRec.UserAppr = UserName;
|
||||
currRec.LastMod = adesso;
|
||||
currRec.LastCheck = adesso;
|
||||
//currFile.DiskStatus = FileState.Ok;
|
||||
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
||||
// salvo DB
|
||||
localDbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna un record FILE rileggendo e ricalcolando...
|
||||
/// </summary>
|
||||
@@ -859,6 +1163,10 @@ namespace MP.FileData.Controllers
|
||||
.Where(x => x.DiskStatus == FileState.Changed)
|
||||
.Count();
|
||||
|
||||
item.NumMissing = activeRecords
|
||||
.Where(x => x.DiskStatus == FileState.Deleted)
|
||||
.Count();
|
||||
|
||||
item.NoTags = activeRecords
|
||||
.Where(x => x.Tags.Count == 0)
|
||||
.Count();
|
||||
|
||||
Reference in New Issue
Block a user