146 lines
4.5 KiB
C#
146 lines
4.5 KiB
C#
using MapoDb;
|
|
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
|
|
{
|
|
#region Private Fields
|
|
|
|
private DataLayer DataLayerObj = new DataLayer();
|
|
private MapoMonEntities db = new MapoMonEntities();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Restituisce dati da DB (e li salva su REDIS...)
|
|
/// </summary>
|
|
/// <param name="dataRefresh">Parametro x procedura ricalcolo MSE</param>
|
|
private List<MappaStatoExpl> getDbSaveRedis(int dataRefresh)
|
|
{
|
|
List<MappaStatoExpl> dati = new List<MappaStatoExpl>();
|
|
// se non c'è rileggo...
|
|
logger.lg.scriviLog("Recuperata MSE da DB");
|
|
dati = db.stp_MSE_getData(dataRefresh).ToList();
|
|
// serializzo
|
|
DataLayerObj.currMSE = JsonConvert.SerializeObject(dati);
|
|
return dati;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Output MSE in formato string/json
|
|
/// </summary>
|
|
public string getData(string id)
|
|
{
|
|
int dataRefresh = 2000;
|
|
string answ = "";
|
|
answ = DataLayerObj.currMSE;
|
|
if (!string.IsNullOrEmpty(answ))
|
|
{
|
|
List<MappaStatoExpl> dati = getDbSaveRedis(dataRefresh);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
// GET: StatusMap
|
|
public ActionResult SingleStatus(string baseCss, string IdxMacchina)
|
|
{
|
|
int dataRefresh = 2000;
|
|
// salvo idxMacc in sessione se c'è...
|
|
if (!string.IsNullOrEmpty(IdxMacchina))
|
|
{
|
|
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>();
|
|
string currMse = DataLayerObj.currMSE;
|
|
if (!string.IsNullOrEmpty(currMse))
|
|
{
|
|
try
|
|
{
|
|
dati = JsonConvert.DeserializeObject<List<MappaStatoExpl>>(currMse);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
dati = getDbSaveRedis(dataRefresh);
|
|
logger.lg.scriviLog(string.Format("Recuperata MSE da DB{0}{1}", Environment.NewLine, exc));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dati = getDbSaveRedis(dataRefresh);
|
|
}
|
|
// filtro dati SOLO PER la macchina che mi interessa... SE C'E'...
|
|
string reqView = "_StatusMap";
|
|
if (IdxMacchina != "***ALL***")
|
|
{
|
|
// se ho elenco macchine idxMacc|idxMacc
|
|
if (IdxMacchina.IndexOf("|") > 0)
|
|
{
|
|
dati = dati.Where(e => IdxMacchina.IndexOf(e.IdxMacchina) >= 0).ToList();
|
|
reqView = "_StatusMapSingle";
|
|
}
|
|
else
|
|
{
|
|
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);
|
|
}
|
|
|
|
// GET: StatusMap
|
|
public ActionResult StatusMap(string baseCss)
|
|
{
|
|
memLayer.ML.setSessionVal("IdxMacchina", "***ALL***");
|
|
return SingleStatus(baseCss, "***ALL***");
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |