Files
MoonPro.net/MP-LAND/Controllers/HomeController.cs
T
Samuele E. Locatelli 260bc61e7c Renaming progetto LAND
2018-10-19 11:37:24 +02:00

247 lines
8.2 KiB
C#

using MP.Models;
using SteamWare;
using System;
using System.Diagnostics;
using System.Linq;
using System.Web.Configuration;
using System.Web.Mvc;
using ZXing.Common;
using ZXing;
using ZXing.QrCode;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
namespace MP.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Title = "MoonPro";
// x sicurezza leggo da web.config
ViewBag.Environment = WebConfigurationManager.AppSettings["Environment"];
using (var ctx = new MoonProEntities())
{
try
{
// esegue stored procedure come function, recuperando chiave desiderata...
var keyVal = ctx.stp_AKV_getByKey("Environment").ToList<AnagKeyValue>();
ViewBag.Environment = keyVal[0].valString;
// imposto URL dei vari siti
ViewBag.UrlMpSite = ctx.stp_AKV_getByKey("UrlMpSite").ToList<AnagKeyValue>()[0].valString;
ViewBag.UrlMpAdmin = ctx.stp_AKV_getByKey("UrlMpAdmin").ToList<AnagKeyValue>()[0].valString;
ViewBag.UrlMpIO = ctx.stp_AKV_getByKey("UrlMpIO").ToList<AnagKeyValue>()[0].valString;
ViewBag.UrlMpMON = ctx.stp_AKV_getByKey("UrlMpMON").ToList<AnagKeyValue>()[0].valString;
ViewBag.UrlMpTAB = ctx.stp_AKV_getByKey("UrlMpTAB").ToList<AnagKeyValue>()[0].valString;
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Eccezione in composizione HOME page LAND:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
ViewBag.UrlMpSite = WebConfigurationManager.AppSettings["UrlMpSite"];//"../MP/SITE";
ViewBag.UrlMpAdmin = WebConfigurationManager.AppSettings["UrlMpAdmin"];//"../MP/ADM";
ViewBag.UrlMpIO = WebConfigurationManager.AppSettings["UrlMpIO"];//"../MP/IO";
ViewBag.UrlMpMON = WebConfigurationManager.AppSettings["UrlMpMON"];//"../MP/MON";
ViewBag.UrlMpTAB = WebConfigurationManager.AppSettings["UrlMpTAB"];//"../MP/TAB";
}
}
return View();
}
public ActionResult About()
{
ViewBag.Title = "MES | SCADA | IOT";
ViewBag.Message = "Soluzione integrata per la gestione della produzione";
return View();
}
public ActionResult Contact()
{
ViewBag.Title = "MAPO";
ViewBag.Message = "Per contattarci";
return View();
}
public ActionResult Packages(string results)
{
ViewBag.Title = "Steamware's MAPO Suite";
ViewBag.Message = "Ultime release applicazioni";
UpdateInfoEventArgs updArgs = new UpdateInfoEventArgs();
// Recupero info ADM...
updArgs = UpdateMan.obj.getUpdateInfo(updateUrl("ADM"));
if (updArgs.IsUpdateAvailable)
{
ViewBag.VersMpAdmin = updArgs.CurrentVersion;
}
else
{
ViewBag.VersMpAdmin = "ND";
ViewBag.AdmDisabled = "disabled";
}
// Recupero info IO...
updArgs = UpdateMan.obj.getUpdateInfo(updateUrl("IO"));
if (updArgs.IsUpdateAvailable)
{
ViewBag.VersMpIO = updArgs.CurrentVersion;
}
else
{
ViewBag.VersMpIO = "ND";
ViewBag.IODisabled = "disabled";
}
// Recupero info LAND...
updArgs = UpdateMan.obj.getUpdateInfo(updateUrl("LAND"));
if (updArgs.IsUpdateAvailable)
{
ViewBag.VersMpLand = updArgs.CurrentVersion;
}
else
{
ViewBag.VersMpLand = "ND";
ViewBag.LandDisabled = "disabled";
}
// Recupero info MON...
updArgs = UpdateMan.obj.getUpdateInfo(updateUrl("MON"));
if (updArgs.IsUpdateAvailable)
{
ViewBag.VersMpMon = updArgs.CurrentVersion;
}
else
{
ViewBag.VersMpMon = "ND";
ViewBag.MonDisabled = "disabled";
}
// Recupero info SITE...
updArgs = UpdateMan.obj.getUpdateInfo(updateUrl("SITE"));
if (updArgs.IsUpdateAvailable)
{
ViewBag.VersMpSite = updArgs.CurrentVersion;
}
else
{
ViewBag.VersMpSite = "ND";
ViewBag.SiteDisabled = "disabled";
}
// Recupero info TAB...
updArgs = UpdateMan.obj.getUpdateInfo(updateUrl("TAB"));
if (updArgs.IsUpdateAvailable)
{
ViewBag.VersMpTab = updArgs.CurrentVersion;
}
else
{
ViewBag.VersMpTab = "ND";
ViewBag.TabDisabled = "disabled";
}
// salvo risultati...
ViewBag.Results = results;
// VIEW!
return View();
}
// GET: Home/Download/Caller (ALL|ADM|IO|LAND|MON|SITE|TAB)
public ActionResult Download(string caller)
{
string resultsMsg = "";
// in base al caller scarico il file installazione richiesto...
if (caller == null)
{
caller = "ALL";
}
// ora verifico COSA devo scaricare...
if (updateUrl(caller) != "")
{
// se è ALL scarico tuttoi...
if (caller == "ALL")
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
int done = 0;
// scarico TUTTI...
done += UpdateMan.obj.downloadLatest(updateUrl("ADM"), localDownloadPath("ADM"), "ADM");
done += UpdateMan.obj.downloadLatest(updateUrl("IO"), localDownloadPath("IO"), "IO");
done += UpdateMan.obj.downloadLatest(updateUrl("LAND"), localDownloadPath("LAND"), "LAND");
done += UpdateMan.obj.downloadLatest(updateUrl("MON"), localDownloadPath("MON"), "MON");
done += UpdateMan.obj.downloadLatest(updateUrl("SITE"), localDownloadPath("SITE"), "SITE");
done += UpdateMan.obj.downloadLatest(updateUrl("TAB"), localDownloadPath("TAB"), "TAB");
stopWatch.Stop();
// calcolo elapsed time come TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
resultsMsg = string.Format("OK: {0} Package downloaded, {1:0.000} sec", done, ts.TotalSeconds);
}
else
{
// scarico singolo target...
UpdateMan.obj.downloadLatest(updateUrl(caller), localDownloadPath(caller), caller);
resultsMsg = string.Format("OK: {0} DOWNLOADED | {1} --> {2}", caller, updateUrl(caller), localDownloadPath(caller));
}
}
// ...chiamo action
return RedirectToAction("Packages", "Home", new { results = resultsMsg });
}
public ActionResult UserListQR()
{
ViewBag.Title = "QR link";
ViewBag.Message = WebConfigurationManager.AppSettings["Cliente"];
ViewBag.BaseUrl = WebConfigurationManager.AppSettings["baseAuthUrl"];
ViewBag.Environment = WebConfigurationManager.AppSettings["Environment"];
using (var ctx = new MoonProEntities())
{
try
{
// esegue stored procedure come function, recuperando chiave desiderata...
var elOperatori = ctx.AnagraficaOperatori.ToList<AnagraficaOperatori>();
ViewBag.elOperatori = elOperatori;
}
catch
{ }
}
return View((object)ViewBag.elOperatori);
}
/// <summary>
/// Restituisce un QR code dato valore
/// </summary>
/// <param name="valore"></param>
/// <returns></returns>
public ActionResult QR(string valore)
{
QrCodeEncodingOptions options = new QrCodeEncodingOptions
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = 600,
Height = 600,
Margin = 0
};
var writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;
// scrivo bitmap
var pixelData = writer.Write(valore);
// Return Image
MemoryStream ms = new MemoryStream();
pixelData.Save(ms, ImageFormat.Png);
ms.Position = 0;
return new FileStreamResult(ms, "image/png");
}
/// <summary>
/// Path locale dove scaricare gli installer
/// </summary>
protected string localDownloadPath(string package)
{
return string.Format(@"{0}{1}\{2}", memLayer.ML.CRS("downloadPath"), package, memLayer.ML.CRS("appVers"));
}
/// <summary>
/// URLK stringa di UPDATE...
/// </summary>
protected string updateUrl(string package)
{
return string.Format("http://seriate.steamware.net:8083/SWS/MAPO/{0}/{1}/manifest.xml", package, memLayer.ML.CRS("appVers"));
}
}
}