Update sync: su PROD e non su PROJ
This commit is contained in:
@@ -491,13 +491,29 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue sync di un SINGOLO progetto:
|
||||
/// Esegue sync di un SINGOLO PROD (cloud proj):
|
||||
/// - legge il progetto locale + upload x sync (verso cloud)
|
||||
/// - riceve ID cloud e aggiorna in locale...
|
||||
/// </summary>
|
||||
/// <param name="ProjId">Id del Proj da sincronizzare (invio dati con eventuale fix ProjCloudId)</param>
|
||||
/// <param name="ProdId">Id del Prod da sincronizzare (invio dati con eventuale fix ProjCloudId)</param>
|
||||
/// <returns>Risultato sincronizzazione</returns>
|
||||
public SyncResult ProjSyncro(int ProjId)
|
||||
public SyncResult ProjSyncro(int ProdId)
|
||||
{
|
||||
int cloudId = 0;
|
||||
SyncResult answ = ProjSyncro(ProdId, ref cloudId);
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Esegue sync di un SINGOLO PROD (cloud proj):
|
||||
/// - legge il progetto locale + upload x sync (verso cloud)
|
||||
/// - riceve ID cloud e aggiorna in locale...
|
||||
/// </summary>
|
||||
/// <param name="ProdId">Id del Prod da sincronizzare (invio dati con eventuale fix ProjCloudId)</param>
|
||||
/// <param name="ProjCloudId">Id del Prod in rete (eventualmente creato) che verrà RESTITUITO x reference</param>
|
||||
/// <returns>Risultato sincronizzazione</returns>
|
||||
public SyncResult ProjSyncro(int ProdId, ref int ProjCloudId)
|
||||
{
|
||||
SyncResult answ = SyncResult.ERR_ND;
|
||||
// verifico server ok
|
||||
@@ -508,10 +524,10 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
using (ProjController dbContr = new ProjController())
|
||||
using (ProdController dbContr = new ProdController())
|
||||
{
|
||||
// in primis recupero item
|
||||
var currRec = dbContr.FindByProjId(ProjId);
|
||||
var currRec = dbContr.FindByProdId(ProdId);
|
||||
if (currRec == null)
|
||||
{
|
||||
answ = SyncResult.ERR_ProjIdNotFound;
|
||||
@@ -519,21 +535,20 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
else
|
||||
{
|
||||
// preparo obj da inviare...
|
||||
var projDto = ProjController.ConvToDto(currRec);
|
||||
//List<MaterialDTO> list2send = matListDb.Select(x => MaterialsController.ConvToDto(x)).ToList();
|
||||
var projDto = ProdController.ConvToDto(currRec);
|
||||
// invio e recupero ID...
|
||||
int cloudId = commLib.ProjectSend(projDto);
|
||||
ProjCloudId = commLib.ProjectSend(projDto);
|
||||
// se inviato, faccio upgrade locale...
|
||||
if (cloudId == 0)
|
||||
if (ProjCloudId == 0)
|
||||
{
|
||||
answ = SyncResult.ERR_ProjNotSync;
|
||||
}
|
||||
else
|
||||
{
|
||||
// verifico SE SIA da scrivere cloud ID...
|
||||
if (cloudId != currRec.ProjCloudId)
|
||||
if (ProjCloudId != currRec.ProjCloudId)
|
||||
{
|
||||
dbContr.UpdateCloudId(ProjId, cloudId);
|
||||
dbContr.UpdateCloudId(ProdId, ProjCloudId);
|
||||
}
|
||||
answ = SyncResult.ALL_OK;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using EgtBEAMWALL.DataLayer.DatabaseModels;
|
||||
using EgwProxy.MagMan.DTO;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -58,6 +59,41 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper conversione a ProjectDTO
|
||||
/// </summary>
|
||||
/// <param name="currRec">record in formato ProdModel</param>
|
||||
/// <returns></returns>
|
||||
public static ProjectDTO ConvToDto(ProdModel currRec)
|
||||
{
|
||||
// ho valori mancanti che saranno calcolati dal cloud e valori messi a zero di default
|
||||
ProjectDTO answ = new ProjectDTO()
|
||||
{
|
||||
ProjCloudId = currRec.ProjCloudId,
|
||||
ProjLocalId = currRec.ProdDbId,
|
||||
ProjExtId = currRec.ProdId,
|
||||
// è calcolato sul cloud, da token --> machine ID
|
||||
MachineCloudId = 0,
|
||||
// è calcolato sul cloud, da token --> KeyNum
|
||||
KeyNum = 0,
|
||||
// disponibile solo su PROJ
|
||||
BTLFileName = "",
|
||||
PType = (EgwProxy.MagMan.BWType)currRec.PType,
|
||||
Machine = currRec.Machine,
|
||||
ProjDescription = currRec.Description,
|
||||
DtCreated = currRec.DtCreated,
|
||||
DtLastAction = DateTime.MinValue,
|
||||
DtSchedule = DateTime.MinValue,
|
||||
DtStartProd = DateTime.MinValue,
|
||||
// disponibile solo su PROJ
|
||||
ListName = "",
|
||||
ProcTimeEst = 0,
|
||||
ProcTimeReal = 0,
|
||||
IsActive = currRec.IsActive,
|
||||
IsArchived = currRec.IsArchived
|
||||
};
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Helper conversione modelli verso Core.ProdItem
|
||||
/// </summary>
|
||||
@@ -88,7 +124,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
public Core.ProdFileM ConvToCoreFile(ProdModel currProd)
|
||||
{
|
||||
Core.ProdFileM answ = Core.ProdFileM.CreateProdFileM(currProd.ProdId, ProjIdByProd(currProd.ProdId), currProd.DtCreated, currProd.Description, currProd.PType, currProd.Machine, currProd.LockedBy, currProd.LockDate, currProd.IsActive, currProd.IsProduced, currProd.IsArchived, currProd.ProjCloudId);
|
||||
//Core.ProdFileM answ = Core.ProdFileM.CreateProdFileM(currProd.ProdId, ProjIdByProd(currProd.ProdId), currProd.DtCreated, currProd.Description, currProd.PType, currProd.Machine, currProd.LockedBy, currProd.LockDate, currProd.IsActive, currProd.IsProduced, currProd.IsArchived, currProd.ProjListNav.Select(j => Core.ProjFileM.CreateProjFileM(j.ProjId, currProd.ProdId, j.DtCreated, j.DtExported, j.ListName, j.BTLFileName, j.ProjDescription, j.IsNew, j.Locked, j.PType, j.Machine, j.IsActive, j.IsActive)).ToList());
|
||||
//Core.ProdFileM answ = Core.ProdFileM.CreateProdFileM(currProd.ProdId, ProjIdByProd(currProd.ProdId), currProd.DtCreated, currProd.Description, currProd.PType, currProd.Machine, currProd.LockedBy, currProd.LockDate, currProd.IsActive, currProd.IsProduced, currProd.IsArchived, currProd.ProjListNav.Select(j => Core.ProjFileM.CreateProjFileM(j.ProdId, currProd.ProdId, j.DtCreated, j.DtExported, j.ListName, j.BTLFileName, j.ProjDescription, j.IsNew, j.Locked, j.PType, j.Machine, j.IsActive, j.IsActive)).ToList());
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -750,6 +786,64 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update record su DB x ProjectCloudId
|
||||
/// </summary>
|
||||
/// <param name="ProdId"></param>
|
||||
/// <param name="Description"></param>
|
||||
/// <returns></returns>
|
||||
public Core.ProdFileM UpdateCloudId(int ProdId, int ProjCloudId)
|
||||
{
|
||||
// cerco specifico Proj
|
||||
ProdModel currData;
|
||||
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
currData = localDbCtx
|
||||
.ProdList
|
||||
.Where(x => x.ProdId == ProdId)
|
||||
.SingleOrDefault();
|
||||
if (currData != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// aggiorno valore BTL
|
||||
currData.ProjCloudId = ProjCloudId;
|
||||
|
||||
// salvo record PROD
|
||||
localDbCtx.SaveChanges();
|
||||
|
||||
// cerco se ci siano prod colelgati ed aggiorno pure loro...
|
||||
var projList = localDbCtx
|
||||
.ProjList
|
||||
.Where(x => x.ProdDbId == currData.ProdDbId)
|
||||
.ToList();
|
||||
if (projList != null)
|
||||
{
|
||||
foreach (var item in projList)
|
||||
{
|
||||
item.ProjCloudId = ProjCloudId;
|
||||
}
|
||||
// salvo modifihce ai PROJ
|
||||
localDbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
string errMessage = $"EXCEPTION on Prod.UpdateCloudId:{Environment.NewLine}{exc}";
|
||||
Console.WriteLine(errMessage);
|
||||
Log.Error(errMessage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errMessage = $"ERROR on Prod.UpdateCloudId: req item was not found | ProdId {ProdId} | ProjCloudId {ProjCloudId}";
|
||||
Console.WriteLine(errMessage);
|
||||
Log.Error(errMessage);
|
||||
}
|
||||
}
|
||||
return ConvToCoreFile(currData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update record su DB x Description
|
||||
/// </summary>
|
||||
@@ -1041,7 +1135,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
.SingleOrDefault();
|
||||
if (currData != null)
|
||||
{
|
||||
// aggiorno valore BTL
|
||||
// aggiorno valore tipo
|
||||
currData.PType = PType;
|
||||
|
||||
// Commit changes
|
||||
|
||||
@@ -20,48 +20,6 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Search for already imported BTL from FileName (only)
|
||||
/// =0 : NOT found >0 : ProjId (already present) for overwrite
|
||||
/// </summary>
|
||||
/// <param name="BTLFileName"></param>
|
||||
/// <returns></returns>
|
||||
public int AlreadyImported(string BTLFileName)
|
||||
{
|
||||
int answ = 0;
|
||||
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
var dbResult = localDbCtx
|
||||
.ProjList
|
||||
.Where(x => x.BTLFileName == BTLFileName)
|
||||
//valutare se usare solo attivi...
|
||||
//.Where(x => x.BTLFileName == BTLFileName && x.IsActive == true)
|
||||
.FirstOrDefault();
|
||||
|
||||
//se avesse trovato-- > riporto id...
|
||||
if (dbResult != null && dbResult.ProjId > 0)
|
||||
{
|
||||
answ = dbResult.ProjId;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper conversione modelli
|
||||
/// </summary>
|
||||
/// <param name="currRec">record in formato ProjModel</param>
|
||||
/// <returns></returns>
|
||||
public Core.ProjFileM ConvToCore(ProjModel currRec)
|
||||
{
|
||||
Core.ProjFileM answ = null;
|
||||
if (currRec != null)
|
||||
{
|
||||
answ = Core.ProjFileM.CreateProjFileM(currRec.ProjId, ProdIdByProdDbId(currRec.ProdDbId), currRec.DtCreated, currRec.DtExported, currRec.ListName, currRec.BTLFileName, currRec.ProjDescription, currRec.IsNew, currRec.Locked, currRec.PType, currRec.Machine, currRec.IsActive, currRec.IsArchived, currRec.ProjCloudId);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper conversione a ProjectDTO
|
||||
/// </summary>
|
||||
@@ -128,6 +86,48 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search for already imported BTL from FileName (only)
|
||||
/// =0 : NOT found >0 : ProjId (already present) for overwrite
|
||||
/// </summary>
|
||||
/// <param name="BTLFileName"></param>
|
||||
/// <returns></returns>
|
||||
public int AlreadyImported(string BTLFileName)
|
||||
{
|
||||
int answ = 0;
|
||||
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
var dbResult = localDbCtx
|
||||
.ProjList
|
||||
.Where(x => x.BTLFileName == BTLFileName)
|
||||
//valutare se usare solo attivi...
|
||||
//.Where(x => x.BTLFileName == BTLFileName && x.IsActive == true)
|
||||
.FirstOrDefault();
|
||||
|
||||
//se avesse trovato-- > riporto id...
|
||||
if (dbResult != null && dbResult.ProjId > 0)
|
||||
{
|
||||
answ = dbResult.ProjId;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper conversione modelli
|
||||
/// </summary>
|
||||
/// <param name="currRec">record in formato ProjModel</param>
|
||||
/// <returns></returns>
|
||||
public Core.ProjFileM ConvToCore(ProjModel currRec)
|
||||
{
|
||||
Core.ProjFileM answ = null;
|
||||
if (currRec != null)
|
||||
{
|
||||
answ = Core.ProjFileM.CreateProjFileM(currRec.ProjId, ProdIdByProdDbId(currRec.ProdDbId), currRec.DtCreated, currRec.DtExported, currRec.ListName, currRec.BTLFileName, currRec.ProjDescription, currRec.IsNew, currRec.Locked, currRec.PType, currRec.Machine, currRec.IsActive, currRec.IsArchived, currRec.ProjCloudId);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete Proj logically / on DB by ProjId
|
||||
/// </summary>
|
||||
@@ -753,51 +753,6 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
return currData;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update record su DB x ProjectCloudId
|
||||
/// </summary>
|
||||
/// <param name="ProjId"></param>
|
||||
/// <param name="Description"></param>
|
||||
/// <returns></returns>
|
||||
public Core.ProjFileM UpdateCloudId(int ProjId, int ProjCloudId)
|
||||
{
|
||||
// cerco specifico Proj
|
||||
ProjModel currData;
|
||||
using (DatabaseContext localDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
currData = localDbCtx
|
||||
.ProjList
|
||||
.Where(x => x.ProjId == ProjId)
|
||||
.SingleOrDefault();
|
||||
if (currData != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// aggiorno valore BTL
|
||||
currData.ProjCloudId = ProjCloudId;
|
||||
|
||||
// Commit changes
|
||||
localDbCtx.SaveChanges();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
string errMessage = $"EXCEPTION on Proj.UpdateCloudId:{Environment.NewLine}{exc}";
|
||||
Console.WriteLine(errMessage);
|
||||
Log.Error(errMessage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string errMessage = $"ERROR on Proj.UpdateCloudId: req item was not found | ProjId {ProjId} | ProjCloudId {ProjCloudId}";
|
||||
Console.WriteLine(errMessage);
|
||||
Log.Error(errMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return ConvToCore(currData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update record su DB x Description
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user