completata modifica x invio con payload in blocco, DA TESTARE!!!

This commit is contained in:
Samuele E. Locatelli
2019-11-02 16:51:53 +01:00
parent 739c6fc339
commit db06dce755
3 changed files with 61 additions and 7 deletions
Binary file not shown.
+56 -1
View File
@@ -16,7 +16,7 @@ namespace IOB_UT
{
/// <summary>
/// Override metodo WebCLient con gesitone TimeOut corto
/// Override metodo WebClient con gesitone TimeOut corto
/// </summary>
public class WebClientWT : WebClient
{
@@ -518,13 +518,68 @@ namespace IOB_UT
}
return answ;
}
/// <summary>
/// Effettua chiamata URL e restituisce risultato
/// </summary>
/// <param name="URL"></param>
/// <param name="payload"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Versione async della chiamata ad URL
/// </summary>
/// <param name="URL"></param>
/// <returns></returns>
public static string callUrlAsync(string URL)
{
// Chiamo in modalità task...
var resp = TaskEx.Run(() => callUrl(URL));
return resp.Result;
}
/// <summary>
/// Versione async della chiamata ad URL
/// </summary>
/// <param name="URL"></param>
/// <param name="payload"></param>
/// <returns></returns>
public static string callUrlAsync(string URL, string payload)
{
// Chiamo in modalità task...
var resp = TaskEx.Run(() => callUrl(URL, payload));
return resp.Result;
}
/// <summary>
/// provvede a verificare la dim della cartella dei log e cancella i + vecchi fino a restare a dim inferiori a _logMaxMb
+5 -6
View File
@@ -1983,19 +1983,16 @@ namespace IOB_WIN
/// <returns></returns>
public string callUrlWithPayload(string URL, string payload, bool doAsync)
{
//!!!FUXME!!!
string answ = "";
// Chiamata ASINCRONA
if (doAsync)
{
//Task<string> 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