modifica (importante) modallo dati x tags + MD% check

This commit is contained in:
Samuele Locatelli
2021-09-07 12:03:01 +02:00
parent 68b9cd4d78
commit 607e096609
7 changed files with 264 additions and 64 deletions
+76 -55
View File
@@ -101,7 +101,11 @@ namespace MP.FileData.Controllers
}
else
{
fileMod.Add(file);
// verifico se data modifica e dimensione siano cambiati...
if (currRecord.LastMod != file.LastWriteTime || currRecord.Size != file.Length)
{
fileMod.Add(file);
}
}
}
@@ -182,7 +186,7 @@ namespace MP.FileData.Controllers
{
dbResult = localDbCtx
.DbSetProgFile
.Where(x => x.Path.StartsWith(path) && ((onlyActive && x.Active) || !onlyActive))
.Where(x => x.Path.StartsWith(path) && ((onlyActive == x.Active) || !onlyActive))
.OrderBy(x => x.Name)
.ToList();
}
@@ -198,7 +202,7 @@ namespace MP.FileData.Controllers
.DbSetProgFile
.Include(m => m.Macchina)
.Include(a => a.Articolo)
.Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.CodArticolo == CodArticolo || CodArticolo == "ND" || CodArticolo.StartsWith("##") || string.IsNullOrEmpty(CodArticolo))) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)) && (!OnlyMod || x.Changed))
.Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.CodArticolo == CodArticolo || CodArticolo == "ND" || CodArticolo.StartsWith("##") || string.IsNullOrEmpty(CodArticolo))) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)) && (!OnlyMod || x.DiskState != FileState.Unchanged))
.OrderBy(x => x.Name)
.ToList();
}
@@ -215,33 +219,44 @@ namespace MP.FileData.Controllers
{
bool answ = false;
DateTime adesso = DateTime.Now;
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
// MD5 hash
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
// converto
List<DatabaseModels.FileModel> newRec = newFiles.Select(o => new DatabaseModels.FileModel()
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
Active = true,
CodArticolo = "ND",
Changed = false,
IdxMacchina = idxMacchina,
LastCheck = adesso,
LastMod = o.LastWriteTime,
MimeType = o.Extension,
Name = o.Name,
Path = o.FullName,
Rev = 0,
Size = o.Length,
FileContent = File.ReadAllBytes(o.FullName)
}).ToList();
// converto
List<DatabaseModels.FileModel> newRec = newFiles.Select(o => new DatabaseModels.FileModel()
{
Active = true,
CodArticolo = "ND",
DiskState = FileState.New,
IdxMacchina = idxMacchina,
LastCheck = adesso,
LastMod = o.LastWriteTime,
MimeType = o.Extension,
Name = o.Name,
Path = o.FullName,
Rev = 0,
Size = o.Length,
FileContent = File.ReadAllBytes(o.FullName)
}).ToList();
// aggiungo in blocco
localDbCtx
.DbSetProgFile
.AddRange(newRec);
// calcolo MD5
foreach (var item in newRec)
{
var hash = md5.ComputeHash(item.FileContent);
item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
// salvo
localDbCtx.SaveChanges();
answ = true;
// aggiungo in blocco
localDbCtx
.DbSetProgFile
.AddRange(newRec);
// salvo
localDbCtx.SaveChanges();
answ = true;
}
}
return answ;
}
@@ -265,12 +280,7 @@ namespace MP.FileData.Controllers
.FirstOrDefault();
if (currData != null)
{
//// se ho modificato data --> cambio codice ordine!
//if (!localDbCtx.Entry(updItem).OriginalValues["DtOrder"].Equals(localDbCtx.Entry(updItem).CurrentValues["DtOrder"]))
//{
// updItem.OrderCode = $"O{updItem.Plant.PlantCode}{updItem.DtOrder:yyMMddHHmm}";
// updItem.OrderDesc = $"Ordine {updItem.Plant.PlantDesc} - {updItem.DtOrder}";
//}
updItem.DiskState = FileState.Changed;
localDbCtx.Entry(updItem).State = EntityState.Modified;
localDbCtx.SaveChanges();
}
@@ -358,33 +368,44 @@ namespace MP.FileData.Controllers
{
bool answ = false;
DateTime adesso = DateTime.Now;
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
// MD5 hash
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
// converto
List<DatabaseModels.FileModel> newRec = updFiles.Select(o => new DatabaseModels.FileModel()
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
{
Active = true,
CodArticolo = "ND",
Changed = false,
IdxMacchina = idxMacchina,
LastCheck = adesso,
LastMod = o.LastWriteTime,
MimeType = o.Extension,
Name = o.Name,
Path = o.FullName,
Rev = 0,
Size = o.Length,
FileContent = File.ReadAllBytes(o.FullName)
}).ToList();
// converto
List<DatabaseModels.FileModel> newRec = updFiles.Select(o => new DatabaseModels.FileModel()
{
Active = true,
DiskState = FileState.Changed,
CodArticolo = "ND",
FileContent = File.ReadAllBytes(o.FullName),
IdxMacchina = idxMacchina,
LastCheck = adesso,
LastMod = o.LastWriteTime,
MimeType = o.Extension,
Name = o.Name,
Path = o.FullName,
Rev = 0,
Size = o.Length
}).ToList();
// aggiungo in blocco
localDbCtx
.DbSetProgFile
.UpdateRange(newRec);
// calcolo MD5
foreach (var item in newRec)
{
var hash = md5.ComputeHash(item.FileContent);
item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
// salvo
localDbCtx.SaveChanges();
answ = true;
// aggiungo in blocco
localDbCtx
.DbSetProgFile
.UpdateRange(newRec);
// salvo
localDbCtx.SaveChanges();
answ = true;
}
}
return answ;
}