From 6d439106bfeac7a4ebf195a4e4a3892dc3afc44b Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Mon, 4 Nov 2019 12:36:55 +0100 Subject: [PATCH] =?UTF-8?q?Miglioramenti=20check=20online=20MP7IO=20e=20IO?= =?UTF-8?q?B=20x=20migliorare=20fluidit=C3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IOB-UT/baseUtils.cs | 8 ++++ IOB-WIN/AdapterForm.cs | 4 +- IOB-WIN/DATA/CONF/MAIN.ini | 1 - IOB-WIN/IobGeneric.cs | 42 ++++++++++++++--- IOB-WIN/MainForm.cs | 92 +++++++++++++++++++++++++++++++++----- Jenkinsfile | 2 +- 6 files changed, 127 insertions(+), 22 deletions(-) diff --git a/IOB-UT/baseUtils.cs b/IOB-UT/baseUtils.cs index 9cdd0859..097de556 100644 --- a/IOB-UT/baseUtils.cs +++ b/IOB-UT/baseUtils.cs @@ -46,6 +46,14 @@ namespace IOB_UT public class baseUtils { + /// + /// Variabile in cui viene salvato lo stato del server MP-IO + /// + public static bool MPIO_Online = false; + /// + /// Indicazione VETO PING a server sino alla data-ora indicata + /// + public static DateTime dtVetoPing = DateTime.Now; /// /// Indicazione VETO invio a server sino alla data-ora indicata /// diff --git a/IOB-WIN/AdapterForm.cs b/IOB-WIN/AdapterForm.cs index 011fae7c..bd35b0b5 100644 --- a/IOB-WIN/AdapterForm.cs +++ b/IOB-WIN/AdapterForm.cs @@ -55,11 +55,11 @@ namespace IOB_WIN /// /// Oggetto x gestione dell'adapter GENERICO (x poter usare metodi di ognuno...) /// - IobGeneric iobObj; + public IobGeneric iobObj; /// /// configurazione caricata /// - IobConfiguration IOBConf; + public IobConfiguration IOBConf; /// /// tipo di adapter prescelto... /// diff --git a/IOB-WIN/DATA/CONF/MAIN.ini b/IOB-WIN/DATA/CONF/MAIN.ini index 5327409f..58d9bc02 100644 --- a/IOB-WIN/DATA/CONF/MAIN.ini +++ b/IOB-WIN/DATA/CONF/MAIN.ini @@ -9,7 +9,6 @@ NAME=master ;MPIP=192.168.214.4 ; Server Steamware MPIP=10.74.82.218 - MPURL=/MP/IO CMDREBO=/IOB/sendRebootGateway?GWIP= CMDIOB2CALL=/IOB/getIob2call?GWIP= diff --git a/IOB-WIN/IobGeneric.cs b/IOB-WIN/IobGeneric.cs index 937bd013..4bcc5872 100644 --- a/IOB-WIN/IobGeneric.cs +++ b/IOB-WIN/IobGeneric.cs @@ -34,7 +34,17 @@ namespace IOB_WIN /// /// Indicazione VETO invio a server sino alla data-ora indicata /// - public static DateTime dtVetoPing = DateTime.Now; + public static DateTime dtVetoPing + { + get + { + return utils.dtVetoPing; + } + set + { + utils.dtVetoPing = value; + } + } /// /// Indicazione VETO check status IOB x evitare loop troppo stretti... /// @@ -350,9 +360,19 @@ namespace IOB_WIN /// public bool IobOnline; /// - /// stato Online/Offline del server MP IO + /// stato Online/Offline del server MP IO (su utils condiviso) /// - public bool MPOnline; + public bool MPOnline + { + get + { + return utils.MPIO_Online; + } + set + { + utils.MPIO_Online = value; + } + } /// /// Dizionario di VC da trattare come TimeSeries (con conf decodificata + processing successivo...) /// @@ -2143,8 +2163,7 @@ namespace IOB_WIN { lgInfo("SERVER ONLINE"); parentForm.commSrvActive = 1; - dtVetoPing = DateTime.Now.AddMinutes(-5); - utils.dtVetoSend = DateTime.Now.AddMinutes(-5); + dtVetoPing = DateTime.Now.AddMilliseconds(baseUtils.nextPauseSendMSec); } else { @@ -2154,6 +2173,11 @@ namespace IOB_WIN // salvo nuovo status... MPOnline = answ; } + else + { + // allungo periodo controllo... + dtVetoPing = DateTime.Now.AddMilliseconds(baseUtils.nextPauseSendMSec * 2); + } } else { @@ -2193,7 +2217,8 @@ namespace IOB_WIN try { // chiamo URL, se restituisce "OK" è enabled! - answ = (callUrl(urlIobEnabled, true) == "OK"); + string callResp = callUrl(urlIobEnabled, false); + answ = (callResp == "OK"); // salvo status... IobOnline = answ; // se offline imposto veto check a 5 x tempo reinvio... @@ -2201,6 +2226,11 @@ namespace IOB_WIN { dtVetoCheckIOB = DateTime.Now.AddMilliseconds(baseUtils.nextPauseSendMSec * 5); } + else + { + // non controllo x meno... + dtVetoCheckIOB = DateTime.Now.AddMilliseconds(baseUtils.nextPauseSendMSec * 1); + } } catch { } diff --git a/IOB-WIN/MainForm.cs b/IOB-WIN/MainForm.cs index 3a37439f..4cc7de20 100644 --- a/IOB-WIN/MainForm.cs +++ b/IOB-WIN/MainForm.cs @@ -78,11 +78,12 @@ namespace IOB_WIN /// Mostra update delle statistiche di comunicazione (num plc connessi, indirizzo server) con colore ad indicare anomalie... /// /// + /// /// - public void updateComStats(int numPLC, bool serverOk) + public void updateComStats(int numPLC, int numAttivi, bool serverOk) { // testo - lblComStats.Text = string.Format("{0} PLC --> {1} (MP/IO)", numPLC, MPIP); + lblComStats.Text = $"{numAttivi}/{numPLC} PLC --> {MPIP} (MP/IO)"; // colore secondo valori... server !="ND" è ok, PLC > 0 è OK int score = 0; if (serverOk) @@ -345,7 +346,7 @@ namespace IOB_WIN IPAddress.TryParse(ipAdrr, out address); try { - reply = pingSender.Send(address, 100); + reply = pingSender.Send(address, 200); answ = reply.Status; } catch (Exception exc) @@ -424,33 +425,99 @@ namespace IOB_WIN lastComCheck = DateTime.Now; // conta quanti child form di adapter verso PLC siano aperti !!!FARE!!! chiedere con un metodo che siano ATTIVI e contare quello... int numPLC = this.MdiChildren.Count
(); + int numAttivi = 0; + foreach (var item in this.MdiChildren) + { + try + { + var currForm = (AdapterForm)item; + numAttivi += currForm.iobObj.IobOnline ? 1 : 0; + } + catch + { } + } // update stato! - updateComStats(numPLC, testServer); + updateComStats(numPLC, numAttivi, testServer); + } + } + /// + /// URL per check alive... + /// + public string urlAlive + { + get + { + return string.Format(@"http://{0}{1}/IOB", MPIP, MPURL); } } /// /// Verifica il server: esiste IP, risponde a ping, risponde a pagina ALIVE /// - protected bool testServer + public bool testServer { get { bool answ = false; - // check server: indirizzo esiste if (MPIP != "") { - IPAddress address = IPAddress.Loopback; - // check stato server (SOLO PING!) - IPAddress.TryParse(MPIP, out address); - if (address != IPAddress.Loopback) + if (utils.dtVetoPing < DateTime.Now) { - answ = utils.pingAddress(address); + IPStatus pingStatus = testPingServer; + // se passa il ping faccio il resto... + if (pingStatus == IPStatus.Success) + { + try + { + // chiamo URL, se restituisce "OK" è alive! + string callResp = utils.callUrl(urlAlive); + answ = (callResp == "OK"); + } + catch (Exception exc) + { + lgError($"Errore in checkServerAlive:{Environment.NewLine}{exc}"); + } + // verifico SE è variato stato online/offline... + if (utils.MPIO_Online != answ) + { + // se ORA sono online riporto... + if (answ) + { + lgInfo("SERVER ONLINE"); + utils.dtVetoPing = DateTime.Now.AddMilliseconds(baseUtils.nextPauseSendMSec); + } + else + { + lgInfo("SERVER OFFLINE"); + } + // salvo nuovo status... + utils.MPIO_Online = answ; + } + else + { + // allungo periodo controllo... + utils.dtVetoPing = DateTime.Now.AddMilliseconds(baseUtils.nextPauseSendMSec * 2); + } + } + else + { + lgInfo($"SERVER NOT RESPONDING (PING at {MPIP})"); + utils.MPIO_Online = false; + // imposto veto a 10 volte reinvio dati standard... + utils.dtVetoPing = DateTime.Now.AddMilliseconds(baseUtils.nextPauseSendMSec * 10); + utils.dtVetoSend = utils.dtVetoPing; + } + } + else + { + // altrimenti passo ultimo valore noto... + answ = utils.MPIO_Online; } } return answ; } } + #endregion #region gestione child form @@ -780,7 +847,6 @@ namespace IOB_WIN this.LayoutMdi(MdiLayout.TileHorizontal); } - #endregion private void minimizeALLToolStripMenuItem_Click(object sender, EventArgs e) { @@ -819,5 +885,7 @@ namespace IOB_WIN lgError($"Eccezione in show log (MAIN):{Environment.NewLine}{exc}"); } } + + #endregion } } diff --git a/Jenkinsfile b/Jenkinsfile index f29e4c0f..010dcead 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=488']) { + withEnv(['NEXT_BUILD_NUMBER=489']) { // env.versionNumber = VersionNumber(versionNumberString : '2.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '2.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO-IOB-WIN'