Update detalayer: metodi sync/async
This commit is contained in:
@@ -42,9 +42,9 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
/// - upload + sync (cloud)
|
||||
/// - download + sync (locale)
|
||||
/// </summary>
|
||||
/// <param name="MatCode">Se "" --> tutti, altrimenti limitatamente al MatCode cercato</param>
|
||||
/// <param name="MatCode">Se "" esegue per tutti, altrimenti limitatamente al MatCode cercato</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> MaterialsSync(string MatCode = "")
|
||||
public bool MaterialsSyncro(string MatCode = "")
|
||||
{
|
||||
bool answ = false;
|
||||
// verifico server ok
|
||||
@@ -59,11 +59,60 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
{
|
||||
List<MaterialDTO> list2send = matListDb.Select(x => MaterialsController.ConvToDto(x)).ToList();
|
||||
// preparo pacchetto invio...
|
||||
answ = await commLib.MaterialsSend(list2send);
|
||||
answ = commLib.MaterialsSend(list2send);
|
||||
// se inviato, scarico x merge locale
|
||||
if (answ)
|
||||
{
|
||||
List<MaterialDTO> list2merge = await commLib.MaterialsGet();
|
||||
List<MaterialDTO> list2merge = commLib.MaterialsGet();
|
||||
// se filtro x materiale processo solo quello...
|
||||
if (!string.IsNullOrEmpty(MatCode))
|
||||
{
|
||||
list2merge = list2merge.Where(x => x.MatCode == MatCode).ToList();
|
||||
}
|
||||
// effettuo conversione DTO --> model + merge
|
||||
List<MaterialModel> list2MergeDb = list2merge.Select(x => MaterialsController.ConvToModel(x)).ToList();
|
||||
// ciclo...
|
||||
if (list2MergeDb != null)
|
||||
{
|
||||
foreach (var item in list2MergeDb)
|
||||
{
|
||||
_ = dbContr.Insert(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue sync materiali in modalità asincrona:
|
||||
/// - upload + sync (cloud)
|
||||
/// - download + sync (locale)
|
||||
/// </summary>
|
||||
/// <param name="MatCode">Se "" esegue per tutti, altrimenti limitatamente al MatCode cercato</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> MaterialsSyncroAsync(string MatCode = "")
|
||||
{
|
||||
bool answ = false;
|
||||
// verifico server ok
|
||||
bool servOk = commLib.CheckRemote();
|
||||
if (servOk)
|
||||
{
|
||||
using (MaterialsController dbContr = new MaterialsController())
|
||||
{
|
||||
// in primis leggo l'elenco materiali dal DB locale
|
||||
List<MaterialModel> matListDb = dbContr.GetFiltModel(MatCode);
|
||||
if (matListDb != null)
|
||||
{
|
||||
List<MaterialDTO> list2send = matListDb.Select(x => MaterialsController.ConvToDto(x)).ToList();
|
||||
// preparo pacchetto invio...
|
||||
answ = await commLib.MaterialsSendAsync(list2send);
|
||||
// se inviato, scarico x merge locale
|
||||
if (answ)
|
||||
{
|
||||
List<MaterialDTO> list2merge = await commLib.MaterialsGetAsync();
|
||||
// se filtro x materiale processo solo quello...
|
||||
if (!string.IsNullOrEmpty(MatCode))
|
||||
{
|
||||
@@ -94,20 +143,47 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
/// Lista items e quantità consumate, se fossero positive vengono cambiate di segno...
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResourceSendCons(int idxProjDbId, List<RawItemModel> rec2send)
|
||||
public bool ResourceSendCons(int idxProjDbId, List<RawItemModel> rec2send)
|
||||
{
|
||||
bool answ = false;
|
||||
// verifico server ok
|
||||
bool servOk = commLib.CheckRemote();
|
||||
if (servOk)
|
||||
{
|
||||
answ = await ResourcesSync(rec2send);
|
||||
answ = ResourcesSync(rec2send);
|
||||
if (answ)
|
||||
{
|
||||
// in primis converto le risorse...
|
||||
List<ResourceDTO> list2send = rec2send.Select(x => RawItemsController.ConvToResDtoNeg(x)).ToList();
|
||||
// effettuo invio...
|
||||
answ = await commLib.ResourceSend(idxProjDbId, ProjResState.Consumed, list2send);
|
||||
answ = commLib.ResourceSend(idxProjDbId, ProjResState.Consumed, list2send);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue registrazione Risorse (RawItems) come CONSUMI effettivi, versione ASYNC:
|
||||
/// </summary>
|
||||
/// <param name="idxProjDbId">DB Id del progetto x cui si inviano i dati</param>
|
||||
/// <param name="rec2send">
|
||||
/// Lista items e quantità consumate, se fossero positive vengono cambiate di segno...
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResourceSendConsAsync(int idxProjDbId, List<RawItemModel> rec2send)
|
||||
{
|
||||
bool answ = false;
|
||||
// verifico server ok
|
||||
bool servOk = commLib.CheckRemote();
|
||||
if (servOk)
|
||||
{
|
||||
answ = await ResourcesSyncAsync(rec2send);
|
||||
if (answ)
|
||||
{
|
||||
// in primis converto le risorse...
|
||||
List<ResourceDTO> list2send = rec2send.Select(x => RawItemsController.ConvToResDtoNeg(x)).ToList();
|
||||
// effettuo invio...
|
||||
answ = await commLib.ResourceSendAsync(idxProjDbId, ProjResState.Consumed, list2send);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
@@ -119,20 +195,45 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
/// <param name="idxProjDbId">DB Id del progetto x cui si inviano i dati</param>
|
||||
/// <param name="rec2send">Lista items con quantità prevista</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResourceSendEstimate(int idxProjDbId, List<RawItemModel> rec2send)
|
||||
public bool ResourceSendEstimate(int idxProjDbId, List<RawItemModel> rec2send)
|
||||
{
|
||||
bool answ = false;
|
||||
// verifico server ok
|
||||
bool servOk = commLib.CheckRemote();
|
||||
if (servOk)
|
||||
{
|
||||
answ = await ResourcesSync(rec2send);
|
||||
answ = ResourcesSync(rec2send);
|
||||
if (answ)
|
||||
{
|
||||
// in primis converto le risorse...
|
||||
List<ResourceDTO> list2send = rec2send.Select(x => RawItemsController.ConvToResDto(x)).ToList();
|
||||
// effettuo invio...
|
||||
answ = await commLib.ResourceSend(idxProjDbId, ProjResState.Estimated, list2send);
|
||||
answ = commLib.ResourceSend(idxProjDbId, ProjResState.Estimated, list2send);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue registrazione Risorse (RawItems) come stima, versione ASYNC:
|
||||
/// </summary>
|
||||
/// <param name="idxProjDbId">DB Id del progetto x cui si inviano i dati</param>
|
||||
/// <param name="rec2send">Lista items con quantità prevista</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResourceSendEstimateAsync(int idxProjDbId, List<RawItemModel> rec2send)
|
||||
{
|
||||
bool answ = false;
|
||||
// verifico server ok
|
||||
bool servOk = commLib.CheckRemote();
|
||||
if (servOk)
|
||||
{
|
||||
answ = await ResourcesSyncAsync(rec2send);
|
||||
if (answ)
|
||||
{
|
||||
// in primis converto le risorse...
|
||||
List<ResourceDTO> list2send = rec2send.Select(x => RawItemsController.ConvToResDto(x)).ToList();
|
||||
// effettuo invio...
|
||||
answ = await commLib.ResourceSendAsync(idxProjDbId, ProjResState.Estimated, list2send);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
@@ -144,11 +245,10 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
/// - download + sync (locale)
|
||||
/// </summary>
|
||||
/// <param name="itemList">
|
||||
/// Elenco item, saranno inviati x sync (con quantità sovrascritta) SOLO SE RawItemCloudId
|
||||
/// == 0
|
||||
/// Elenco item, saranno inviati x sync (con quantità sovrascritta) SOLO SE RawItemCloudId==0
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResourcesSync(List<int> MatIdList)
|
||||
public bool ResourcesSync(List<int> MatIdList)
|
||||
{
|
||||
bool fatto = false;
|
||||
// verifico server ok
|
||||
@@ -163,7 +263,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
// recupero elenco rawItem
|
||||
var currList = rawItemDbContr.GetFiltModel(item);
|
||||
// effettuo sync...
|
||||
bool callOk = await ResourcesSync(currList);
|
||||
bool callOk = ResourcesSync(currList);
|
||||
fatto = fatto && callOk;
|
||||
}
|
||||
}
|
||||
@@ -177,11 +277,10 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
/// - download + sync (locale)
|
||||
/// </summary>
|
||||
/// <param name="itemList">
|
||||
/// Elenco item, saranno inviati x sync (con quantità sovrascritta) SOLO SE RawItemCloudId
|
||||
/// == 0
|
||||
/// Elenco item, saranno inviati x sync (con quantità sovrascritta) SOLO SE RawItemCloudId==0
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResourcesSync(List<RawItemModel> itemList)
|
||||
public bool ResourcesSync(List<RawItemModel> itemList)
|
||||
{
|
||||
bool answ = false;
|
||||
// verifico server ok
|
||||
@@ -218,11 +317,118 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
foreach (var matKVP in dictMat)
|
||||
{
|
||||
// invio!
|
||||
answ = await commLib.InventorySend(matKVP.Value.ItemList);
|
||||
answ = commLib.InventorySend(matKVP.Value.ItemList);
|
||||
// ora rileggo dati...
|
||||
if (answ)
|
||||
{
|
||||
List<MaterialDTO> list2merge = await commLib.InventoryGet(matKVP.Key);
|
||||
List<MaterialDTO> list2merge = commLib.InventoryGet(matKVP.Key);
|
||||
// ciclo sui materiali...
|
||||
if (list2merge != null)
|
||||
{
|
||||
foreach (var item in list2merge)
|
||||
{
|
||||
_ = matDbContr.Insert(MaterialsController.ConvToModel(item));
|
||||
// ora processo 1:1 gli items...
|
||||
foreach (var rawItem in item.ItemList)
|
||||
{
|
||||
rawItemDbContr.Upsert(RawItemsController.ConvToModel(rawItem, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue sync risorse (Materiali + RawItem) dato elenco MatId, versione ASYNC:
|
||||
/// - upload + sync (cloud)
|
||||
/// - download + sync (locale)
|
||||
/// </summary>
|
||||
/// <param name="itemList">
|
||||
/// Elenco item, saranno inviati x sync (con quantità sovrascritta) SOLO SE RawItemCloudId
|
||||
/// == 0
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResourcesSyncAsync(List<int> MatIdList)
|
||||
{
|
||||
bool fatto = false;
|
||||
// verifico server ok
|
||||
bool servOk = commLib.CheckRemote();
|
||||
if (servOk)
|
||||
{
|
||||
using (RawItemsController rawItemDbContr = new RawItemsController())
|
||||
{
|
||||
// ciclo per ogni materiale indicato
|
||||
foreach (var item in MatIdList)
|
||||
{
|
||||
// recupero elenco rawItem
|
||||
var currList = rawItemDbContr.GetFiltModel(item);
|
||||
// effettuo sync...
|
||||
bool callOk = await ResourcesSyncAsync(currList);
|
||||
fatto = fatto && callOk;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue sync risorse (Materiali + RawItem):
|
||||
/// - upload + sync (cloud)
|
||||
/// - download + sync (locale)
|
||||
/// </summary>
|
||||
/// <param name="itemList">
|
||||
/// Elenco item, saranno inviati x sync (con quantità sovrascritta) SOLO SE RawItemCloudId
|
||||
/// == 0
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResourcesSyncAsync(List<RawItemModel> itemList)
|
||||
{
|
||||
bool answ = false;
|
||||
// verifico server ok
|
||||
bool servOk = commLib.CheckRemote();
|
||||
if (servOk)
|
||||
{
|
||||
using (MaterialsController matDbContr = new MaterialsController())
|
||||
{
|
||||
using (RawItemsController rawItemDbContr = new RawItemsController())
|
||||
{
|
||||
// per prima cosa invio dati
|
||||
Dictionary<int, MaterialDTO> dictMat = new Dictionary<int, MaterialDTO>();
|
||||
// costruisco elenco materiali da inviare in magazzino (se RawItemCloudId==
|
||||
// 0) ...
|
||||
var rec2sync = itemList.Where(x => x.RawItemCloudId == 0).ToList();
|
||||
foreach (var item in rec2sync)
|
||||
{
|
||||
// verifico se mancasse il materiale nel caso lo aggiungo...
|
||||
if (!dictMat.ContainsKey(item.MatId))
|
||||
{
|
||||
var rigaMat = matDbContr.FindByDbIdModel(item.MatId);
|
||||
if (rigaMat != null)
|
||||
{
|
||||
var rigaMatDto = MaterialsController.ConvToDto(rigaMat);
|
||||
dictMat.Add(item.MatId, rigaMatDto);
|
||||
}
|
||||
}
|
||||
// a questo punto aggiungo item nel DTO del dictionary
|
||||
dictMat[item.MatId].ItemList.Add(RawItemsController.ConvToItemDto(item));
|
||||
}
|
||||
// per ogni materiale faccio invio + rilettura/sync...
|
||||
if (dictMat != null && dictMat.Count > 0)
|
||||
{
|
||||
foreach (var matKVP in dictMat)
|
||||
{
|
||||
// invio!
|
||||
answ = await commLib.InventorySendAsync(matKVP.Value.ItemList);
|
||||
// ora rileggo dati...
|
||||
if (answ)
|
||||
{
|
||||
List<MaterialDTO> list2merge = await commLib.InventoryGetAsync(matKVP.Key);
|
||||
// ciclo sui materiali...
|
||||
if (list2merge != null)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<HintPath>..\ExtLibs\EgtWPFLib5.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EgwProxy.MagMan, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EgwProxy.MagMan.1.0.2402.610\lib\EgwProxy.MagMan.dll</HintPath>
|
||||
<HintPath>..\packages\EgwProxy.MagMan.1.0.2402.614\lib\EgwProxy.MagMan.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<packages>
|
||||
<package id="BouncyCastle" version="1.8.5" targetFramework="net472" />
|
||||
<package id="DotNetZip" version="1.16.0" targetFramework="net472" />
|
||||
<package id="EgwProxy.MagMan" version="1.0.2402.610" targetFramework="net472" />
|
||||
<package id="EgwProxy.MagMan" version="1.0.2402.614" targetFramework="net472" />
|
||||
<package id="EntityFramework" version="6.4.4" targetFramework="net452" />
|
||||
<package id="Google.Protobuf" version="3.21.9" targetFramework="net472" />
|
||||
<package id="K4os.Compression.LZ4" version="1.3.5" targetFramework="net472" />
|
||||
|
||||
Reference in New Issue
Block a user