diff --git a/IOB-UT-NEXT/Objects.cs b/IOB-UT-NEXT/Objects.cs
index 5d76a33e..d680955d 100644
--- a/IOB-UT-NEXT/Objects.cs
+++ b/IOB-UT-NEXT/Objects.cs
@@ -816,4 +816,13 @@ namespace IOB_UT_NEXT
#endregion Public Properties
}
+ ///
+ /// Generico evento log
+ ///
+ public class GenLogRow
+ {
+ public DateTime dtRif { get; set; } = DateTime.Now;
+
+ public string valString { get; set; } = "";
+ }
}
\ No newline at end of file
diff --git a/IOB-WIN-NEXT/IobSqlServLantek.cs b/IOB-WIN-NEXT/IobSqlServLantek.cs
index b9fbd41e..bac78945 100644
--- a/IOB-WIN-NEXT/IobSqlServLantek.cs
+++ b/IOB-WIN-NEXT/IobSqlServLantek.cs
@@ -41,6 +41,7 @@ namespace IOB_WIN_NEXT
/// Configurazione IOB per avvio
public IobSqlServLantek(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
{
+ DateTime adesso = DateTime.Now;
string SyncStateServ = getOptPar("SyncStateServer");
string SyncStateDb = getOptPar("SyncStateDb");
string SyncStateUser = getOptPar("SyncStateUser");
@@ -54,7 +55,8 @@ namespace IOB_WIN_NEXT
{
logDirPath = pathList["path-remBase"];
}
- getRemoteLog();
+ bool acquireLog = getRemoteLog();
+ bool sentSignLog = processSignLogTable(adesso);
string connSyncState = $"data source={SyncStateServ};initial catalog={SyncStateDb};persist security info=True;user id={SyncStateUser};password={SyncStatePwd};MultipleActiveResultSets=True;App=IOB-WIN-NEXT";
@@ -375,6 +377,40 @@ namespace IOB_WIN_NEXT
#region Private Methods
+ ///
+ /// converte un file di log della amcchina in un dizionario
+ ///
+ ///
+ ///
+ private List getToMachineLog(string dailyLog)
+ {
+ List result = new List();
+ //se ho valori.. faccio split!
+ if (!string.IsNullOrEmpty(dailyLog))
+ {
+ var rowList = dailyLog.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
+ if (rowList != null && rowList.Length > 0)
+ {
+ result = rowList.Select(x => convertToMachineLog(x)).ToList();
+ }
+ }
+ return result;
+ }
+
+ private GenLogRow convertToMachineLog(string dailyLog)
+ {
+ GenLogRow answ = new GenLogRow();
+ if (!string.IsNullOrEmpty(dailyLog))
+ {
+ // preventivamente: doppio ";;" --> ";"
+ dailyLog = dailyLog.Replace(";;", ";");
+ var sSplit = dailyLog.Split(';');
+ answ.dtRif = DateTime.ParseExact($"{sSplit[0]} {sSplit[1]}", "yyyy-M-d HH:mm:ss", null);
+ answ.valString = $"{sSplit[2]};{sSplit[3]}";
+ }
+ return answ;
+ }
+
///
/// Esegue task EXPORT (MES PODL to MACHINE)
///
@@ -624,90 +660,77 @@ namespace IOB_WIN_NEXT
private bool processSignLogTable(DateTime adesso)
{
bool fatto = false;
- string tabNameIn = "SignLog";
- string tabNameOut = "SignLogToMes";
- // cerco info sui SignLog (ToMes e letti)
- var currSignLogRead = elencoSyncState.FirstOrDefault(x => x.TableName == tabNameIn);
- // se nullo inizializzo
- if (currSignLogRead == null)
- {
- currSignLogRead = new SyncStateModel()
- {
- LastIdx = 0,
- LastUpdate = adesso,
- TableName = tabNameIn,
- Note = "Init"
- };
- }
- var currSignLogSent = elencoSyncState.FirstOrDefault(x => x.TableName == tabNameOut);
- // se nullo inizializzo
- if (currSignLogSent == null)
- {
- currSignLogSent = new SyncStateModel()
- {
- LastIdx = 0,
- LastUpdate = adesso,
- TableName = tabNameOut,
- Note = "Init"
- };
- }
- // verifica se ci siano dati da trasmettere (sui valori LastIdx)
- if (currSignLogRead.LastIdx > currSignLogSent.LastIdx)
- {
- // init oggetto x processing
- Dictionary sigLogFromFile = new Dictionary();
- // recupero i dati dai logs files, attuale e nuovo...
- string redKeyAct = redisMan.redHash($"IOB:CurrData:{cIobConf.codIOB}:LogFile:Act");
- string redKeyLast = redisMan.redHash($"IOB:CurrData:{cIobConf.codIOB}:LogFile:Last");
- string fileAct = redisMan.getRSV(redKeyAct);
- string fileLast = redisMan.getRSV(redKeyLast);
- // confronto con i dati dell'ultimo LOG FILE processato
- int lenghtAct = fileAct.Length;
- int lenghtLast = fileLast.Length;
- if (lenghtAct > 0 && lenghtAct > lenghtLast)
- {
- // prendo SOLAMENTE le righe nuove
- // processo le righe nuove trasformandole in un elenco data/codice evento
-
- // salvo in last il valore di act...
- redisMan.setRSV(redKeyLast, fileAct);
+ // init oggetto x processing
+ Dictionary sigLogFromFile = new Dictionary();
+ // recupero i dati dai logs files, attuale e nuovo...
+ string redKeyAct = redisMan.redHash($"IOB:CurrData:{cIobConf.codIOB}:LogFile:Act");
+ string redKeyLast = redisMan.redHash($"IOB:CurrData:{cIobConf.codIOB}:LogFile:Last");
+ string fileAct = redisMan.getRSV(redKeyAct);
+ string fileLast = redisMan.getRSV(redKeyLast);
+ // confronto con i dati dell'ultimo LOG FILE processato
+ int lenghtAct = fileAct.Length;
+ int lenghtLast = fileLast.Length;
+ //if (lenghtAct > 0 && lenghtAct != lenghtLast)
+ if (lenghtAct > 0)
+ {
+ List logNew = new List();
+ List logLast = getToMachineLog(fileLast);
+ List logAct = getToMachineLog(fileAct);
+ // SE c'è prendo ultima riga inviata x confronto...
+ var fileLastEnd = logLast.LastOrDefault();
+ if (fileLastEnd != null)
+ {
+ // ora prendo SOLAMENTE le righe nuove
+ logNew = logAct
+ .Where(x => x.dtRif > fileLastEnd.dtRif)
+ .ToList();
}
-
- List data2send = dbProxy.MachSigLogGetNew(currSignLogSent.LastIdx);
- // se ho dati preparo invio
- if (data2send != null && data2send.Count > 0)
+ else
{
- foreach (var sLog2send in data2send)
+ logNew = logAct;
+ }
+ // processo le righe nuove trasformandole in un elenco data/codice evento
+ //var sigLogRows =
+
+#if false
+ // salvo in last il valore di act...
+ redisMan.setRSV(redKeyLast, fileAct);
+#endif
+ }
+
+#if false
+ List data2send = dbProxy.MachSigLogGetNew(currSignLogSent.LastIdx);
+ // se ho dati preparo invio
+ if (data2send != null && data2send.Count > 0)
+ {
+ foreach (var sLog2send in data2send)
+ {
+ string currVal = getEncodSigLog(sLog2send.DtEve, sLog2send.ValInt, counterSigIN);
+ // --> accodo (valore già formattato)!
+ QueueIN.Enqueue(currVal);
+ // loggo!
+ lgTrace(string.Format("[QUEUE-IN] {0}", currVal));
+ counterSigIN++;
+ if (counterSigIN > 9999)
{
- string currVal = getEncodSigLog(sLog2send.DtEve, sLog2send.ValInt, counterSigIN);
- // --> accodo (valore già formattato)!
- QueueIN.Enqueue(currVal);
- // loggo!
- lgTrace(string.Format("[QUEUE-IN] {0}", currVal));
- counterSigIN++;
- if (counterSigIN > 9999)
- {
- counterSigIN = 0;
- }
+ counterSigIN = 0;
}
}
-
- // aggiorno idx inviato...
- currSignLogSent.Note = $"Updated from {currSignLogRead.LastIdx}";
- currSignLogSent.LastUpdate = adesso;
- currSignLogSent.LastIdx = currSignLogRead.LastIdx;
- var lastRec = data2send.LastOrDefault();
- if (lastRec != null)
- {
- // salvo in B_input ultimo valore letto...
- B_input = lastRec.ValInt;
- }
- fatto = true;
}
- // alla fine aggiorno i dati inviati!
- dbProxy.SyncStateUpsert(currSignLogSent);
+ // aggiorno idx inviato...
+ currSignLogSent.Note = $"Updated from {currSignLogRead.LastIdx}";
+ currSignLogSent.LastUpdate = adesso;
+ currSignLogSent.LastIdx = currSignLogRead.LastIdx;
+ var lastRec = data2send.LastOrDefault();
+ if (lastRec != null)
+ {
+ // salvo in B_input ultimo valore letto...
+ B_input = lastRec.ValInt;
+ }
+#endif
+ fatto = true;
return fatto;
}