146 lines
3.8 KiB
C#
146 lines
3.8 KiB
C#
using MP_MON.Models;
|
|
using Newtonsoft.Json;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
|
|
namespace MP_MON.Controllers
|
|
{
|
|
public class MSEController : Controller
|
|
{
|
|
private MoonProEntities db = new MoonProEntities();
|
|
|
|
// GET: StatusMap
|
|
public ActionResult StatusMap(string baseCss)
|
|
{
|
|
memLayer.ML.setSessionVal("IdxMacchina", "***ALL***");
|
|
return SingleStatus(baseCss, "***ALL***");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Output MSE in formato string/json
|
|
/// </summary>
|
|
public string getData(string id)
|
|
{
|
|
int dataRefresh = 2000;
|
|
string answ = "";
|
|
answ = dataSer;
|
|
if (answ == null || answ == "")
|
|
{
|
|
var dati = db.stp_MSE_getData(dataRefresh).ToList();
|
|
// serializzo
|
|
answ = JsonConvert.SerializeObject(dati);
|
|
dataSer = answ;
|
|
}
|
|
return answ;
|
|
}
|
|
// GET: StatusMap
|
|
public ActionResult SingleStatus(string baseCss, string IdxMacchina)
|
|
{
|
|
int dataRefresh = 2000;
|
|
// salvo idxMacc in sessione se c'è...
|
|
if (IdxMacchina != "" && IdxMacchina != null)
|
|
{
|
|
memLayer.ML.setSessionVal("IdxMacchina", IdxMacchina);
|
|
}
|
|
else
|
|
{
|
|
IdxMacchina = memLayer.ML.StringSessionObj("IdxMacchina");
|
|
}
|
|
try
|
|
{
|
|
dataRefresh = Convert.ToInt32(System.Web.Configuration.WebConfigurationManager.AppSettings["dataRefreshMs"]);
|
|
}
|
|
catch
|
|
{ }
|
|
List<MappaStatoExpl> dati = new List<MappaStatoExpl>();
|
|
if (dataSer != "" && dataSer != null)
|
|
{
|
|
try
|
|
{
|
|
dati = JsonConvert.DeserializeObject<List<MappaStatoExpl>>(dataSer);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
getDbSaveRedis(dataRefresh, hMSE, out dati);
|
|
logger.lg.scriviLog(string.Format("Recuperata MSE da DB{0}{1}", Environment.NewLine, exc));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
getDbSaveRedis(dataRefresh, hMSE, out dati);
|
|
}
|
|
// filtro dati SOLO PER la macchina che mi interessa... SE C'E'...
|
|
string reqView = "_StatusMap";
|
|
if (IdxMacchina != "***ALL***")
|
|
{
|
|
dati = dati.Where(e => e.IdxMacchina == IdxMacchina).ToList();
|
|
reqView = "_StatusMapSingle";
|
|
}
|
|
ViewBag.baseCss = baseCss;
|
|
ViewBag.IdxMacchina = IdxMacchina;
|
|
// aggiungo il controllo del NUM MAX col x singola riga
|
|
int maxCol = 6;
|
|
try
|
|
{
|
|
maxCol = memLayer.ML.cdvi("MON_maxCol");
|
|
}
|
|
catch
|
|
{ }
|
|
ViewBag.maxCol = maxCol;
|
|
return PartialView(reqView, dati);
|
|
}
|
|
/// <summary>
|
|
/// Recupera dati da DB e salva su REDIS
|
|
/// </summary>
|
|
/// <param name="dataRefresh"></param>
|
|
/// <param name="hMSE"></param>
|
|
/// <param name="dati"></param>
|
|
private void getDbSaveRedis(int dataRefresh, string hMSE, out List<MappaStatoExpl> dati)
|
|
{
|
|
// se non c'è rileggo...
|
|
logger.lg.scriviLog("Recuperata MSE da DB");
|
|
dati = db.stp_MSE_getData(dataRefresh).ToList();
|
|
// serializzo
|
|
dataSer = JsonConvert.SerializeObject(dati);
|
|
}
|
|
/// <summary>
|
|
/// Hash chaive dati MSE
|
|
/// </summary>
|
|
protected string hMSE
|
|
{
|
|
get
|
|
{
|
|
return MapoDb.DataLayer.hMSE();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Dati MSE serializzati in REDIS (get/set)
|
|
/// </summary>
|
|
protected string dataSer
|
|
{
|
|
get
|
|
{
|
|
logger.lg.scriviLog("Recuperata MSE da REDIS");
|
|
return memLayer.ML.getRSV(hMSE);
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setRSV(hMSE, value, memLayer.ML.CRI("MSE_cacheDuration"));
|
|
}
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
}
|
|
}
|