Aggiunta metodi x resync dati non inviati in cloud
This commit is contained in:
@@ -6,9 +6,7 @@ using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static EgwProxy.MagMan.RestPayload;
|
||||
|
||||
namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
{
|
||||
@@ -1144,12 +1142,55 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Forza sincronizzazione invii non completati
|
||||
/// Forza sincronizzazione invii non completati SOLO di consumi...
|
||||
/// </summary>
|
||||
/// <returns>MockUp: mostra sempre ok anche senza eseguire davvero</returns>
|
||||
/// <returns>Restituisce esito resync, ALL OK solo se ha fatto tutti gli invii necessari</returns>
|
||||
private SyncResult ForceSyncroSend()
|
||||
{
|
||||
SyncResult answ = SyncResult.ALL_OK;
|
||||
SyncResult answ = SyncResult.ERR_ND;
|
||||
ProjResState projType = ProjResState.Consumed;
|
||||
// recupero da DB eventuale elenco dati da sincronizzare
|
||||
using (MagmanSyncController msContr = new MagmanSyncController())
|
||||
{
|
||||
var list2resend = msContr.GetUnsentFilt("", DateTime.Now.AddDays(1), 1000);
|
||||
if (list2resend == null || list2resend.Count == 0)
|
||||
{
|
||||
answ = SyncResult.ALL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
// verifico server ok
|
||||
bool servOk = commLib.CheckRemote();
|
||||
if (!servOk)
|
||||
{
|
||||
answ = SyncResult.ERR_ServerKo;
|
||||
}
|
||||
else
|
||||
{
|
||||
// eseguo re-invio 1:1...
|
||||
List<ResourceDTO> list2send = new List<ResourceDTO>();
|
||||
foreach (var record in list2resend)
|
||||
{
|
||||
list2send = JsonConvert.DeserializeObject<List<ResourceDTO>>(record.Payload);
|
||||
if (Enum.TryParse(record.SyncType, out projType))
|
||||
{
|
||||
// effettuo invio...
|
||||
bool resOk = commLib.ResourceSend(record.CloudId, projType, list2send);
|
||||
if (!resOk)
|
||||
{
|
||||
answ = SyncResult.ERR_CloudResNotSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = SyncResult.ALL_OK;
|
||||
// registro su DB dataora conclusione invio
|
||||
msContr.SetCompleted(record.SyncId, DateTime.Now);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,28 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lista record NON inviati filtrati x tipo e num max
|
||||
/// </summary>
|
||||
/// <param name="SyncType">Tipo di record richiesti, se "" = tutti</param>
|
||||
/// <param name="DtMax">Data-Ora limite per recupero ordinato ASC</param>
|
||||
/// <param name="NumMax">num max di record da restituire</param>
|
||||
/// <returns></returns>
|
||||
public List<MagmanSyncModel> GetUnsentFilt(string SyncType, DateTime DtMax, int NumMax)
|
||||
{
|
||||
List<MagmanSyncModel> dbResult = new List<MagmanSyncModel>();
|
||||
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.SyncList
|
||||
.Where(x => x.DtExe == null && (string.IsNullOrEmpty(SyncType) || x.SyncType == SyncType) && x.DtReq <= DtMax)
|
||||
.OrderBy(x => x.DtReq)
|
||||
.Take(NumMax)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Insert record MagmanSync
|
||||
/// </summary>
|
||||
@@ -90,9 +112,9 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
// inserisco record
|
||||
localDbCtx.SyncList.Add(newRec);
|
||||
|
||||
// inserisco record
|
||||
localDbCtx.SyncList.Add(newRec);
|
||||
|
||||
// Commit changes
|
||||
localDbCtx.SaveChanges();
|
||||
newId = newRec.SyncId;
|
||||
|
||||
Reference in New Issue
Block a user