Continuo pulizia metodi refusi
This commit is contained in:
@@ -4,6 +4,7 @@ using IOB_UT_NEXT.Services.Cache;
|
||||
using IOB_UT_NEXT.Services.Core;
|
||||
using IOB_UT_NEXT.Services.Data;
|
||||
using IOB_UT_NEXT.Services.Files;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -598,6 +599,11 @@ namespace IOB_UT_NEXT.Iob
|
||||
/// </summary>
|
||||
protected string JsonSerialize<T>(T obj) => IOB_UT_NEXT.Services.Data.DataSerializer.Serialize(obj);
|
||||
|
||||
/// <summary>
|
||||
/// Serializza un oggetto in formato JSON con opzioni serializzazione.
|
||||
/// </summary>
|
||||
protected string JsonSerialize<T>(T obj, Formatting reqFormat) => IOB_UT_NEXT.Services.Data.DataSerializer.Serialize(obj, reqFormat);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializza una stringa JSON in un oggetto.
|
||||
/// </summary>
|
||||
|
||||
@@ -23,6 +23,17 @@ namespace IOB_UT_NEXT.Services.Data
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializza un oggetto in una stringa JSON utilizzando la cultura invariante.
|
||||
/// </summary>
|
||||
public static string Serialize<T>(T obj, Formatting reqFormat)
|
||||
{
|
||||
if (obj == null) return null;
|
||||
// Utilizzo di CultureInfo.InvariantCulture per garantire la coerenza dei formati (es. decimali)
|
||||
return JsonConvert.SerializeObject(obj, reqFormat);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Deserializza una stringa JSON in un oggetto del tipo specificato.
|
||||
/// </summary>
|
||||
|
||||
@@ -111,41 +111,6 @@ namespace IOB_WIN_FILE.IobFile
|
||||
// ciclo!
|
||||
try
|
||||
{
|
||||
#if false
|
||||
// controllo SE il driver SIA attivo...
|
||||
if (driver != null)
|
||||
{
|
||||
string cKey = "";
|
||||
string cVal = "";
|
||||
// IPOTESI: un UNICO oggetto decodifica status
|
||||
if (monitoredItems.Status.Count == 1)
|
||||
{
|
||||
var item = monitoredItems.Status[0];
|
||||
// cerco elemento indicato
|
||||
element = driver.FindElement(By.Id(item.val));
|
||||
cKey = element.Text;
|
||||
// verifico se mancasse il mapping...
|
||||
if (!item.codeMapping.ContainsKey(cKey))
|
||||
{
|
||||
processUnknStatus(cKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ora decodifico da variabile status a valore secondo impostazione "codeMapping"
|
||||
cVal = item.codeMapping[cKey];
|
||||
B_input = int.Parse(cVal, System.Globalization.NumberStyles.HexNumber);
|
||||
if (currDispData != null)
|
||||
{
|
||||
currDispData.semIn = Semaforo.SV;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lgError("Errore: driver non pronto (null)");
|
||||
}
|
||||
#endif
|
||||
// riporto bitmap...
|
||||
reportRawInput(ref currDispData);
|
||||
}
|
||||
|
||||
+19
-19
@@ -1825,7 +1825,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
// conversione finale
|
||||
try
|
||||
{
|
||||
answ = JsonConvert.SerializeObject(fullFlObj);
|
||||
answ = JsonSerialize(fullFlObj);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
@@ -1856,7 +1856,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
// conversione finale
|
||||
try
|
||||
{
|
||||
answ = JsonConvert.SerializeObject(fullEvObj);
|
||||
answ = JsonSerialize(fullEvObj);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
@@ -1915,7 +1915,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
// conversione finale
|
||||
try
|
||||
{
|
||||
answ = JsonConvert.SerializeObject(fullUlObj);
|
||||
answ = JsonSerialize(fullUlObj);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
@@ -1942,11 +1942,11 @@ namespace IOB_WIN_FORM.Iob
|
||||
string rawVal = redisMan.redGetHashField(lastSendKey, keyReq);
|
||||
if (!string.IsNullOrEmpty(rawVal))
|
||||
{
|
||||
lastSend = DataSerializer.Deserialize<DateTime>(rawVal);
|
||||
lastSend = JsonDeserialize<DateTime>(rawVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
rawVal = DataSerializer.Serialize(lastSend);
|
||||
rawVal = JsonSerialize(lastSend);
|
||||
KeyValuePair<string, string>[] hashFields = new KeyValuePair<string, string>[1];
|
||||
hashFields[0] = new KeyValuePair<string, string>(keyReq, rawVal);
|
||||
redisMan.redSaveHash(lastSendKey, hashFields);
|
||||
@@ -1962,7 +1962,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
public bool LastSendSet(string keyReq, DateTime dtRif)
|
||||
{
|
||||
string lastSendKey = GetStatusField("LastSend");
|
||||
string rawVal = DataSerializer.Serialize(dtRif);
|
||||
string rawVal = JsonSerialize(dtRif);
|
||||
KeyValuePair<string, string>[] hashFields = new KeyValuePair<string, string>[1];
|
||||
hashFields[0] = new KeyValuePair<string, string>(keyReq, rawVal);
|
||||
bool fatto = redisMan.redSaveHash(lastSendKey, hashFields);
|
||||
@@ -5771,7 +5771,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
item.updStatusVal(i, (uint)(item.alarmsMask[i] & currStatus));
|
||||
// salvo in redis...
|
||||
string alarmHash = redisMan.redHash($"IOB:ALARM_STATUS:{IOBConfFull.General.FilenameIOB}:{item.memAddr}");
|
||||
string rawAlarms = JsonConvert.SerializeObject(item.alarmsState);
|
||||
string rawAlarms = JsonSerialize(item.alarmsState);
|
||||
redisMan.setRSV(alarmHash, rawAlarms);
|
||||
}
|
||||
else
|
||||
@@ -6439,7 +6439,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
// richiamo scrittura parametri su PLC
|
||||
plcWriteParams(ref updatedPar);
|
||||
// invio su cloud parametri!
|
||||
string rawData = JsonConvert.SerializeObject(updatedPar);
|
||||
string rawData = JsonSerialize(updatedPar);
|
||||
HttpService.CallUrl($"{urlUpdateWriteParams}", rawData);
|
||||
lgInfo($"Notifica a server scrittura {updatedPar.Count} parametri");
|
||||
}
|
||||
@@ -6642,7 +6642,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
// leggo contenuto XML
|
||||
string rawData = File.ReadAllText(recipeFile);
|
||||
// deserializza file XML x recuperare righe consumo
|
||||
var currRecipe = XmlDataSerializer.Deserialize<ARecipe>(rawData);
|
||||
var currRecipe = XmlDeserialize<ARecipe>(rawData);
|
||||
if (currRecipe != null)
|
||||
{
|
||||
// recupero data-ora ricetta da campo string
|
||||
@@ -6721,7 +6721,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
CurrStatus = "Ricevute",
|
||||
ActionList = stdActList
|
||||
};
|
||||
string rawWeek = JsonConvert.SerializeObject(cPerInfo);
|
||||
string rawWeek = JsonSerialize(cPerInfo);
|
||||
redHashWeek.Add(cWeek, rawWeek);
|
||||
}
|
||||
// salvo in redis...
|
||||
@@ -6730,7 +6730,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
|
||||
// invio ANCHE in MP-IO l'update delle info...
|
||||
string remUrl = urlSetHashDict;
|
||||
string dictPayload = JsonConvert.SerializeObject(redHashWeek);
|
||||
string dictPayload = JsonSerialize(redHashWeek);
|
||||
await HttpService.CallUrlAsync(remUrl, dictPayload);
|
||||
}
|
||||
}
|
||||
@@ -7505,7 +7505,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
if (!string.IsNullOrEmpty(rawVal))
|
||||
{
|
||||
// provo a convertire
|
||||
var lastState = JsonConvert.DeserializeObject<uint[]>(rawVal);
|
||||
var lastState = JsonDeserialize<uint[]>(rawVal);
|
||||
if (lastState != null && lastState.Length > 0)
|
||||
{
|
||||
item.loadPrev(lastState);
|
||||
@@ -7561,7 +7561,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
lgDebug($"setupMemMap | trovati {memMap.mMapWrite.Count} parametri Write");
|
||||
if (utils.CRB("verbose"))
|
||||
{
|
||||
string rawMemConf = JsonConvert.SerializeObject(memMap, Formatting.Indented);
|
||||
string rawMemConf = JsonSerialize(memMap, Formatting.Indented);
|
||||
lgDebug($"setupMemMap | configurazione memoria R/W:{Environment.NewLine}{rawMemConf}");
|
||||
}
|
||||
// se ho variabili read --> genero dati TSVC...
|
||||
@@ -7601,7 +7601,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
if (memMap != null)
|
||||
{
|
||||
// invio su cloud conf memoria...
|
||||
string rawData = JsonConvert.SerializeObject(memMap, Formatting.Indented);
|
||||
string rawData = JsonSerialize(memMap, Formatting.Indented);
|
||||
// controllo ping al server...
|
||||
if (serverOk)
|
||||
{
|
||||
@@ -7677,7 +7677,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
}
|
||||
// invio su cloud parametri SE sono connesso alla macchina... in pratica reset parametri...
|
||||
string tipoCall = urlSaveAllParams;
|
||||
rawData = JsonConvert.SerializeObject(allParam, Formatting.Indented);
|
||||
rawData = JsonSerialize(allParam, Formatting.Indented);
|
||||
if (serverOk)
|
||||
{
|
||||
// verifica se sia un IOB "parziale" --> salva solo update ai parametri
|
||||
@@ -9212,7 +9212,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
lgInfo($"Chiamata di plcWriteParams da processMem2Write: {updatedPar.Count} updatedPar");
|
||||
plcWriteParams(ref updatedPar);
|
||||
// invio su cloud parametri!
|
||||
string rawData = JsonConvert.SerializeObject(updatedPar);
|
||||
string rawData = JsonSerialize(updatedPar);
|
||||
HttpService.CallUrlPost($"{urlUpdateWriteParams}", rawData);
|
||||
lgInfo($"Notificato a server scrittura {updatedPar.Count} parametri");
|
||||
}
|
||||
@@ -9222,7 +9222,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
if (currWritePar.Count > 0 && (lastWriteParamsUpsert.AddMinutes(vetoSendWriteUpsert) < adesso))
|
||||
{
|
||||
// invio su cloud parametri!
|
||||
string rawData = JsonConvert.SerializeObject(currWritePar);
|
||||
string rawData = JsonSerialize(currWritePar);
|
||||
var res = HttpService.CallUrlPost($"{urlUpdateWriteParams}", rawData);
|
||||
lgInfo($"Reinviato a server stato {updatedPar.Count} parametri WRITE");
|
||||
lastWriteParamsUpsert = adesso;
|
||||
@@ -9348,7 +9348,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
string rawConfFile = File.ReadAllText(confSetupPath);
|
||||
if (!string.IsNullOrEmpty(rawConfFile))
|
||||
{
|
||||
currConf = JsonConvert.DeserializeObject<ConvSetup>(rawConfFile);
|
||||
currConf = JsonDeserialize<ConvSetup>(rawConfFile);
|
||||
if (currConf != null)
|
||||
{
|
||||
addHeader = currConf.addHeader;
|
||||
@@ -9510,7 +9510,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
Dictionary<string, string> currDict = redisMan.redGetHashDict(fullKey);
|
||||
// invio ANCHE in MP-IO l'update delle info...
|
||||
string remUrl = urlSetHashDict;
|
||||
string dictPayload = JsonConvert.SerializeObject(currDict);
|
||||
string dictPayload = JsonSerialize(currDict);
|
||||
await HttpService.CallUrlAsync(remUrl, dictPayload);
|
||||
//await callUrlWithPayloadAsync(remUrl, dictPayload, true);
|
||||
//await callUrlWithPayloadAsync(remUrl, dictPayload, false);
|
||||
|
||||
@@ -326,28 +326,6 @@ namespace IOB_WIN_KAWASAKI.Iob
|
||||
{
|
||||
// impiego override metodo set...
|
||||
bool answ = setcontapezziPLC(0, codTav);
|
||||
#if false
|
||||
bool answ = false;
|
||||
// ...SE abilitato da conf IOB
|
||||
if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE")
|
||||
{
|
||||
// scrivo valore 0 x il contapezzi
|
||||
try
|
||||
{
|
||||
pzCounter = 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError(exc, "Errore in RESET contapezzi KAWASAKI");
|
||||
connectionOk = false;
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
lgError("Impossibile effettuare RESET contapezzi KAWASAKI, mancanza parametro OPT:ENABLE_PZ_RESET");
|
||||
}
|
||||
#endif
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user