using MP.Models; using SteamWare; using System; using System.Diagnostics; using System.Linq; using System.Web.Configuration; using System.Web.Mvc; 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(); ViewBag.Environment = keyVal[0].valString; // imposto URL dei vari siti ViewBag.UrlMpSite = ctx.stp_AKV_getByKey("UrlMpSite").ToList()[0].valString; ViewBag.UrlMpAdmin = ctx.stp_AKV_getByKey("UrlMpAdmin").ToList()[0].valString; ViewBag.UrlMpIO = ctx.stp_AKV_getByKey("UrlMpIO").ToList()[0].valString; ViewBag.UrlMpMON = ctx.stp_AKV_getByKey("UrlMpMON").ToList()[0].valString; ViewBag.UrlMpTAB = ctx.stp_AKV_getByKey("UrlMpTAB").ToList()[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 = "MoonPro"; ViewBag.Message = "MoonPro è il motore software di MAPO, la nostra soluzione hardware"; return View(); } public ActionResult Contact() { ViewBag.Title = "MoonPro"; ViewBag.Message = "Per contattarci"; return View(); } public ActionResult Packages(string results) { ViewBag.Title = "MoonPro"; 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 }); } /// /// Path locale dove scaricare gli installer /// protected string localDownloadPath(string package) { return string.Format(@"{0}{1}\{2}", memLayer.ML.CRS("downloadPath"), package, memLayer.ML.CRS("appVers")); } /// /// URLK stringa di UPDATE... /// protected string updateUrl(string package) { return string.Format("http://seriate.steamware.net:8083/SWS/MAPO/{0}/{1}/manifest.xml", package, memLayer.ML.CRS("appVers")); } } }