Update x evitare errori clientWT

This commit is contained in:
Samuele Locatelli
2026-02-24 07:30:38 +01:00
parent c604fa9e26
commit 4ce2096f7e
9 changed files with 79 additions and 102 deletions
+61 -47
View File
@@ -326,7 +326,7 @@ namespace IOB_UT_NEXT
/// <param name="URL"></param>
/// <param name="ct"></param>
/// <returns></returns>
public static async Task<string> callUrlAsync(string URL,CancellationToken ct = default)
public static async Task<string> 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
}
/// <summary>
@@ -985,6 +997,7 @@ namespace IOB_UT_NEXT
#region Protected Properties
#if false
/// <summary>
/// Oggetto WebClient BASE da riutilizzare
/// </summary>
@@ -993,7 +1006,8 @@ namespace IOB_UT_NEXT
/// <summary>
/// Oggetto WebClient con PAYLOAD da riutilizzare
/// </summary>
protected static WebClientWT clientPayload { get; set; }
protected static WebClientWT clientPayload { get; set; }
#endif
#endregion Protected Properties
+10 -49
View File
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
namespace IOB_UT_NEXT
@@ -12,10 +13,7 @@ namespace IOB_UT_NEXT
/// </summary>
public static string confDir
{
get
{
return string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, CRS("dataConfPath"));
}
get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("dataConfPath"));
}
/// <summary>
@@ -23,10 +21,7 @@ namespace IOB_UT_NEXT
/// </summary>
public static string dataDatDir
{
get
{
return string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, CRS("dataDatPath"));
}
get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("dataDatPath"));
}
/// <summary>
@@ -34,10 +29,7 @@ namespace IOB_UT_NEXT
/// </summary>
public static string dataDir
{
get
{
return string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, CRS("dataPath"));
}
get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("dataPath"));
}
/// <summary>
@@ -45,45 +37,15 @@ namespace IOB_UT_NEXT
/// </summary>
public static string defIconFilePath
{
get
{
return string.Format(@"{0}\SteamWare.ico", utils.resxDir);
}
get => Path.Combine(utils.resxDir, "SteamWare.ico");
}
#if false
/// <summary>
/// File persistenza generale
/// </summary>
public static string defPersLayerFile
{
get
{
return string.Format(@"{0}\{1}", utils.dataDatDir, utils.CRS("defaultPersLayerFile"));
}
}
/// <summary>
/// file persistenza generale
/// </summary>
public static string histPersLayerFile
{
get
{
return string.Format(@"{0}\{1:yyyy}\{1:yyyy-MM-dd}.mtc", utils.dataDatDir, DateTime.Now);
}
}
#endif
/// <summary>
/// File configurazione default x MAIN
/// </summary>
public static string mainConfFilePath
{
get
{
return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("mainConfFile"));
}
get=> Path.Combine(utils.confDir, utils.CRS("mainConfFile"));
}
/// <summary>
@@ -91,10 +53,7 @@ namespace IOB_UT_NEXT
/// </summary>
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
/// <returns></returns>
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;
}
/// <summary>
+1 -1
View File
@@ -19,4 +19,4 @@ CLI_INST=SteamWareSim
;STARTLIST=IMI_SONATEST
STARTLIST=FTP_SONATEST
MAXCNC=10
MAXCNC=10
+1 -1
View File
@@ -25,4 +25,4 @@ CLI_INST=SteamWareSim
STARTLIST=FOV062
;STARTLIST=SIMUL_01
MAXCNC=10
MAXCNC=10
+1 -1
View File
@@ -31,4 +31,4 @@ CLI_INST=SteamWareSim
STARTLIST=1042
;STARTLIST=2016
MAXCNC=10
MAXCNC=10
+1 -1
View File
@@ -19,4 +19,4 @@ STARTLIST=SIMUL_08
;STARTLIST=3024-PING
;STARTLIST=3023-PING,3024-PING
MAXCNC=10
MAXCNC=10
+2
View File
@@ -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
+1 -1
View File
@@ -38,4 +38,4 @@ CLI_INST=SteamWareSim
STARTLIST=PIZ03
;STARTLIST=iBTB1P
MAXCNC=10
MAXCNC=10
+1 -1
View File
@@ -23,4 +23,4 @@ CLI_INST=SteamWareSim
;STARTLIST=3019
STARTLIST=SIMUL_06
MAXCNC=10
MAXCNC=10