From 4ce2096f7e083f0965a71cf275972c4a11ab8bc9 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 24 Feb 2026 07:30:38 +0100 Subject: [PATCH] Update x evitare errori clientWT --- IOB-UT-NEXT/baseUtils.cs | 108 ++++++++++++++++------------- IOB-UT-NEXT/utils.cs | 59 +++------------- IOB-WIN-FTP/DATA/CONF/MAIN.ini | 2 +- IOB-WIN-MTC/DATA/CONF/MAIN.ini | 2 +- IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini | 2 +- IOB-WIN-PING/DATA/CONF/MAIN.ini | 2 +- IOB-WIN-SHELLY/DATA/CONF/MAIN.ini | 2 + IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini | 2 +- IOB-WIN-WPS/DATA/CONF/MAIN.ini | 2 +- 9 files changed, 79 insertions(+), 102 deletions(-) diff --git a/IOB-UT-NEXT/baseUtils.cs b/IOB-UT-NEXT/baseUtils.cs index 159da62a..3346c9b4 100644 --- a/IOB-UT-NEXT/baseUtils.cs +++ b/IOB-UT-NEXT/baseUtils.cs @@ -326,7 +326,7 @@ namespace IOB_UT_NEXT /// /// /// - public static async Task callUrlAsync(string URL,CancellationToken ct = default) + public static async Task callUrlAsync(string URL, CancellationToken ct = default) { try { @@ -359,32 +359,37 @@ namespace IOB_UT_NEXT public static string callUrlNow(string URL) { string answ = ""; +#if false if (client == null) { client = new WebClientWT(); - } - client.Headers.Add("user-agent", $"{CRS("appName")}"); - try + } +#endif + using (WebClient client = new WebClient()) { - // problema certificati locali... - // https://living-sun.com/it/c/226351-webexception-could-not-establish-trust-relationship-for-the-ssl-tls-secure-channel-c-aspnet-web-services-ssl-webexception.html - // hack x certificati locali in 10.74.82.* - if (URL.Contains("10.74.82.")) + client.Headers.Add("user-agent", CRS("appName")); + try { - System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return true; }; + // problema certificati locali... + // https://living-sun.com/it/c/226351-webexception-could-not-establish-trust-relationship-for-the-ssl-tls-secure-channel-c-aspnet-web-services-ssl-webexception.html + // hack x certificati locali in 10.74.82.* + if (URL.Contains("10.74.82.")) + { + System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return true; }; + } + answ = client.DownloadString(URL); } - answ = client.DownloadString(URL); - } - catch (Exception exc) - { - // imposto veto - int pauseSendMSec = nextPauseSendMSec; - dtVetoSend = DateTime.Now.AddMilliseconds(pauseSendMSec); - - // controllo log permesso... - if (logValuePermit(URL)) + catch (Exception exc) { - lg.Error($"Errore in callURL verso {URL}: impostato attesa di {pauseSendMSec} ms prima della prossima chiamata{Environment.NewLine}Eccezione:{Environment.NewLine}{exc}"); + // imposto veto + int pauseSendMSec = nextPauseSendMSec; + dtVetoSend = DateTime.Now.AddMilliseconds(pauseSendMSec); + + // controllo log permesso... + if (logValuePermit(URL)) + { + lg.Error($"Errore in callURL verso {URL}: impostato attesa di {pauseSendMSec} ms prima della prossima chiamata{Environment.NewLine}Eccezione:{Environment.NewLine}{exc}"); + } } } // restituisco valore! @@ -400,40 +405,45 @@ namespace IOB_UT_NEXT public static string callUrlNow(string URL, string payload) { string answ = ""; +#if false if (clientPayload == null) { clientPayload = new WebClientWT(); - } - clientPayload.Headers.Add("user-agent", $"{CRS("appName")}-PAYLOAD"); - clientPayload.Headers.Add("Content-ContextType", "application/json"); - try + } +#endif + using (WebClient clientPayload = new WebClient()) { - // problema certificati locali... - // https://living-sun.com/it/c/226351-webexception-could-not-establish-trust-relationship-for-the-ssl-tls-secure-channel-c-aspnet-web-services-ssl-webexception.html - // hack x certificati locali in 10.74.* - if (URL.Contains("10.74.")) + clientPayload.Headers.Add("user-agent", $"{CRS("appName")}-PAYLOAD"); + clientPayload.Headers.Add("Content-ContextType", "application/json"); + try { - System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return true; }; - } - answ = clientPayload.UploadString(URL, payload); - if (answ != "OK") - { - // controllo log permesso... - if (logValuePermit($"{URL}|[{answ}]")) + // problema certificati locali... + // https://living-sun.com/it/c/226351-webexception-could-not-establish-trust-relationship-for-the-ssl-tls-secure-channel-c-aspnet-web-services-ssl-webexception.html + // hack x certificati locali in 10.74.* + if (URL.Contains("10.74.")) { - lg.Error($"Invio dati fallito, ricevuto messaggio [{answ}]:{Environment.NewLine}- URL{Environment.NewLine}{URL}{Environment.NewLine}- payload{Environment.NewLine}{payload}"); + System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return true; }; + } + answ = clientPayload.UploadString(URL, payload); + if (answ != "OK") + { + // controllo log permesso... + if (logValuePermit($"{URL}|[{answ}]")) + { + lg.Error($"Invio dati fallito, ricevuto messaggio [{answ}]:{Environment.NewLine}- URL{Environment.NewLine}{URL}{Environment.NewLine}- payload{Environment.NewLine}{payload}"); + } } } - } - catch (Exception exc) - { - // imposto veto - int pauseSendMSec = nextPauseSendMSec; - dtVetoSend = DateTime.Now.AddMilliseconds(pauseSendMSec); - // controllo log permesso... - if (logValuePermit(URL)) + catch (Exception exc) { - lg.Error($"Errore in callURL con PAYLOAD verso {URL}: impostato attesa di {pauseSendMSec} ms prima della prossima chiamata. Dump Payload:{Environment.NewLine}{payload}{Environment.NewLine}Eccezione:{Environment.NewLine}{exc}"); + // imposto veto + int pauseSendMSec = nextPauseSendMSec; + dtVetoSend = DateTime.Now.AddMilliseconds(pauseSendMSec); + // controllo log permesso... + if (logValuePermit(URL)) + { + lg.Error($"Errore in callURL con PAYLOAD verso {URL}: impostato attesa di {pauseSendMSec} ms prima della prossima chiamata. Dump Payload:{Environment.NewLine}{payload}{Environment.NewLine}Eccezione:{Environment.NewLine}{exc}"); + } } } // restituisco valore! @@ -770,9 +780,11 @@ namespace IOB_UT_NEXT public static void resetWebClients() { +#if false // resetto i webclients... client = new WebClientWT(); - clientPayload = new WebClientWT(); + clientPayload = new WebClientWT(); +#endif } /// @@ -985,6 +997,7 @@ namespace IOB_UT_NEXT #region Protected Properties +#if false /// /// Oggetto WebClient BASE da riutilizzare /// @@ -993,7 +1006,8 @@ namespace IOB_UT_NEXT /// /// Oggetto WebClient con PAYLOAD da riutilizzare /// - protected static WebClientWT clientPayload { get; set; } + protected static WebClientWT clientPayload { get; set; } +#endif #endregion Protected Properties diff --git a/IOB-UT-NEXT/utils.cs b/IOB-UT-NEXT/utils.cs index 2608640e..8c46fff2 100644 --- a/IOB-UT-NEXT/utils.cs +++ b/IOB-UT-NEXT/utils.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; namespace IOB_UT_NEXT @@ -12,10 +13,7 @@ namespace IOB_UT_NEXT /// public static string confDir { - get - { - return string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, CRS("dataConfPath")); - } + get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("dataConfPath")); } /// @@ -23,10 +21,7 @@ namespace IOB_UT_NEXT /// public static string dataDatDir { - get - { - return string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, CRS("dataDatPath")); - } + get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("dataDatPath")); } /// @@ -34,10 +29,7 @@ namespace IOB_UT_NEXT /// public static string dataDir { - get - { - return string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, CRS("dataPath")); - } + get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("dataPath")); } /// @@ -45,45 +37,15 @@ namespace IOB_UT_NEXT /// public static string defIconFilePath { - get - { - return string.Format(@"{0}\SteamWare.ico", utils.resxDir); - } + get => Path.Combine(utils.resxDir, "SteamWare.ico"); } -#if false - /// - /// File persistenza generale - /// - public static string defPersLayerFile - { - get - { - return string.Format(@"{0}\{1}", utils.dataDatDir, utils.CRS("defaultPersLayerFile")); - } - } - - /// - /// file persistenza generale - /// - public static string histPersLayerFile - { - get - { - return string.Format(@"{0}\{1:yyyy}\{1:yyyy-MM-dd}.mtc", utils.dataDatDir, DateTime.Now); - } - } -#endif - /// /// File configurazione default x MAIN /// public static string mainConfFilePath { - get - { - return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("mainConfFile")); - } + get=> Path.Combine(utils.confDir, utils.CRS("mainConfFile")); } /// @@ -91,10 +53,7 @@ namespace IOB_UT_NEXT /// public static string resxDir { - get - { - return string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, CRS("resxPath")); - } + get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("resxPath")); } #endregion Public Properties @@ -108,7 +67,9 @@ namespace IOB_UT_NEXT /// public static string prevPersLayerFile(int numDD) { - return string.Format(@"{0}\{1:yyyy}\{1:yyyy-MM-dd}.mtc", utils.dataDatDir, DateTime.Now.AddDays(-numDD)); + var dtRif = DateTime.Now.AddDays(-numDD); + string calcPath = Path.Combine(utils.dataDatDir, $"{dtRif:yyyy}",$"{dtRif:yyyy-MM-dd}.mtc"); + return calcPath; } /// diff --git a/IOB-WIN-FTP/DATA/CONF/MAIN.ini b/IOB-WIN-FTP/DATA/CONF/MAIN.ini index 1494af89..ebc0bef6 100644 --- a/IOB-WIN-FTP/DATA/CONF/MAIN.ini +++ b/IOB-WIN-FTP/DATA/CONF/MAIN.ini @@ -19,4 +19,4 @@ CLI_INST=SteamWareSim ;STARTLIST=IMI_SONATEST STARTLIST=FTP_SONATEST -MAXCNC=10 \ No newline at end of file +MAXCNC=10 diff --git a/IOB-WIN-MTC/DATA/CONF/MAIN.ini b/IOB-WIN-MTC/DATA/CONF/MAIN.ini index 83a3970a..1bb98dca 100644 --- a/IOB-WIN-MTC/DATA/CONF/MAIN.ini +++ b/IOB-WIN-MTC/DATA/CONF/MAIN.ini @@ -25,4 +25,4 @@ CLI_INST=SteamWareSim STARTLIST=FOV062 ;STARTLIST=SIMUL_01 -MAXCNC=10 \ No newline at end of file +MAXCNC=10 diff --git a/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini b/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini index 60f333fd..1a07197f 100644 --- a/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini +++ b/IOB-WIN-OPC-UA/DATA/CONF/MAIN.ini @@ -31,4 +31,4 @@ CLI_INST=SteamWareSim STARTLIST=1042 ;STARTLIST=2016 -MAXCNC=10 \ No newline at end of file +MAXCNC=10 diff --git a/IOB-WIN-PING/DATA/CONF/MAIN.ini b/IOB-WIN-PING/DATA/CONF/MAIN.ini index 79d8004e..ab68298b 100644 --- a/IOB-WIN-PING/DATA/CONF/MAIN.ini +++ b/IOB-WIN-PING/DATA/CONF/MAIN.ini @@ -19,4 +19,4 @@ STARTLIST=SIMUL_08 ;STARTLIST=3024-PING ;STARTLIST=3023-PING,3024-PING -MAXCNC=10 \ No newline at end of file +MAXCNC=10 diff --git a/IOB-WIN-SHELLY/DATA/CONF/MAIN.ini b/IOB-WIN-SHELLY/DATA/CONF/MAIN.ini index 68993cad..a26f68cf 100644 --- a/IOB-WIN-SHELLY/DATA/CONF/MAIN.ini +++ b/IOB-WIN-SHELLY/DATA/CONF/MAIN.ini @@ -24,5 +24,7 @@ CLI_INST=SteamWareSim ;STARTLIST=SIMUL_05_SHELLY ;STARTLIST=i727_SHELLY STARTLIST=SIMUL_03_SHELLY +STARTLIST=SIMUL_03_SHELLY +STARTLIST=SIMUL_03_SHELLY MAXCNC=10 \ No newline at end of file diff --git a/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini b/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini index ca1f0fe1..aeb1fb44 100644 --- a/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini +++ b/IOB-WIN-SIEMENS/DATA/CONF/MAIN.ini @@ -38,4 +38,4 @@ CLI_INST=SteamWareSim STARTLIST=PIZ03 ;STARTLIST=iBTB1P -MAXCNC=10 \ No newline at end of file +MAXCNC=10 diff --git a/IOB-WIN-WPS/DATA/CONF/MAIN.ini b/IOB-WIN-WPS/DATA/CONF/MAIN.ini index bcdc49a2..f9bc9700 100644 --- a/IOB-WIN-WPS/DATA/CONF/MAIN.ini +++ b/IOB-WIN-WPS/DATA/CONF/MAIN.ini @@ -23,4 +23,4 @@ CLI_INST=SteamWareSim ;STARTLIST=3019 STARTLIST=SIMUL_06 -MAXCNC=10 \ No newline at end of file +MAXCNC=10