a2171e643d
- FTP - Gomba - Icoel - MultiCcn - OSAI - SqlDB
385 lines
15 KiB
C#
385 lines
15 KiB
C#
using EgwProxy.Icoel.DataLayer.DatabaseModels;
|
|
using EgwProxy.Icoel.SizerService;
|
|
//using EgwProxy.Icoel.Test.INI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Diagnostics;
|
|
|
|
namespace EgwProxy.Icoel.Test
|
|
{
|
|
internal class Program
|
|
{
|
|
#region Internal Methods
|
|
|
|
/// <summary>
|
|
/// Mostra tutte le metriche di performance ricevute
|
|
/// </summary>
|
|
/// <param name="perfMeter"></param>
|
|
internal static void DisplayPerfMeter(Dictionary<string, double> perfMeter)
|
|
{
|
|
// mostra tutti i parametri rilevati...
|
|
foreach (var item in perfMeter)
|
|
{
|
|
Console.WriteLine($"{item.Key} | {item.Value:N2}");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Mostra tutte le metriche di performance ricevute
|
|
/// </summary>
|
|
/// <param name="currData"></param>
|
|
internal static void DisplayCurrBatch(Dictionary<string, string> currData)
|
|
{
|
|
// mostra tutti i parametri rilevati...
|
|
foreach (var item in currData)
|
|
{
|
|
Console.WriteLine($"{item.Key} | {item.Value}");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Generazione di una list di info sui dati variety
|
|
/// </summary>
|
|
/// <param name="varietiesList"></param>
|
|
/// <returns></returns>
|
|
internal static void DisplayVariety(Variety[] varietyData)
|
|
{
|
|
foreach (var item in varietyData)
|
|
{
|
|
Console.WriteLine("--------------------------");
|
|
Console.WriteLine($"Variety Id: {item.Id} | Variety Name: {item.Name}");
|
|
Console.WriteLine(" - Qualities");
|
|
foreach (var quality in item.Qualities)
|
|
{
|
|
Console.WriteLine($" Name: {quality.Name}");
|
|
}
|
|
Console.WriteLine(" - Grades");
|
|
foreach (var grade in item.Grades)
|
|
{
|
|
Console.WriteLine($" Name: {grade.Name}");
|
|
}
|
|
Console.WriteLine(" - Sizes");
|
|
foreach (var size in item.SizingMaps)
|
|
{
|
|
Console.WriteLine($" Name: {size.Name}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generazione di una list di info sui dati variety
|
|
/// </summary>
|
|
/// <param name="varietiesList"></param>
|
|
/// <returns></returns>
|
|
internal static void DisplayVarietyLayout(Dictionary<Variety, Layout[]> varietyData)
|
|
{
|
|
foreach (var item in varietyData)
|
|
{
|
|
Console.WriteLine("--------------------------");
|
|
Console.WriteLine($"Variety Id: {item.Key.Id} | Variety Name: {item.Key.Name}");
|
|
Console.WriteLine(" - Qualities");
|
|
foreach (var quality in item.Key.Qualities)
|
|
{
|
|
Console.WriteLine($" Name: {quality.Name}");
|
|
}
|
|
Console.WriteLine(" - Grades");
|
|
foreach (var grade in item.Key.Grades)
|
|
{
|
|
Console.WriteLine($" Name: {grade.Name}");
|
|
}
|
|
Console.WriteLine(" - Sizes");
|
|
foreach (var size in item.Key.SizingMaps)
|
|
{
|
|
Console.WriteLine($" Name: {size.Name}");
|
|
}
|
|
Console.WriteLine(" - LAYOUTS");
|
|
foreach (var layout in item.Value)
|
|
{
|
|
Console.WriteLine($" Id: {layout.Id} | Name: {layout.Name}");
|
|
Console.WriteLine(" - Products");
|
|
foreach (var product in layout.Products)
|
|
{
|
|
Console.WriteLine($" Id: {product.Id} | Name: {product.Name} | DisplayName: {product.DisplayName} | Pack: {product.Pack}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mostra elenco variety e quanod utente seleziona restituisce varGuid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static Guid selLayout(Connector IcoelSizer, Guid varGuid)
|
|
{
|
|
int idxLay = -1;
|
|
Guid layGuid = Guid.NewGuid();
|
|
|
|
// recupero layout della varietà
|
|
var layoutList = IcoelSizer.GetLayoutForVariety(varGuid);
|
|
|
|
Console.WriteLine("--------------------");
|
|
Console.WriteLine("Layout disponibili:");
|
|
Console.WriteLine("--------------------");
|
|
DisplayLayout(layoutList);
|
|
// recupero layout x varietà
|
|
while (idxLay <= 0)
|
|
{
|
|
Console.WriteLine("");
|
|
Console.WriteLine("indicare layout");
|
|
var rawData = Console.ReadLine();
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
int.TryParse(rawData, out idxLay);
|
|
// verifico sia valida..
|
|
if (layoutList.Length >= idxLay && idxLay > 0)
|
|
{
|
|
layGuid = layoutList[idxLay - 1].Id;
|
|
}
|
|
else
|
|
{
|
|
idxLay = -1;
|
|
}
|
|
}
|
|
}
|
|
return layGuid;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mostra elenco variety e quanod utente seleziona restituisce varGuid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static Guid selVariety(Connector IcoelSizer)
|
|
{
|
|
int idxVar = -1;
|
|
Guid varGuid = Guid.NewGuid();
|
|
var varList = IcoelSizer.GetVarietyList(true);
|
|
|
|
Console.WriteLine("--------------------");
|
|
Console.WriteLine("Varietà disponibili:");
|
|
Console.WriteLine("--------------------");
|
|
DisplayVariety(varList);
|
|
// chiedo di selezionare
|
|
while (idxVar <= 0)
|
|
{
|
|
Console.WriteLine("");
|
|
Console.WriteLine("indicare varietà richiesta (#)");
|
|
var rawData = Console.ReadLine();
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
int.TryParse(rawData, out idxVar);
|
|
// verifico sia valida..
|
|
if (varList.Length >= idxVar && idxVar > 0)
|
|
{
|
|
varGuid = varList[idxVar - 1].Id;
|
|
}
|
|
else
|
|
{
|
|
idxVar = -1;
|
|
}
|
|
}
|
|
}
|
|
return varGuid;
|
|
}
|
|
|
|
#endregion Internal Methods
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Generazione di una list di layout dato elenco
|
|
/// </summary>
|
|
/// <param name="layoutList"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
internal static void DisplayLayout(Layout[] layoutList)
|
|
{
|
|
foreach (var layout in layoutList)
|
|
{
|
|
Console.WriteLine($" Id: {layout.Id} | Name: {layout.Name}");
|
|
Console.WriteLine(" - Products");
|
|
foreach (var product in layout.Products)
|
|
{
|
|
Console.WriteLine($" Id: {product.Id} | Name: {product.Name} | DisplayName: {product.DisplayName} | Pack: {product.Pack}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// legge conf in formato stringa
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
protected static string ReadSetting(string key)
|
|
{
|
|
string answ = "";
|
|
try
|
|
{
|
|
answ = $"{ConfigurationManager.AppSettings[key]}" ?? "";
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Console.Write("Eccezione in ReadSettings");
|
|
Console.Write(exc.Message);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Programma principale
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
private static void Main(string[] args)
|
|
{
|
|
// leggo conf da file ini (ip/port)
|
|
Console.WriteLine("Loading Files...");
|
|
string userInput = "";
|
|
|
|
Console.WriteLine("------------ Test DB ------------");
|
|
EgwProxy.Icoel.DbProxy dbProxy = new DbProxy(ReadSetting("SyncState"));
|
|
Console.WriteLine();
|
|
Console.WriteLine("--- SyncState ---");
|
|
bool needRedo = true;
|
|
int numTry = 1;
|
|
//int numTry = 3;
|
|
var elencoSyncState = dbProxy.DataController.SyncStateGetAll();
|
|
while (needRedo && numTry >= 0)
|
|
{
|
|
Console.WriteLine(" --- PRE --- ");
|
|
if (elencoSyncState != null)
|
|
{
|
|
foreach (var item in elencoSyncState)
|
|
{
|
|
Console.WriteLine($"TAB: {item.TableName} | IdxIN / IdxLocal {item.LastIdxIn} / {item.LastIdx} | NumIn / NumLocal {item.NumRecIn} / {item.NumRec}");
|
|
// verifico se serva redo..
|
|
}
|
|
}
|
|
Console.WriteLine();
|
|
Console.WriteLine("Premere un tasto x continuare...");
|
|
Console.ReadKey();
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
elencoSyncState = dbProxy.DataController.SyncStateDoImportAll();
|
|
sw.Stop();
|
|
Console.WriteLine($" process time: {sw.ElapsedMilliseconds} ms ");
|
|
Console.WriteLine(" --- POST --- ");
|
|
if (elencoSyncState != null)
|
|
{
|
|
foreach (var item in elencoSyncState)
|
|
{
|
|
Console.WriteLine($"TAB: {item.TableName} | IdxIN / IdxLocal {item.LastIdxIn} / {item.LastIdx} | NumIn / NumLocal {item.NumRecIn} / {item.NumRec}");
|
|
// verifico se serva redo..
|
|
}
|
|
}
|
|
// processo
|
|
needRedo = testNeedRedo(elencoSyncState);
|
|
numTry--;
|
|
}
|
|
Console.WriteLine();
|
|
Console.WriteLine("Premere un tasto x continuare...");
|
|
Console.ReadKey();
|
|
|
|
// oggetto x connessione al sizer icoel
|
|
Connector IcoelSizer = new Connector(ReadSetting("IndirizzoIpSizer"), ReadSetting("SizerTcpPort"));
|
|
//Connector IcoelSizer = new Connector(setup.IndirizzoIpSizer, setup.SizerTcpPort);
|
|
|
|
Console.WriteLine("------------ Parametri CurrBatch rilevati ------------");
|
|
var cBatch = IcoelSizer.GetCurrBatchData();
|
|
if (cBatch != null)
|
|
{
|
|
DisplayCurrBatch(cBatch);
|
|
}
|
|
|
|
// ora effettua un pò di letture/scritture
|
|
try
|
|
{
|
|
|
|
Console.WriteLine("------------ TUTTE variety ------------");
|
|
var varList = IcoelSizer.GetVarietyList(false);
|
|
var varietyData = IcoelSizer.GetLayoutForVarietyList(varList);
|
|
if (varietyData != null)
|
|
{
|
|
DisplayVarietyLayout(varietyData);
|
|
}
|
|
Console.WriteLine();
|
|
Console.WriteLine("Premere un tasto x continuare...");
|
|
userInput = Console.ReadLine();
|
|
|
|
|
|
Console.WriteLine("------------ Parametri velocità rilevati ------------");
|
|
var perfMeter = IcoelSizer.GetPerfMeters();
|
|
if (perfMeter != null)
|
|
{
|
|
DisplayPerfMeter(perfMeter);
|
|
}
|
|
Console.WriteLine();
|
|
Console.WriteLine("Premere un tasto x continuare...");
|
|
userInput = Console.ReadLine();
|
|
|
|
// solo attive
|
|
Console.WriteLine("------------ solo attive ------------");
|
|
varList = IcoelSizer.GetVarietyList();
|
|
varietyData = IcoelSizer.GetLayoutForVarietyList(varList);
|
|
if (varietyData != null)
|
|
{
|
|
DisplayVarietyLayout(varietyData);
|
|
}
|
|
Console.WriteLine();
|
|
Console.WriteLine("Premere un tasto x continuare...");
|
|
userInput = Console.ReadLine();
|
|
|
|
Console.WriteLine("------------ BATCH correnti ------------");
|
|
var currBatch = IcoelSizer.GetCurrentBatch();
|
|
foreach (var item in currBatch)
|
|
{
|
|
string lato = item.Key == 1 ? "SX" : "DX";
|
|
Console.WriteLine($"[{item.Key}-{lato}] Grower code: {item.Value.GrowerCode} | Layout Name: {item.Value.LayoutName} | Totalling: [{item.Value.TotallingVarietyCode}] {item.Value.TotallingVariety} | Sizing: {item.Value.SizingProfileName} | Start {item.Value.StartTime} | End {item.Value.EndTime}");
|
|
}
|
|
Console.WriteLine();
|
|
Console.WriteLine("Premere un tasto x continuare...");
|
|
userInput = Console.ReadLine();
|
|
|
|
Console.WriteLine("------------ Prova invio BATCH ------------");
|
|
// recupero GUID x variety e layout
|
|
var varGuid = selVariety(IcoelSizer);
|
|
var layGuid = selLayout(IcoelSizer, varGuid);
|
|
|
|
GrowerInfo GrowerData = new GrowerInfo();
|
|
IcoelSizer.EnqueueBatch(GrowerData, varGuid, layGuid);
|
|
|
|
currBatch = IcoelSizer.GetCurrentBatch();
|
|
foreach (var item in currBatch)
|
|
{
|
|
string lato = item.Key == 1 ? "SX" : "DX";
|
|
Console.WriteLine($"[{item.Key}-{lato}] Grower code: {item.Value.GrowerCode} | Layout Name: {item.Value.LayoutName} | Totalling: [{item.Value.TotallingVarietyCode}] {item.Value.TotallingVariety} | Sizing: {item.Value.SizingProfileName} | Start {item.Value.StartTime} | End {item.Value.EndTime}");
|
|
}
|
|
Console.WriteLine("Test completato");
|
|
Console.WriteLine("Premere un tasto x chiudere");
|
|
Console.ReadKey();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("ECCEZIONE" + ex.Message + ex.StackTrace);
|
|
Console.ReadKey();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Verifico necessità di rifare sync
|
|
/// </summary>
|
|
/// <param name="elencoSyncState"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private static bool testNeedRedo(List<SyncStateModel> elencoSyncState)
|
|
{
|
|
bool answ = false;
|
|
foreach (var item in elencoSyncState)
|
|
{
|
|
answ = answ || (item.NumRecIn > item.NumRec || item.LastIdxIn > item.LastIdx);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |