From db06dce755c29ebb5c1afd07d18a31dacbeee1fe Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 2 Nov 2019 16:51:53 +0100 Subject: [PATCH] completata modifica x invio con payload in blocco, DA TESTARE!!! --- CVCncLib/testSam.dll | Bin 967680 -> 967680 bytes IOB-UT/baseUtils.cs | 57 +++++++++++++++++++++++++++++++++++++++++- IOB-WIN/IobGeneric.cs | 11 ++++---- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/CVCncLib/testSam.dll b/CVCncLib/testSam.dll index 4fa74bea4c4b6469b5e21602442775abb6342538..430d17709cce58bf0fb0aa80e2906c8ccda257b9 100644 GIT binary patch delta 150 zcmV;H0BQe#h&zCYJCKM2tfjqyi-n5;g^L1(ivxv=1ci$Qg^LD-iwA{^2!)FYg^LP> ziwm`j3^Ab)N`jhcb%uLFnY<^eAwRUxhs>c2hs>c3x6Gjq{0;-FrM;KSunrj{>v=*r zsr-&ks(AvA8eWcs0RR91Lpoelb7gXKTytSawKN;hWC7bwVf-ITK@H*Pk|v-UF!d4QOA` - /// Override metodo WebCLient con gesitone TimeOut corto + /// Override metodo WebClient con gesitone TimeOut corto /// public class WebClientWT : WebClient { @@ -518,13 +518,68 @@ namespace IOB_UT } return answ; } + /// + /// Effettua chiamata URL e restituisce risultato + /// + /// + /// + /// + public static string callUrl(string URL, string payload) + { + string answ = ""; + // controllo se ho un VETO all'invio... + if (dtVetoSend < DateTime.Now) + { + var client = new WebClientWT(); + //var client = new WebClient(); + client.Headers.Add("user-agent", CRS("appName")); + try + { + answ = client.UploadString(URL, payload); + } + catch (Exception exc) + { + // imposto veto + int pauseSendMSec = nextPauseSendMSec; + dtVetoSend = DateTime.Now.AddMilliseconds(pauseSendMSec); + // log ogni + lg.Info($"Errore in callURL con PAYLOAD verso {URL}: impostato attesa di {pauseSendMSec} ms prima della prossima chiamata"); + logReduxFactor--; + if (logReduxFactor <= 0) + { + lg.Error("Eccezione in esecuzione callURL: {0}{1}{2}", URL, Environment.NewLine, exc); + logReduxFactor = 10; + } + } + } + // restituisco valore! + return answ; + } + /// + /// Versione async della chiamata ad URL + /// + /// + /// public static string callUrlAsync(string URL) { // Chiamo in modalità task... var resp = TaskEx.Run(() => callUrl(URL)); return resp.Result; } + /// + /// Versione async della chiamata ad URL + /// + /// + /// + /// + public static string callUrlAsync(string URL, string payload) + { + // Chiamo in modalità task... + var resp = TaskEx.Run(() => callUrl(URL, payload)); + return resp.Result; + } + /// /// provvede a verificare la dim della cartella dei log e cancella i + vecchi fino a restare a dim inferiori a _logMaxMb diff --git a/IOB-WIN/IobGeneric.cs b/IOB-WIN/IobGeneric.cs index bf3e493a..4e8afa77 100644 --- a/IOB-WIN/IobGeneric.cs +++ b/IOB-WIN/IobGeneric.cs @@ -1983,19 +1983,16 @@ namespace IOB_WIN /// public string callUrlWithPayload(string URL, string payload, bool doAsync) { - //!!!FUXME!!! string answ = ""; // Chiamata ASINCRONA if (doAsync) { - //Task resp = utils.callUrlAsync(URL); - //answ = resp.Result; - answ = utils.callUrlAsync(URL); + answ = utils.callUrlAsync(URL, payload); } // chiamata SOLO NORMALE SINCRONA... else { - answ = utils.callUrl(URL); + answ = utils.callUrl(URL, payload); } return answ; } @@ -2896,6 +2893,8 @@ namespace IOB_WIN lastUrl = urlDataBlock(tipoUrl); // in base al tipo di dato compongo il payload Json da inviare string payload = jsonPayload(tipoUrl, listQueueVal); + // async a true SE FLog + bool doAsync = tipoUrl == urlType.FLog ? true : false; // se NON sono in demo effettuo invio! if (!DemoOut) { @@ -2903,7 +2902,7 @@ namespace IOB_WIN if (checkServerAlive) { // chiamo URL! - string answ = callUrlWithPayload(lastUrl, payload, false); + string answ = callUrlWithPayload(lastUrl, payload, doAsync); // loggo! lgInfo($"[SEND payload] {listQueueVal.Count} records --> {answ}"); // se "OK" verde, altrimenti errore --> ROSSO