From e769f1f89e2e79032b63921713a438fa3522428c Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 18 Dec 2019 11:23:33 +0100 Subject: [PATCH] Aggiunti metodi x upload Json multievento (da testare!) --- Jenkinsfile | 2 +- MP-IO/Controllers/IOBController.cs | 65 +++++++++++++++++++++++++++++- MapoSDK/Objects.cs | 19 ++++++++- 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bf62c97d..e45206e9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,7 @@ pipeline { steps { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=1266']) { + withEnv(['NEXT_BUILD_NUMBER=1267']) { // env.versionNumber = VersionNumber(versionNumberString : '6.9.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '6.9.${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/Controllers/IOBController.cs b/MP-IO/Controllers/IOBController.cs index 8d1818c4..db9bd544 100644 --- a/MP-IO/Controllers/IOBController.cs +++ b/MP-IO/Controllers/IOBController.cs @@ -104,6 +104,67 @@ namespace MP_IO.Controllers } return answ; } + /// + /// Processa una chiamata POST per l'invio di un array Json di oggetti input (EVENTI) + /// PUT: IOB/input/SIMUL_03 + /// + /// ID dell'IOB + /// + [HttpPost] + public string inputJson(string id) + { + string answ = "-"; + // questa classe รจ 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; + // se ho dati... + if (content != "") + { + // procedo a deserializzare in blocco l'oggetto... + evJsonPayload receivedData = new evJsonPayload(); + try + { + // deserializzo. + receivedData = JsonConvert.DeserializeObject(content); + } + catch (Exception exc) + { + logger.lg.scriviLog($"Errore in fase deserializzazione inputJson{Environment.NewLine}{exc}"); + answ = "NO"; + } + // se ho qualcosa da processare... + if (receivedData != null) + { + // per ogni valore --> processo! + try + { + foreach (var item in receivedData.eventsData) + { + if (memLayer.ML.CRI("_logLevel") > 6) + { + logger.lg.scriviLog(string.Format("Valori letti:{0}idxMacchina: {1}{0}valore: {2}{0}dtEve: {3}{0}dtCurr: {4}{0}cnt: {5}", Environment.NewLine, id, item.valore, item.dtEve, item.dtCurr, item.cnt), tipoLog.INFO); + } + + // formato datetime come yyyyMMddHHmmssfff -->es: 20181223180600000 + answ = DataLayer.processInput(id, item.valore, item.dtEve.ToString("yyyyMMddHHmmssfff"), item.dtCurr.ToString("yyyyMMddHHmmssfff"), item.cnt.ToString()); + } + } + catch (Exception exc) + { + logger.lg.scriviLog($"Errore in fase invio valori inputJson{Environment.NewLine}{exc}"); + answ = "NO"; + } + } + } + return answ; + } // GET: IOB/flog/SIMUL_03?flux=PROG&valore=P0001&dtEve=20161223180600000&dtCurr=20161223180600000&cnt=999 public string flog(string id, string flux, string valore, string dtEve, string dtCurr, string cnt) { @@ -156,11 +217,11 @@ namespace MP_IO.Controllers if (content != "") { // procedo a deserializzare in blocco l'oggetto... - flogJson receivedData = new flogJson(); + flogJsonPayload receivedData = new flogJsonPayload(); try { // deserializzo. - receivedData = JsonConvert.DeserializeObject(content); + receivedData = JsonConvert.DeserializeObject(content); } catch (Exception exc) { diff --git a/MapoSDK/Objects.cs b/MapoSDK/Objects.cs index 18b513bc..0d364a21 100644 --- a/MapoSDK/Objects.cs +++ b/MapoSDK/Objects.cs @@ -35,19 +35,34 @@ namespace MapoSDK /// /// Array valori tipo flogData inviati come JSon /// - public class flogJson + public class flogJsonPayload { public List fluxData { get; set; } } /// /// Tracciato FluxLog in formato JSON valido /// - public class flogData + public class flogData : evData { /// /// nome del flusso /// public string flux { get; set; } = "ND"; + } + + /// + /// Array valori tipo evData inviati come JSon + /// + public class evJsonPayload + { + public List eventsData { get; set; } + } + /// + /// Tracciato InputEvents in formato JSON valido + /// Derivato da input realtime valore=3&dtEve=20181206180600000&dtCurr=20181206180600000&cnt=999 + /// + public class evData + { /// /// Valore del dato di flusso registrato ///