236 lines
8.7 KiB
C#
236 lines
8.7 KiB
C#
using EgwProxy.Icoel;
|
|
using EgwProxy.Icoel.SizerService;
|
|
using IOB_UT_NEXT;
|
|
using MapoSDK;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.NetworkInformation;
|
|
|
|
namespace IOB_WIN_NEXT
|
|
{
|
|
/// <summary>
|
|
/// Adapter specializzato per ICOEL e le chiamate tramite WS Soap al Sizer, con libreria EgwProxy.Icoel
|
|
/// </summary>
|
|
public class IobIcoelSoap : IobGeneric
|
|
{
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Costruttore dell'IOB Icoel SOAP
|
|
/// </summary>
|
|
/// <param name="caller">AdapterForm chiamante</param>
|
|
/// <param name="IOBConf">Configurazione IOB per avvio</param>
|
|
public IobIcoelSoap(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
|
{
|
|
/* --------------------------------------
|
|
* todo's
|
|
* --------------------------------------
|
|
* - init obj comunicazione da conf e nuget
|
|
* - test comunicazione
|
|
* - estensione IOB come OPT_PAR di OVERRIDE (x inviare dati di un unico iOB da più IOB programs)
|
|
* - gestione processCustomTaskLF
|
|
* - x lettura dei 2 batch correnti (sx/dx)
|
|
* - calcolo batch in corso/chiusi da date inizio/fine
|
|
* - trasmettere a MP/IO risultato valutazioni
|
|
* - gestione executeTasks
|
|
* - task di invio batch configurato in coda
|
|
* - task di recupero info anagrafiche (grower, variety, layout,...)
|
|
* - contapezzi (SE ha senso con sizer oppure saltare)
|
|
*/
|
|
|
|
IcoelSizer = new Connector(IOBConf.cncIpAddr, IOBConf.cncPort);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua lettura semafori principale
|
|
/// <paramref name="currDispData">Parametri da aggiornare x display in form</paramref>
|
|
/// </summary>
|
|
public override void readSemafori(ref newDisplayData currDispData)
|
|
{
|
|
if (connectionOk)
|
|
{
|
|
B_input = 1;
|
|
currDispData.semIn = Semaforo.SV;
|
|
if (currBatchList != null)
|
|
{
|
|
// se ho batch NON chiusi (data = minValue) allora lavora
|
|
if (currBatchList[1].EndTime == DateTime.MinValue || currBatchList[1].EndTime == DateTime.MinValue)
|
|
{
|
|
B_input = 3;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
B_input = 0;
|
|
currDispData.semIn = Semaforo.SR;
|
|
}
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Implementazione custom esecuzione task specifici
|
|
/// </summary>
|
|
/// <param name="task2exe"></param>
|
|
/// <returns></returns>
|
|
public override Dictionary<string, string> executeTasks(Dictionary<string, string> task2exe)
|
|
{
|
|
/*---------------------------------------
|
|
* fixme todo fare !!!
|
|
* gestione execute task SPECIFICI x il sizer:
|
|
* - recupero anagrafice variety/layout (attivi)
|
|
* - recupero grower
|
|
* - invio batch da accodare
|
|
* - recupero dati da sizer (OVE disponibili)
|
|
* - recupero batch corrente (modalità force/resync?)
|
|
*
|
|
*---------------------------------------*/
|
|
|
|
return base.executeTasks(task2exe);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua processing CUSTOM x Icoel:
|
|
/// - recupera elenco batch delle 2 linee
|
|
/// - invia al sistema
|
|
/// </summary>
|
|
public override void processCustomTaskLF()
|
|
{
|
|
lgInfo($"Richiesto processCustomTaskLF");
|
|
var currBatch = IcoelSizer.GetCurrentBatch();
|
|
if (currBatch != null)
|
|
{
|
|
// verifico se i batch siano variati... e quindi da inviare...
|
|
bool doSend = (currBatchList == null || currBatchList.Count == 0);
|
|
if (currBatch.Count > 0 && !doSend)
|
|
{
|
|
foreach (var item in currBatch)
|
|
{
|
|
// se variato ID è cambiato
|
|
doSend = (currBatchList[item.Key].Id != item.Value.Id);
|
|
}
|
|
}
|
|
// se devo inviare impacchetto dati
|
|
if (doSend)
|
|
{
|
|
// accodo per invio...
|
|
accodaRawData(IOB_UT_NEXT.rawTransfType.IcoelBatch, currBatch);
|
|
currBatchList = currBatch;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Override connessione
|
|
/// </summary>
|
|
public override void tryConnect()
|
|
{
|
|
if (!connectionOk)
|
|
{
|
|
// controllo che il ping sia stato tentato almeno pingTestSec fa...
|
|
if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec"))
|
|
{
|
|
if (verboseLog || periodicLog)
|
|
{
|
|
lgInfo("IcoelSoap: ConnKO - tryConnect");
|
|
}
|
|
// in primis salvo data ping...
|
|
lastPING = DateTime.Now;
|
|
// se passa il ping faccio il resto...
|
|
if (testPingMachine == IPStatus.Success)
|
|
{
|
|
string szStatusConnection = "";
|
|
try
|
|
{
|
|
// ora provo connessione...
|
|
parentForm.commPlcActive = true;
|
|
// recupero elenco batch... se != vuoto -_> connesso!
|
|
var batchList = IcoelSizer.GetCurrentBatch();
|
|
if (batchList != null && batchList.Count > 0)
|
|
{
|
|
lgInfo($"szStatusConnection IcoelSoap, recuperato elenco di {batchList.Count} batch");
|
|
parentForm.commPlcActive = false;
|
|
connectionOk = true;
|
|
}
|
|
// refresh stato connessione!!!
|
|
if (connectionOk)
|
|
{
|
|
if (adpRunning)
|
|
{
|
|
lgInfo("Connessione OK");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lgError("Impossibile procedere, connessione mancante...");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgFatal($"Errore nella connessione all'adapter IcoelSoap: {szStatusConnection}{Environment.NewLine}{exc}");
|
|
connectionOk = false;
|
|
lgInfo($"Eccezione in TryConnect, Adapter IcoelSoap NON running, pausa di {utils.CRI("waitRecMSec")} msec prima di ulteriori tentativi di riconnessione");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// loggo no risposta ping ...
|
|
connectionOk = false;
|
|
if (verboseLog || periodicLog)
|
|
{
|
|
lgInfo($"Attenzione: IcoelSoap controllo PING fallito per IP {cIobConf.cncIpAddr}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
needRefresh = true;
|
|
}
|
|
}
|
|
|
|
public override void tryDisconnect()
|
|
{
|
|
// registro solo che è disconnesso
|
|
connectionOk = false;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// elenco dei BAtch correntemente caricati x testing variazione
|
|
/// </summary>
|
|
protected Dictionary<int, Batch> currBatchList { get; set; }
|
|
|
|
protected Connector IcoelSizer { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// recupera le variety ed i rispettivi layout e li invia al sistema MP/IO
|
|
/// </summary>
|
|
protected void refreshVarietyData()
|
|
{
|
|
///determina se recuperare SOLO varietà attive o tutte
|
|
bool soloAttive = false;
|
|
var varList = IcoelSizer.GetVarietyList(soloAttive);
|
|
if (varList != null && varList.Length > 0)
|
|
{
|
|
var varietyData = IcoelSizer.GetLayoutForVarietyList(varList);
|
|
// invio dai al server IO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |