diff --git a/Jenkinsfile b/Jenkinsfile index b91fb78e..a5162e72 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,7 +18,7 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=1243']) { + withEnv(['NEXT_BUILD_NUMBER=1245']) { // env.versionNumber = VersionNumber(versionNumberString : '6.7.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '6.7.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO' diff --git a/MP-IO/App_Start/RouteConfig.cs b/MP-IO/App_Start/RouteConfig.cs index 53ce342c..10fd6aa3 100644 --- a/MP-IO/App_Start/RouteConfig.cs +++ b/MP-IO/App_Start/RouteConfig.cs @@ -4,21 +4,21 @@ using System.Web.Routing; namespace MP_IO { - public class RouteConfig + public class RouteConfig + { + public static void RegisterRoutes(RouteCollection routes) { - public static void RegisterRoutes(RouteCollection routes) - { - var settings = new FriendlyUrlSettings(); - settings.AutoRedirectMode = RedirectMode.Permanent; - routes.EnableFriendlyUrls(settings); - // aggiungo route x gestione controller IOB - routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); + var settings = new FriendlyUrlSettings(); + settings.AutoRedirectMode = RedirectMode.Permanent; + routes.EnableFriendlyUrls(settings); + // aggiungo route x gestione controller IOB + routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); - routes.MapRoute( - name: "Default", - url: "{controller}/{action}/{id}", - defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } - ); - } + routes.MapRoute( + name: "Default", + url: "{controller}/{action}/{id}", + defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } + ); } + } } diff --git a/MP-IO/Controllers/IOBController.cs b/MP-IO/Controllers/IOBController.cs index 296c823b..8f1d6b51 100644 --- a/MP-IO/Controllers/IOBController.cs +++ b/MP-IO/Controllers/IOBController.cs @@ -3,6 +3,8 @@ using Newtonsoft.Json; using SteamWare; using System; using System.Collections.Generic; +using System.IO; +using System.Net.Http; using System.Web.Mvc; namespace MP_IO.Controllers @@ -130,6 +132,77 @@ namespace MP_IO.Controllers } return answ; } + /// + /// Processa una chiamata POST per l'invio di un array jSon di oggetti fluxLog + /// PUT: IOB/flogJson/SIMUL_03 + /// + /// ID dell'IOB + /// + [HttpPost] + public string flogJson(string id) + { + string answ = "-"; + // questa calsse è derivata da Controller.Response... x cui recupero lo stream in altro modo... + string content = ""; + System.Web.HttpContext.Current.Request.InputStream.Position = 0; + using (var reader = new StreamReader( + Request.InputStream, System.Text.Encoding.UTF8, true, 4096, true)) + { + content = reader.ReadToEnd(); + } + //Rest + System.Web.HttpContext.Current.Request.InputStream.Position = 0; + // procedo a deserializzare in blocco l'oggetto... + try + { + // deserializzo. + flogJson receivedData = JsonConvert.DeserializeObject(content); + // per ogni valore --> salvo! + foreach (var item in receivedData.fluxData) + { + // formato datetime come yyyyMMddHHmmssfff -->es: 20181223180600000 + answ = DataLayer.processFluxLog(id, item.flux, item.valore, item.dtEve.ToString("yyyyMMddHHmmssfff"), item.dtCurr.ToString("yyyyMMddHHmmssfff"), item.cnt); + } + } + catch + { } + return answ; + } + /// + /// Processa una chiamata POST per l'invio di un array jSon di oggetti LIVE REC + /// PUT: IOB/liveJson/SIMUL_03 + /// + /// ID dell'IOB + /// + [HttpPost] + public string liveJson(string id) + { + string answ = "-"; + // questa calsse è derivata da Controller.Response... x cui recupero lo stream in altro modo... + string content = ""; + System.Web.HttpContext.Current.Request.InputStream.Position = 0; + using (var reader = new StreamReader( + Request.InputStream, System.Text.Encoding.UTF8, true, 4096, true)) + { + content = reader.ReadToEnd(); + } + //Rest + System.Web.HttpContext.Current.Request.InputStream.Position = 0; + // procedo a deserializzare in blocco l'oggetto... + try + { + // deserializzo. + liveIOB receivedData = JsonConvert.DeserializeObject(content); + answ = DataLayer.processLiveJson(id, receivedData); + } + catch (Exception exc) + { + logger.lg.scriviLog($"Errore in liveJson{Environment.NewLine}{exc}"); + answ = "NO"; + } + return answ; + } + // GET: IOB/liveRec/SIMUL_03?&liveData=chiave1|valore1#chiave2|valore#|chiave3|valore3 public string liveRec(string id, string liveData) { @@ -137,7 +210,7 @@ namespace MP_IO.Controllers DateTime dataOraEvento = DateTime.Now; if (memLayer.ML.CRI("_logLevel") > 6) { - logger.lg.scriviLog(string.Format("Valori Live:{0}idxMacchina: {1}{0}liveData: {2}", Environment.NewLine, id, liveData), tipoLog.INFO); + logger.lg.scriviLog($"Valori Live:{Environment.NewLine}idxMacchina: {id}{Environment.NewLine}liveData: {liveData}", tipoLog.INFO); } try { @@ -145,7 +218,7 @@ namespace MP_IO.Controllers } catch (Exception exc) { - logger.lg.scriviLog(string.Format("Errore in liveRec{0}{1}", Environment.NewLine, exc)); + logger.lg.scriviLog($"Errore in liveRec{Environment.NewLine}{exc}"); answ = "NO"; } return answ; @@ -685,5 +758,6 @@ namespace MP_IO.Controllers return answ; } + } } \ No newline at end of file diff --git a/MapoDb/DataLayer.cs b/MapoDb/DataLayer.cs index ea8f6db6..74e44437 100644 --- a/MapoDb/DataLayer.cs +++ b/MapoDb/DataLayer.cs @@ -822,6 +822,60 @@ namespace MapoDb return answ; } + + /// + /// Processa registrazione di uno stream di dati LIVE da IOB + /// + /// + /// Dati live nel formato di lista di KVP chiave/valore1 + /// + public static string processLiveJson(string idxMacchina, liveIOB liveData) + { + if (liveData == null) + { + throw new ArgumentNullException(nameof(liveData)); + } + // registro conteggio impiego chiamate REDIS + if (memLayer.ML.CRB("IOB_RedEnab")) + { + saveCallRec("processLiveJson"); + } + string answ = ""; + DateTime dataOraEvento = DateTime.Now; + // inizio processing vero e proprio INPUT... + if (!string.IsNullOrEmpty(idxMacchina) && liveData != null) + { + // SE ho dei segnali... + if (liveData.dataList.Count > 0) + { + // salvo in Redis nell'area CURR_VAL TUTTI i valori live + memLayer.ML.redSaveHashList(LiveCurrValHash(idxMacchina), liveData.dataList); + // accodo in buffer ULTIMI valori con dataora uno ad uno... + KeyValuePair[] newData = new KeyValuePair[1]; + foreach (var item in liveData.dataList) + { + // accodo update valori... + newData[0] = new KeyValuePair(dataOraEvento.ToString(), item.Value); + memLayer.ML.redSaveHash(LiveBufferHash(idxMacchina, item.Key), newData); + } + } + else + { + string errore = "Errore: formato liveData errato (split #)"; + logger.lg.scriviLog(errore, tipoLog.ERROR); + answ = errore; + } + // registro in risposta che è andato tutto bene... + answ = "OK"; + } + else + { + string errore = "Errore: mancano parametri macchina/liveData come Json"; + logger.lg.scriviLog(errore, tipoLog.ERROR); + answ = errore; + } + return answ; + } /// /// Processa registrazione di uno stream di dati LIVE da IOB /// diff --git a/MapoDb/utility.cs b/MapoDb/utility.cs index c15e7c71..347ee7f9 100644 --- a/MapoDb/utility.cs +++ b/MapoDb/utility.cs @@ -1,6 +1,7 @@ using MapoDb; using SteamWare; using System; +using System.Collections.Generic; /// /// Summary description for utility @@ -314,6 +315,46 @@ public class IOB_data public string typeCss; public bool CNC_Counter; } +/// +/// Array elementi tipo KeyValuePair inviati come JSon che indicano lo stato LIVE dell'IOB +/// +public class liveIOB +{ + public List> dataList { get; set; } +} +/// +/// Array valori tipo flogData inviati come JSon +/// +public class flogJson +{ + public List fluxData { get; set; } +} +/// +/// Tracciato FluxLog in formato JSON valido +/// +public class flogData +{ + /// + /// nome del flusso + /// + public string flux { get; set; } = "ND"; + /// + /// Valore del dato di flusso registrato + /// + public string valore { get; set; } = "-"; + /// + /// DataOra evento + /// + public DateTime dtEve { get; set; } = DateTime.Now; + /// + /// DataOra corrente della trasmissione + /// + public DateTime dtCurr { get; set; } = DateTime.Now; + /// + /// Contatore incrementale x riordino invio (opzionale) + /// + public int cnt { get; set; } = 0; +} #if false ///