modifica x invio dati ULog x iobGen + iobSim

This commit is contained in:
Samuele Locatelli
2022-03-01 08:56:34 +01:00
parent 859a91976f
commit da6e3a77f4
2 changed files with 167 additions and 156 deletions
+129 -123
View File
@@ -1069,16 +1069,16 @@ namespace IOB_WIN_NEXT
/// </summary>
public int counterFLog { get; set; }
/// <summary>
/// Contatore x invio dati UserLog
/// </summary>
public int counterULog { get; set; }
/// <summary>
/// Contatore x invio dati SignalIN
/// </summary>
public int counterSigIN { get; set; }
/// <summary>
/// Contatore x invio dati UserLog
/// </summary>
public int counterULog { get; set; }
/// <summary>
/// Verifica se sia in modalità DEMO --> da tipo IOB SIMULA...
/// </summary>
@@ -2183,36 +2183,26 @@ namespace IOB_WIN_NEXT
{
if (IobOnline)
{
// se ho + di 2 elementi in coda --> uso invio JSON in blocco...
if (QueueULog.Count > 1)
List<string> listaValori = new List<string>();
// se ho + di maxJsonData elementi --> invio un set di dati alla volta
if (QueueULog.Count > maxJsonData)
{
List<string> listaValori = new List<string>();
// se ho + di maxJsonData elementi --> invio un set di dati alla volta
if (QueueULog.Count > maxJsonData)
// prendoi primi maxJsonDataValori
for (int j = 0; j < maxJsonData; j++)
{
// prendoi primi maxJsonDataValori
for (int j = 0; j < maxJsonData; j++)
{
QueueULog.TryDequeue(out currVal);
listaValori.Add(currVal);
}
sendDataBlock(urlType.ULog, listaValori);
}
else
{
// invio in blocco
listaValori = QueueULog.ToList();
// invio
sendDataBlock(urlType.ULog, listaValori);
// svuoto!
QueueULog = new ConcurrentQueue<string>();
QueueULog.TryDequeue(out currVal);
listaValori.Add(currVal);
}
sendDataBlock(urlType.ULog, listaValori);
}
else
{
// INVIO SINGOLO...!!!
QueueULog.TryDequeue(out currVal);
sendToMoonPro(urlType.ULog, currVal);
// invio in blocco
listaValori = QueueULog.ToList();
// invio
sendDataBlock(urlType.ULog, listaValori);
// svuoto!
QueueULog = new ConcurrentQueue<string>();
}
}
else
@@ -2540,6 +2530,38 @@ namespace IOB_WIN_NEXT
return answ;
}
/// <summary>
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
/// <param name="message"></param>
protected void lgDebug(string message, bool sendToForm = true)
{
//if (isVerboseLog)
//{
lg.Factory.Configuration.Variables["codIOB"] = cIobConf.codIOB;
lg.Debug(message);
if (sendToForm)
{
sendToLogWatch("DEBUG", message);
}
//}
}
/// <summary>
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
protected void lgDebug(string message, params object[] args)
{
//if (isVerboseLog)
//{
lg.Factory.Configuration.Variables["codIOB"] = cIobConf.codIOB;
lg.Debug(message, args);
sendToLogWatch("DEBUG", message, args);
//}
}
/// <summary>
/// Effettua logging ERROR corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
@@ -2669,36 +2691,6 @@ namespace IOB_WIN_NEXT
lg.Trace(message, args);
sendToLogWatch("INFO", message, args);
}
/// <summary>
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
/// <param name="message"></param>
protected void lgDebug(string message, bool sendToForm = true)
{
//if (isVerboseLog)
//{
lg.Factory.Configuration.Variables["codIOB"] = cIobConf.codIOB;
lg.Debug(message);
if (sendToForm)
{
sendToLogWatch("DEBUG", message);
}
//}
}
/// <summary>
/// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere...
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
protected void lgDebug(string message, params object[] args)
{
//if (isVerboseLog)
//{
lg.Factory.Configuration.Variables["codIOB"] = cIobConf.codIOB;
lg.Debug(message, args);
sendToLogWatch("DEBUG", message, args);
//}
}
/// <summary>
/// Legge il file di conf di una MAP di informazioni da gestire con lettura set memoria
@@ -3289,28 +3281,6 @@ namespace IOB_WIN_NEXT
}
}
/// <summary>
/// Accumula in coda i valori USER LOG e logga...
/// </summary>
/// <param name="val">VALORE RAW (x display)</param>
/// <param name="encodedVal">VALORE già processato con qEncodeULog(...)</param>
public void accodaUserLog(string val, string encodedVal)
{
// mostro dati variati letti...
displayOtherData(val);
// accodo IN PRIMIS al FluxLog --> accodo (valore già formattato)!
QueueULog.Enqueue(encodedVal);
// loggo!
lgInfo(string.Format("[QUEUE-USER-LOG] {0}", encodedVal));
counterULog++;
if (counterULog > 9999)
{
counterFLog = 0;
}
}
/// <summary>
/// Accumula in coda i valori Flux Log e logga...
/// </summary>
@@ -3384,6 +3354,27 @@ namespace IOB_WIN_NEXT
}
}
/// <summary>
/// Accumula in coda i valori USER LOG e logga...
/// </summary>
/// <param name="val">VALORE RAW (x display)</param>
/// <param name="encodedVal">VALORE già processato con qEncodeULog(...)</param>
public void accodaUserLog(string val, string encodedVal)
{
// mostro dati variati letti...
displayOtherData(val);
// accodo IN PRIMIS al FluxLog --> accodo (valore già formattato)!
QueueULog.Enqueue(encodedVal);
// loggo!
lgInfo(string.Format("[QUEUE-USER-LOG] {0}", encodedVal));
counterULog++;
if (counterULog > 9999)
{
counterFLog = 0;
}
}
/// <summary>
/// Update visualizzaizone BIT in ingresso
/// <paramref name="currDispData">Parametri da aggiornare x display in form</paramref>
@@ -4010,6 +4001,7 @@ namespace IOB_WIN_NEXT
lgError($"FLog Errore in costruzione jsonPayload:{Environment.NewLine}{exc}");
}
break;
case urlType.SignIN:
evData currSigData = new evData();
evJsonPayload fullEvObj = new evJsonPayload();
@@ -4040,7 +4032,10 @@ namespace IOB_WIN_NEXT
lgError($"SignIN Errore in costruzione jsonPayload:{Environment.NewLine}{exc}");
}
break;
case urlType.ULog:
int numVal = 0;
int matrOp = 0;
ulogData currUlData = new ulogData();
ulogJsonPayload fullUlObj = new ulogJsonPayload();
fullUlObj.fluxData = new List<ulogData>();
@@ -4050,14 +4045,19 @@ namespace IOB_WIN_NEXT
valori = qDecodeIN(item);
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime.TryParseExact(valori[0], "yyyyMMddHHmmssfff", provider, DateTimeStyles.AssumeLocal, out dtEve);
int.TryParse(valori[3], out counter);
int.TryParse(valori[3], out matrOp);
int.TryParse(valori[5], out numVal);
int.TryParse(valori[6], out counter);
currUlData = new ulogData()
{
flux = valori[1],
valore = valori[2],
dtEve = dtEve,
dtCurr = DateTime.Now,
cnt = counter
cnt = counter,
matrOpr = matrOp,
label = valori[4],
valNum = numVal
};
fullUlObj.fluxData.Add(currUlData);
}
@@ -4071,6 +4071,7 @@ namespace IOB_WIN_NEXT
lgError($"ULog Errore in costruzione jsonPayload:{Environment.NewLine}{exc}");
}
break;
default:
break;
}
@@ -4643,27 +4644,12 @@ namespace IOB_WIN_NEXT
}
/// <summary>
/// Fornisce il valore di flusso e valore in formato valido x messa in coda nel formato dtEve#flux#value#cont
/// Fornisce il valore di flusso e valore in formato valido x messa in coda nel formato
/// dtEve#flusso#valore#cont
/// <paramref name="flusso">Flusso dati</paramref>
/// <paramref name="valore">Valore da salvare</paramref>
/// </summary>
public string qEncodeFLog(string flusso, string valore)
{
string answ = "";
try
{
answ = string.Format("{0:yyyyMMddHHmmssfff}#{1}#{2}#{3}", DateTime.Now, flusso, valore, counterFLog);
}
catch
{ }
return answ;
}
/// <summary>
/// Fornisce il valore di UserLog e valore in formato valido x messa in coda nel formato dtEve#flux#value#cont
/// <paramref name="flusso">Flusso dati (RC/RS/DI)</paramref>
/// <paramref name="valore">Valore da inviare</paramref>
/// </summary>
public string qEncodeULog(string flusso, string valore)
{
string answ = "";
try
@@ -4686,7 +4672,28 @@ namespace IOB_WIN_NEXT
string answ = "";
try
{
answ = string.Format("{0:yyyyMMddHHmmssfff}#{1}#{2}#{3}", eventDT, flusso, valore, counterFLog);
answ = $"{eventDT:yyyyMMddHHmmssfff}#{flusso}#{valore}#{counterFLog}";
}
catch
{ }
return answ;
}
/// <summary>
/// Fornisce il valore di UserLog e valore in formato valido x messa in coda nel formato:
/// dtEve#flusso#value#cont#matrOpr#label#valNum
/// <paramref name="flusso">Flusso dati (RC/RS/DI)</paramref>
/// <paramref name="valore">Valore da inviare (valString</paramref>
/// <paramref name="matrOpr">Matricola operatore</paramref>
/// <paramref name="label">Valore etichetta: causale scarto / tagCode</paramref>
/// <paramref name="valNum">Valore numerico: esitoOk (0/1) / nuo scarti</paramref>
/// </summary>
public string qEncodeULog(string flusso, string valore, int matrOpr, string label, int valNum)
{
string answ = "";
try
{
answ = $"{DateTime.Now:yyyyMMddHHmmssfff}#{flusso}#{valore}#{matrOpr}#{label}#{valNum}#{counterULog}";
}
catch
{ }
@@ -4993,10 +5000,6 @@ namespace IOB_WIN_NEXT
lastUrl = urlInput(queueVal);
break;
case urlType.ULog:
lastUrl = urlULog(queueVal);
break;
default:
lastUrl = "";
break;
@@ -5404,12 +5407,15 @@ namespace IOB_WIN_NEXT
case urlType.FLog:
tipoComando = cIobConf.serverData.CMDFLOG_JSON;
break;
case urlType.SignIN:
tipoComando = cIobConf.serverData.CMDBASE_JSON;
break;
case urlType.ULog:
tipoComando = cIobConf.serverData.CMDULOG_JSON;
break;
default:
break;
}
@@ -5436,24 +5442,6 @@ namespace IOB_WIN_NEXT
return answ;
}
/// <summary>
/// Fornisce URL di tipo UserLog
/// </summary>
/// <param name="queueVal">valore salvato in coda nel formato dtEve#flux#valore#counter</param>
/// <returns></returns>
public string urlULog(string queueVal)
{
// URL base x input
string answ = $@"{cIobConf.serverData.TRANSP}://{cIobConf.serverData.MPIP}{cIobConf.serverData.MPURL}{cIobConf.serverData.CMDULOG}";
// decodifica valore!
string[] valori = qDecodeIN(queueVal);
// aggiungo macchina e valore...
answ += string.Format(@"{0}?flux={1}&&valore={2}", cIobConf.codIOB, valori[1], valori[2]);
// aggiondo dataOra evento e corrente + contatore...
answ += string.Format(@"&&dtEve={0}&&dtCurr={1:yyyyMMddHHmmssfff}&&cnt={2}", valori[0], DateTime.Now, valori[3]);
return answ;
}
/// <summary>
/// Fornisce URL INPUT per i parametri richiesti
/// </summary>
@@ -5472,6 +5460,24 @@ namespace IOB_WIN_NEXT
return answ;
}
/// <summary>
/// Fornisce URL di tipo UserLog
/// </summary>
/// <param name="queueVal">valore salvato in coda nel formato dtEve#flux#valore#counter</param>
/// <returns></returns>
public string urlULog(string queueVal)
{
// URL base x input
string answ = $@"{cIobConf.serverData.TRANSP}://{cIobConf.serverData.MPIP}{cIobConf.serverData.MPURL}{cIobConf.serverData.CMDULOG}";
// decodifica valore!
string[] valori = qDecodeIN(queueVal);
// aggiungo macchina e valore...
answ += string.Format(@"{0}?flux={1}&&valore={2}", cIobConf.codIOB, valori[1], valori[2]);
// aggiondo dataOra evento e corrente + contatore...
answ += string.Format(@"&&dtEve={0}&&dtCurr={1:yyyyMMddHHmmssfff}&&cnt={2}", valori[0], DateTime.Now, valori[3]);
return answ;
}
#endregion Public Methods
}
+38 -33
View File
@@ -45,26 +45,6 @@ namespace IOB_WIN_NEXT
/// </summary>
protected int cP = 1;
/// <summary>
/// Simulazione effettuazione controlli utente
/// </summary>
protected simPar simRC;
/// <summary>
/// Simulazione registro scarti utente
/// </summary>
protected simPar simRS;
/// <summary>
/// Simulazione registrazione dichiarazioni utente
/// </summary>
protected simPar simDich;
/// <summary>
/// Matricola OPR simulato
/// </summary>
protected int matrOpr = 1;
protected bool disableSimStatus = false;
/// <summary>
@@ -77,6 +57,11 @@ namespace IOB_WIN_NEXT
/// </summary>
protected DateTime lastSimData;
/// <summary>
/// Matricola OPR simulato
/// </summary>
protected int matrOpr = 1;
/// <summary>
/// Durata minima ODL x reset quando pezzi iob > pezzi macchina...
/// </summary>
@@ -97,11 +82,26 @@ namespace IOB_WIN_NEXT
/// </summary>
protected bool sigPzCount = false;
/// <summary>
/// Simulazione registrazione dichiarazioni utente
/// </summary>
protected simPar simDich;
/// <summary>
/// BOOL: indica se simulare powerOn/Off (bit 0 e 1) compresi WarmUp e CoolDown
/// </summary>
protected bool simPowerOnOff;
/// <summary>
/// Simulazione effettuazione controlli utente
/// </summary>
protected simPar simRC;
/// <summary>
/// Simulazione registro scarti utente
/// </summary>
protected simPar simRS;
/// <summary>
/// Tempo di MINIMO attesa x simulazione parametri
/// </summary>
@@ -503,11 +503,11 @@ namespace IOB_WIN_NEXT
{
// preparo record controlli... guasto se mi esce un secondo divisibile x 25
DateTime adesso = DateTime.Now;
bool esitoOk = adesso.Second % 25 == 0 ? false : true;
string note = esitoOk ? "" : $"SIM Controllo fallito alle {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
string sVal = $"MatrOpr: {matrOpr} | Esito: {esitoOk} | note: {note}";
int esitoNum = adesso.Second % 25 == 0 ? 0 : 1;
string note = esitoNum == 1 ? "" : $"SIM Controllo fallito alle {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
string sVal = $"MatrOpr: {matrOpr} | Esito: {esitoNum} | note: {note}";
// accodo x invio
accodaUserLog(sVal, qEncodeULog("RC", $"{esitoOk}|{note}"));
accodaUserLog(sVal, qEncodeULog("RC", note, matrOpr, "", esitoNum));
// decremento duration
simRC.duration--;
// controllo se sia scaduta la duration... in quel caso reset...
@@ -520,11 +520,13 @@ namespace IOB_WIN_NEXT
{
// preparo record controlli... guasto se mi esce un secondo divisibile x 25
DateTime adesso = DateTime.Now;
int causale = adesso.Second % 5;
string note = $"SIM Scarto alle {DateTime.Now:yyyy-MM-dd HH:mm:ss} | causale: {causale}";
int causaleInt = adesso.Second % 7 + 1;
int numSca = adesso.Second % 5 + 1;
string causale = $"{causaleInt:00}";
string note = $"SIM Scarto [{causale} x {numSca}] {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
string sVal = $"MatrOpr: {matrOpr} | Causale: {causale} | note: {note}";
// accodo x invio
accodaUserLog(sVal, qEncodeULog("RS", $"{causale:00}|{note}"));
accodaUserLog(sVal, qEncodeULog("RS", note, matrOpr, causale, numSca));
// decremento duration
simRS.duration--;
// controllo se sia scaduta la duration... in quel caso reset...
@@ -535,13 +537,14 @@ namespace IOB_WIN_NEXT
}
if (simDich.wait <= 0)
{
// preparo record controlli... guasto se mi esce un secondo divisibile x 25
// preparo record dichiarazione...
DateTime adesso = DateTime.Now;
bool esitoOk = adesso.Second % 25 == 0 ? false : true;
string note = esitoOk ? "" : $"SIM Nota automatica alle {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
string sVal = $"MatrOpr: {matrOpr} | Esito: {esitoOk} | note: {note}";
bool recLogin = adesso.Second % 5 == 0 ? false : true;
string note = recLogin ? "SIM Login Utente STEAMWARE USER" : $"SIM Nota automatica alle {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
string codTag = recLogin ? "UserLogin" : "Note";
string sVal = $"MatrOpr: {matrOpr} | codTag: {codTag} | note: {note}";
// accodo x invio
accodaUserLog(sVal, qEncodeULog("DI", $"{esitoOk}|{note}"));
accodaUserLog(sVal, qEncodeULog("DI", note, matrOpr, codTag, 0));
// decremento duration
simDich.duration--;
// controllo se sia scaduta la duration... in quel caso reset...
@@ -551,7 +554,6 @@ namespace IOB_WIN_NEXT
}
}
// init obj display
newDisplayData currDispData = new newDisplayData();
currDispData.counter = contapezziIOB;
@@ -883,6 +885,9 @@ namespace IOB_WIN_NEXT
bit3.wait--;
bit4.wait--;
bit5.wait--;
simDich.wait--;
simRC.wait--;
simRS.wait--;
lastEvCheck = DateTime.Now;
}
}