- fix missing file x IOB (errore in assegnazione modifica pre salvataggio in EFCore)
This commit is contained in:
Samuele Locatelli
2024-10-29 17:54:35 +01:00
parent a66c0fdadf
commit 8d0870477b
7 changed files with 58 additions and 65 deletions
+45 -56
View File
@@ -869,21 +869,21 @@ namespace MP.FileData.Controllers
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 updFiles)
{
// elenco Tags
List<TagModel> currTags = localDbCtx.DbSetTags.ToList();
FileModel currItem = null;
foreach (var item in updFiles)
{
// recupero record da DB...
currItem = localDbCtx
.DbSetProgFile
.Where(x => x.FileId == item.FileId)
.Include(x => x.Tags)
.FirstOrDefault();
// recupero record da DB...
currItem = localDbCtx
.DbSetProgFile
.Where(x => x.FileId == item.FileId)
.Include(x => x.Tags)
.FirstOrDefault();
// SOLO SE richiesto forzatura tags
if (forceTag)
{
List<string> Tags = new List<string>();
List<TagModel> Tag4File = new List<TagModel>();
// se necessario bonifico filename...
@@ -933,30 +933,24 @@ namespace MP.FileData.Controllers
// salvo i tags relativi ai files
currItem.Tags.Clear();
currItem.Tags = Tag4File;
//localDbCtx.Entry(currItem).State = EntityState.Modified;
}
//localDbCtx.SaveChanges();
}
try
{
// salvo
localDbCtx.SaveChanges();
}
catch (Exception exc)
{
Log.Error($"Errore in salvataggio FileSetChecked{Environment.NewLine}{exc}");
}
}
#if false
// update comunque data-ora
foreach (var item in updFiles)
{
// salvo update file
item.LastCheck = adesso;
localDbCtx.Entry(item).State = EntityState.Modified;
}
#endif
// update comunque data-ora e stato missing
currItem.DiskStatus = FileState.Ok;
currItem.LastCheck = adesso;
localDbCtx.Entry(currItem).State = EntityState.Modified;
}
// salvo
try
{
localDbCtx.SaveChanges();
}
catch (Exception exc)
{
Log.Error($"Errore in salvataggio FileSetChecked{Environment.NewLine}{exc}");
}
answ = true;
}
GC.Collect();
@@ -977,21 +971,21 @@ namespace MP.FileData.Controllers
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)
{
// 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();
// recupero record da DB...
currItem = localDbCtx
.DbSetProgFile
.Where(x => x.FileId == item.FileId)
.Include(x => x.Tags)
.FirstOrDefault();
// SOLO SE richiesto forzatura tags
if (forceTag)
{
List<string> Tags = new List<string>();
List<TagModel> Tag4File = new List<TagModel>();
// se necessario bonifico filename...
@@ -1043,18 +1037,13 @@ namespace MP.FileData.Controllers
currItem.Tags = Tag4File;
//localDbCtx.Entry(currItem).State = EntityState.Modified;
}
//localDbCtx.SaveChanges();
}
// update comunque data-ora e stato missing
currItem.DiskStatus = FileState.Missing;
currItem.LastCheck = adesso;
localDbCtx.Entry(currItem).State = EntityState.Modified;
}
// update comunque data-ora e stato missing
foreach (var item in missFiles)
{
// salvo update file
item.DiskStatus = FileState.Missing;
item.LastCheck = adesso;
localDbCtx.Entry(item).State = EntityState.Modified;
}
try
{
// salvo