Ok confronto righe vecchie/nuove nel log...
This commit is contained in:
@@ -816,4 +816,13 @@ namespace IOB_UT_NEXT
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generico evento log
|
||||
/// </summary>
|
||||
public class GenLogRow
|
||||
{
|
||||
public DateTime dtRif { get; set; } = DateTime.Now;
|
||||
|
||||
public string valString { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ namespace IOB_WIN_NEXT
|
||||
/// <param name="IOBConf">Configurazione IOB per avvio</param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// converte un file di log della amcchina in un dizionario
|
||||
/// </summary>
|
||||
/// <param name="dailyLog"></param>
|
||||
/// <returns></returns>
|
||||
private List<GenLogRow> getToMachineLog(string dailyLog)
|
||||
{
|
||||
List<GenLogRow> result = new List<GenLogRow>();
|
||||
//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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue task EXPORT (MES PODL to MACHINE)
|
||||
/// </summary>
|
||||
@@ -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<DateTime, int> sigLogFromFile = new Dictionary<DateTime, int>();
|
||||
// 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<DateTime, int> sigLogFromFile = new Dictionary<DateTime, int>();
|
||||
// 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<GenLogRow> logNew = new List<GenLogRow>();
|
||||
List<GenLogRow> logLast = getToMachineLog(fileLast);
|
||||
List<GenLogRow> 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<MachSigLogModel> 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<MachSigLogModel> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user