Aggiunta eliminazione stime precedenti se non inviate

This commit is contained in:
Samuele Locatelli
2024-04-17 11:31:54 +02:00
parent 8b5d024feb
commit 1ec81f1359
2 changed files with 43 additions and 3 deletions
@@ -1332,7 +1332,12 @@ namespace EgtBEAMWALL.DataLayer.Controllers
using (MagmanSyncController msContr = new MagmanSyncController())
{
syncId = msContr.Insert(newRec);
// se si tratta di STIMA cancello EVENTUALI record precedenti non inviati
if (trackType == ProjResState.Estimated)
{
// elimino eventuali eventi rimasti fino a 1 sec precedente
msContr.DeleteUnsentFilt(ProjCloudId, $"{trackType}", adesso.AddSeconds(-1));
}
// verifico server ok
bool servOk = commLib.CheckRemote();
if (!servOk)
@@ -1397,7 +1402,6 @@ namespace EgtBEAMWALL.DataLayer.Controllers
}
else
{
int syncId = 0;
string payload = JsonConvert.SerializeObject(list2send);
DateTime adesso = DateTime.Now;
// registro su DB invio..
@@ -46,7 +46,43 @@ namespace EgtBEAMWALL.DataLayer.Controllers
}
catch (Exception exc)
{
Log.Error($"EXCEPTION on Alias.DeleteOlder | NumDayMax: {NumDayMax}{Environment.NewLine}{exc}");
Log.Error($"EXCEPTION on MagmanSync.DeleteOlder | NumDayMax: {NumDayMax}{Environment.NewLine}{exc}");
}
}
return done;
}
/// <summary>
/// Purge dei record NON INVIATI date condizioni filtro
/// </summary>
/// <param name="ProjCloudId">Id progetto x cui filtrare</param>
/// <param name="SyncType">Tipo di record da cercare</param>
/// <param name="DtLimit">DataOra limite (max) x cui cercare record non inviati</param>
/// <returns></returns>
public bool DeleteUnsentFilt(int ProjCloudId, string SyncType, DateTime DtLimit)
{
bool done = false;
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
{
// cercl candidati
var items2del = localDbCtx
.SyncList
.Where(x => x.DtExe == null && x.CloudId == ProjCloudId && x.SyncType == SyncType && x.DtReq <= DtLimit);
// se ne ho trovato...
if (items2del != null && items2del.Count() > 0)
{
try
{
// Add to database
localDbCtx.SyncList.RemoveRange(items2del);
// Commit changes
localDbCtx.SaveChanges();
done = true;
}
catch (Exception exc)
{
Log.Error($"EXCEPTION on MagmanSync.DeleteUnsentFilt | ProjCloudId: {ProjCloudId} | SyncType: {SyncType} | DtLimit: {DtLimit}{Environment.NewLine}{exc}");
}
}
}
return done;