255 lines
11 KiB
C#
255 lines
11 KiB
C#
using EgwProxy.DataLayer.Controllers;
|
|
using EgwProxy.MagMan;
|
|
using EgwProxy.MagMan.DTO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DemoApp
|
|
{
|
|
internal class Program
|
|
{
|
|
|
|
|
|
static async Task Main(string[] args)
|
|
{
|
|
// indica se eseguire step check syncro remota dati via REST
|
|
bool testSync = false;
|
|
// indica se eseguire step check syncro dati LOG da DB a REST remoti
|
|
bool testDbLog = true;
|
|
|
|
// num chiave
|
|
int keyNum = 470;
|
|
#if DEBUG
|
|
// Indirizzo server (DEBUG)
|
|
string servAddr = "localhost:7207";
|
|
|
|
// token di auth nostro
|
|
//string commToken = "e7a81d7a-6fb4-412e-b361-cac7dda517d6";
|
|
string commToken = "79840ba7-00c1-407f-8372-5b60238c04fa";
|
|
#else
|
|
// Indirizzo server (RELEASE)
|
|
string servAddr = "magman.egalware.com";
|
|
|
|
// token di auth
|
|
string commToken = "22fa4426-6670-41ad-ac2b-d7b5c3dfe849";
|
|
#endif
|
|
|
|
string sep = "--------------------------------------------";
|
|
string sepShort = "------------------";
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine("- MagMan REST Demo App");
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine();
|
|
string answ = "";
|
|
DataSyncro commLib = new DataSyncro(servAddr, commToken);
|
|
Console.WriteLine("Premere ENT per check ping");
|
|
answ = Console.ReadLine();
|
|
bool servOk = commLib.CheckRemote();
|
|
string esito = servOk ? "OK" : "KO";
|
|
Console.WriteLine($"Esito controllo server: {esito}");
|
|
// se richiesto eseguo tutto sennò salto
|
|
if (testSync)
|
|
{
|
|
|
|
Console.WriteLine("Premere un tasto per lettura archivio materiali");
|
|
answ = Console.ReadLine();
|
|
// leggo materiali
|
|
var matList = commLib.MaterialsGet();
|
|
if (matList != null)
|
|
{
|
|
foreach (var item in matList)
|
|
{
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine($"Mat ID: {item.MatCloudId}");
|
|
Console.WriteLine($"Mat Code: {item.MatCode}");
|
|
Console.WriteLine($"Dtmx Code: {item.MatDtmx}");
|
|
Console.WriteLine($"descript: {item.MatDesc}");
|
|
Console.WriteLine($"Dimensions W x H x L: {item.WMm:N3} x {item.HMm:N3} x {item.LMm:N3}");
|
|
if (item.ItemList != null)
|
|
{
|
|
Console.WriteLine($"Items count: {item.ItemList.Count}");
|
|
}
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine();
|
|
}
|
|
}
|
|
Console.WriteLine("Enter to next step");
|
|
answ = Console.ReadLine();
|
|
|
|
// leggo inventario
|
|
var inventList = commLib.InventoryGet(0);
|
|
if (inventList != null)
|
|
{
|
|
foreach (var itemMat in inventList)
|
|
{
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine($"Mat ID: {itemMat.MatCloudId}");
|
|
Console.WriteLine($"Mat Code: {itemMat.MatCode}");
|
|
Console.WriteLine($"Dtmx Code: {itemMat.MatDtmx}");
|
|
Console.WriteLine($"descript: {itemMat.MatDesc}");
|
|
Console.WriteLine($"Dimensions W x H x L: {itemMat.WMm:N3} x {itemMat.HMm:N3} x {itemMat.LMm:N3}");
|
|
if (itemMat.ItemList != null)
|
|
{
|
|
Console.WriteLine($"Items count: {itemMat.ItemList.Count}");
|
|
if (itemMat.ItemList.Count > 0)
|
|
{
|
|
Console.WriteLine("Inventario:");
|
|
foreach (var itemInv in itemMat.ItemList)
|
|
{
|
|
Console.WriteLine(sepShort);
|
|
Console.WriteLine($"ID: {itemInv.RawItemCloudId}");
|
|
Console.WriteLine($"Location: {itemInv.Location}");
|
|
Console.WriteLine($"Descript: {itemInv.Note}");
|
|
Console.WriteLine($"Giacenza: {itemInv.QtyAvail}");
|
|
Console.WriteLine($"Dimensions W x H x L: {itemInv.WMm:N3} x {itemInv.HMm:N3} x {itemInv.LMm:N3}");
|
|
Console.WriteLine($"Dtmx Code: {itemInv.ItemDtmx}");
|
|
}
|
|
}
|
|
}
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine();
|
|
}
|
|
}
|
|
Console.WriteLine("Enter to next step");
|
|
answ = Console.ReadLine();
|
|
|
|
|
|
// leggo projectList
|
|
var projList = commLib.ProjectGet(keyNum);
|
|
if (projList != null)
|
|
{
|
|
foreach (var itemProj in projList)
|
|
{
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine($"MachineId: {itemProj.MachineCloudId}");
|
|
Console.WriteLine($"Key: {itemProj.KeyNum}");
|
|
Console.WriteLine($"ProjLocalId: {itemProj.ProjLocalId}");
|
|
Console.WriteLine($"ProjExtId: {itemProj.ProjExtId}");
|
|
Console.WriteLine($"BTL filename: {itemProj.BTLFileName}");
|
|
Console.WriteLine($"PType: {itemProj.PType}");
|
|
Console.WriteLine($"Machine: {itemProj.Machine}");
|
|
Console.WriteLine($"Descript: {itemProj.ProjDescription}");
|
|
Console.WriteLine($"Proc time est/real: {itemProj.ProcTimeEst:N1} / {itemProj.ProcTimeReal:N1}");
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine();
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("Enter to next step: numb of proj to read");
|
|
answ = Console.ReadLine();
|
|
int projId = 1;
|
|
int.TryParse(answ, out projId);
|
|
var singleProj = commLib.ProjectGetSingle(projId);
|
|
if (singleProj != null)
|
|
{
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine($"Proj {projId} data:");
|
|
Console.WriteLine($"MachineId: {singleProj.MachineCloudId}");
|
|
Console.WriteLine($"Key: {singleProj.KeyNum}");
|
|
Console.WriteLine($"ProjLocalId: {singleProj.ProjLocalId}");
|
|
Console.WriteLine($"ProjExtId: {singleProj.ProjExtId}");
|
|
Console.WriteLine($"BTL filename: {singleProj.BTLFileName}");
|
|
Console.WriteLine($"PType: {singleProj.PType}");
|
|
Console.WriteLine($"Machine: {singleProj.Machine}");
|
|
Console.WriteLine($"Descript: {singleProj.ProjDescription}");
|
|
Console.WriteLine($"Proc time est/real: {singleProj.ProcTimeEst:N1} / {singleProj.ProcTimeReal:N1}");
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine();
|
|
}
|
|
|
|
|
|
answ = Console.ReadLine();
|
|
|
|
Console.WriteLine("Inserire Qty materiale syncronizzare (Demo, WxHxL: 100x100x0):");
|
|
var sQty = Console.ReadLine();
|
|
int newQty = 0;
|
|
int.TryParse(sQty, out newQty);
|
|
MaterialDTO newMat = new MaterialDTO()
|
|
{
|
|
MatCode = "DEMO",
|
|
MatDesc = $"DEMO material @{DateTime.Now:HH:mm:ss}",
|
|
HMm = 100,
|
|
WMm = 100,
|
|
LMm = 0,
|
|
QtyTot = newQty
|
|
};
|
|
// creo lista
|
|
List<MaterialDTO> newMaterials = new List<MaterialDTO>();
|
|
newMaterials.Add(newMat);
|
|
// invio
|
|
commLib.MaterialsSend(newMaterials);
|
|
|
|
answ = Console.ReadLine();
|
|
var listAlias = commLib.AliasGet();
|
|
if (listAlias != null)
|
|
{
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine("ALIAS LIST");
|
|
Console.WriteLine(sep);
|
|
foreach (var itemAlias in listAlias)
|
|
{
|
|
Console.WriteLine($"{itemAlias.ValOrig} --> {itemAlias.ValAlias} | active: {itemAlias.IsActive} ");
|
|
}
|
|
Console.WriteLine(sep);
|
|
}
|
|
|
|
List<AliasDTO> alias2send = new List<AliasDTO>();
|
|
alias2send.Add(new AliasDTO() { ValOrig = "Item01", ValAlias = "Gl24h", IsActive = true });
|
|
alias2send.Add(new AliasDTO() { ValOrig = "Item02", ValAlias = "Gl24h", IsActive = true });
|
|
var resAliasSend = commLib.AliasSend(alias2send);
|
|
}
|
|
|
|
if (testDbLog)
|
|
{
|
|
// carico dal DB primi 2000 rec e li invio 100 alla volta...
|
|
LogMachineController lmc = new LogMachineController();
|
|
int num2send = 2000;
|
|
int batchSize = 100;
|
|
int numSent = 0;
|
|
|
|
MagmanController mContr = new MagmanController(servAddr, commToken);
|
|
|
|
// sistemo proj x sync online
|
|
var syncRes = mContr.ProjAllSyncro();
|
|
// sistemo dati mancanti...
|
|
lmc.TryFixProjCloudId();
|
|
|
|
var recList = lmc.GetUnsentAsc(num2send);
|
|
// ciclo!
|
|
while (numSent < num2send)
|
|
{
|
|
var currList = recList
|
|
.Skip(numSent)
|
|
.Take(batchSize)
|
|
.ToList();
|
|
// converto il blocco
|
|
var listDto = currList
|
|
.Select(x => LogMachineController.ConvToItemDto(x))
|
|
.ToList();
|
|
// invio!
|
|
var res = await commLib.LogMachineSendAsync(listDto);
|
|
if (res)
|
|
{
|
|
// registro dati inviati...
|
|
lmc.SetDtSent(currList);
|
|
Console.WriteLine($"Inviati {batchSize}rec | {numSent} --> {numSent + batchSize}");
|
|
numSent += batchSize;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"Errore in invio logMacchina");
|
|
}
|
|
}
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine();
|
|
}
|
|
|
|
Console.WriteLine("Enter to close");
|
|
answ = Console.ReadLine();
|
|
}
|
|
}
|
|
}
|