PROG
- fix esclusione file temp da regexp - fix gestione delete - test update/approve da REST
This commit is contained in:
@@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
||||
using MP.FileData.DatabaseModels;
|
||||
using Newtonsoft.Json;
|
||||
using MP.FileData.DTO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MP.FileData.Controllers
|
||||
{
|
||||
@@ -121,25 +122,10 @@ namespace MP.FileData.Controllers
|
||||
{
|
||||
Log.Info($"CheckFileArchived S00 | macchina: {idxMacchina} | path: {path} | pattern: {searchPattern} | # ExcludedFileExt: {currRule.ExcludedFileExt.Count()}");
|
||||
int checkDone = 0;
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
FileInfo[] fileListRaw = dirInfo.GetFiles(searchPattern, SearchOption.AllDirectories);
|
||||
List<FileInfo> fileList = new List<FileInfo>();
|
||||
DateTime adesso = DateTime.Now;
|
||||
// se ho un limite x giorni indietor x modifiche --> limito!
|
||||
if (numDayPre > 0)
|
||||
{
|
||||
foreach (var item in fileListRaw)
|
||||
{
|
||||
if (adesso.Subtract(item.LastWriteTime).TotalDays <= numDayPre)
|
||||
{
|
||||
fileList.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fileList = fileListRaw.ToList();
|
||||
}
|
||||
// leggo i files rispettando regole e filtri vari
|
||||
fileList = GetFiltFileFromDisk(path, numDayPre, searchPattern, currRule, fileList);
|
||||
|
||||
Log.Debug($"CheckFileArchived S01 | file trovati: {fileList.Count()}");
|
||||
List<FileInfo> fileNew = new List<FileInfo>();
|
||||
List<FileModel> fileChecked = new List<FileModel>();
|
||||
@@ -271,6 +257,61 @@ namespace MP.FileData.Controllers
|
||||
// chiudo
|
||||
return checkDone;
|
||||
}
|
||||
/// <summary>
|
||||
/// Recupera file dal disco saltando eventuali math di esclusione e/o filtro date/nome file
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="numDayPre"></param>
|
||||
/// <param name="searchPattern"></param>
|
||||
/// <param name="currRule"></param>
|
||||
/// <param name="fileList"></param>
|
||||
/// <returns></returns>
|
||||
private static List<FileInfo> GetFiltFileFromDisk(string path, int numDayPre, string searchPattern, SearchRules currRule, List<FileInfo> fileList)
|
||||
{
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
var fileListRaw = dirInfo.GetFiles(searchPattern, SearchOption.AllDirectories).ToList();
|
||||
List<FileInfo> file2Rem = new List<FileInfo>();
|
||||
// se richiesto filtro i files esclusi da regexp li calcolo...
|
||||
if (currRule.ExclFileEnabled)
|
||||
{
|
||||
foreach (var item in fileListRaw)
|
||||
{
|
||||
string pattern = currRule.ExclFileRegExPattern;
|
||||
// uso regexp
|
||||
MatchCollection hasMatch = Regex.Matches(item.Name, pattern);
|
||||
if (hasMatch.Count > 0)
|
||||
{
|
||||
file2Rem.Add(item);
|
||||
}
|
||||
}
|
||||
// quindi li rimuovo da elenco raw...
|
||||
if (file2Rem.Count > 0)
|
||||
{
|
||||
foreach (var f2d in file2Rem)
|
||||
{
|
||||
fileListRaw.Remove(f2d);
|
||||
}
|
||||
}
|
||||
}
|
||||
DateTime adesso = DateTime.Now;
|
||||
// se ho un limite x giorni indietro x modifiche --> limito!
|
||||
if (numDayPre > 0)
|
||||
{
|
||||
foreach (var item in fileListRaw)
|
||||
{
|
||||
if (adesso.Subtract(item.LastWriteTime).TotalDays <= numDayPre)
|
||||
{
|
||||
fileList.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fileList = fileListRaw.ToList();
|
||||
}
|
||||
|
||||
return fileList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck
|
||||
@@ -1010,7 +1051,7 @@ namespace MP.FileData.Controllers
|
||||
foreach (var item in missFiles)
|
||||
{
|
||||
// salvo update file
|
||||
item.DiskStatus = FileState.Deleted;
|
||||
item.DiskStatus = FileState.Missing;
|
||||
item.LastCheck = adesso;
|
||||
localDbCtx.Entry(item).State = EntityState.Modified;
|
||||
}
|
||||
@@ -1163,7 +1204,7 @@ namespace MP.FileData.Controllers
|
||||
.Count();
|
||||
|
||||
item.NumMissing = activeRecords
|
||||
.Where(x => x.DiskStatus == FileState.Deleted)
|
||||
.Where(x => x.DiskStatus == FileState.Missing)
|
||||
.Count();
|
||||
|
||||
item.NoTags = activeRecords
|
||||
|
||||
Reference in New Issue
Block a user