314 lines
14 KiB
C#
314 lines
14 KiB
C#
using EgwProxy.DataLayer.Controllers;
|
|
using EgwProxy.MagMan;
|
|
using EgwProxy.MagMan.DTO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DemoApp
|
|
{
|
|
internal class Program
|
|
{
|
|
#region Private Methods
|
|
|
|
private 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 SAM
|
|
//int keyNum = 470;
|
|
// num chiave Lovato
|
|
int keyNum = 656;
|
|
#if DEBUG
|
|
// Indirizzo server (DEBUG)
|
|
string servAddr = "localhost:7207";
|
|
|
|
// token di auth egalware
|
|
//string commToken = "e7a81d7a-6fb4-412e-b361-cac7dda517d6";
|
|
// token di auth Lovato
|
|
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, 15000);
|
|
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 = await commLib.MaterialsGetAsync();
|
|
if (matList != null && matList.Count > 0)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("No materials found!");
|
|
}
|
|
Console.WriteLine("Enter to next step");
|
|
answ = Console.ReadLine();
|
|
|
|
// leggo inventario
|
|
var inventList = await commLib.InventoryGetAsync(0);
|
|
if (inventList != null && inventList.Count > 0)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("No inventory found!");
|
|
}
|
|
Console.WriteLine("Enter to next step");
|
|
answ = Console.ReadLine();
|
|
|
|
// leggo projectList
|
|
var projList = await commLib.ProjectGetAsync(keyNum);
|
|
if (projList != null && projList.Count > 0)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("No Proj found!");
|
|
}
|
|
|
|
if (projList != null && projList.Count > 0)
|
|
{
|
|
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
|
|
var sendMat = await commLib.MaterialsSendAsync(newMaterials);
|
|
|
|
answ = Console.ReadLine();
|
|
var listAlias = await commLib.AliasGetAsync();
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("No Alias found!");
|
|
}
|
|
|
|
List<AliasDTO> alias2send = new List<AliasDTO>();
|
|
alias2send.Add(new AliasDTO() { ValOrig = "", ValAlias = "Gl24h", IsActive = true });
|
|
alias2send.Add(new AliasDTO() { ValOrig = "GL24H", ValAlias = "Gl24h", IsActive = true });
|
|
var resAliasSend = await commLib.AliasSendAsync(alias2send);
|
|
}
|
|
|
|
if (testDbLog)
|
|
{
|
|
// carico dal DB primi 2000 rec e li invio 100 alla volta...
|
|
LogMachineController lmc = new LogMachineController();
|
|
int num2send = 50000;
|
|
int batchSize = 400;
|
|
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);
|
|
if (recList != null && recList.Count < num2send)
|
|
{
|
|
num2send = recList.Count;
|
|
}
|
|
bool res = false;
|
|
// ciclo!
|
|
Stopwatch sw = new Stopwatch();
|
|
|
|
|
|
// per prima cosa svuoto dati vecchi...
|
|
DateTime dtStart = recList.OrderBy(x => x.DtEvent).First().DtEvent;
|
|
DateTime dtEnd = recList.OrderByDescending(x => x.DtEvent).First().DtEvent;
|
|
// invio cancellazione!
|
|
res = commLib.LogMachineRemoveRange(dtStart, dtEnd);
|
|
sw.Stop();
|
|
Console.WriteLine($"Cancellazione dati preesistenti effettuata | elapsed {sw.Elapsed.TotalSeconds:N3} sec");
|
|
Console.WriteLine("Enter to continue");
|
|
answ = Console.ReadLine();
|
|
|
|
DateTime inizio = DateTime.Now;
|
|
while (numSent < num2send)
|
|
{
|
|
//commLib = new DataSyncro(servAddr, commToken, 5000);
|
|
sw.Restart();
|
|
res = false;
|
|
var currList = recList
|
|
.Skip(numSent)
|
|
.Take(batchSize)
|
|
.ToList();
|
|
// converto il blocco
|
|
var listDto = currList
|
|
.Select(x => LogMachineController.ConvToItemDto(x))
|
|
.ToList();
|
|
// invio!
|
|
try
|
|
{
|
|
//res = commLib.LogMachineSend(listDto);
|
|
res = await commLib.LogMachineSendAsync(listDto);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Console.WriteLine(exc);
|
|
}
|
|
if (res)
|
|
{
|
|
// registro dati inviati...
|
|
lmc.SetDtSent(currList);
|
|
sw.Stop();
|
|
Console.WriteLine($"Inviati {batchSize}rec | {numSent} --> {numSent + batchSize} | elapsed {sw.Elapsed.TotalSeconds:N3} sec");
|
|
}
|
|
else
|
|
{
|
|
sw.Stop();
|
|
Console.WriteLine($"Errore in invio logMacchina, attesa 150ms | elapsed {sw.Elapsed.TotalSeconds:N3} sec");
|
|
await Task.Delay(150);
|
|
}
|
|
numSent += batchSize;
|
|
}
|
|
var durTot = DateTime.Now.Subtract(inizio);
|
|
Console.WriteLine($"Durata totale: {durTot.TotalSeconds:N3} sec");
|
|
Console.WriteLine(sep);
|
|
Console.WriteLine();
|
|
if (durTot.TotalSeconds > 1.5)
|
|
{
|
|
await Task.Delay(250);
|
|
}
|
|
}
|
|
Console.WriteLine("Enter to close");
|
|
answ = Console.ReadLine();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |