Modifica importante MP-IO: accetta upload POST JSON

Sia per metodo liveJson (x live data su redis) che flogJson (x dati FluxLog da storicizzare)
This commit is contained in:
Samuele E. Locatelli
2019-11-02 15:30:44 +01:00
parent 84c5d41a5d
commit 060cb19f62
5 changed files with 186 additions and 17 deletions
Vendored
+1 -1
View File
@@ -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'
+14 -14
View File
@@ -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 }
);
}
}
}
+76 -2
View File
@@ -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;
}
/// <summary>
/// Processa una chiamata POST per l'invio di un array jSon di oggetti fluxLog
/// PUT: IOB/flogJson/SIMUL_03
/// </summary>
/// <param name="id">ID dell'IOB</param>
/// <returns></returns>
[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<flogJson>(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;
}
/// <summary>
/// Processa una chiamata POST per l'invio di un array jSon di oggetti LIVE REC
/// PUT: IOB/liveJson/SIMUL_03
/// </summary>
/// <param name="id">ID dell'IOB</param>
/// <returns></returns>
[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<liveIOB>(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;
}
}
}
+54
View File
@@ -822,6 +822,60 @@ namespace MapoDb
return answ;
}
/// <summary>
/// Processa registrazione di uno stream di dati LIVE da IOB
/// </summary>
/// <param name="idxMacchina"></param>
/// <param name="liveData">Dati live nel formato di lista di KVP chiave/valore1</param>
/// <returns></returns>
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<string, string>[] newData = new KeyValuePair<string, string>[1];
foreach (var item in liveData.dataList)
{
// accodo update valori...
newData[0] = new KeyValuePair<string, string>(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;
}
/// <summary>
/// Processa registrazione di uno stream di dati LIVE da IOB
/// </summary>
+41
View File
@@ -1,6 +1,7 @@
using MapoDb;
using SteamWare;
using System;
using System.Collections.Generic;
/// <summary>
/// Summary description for utility
@@ -314,6 +315,46 @@ public class IOB_data
public string typeCss;
public bool CNC_Counter;
}
/// <summary>
/// Array elementi tipo KeyValuePair inviati come JSon che indicano lo stato LIVE dell'IOB
/// </summary>
public class liveIOB
{
public List<KeyValuePair<string, string>> dataList { get; set; }
}
/// <summary>
/// Array valori tipo flogData inviati come JSon
/// </summary>
public class flogJson
{
public List<flogData> fluxData { get; set; }
}
/// <summary>
/// Tracciato FluxLog in formato JSON valido
/// </summary>
public class flogData
{
/// <summary>
/// nome del flusso
/// </summary>
public string flux { get; set; } = "ND";
/// <summary>
/// Valore del dato di flusso registrato
/// </summary>
public string valore { get; set; } = "-";
/// <summary>
/// DataOra evento
/// </summary>
public DateTime dtEve { get; set; } = DateTime.Now;
/// <summary>
/// DataOra corrente della trasmissione
/// </summary>
public DateTime dtCurr { get; set; } = DateTime.Now;
/// <summary>
/// Contatore incrementale x riordino invio (opzionale)
/// </summary>
public int cnt { get; set; } = 0;
}
#if false
/// <summary>