Files
MoonPro.net/MP-MON/Controllers/HomeController.cs
T
2018-04-26 18:22:18 +02:00

104 lines
3.3 KiB
C#

using MP_MON.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Configuration;
using System.Web.Mvc;
namespace MP_MON.Controllers
{
public class HomeController : Controller
{
private MoonProEntities db = new MoonProEntities();
public ActionResult Index()
{
// ricarico ogni minuto COMUNQUE tutto...
string pageRefreshSec = "60";
// refresh std ogni sec
int pageRefreshMs = 1000;
ViewBag.cssSemBase = "sem";
try
{
pageRefreshSec = WebConfigurationManager.AppSettings["pageRefreshSec"];
}
catch
{ }
if (pageRefreshSec == "") pageRefreshSec = "60";
ViewBag.pageRefreshMs = pageRefreshMs;
Response.AddHeader("Refresh", pageRefreshSec);
return View();
}
public ActionResult Blink()
{
// ricarico ogni minuto COMUNQUE tutto...
string pageRefreshSec = "60";
// se ho animazione refresh è ogni 2 sec...
int pageRefreshMs = 2000;
ViewBag.cssSemBase = "semBlink";
try
{
pageRefreshSec = WebConfigurationManager.AppSettings["pageRefreshSec"];
}
catch
{ }
if (pageRefreshSec == "") pageRefreshSec = "60";
ViewBag.pageRefreshMs = pageRefreshMs;
Response.AddHeader("Refresh", pageRefreshSec);
return View("Index");
}
public ActionResult GetClock()
{
return PartialView("_mmClock");
}
public ActionResult checkIOB()
{
string esito = "ND";
// verifico TUTTE le macchine x il keepAlive e se almeno 1 è offline da oltre "keepAliveMin" minuti --> invio email!!!
int keepAliveMin = 1;
try
{
keepAliveMin = Convert.ToInt32(WebConfigurationManager.AppSettings["keepAliveMin"]);
}
catch
{ }
// recupero elenco macchine offline e mostro!
var MappaStato = db.stp_MSE_getOffline(keepAliveMin);
List<MappaStatoExpl> risultato = MappaStato.ToList();
int numKO = risultato.Count;
if (numKO > 0)
{
// scrivo esito
esito = string.Format("Trovate {0} schede offline", numKO);
// invio email...
string from = WebConfigurationManager.AppSettings["_fromEmail"];
string to = WebConfigurationManager.AppSettings["_checkIobEmail"];
string subject = "MapoIOB - ciclo di controllo schede MapoIOB";
string body = string.Format("<h2>Attenzione!</h2> durante l'ultimo ciclo di controllo sono state {1}{0}", Environment.NewLine, esito);
foreach (MappaStatoExpl item in risultato)
{
body += string.Format("{2}<b>{0}</b> \t\t | Art: {1}", item.Nome, item.CodArticolo, Environment.NewLine);
}
// se ho una pwd/user utilizzo smtp auth, altrimenti base...
if ((WebConfigurationManager.AppSettings["_emailUser"] != "") && (WebConfigurationManager.AppSettings["_emailPwd"] != ""))
{
SteamWare.gestEmail.geAuth.mandaEmail(from, to, subject, body);
}
else
{
SteamWare.gestEmail.ge.mandaEmail(from, to, subject, body);
}
}
else
{
esito = "OK";
}
ViewBag.EsitoVerifica = esito;
// inserisco elenco macchine offline x rendering in partialView
return PartialView("_checkIOB", risultato);
}
}
}