393 lines
13 KiB
C#
393 lines
13 KiB
C#
using MP.Models;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Configuration;
|
|
using System.Web.Mvc;
|
|
using ZXing;
|
|
using ZXing.QrCode;
|
|
|
|
namespace MP.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
public ActionResult Index()
|
|
{
|
|
ViewBag.Title = "MAPO";
|
|
// 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...
|
|
ViewBag.Environment = ctx.stp_AKV_getByKey("Environment").ToList<AnagKeyValue>()[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;
|
|
ViewBag.UrlMpCTrack = ctx.stp_AKV_getByKey("UrlMpCTrack").ToList<AnagKeyValue>()[0].valString;
|
|
// importo verifica abilitazione CTrack - !!!FARE!!! vero check key auth!
|
|
ViewBag.CTrack_Enb = (ctx.stp_AKV_getByKey("CTRACK").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);
|
|
// Default: NO CTrack
|
|
ViewBag.CTrack_Enb = false;
|
|
}
|
|
}
|
|
return View();
|
|
}
|
|
/// <summary>
|
|
/// info steamware
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ActionResult About()
|
|
{
|
|
ViewBag.Title = "MES | SCADA | IOT";
|
|
ViewBag.Message = "Soluzione integrata per la gestione della produzione";
|
|
|
|
return View();
|
|
}
|
|
/// <summary>
|
|
/// contatti
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ActionResult Contact()
|
|
{
|
|
ViewBag.Title = "MAPO";
|
|
ViewBag.Message = "Per contattarci";
|
|
return View();
|
|
}
|
|
/// <summary>
|
|
/// System INFO
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ActionResult System()
|
|
{
|
|
ViewBag.Title = "MAPO System Info";
|
|
ViewBag.Message = "HW & SW details";
|
|
return View();
|
|
}
|
|
/// <summary>
|
|
/// Gestione download aggiornamenti
|
|
/// </summary>
|
|
/// <param name="results"></param>
|
|
/// <returns></returns>
|
|
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";
|
|
}
|
|
// Recupero info CTRACK...
|
|
updArgs = UpdateMan.obj.getUpdateInfo(updateUrl("CTRACK"));
|
|
if (updArgs.IsUpdateAvailable)
|
|
{
|
|
ViewBag.VersMpCTrack = updArgs.CurrentVersion;
|
|
}
|
|
else
|
|
{
|
|
ViewBag.VersMpCTrack = "ND";
|
|
ViewBag.TabDisabled = "disabled";
|
|
}
|
|
// salvo risultati...
|
|
ViewBag.Results = results;
|
|
// fix visibilità CTrack
|
|
using (var ctx = new MoonProEntities())
|
|
{
|
|
try
|
|
{
|
|
// importo verifica abilitazione CTrack - !!!FARE!!! vero check key auth!
|
|
ViewBag.CTrack_Enb = (ctx.stp_AKV_getByKey("CTRACK").ToList<AnagKeyValue>()[0].valString != "");
|
|
}
|
|
catch
|
|
{
|
|
ViewBag.CTrack_Enb = false;
|
|
}
|
|
}
|
|
// VIEW!
|
|
return View();
|
|
}
|
|
/// <summary>
|
|
/// Gestione configurazioni applicativi (DB)
|
|
/// </summary>
|
|
/// <param name="results"></param>
|
|
/// <returns></returns>
|
|
public ActionResult ConfigMan(string sorgente)
|
|
{
|
|
ViewBag.Title = "Steamware's MAPO Suite - Configurations";
|
|
|
|
// cerco file se disponibile...
|
|
string filePath = Path.Combine(Server.MapPath("~/FileUpload"), "web.config");
|
|
bool fileExist = (fileMover.obj.fileExist(Server.MapPath("~/FileUpload"), "web.config"));
|
|
if (fileExist)
|
|
{
|
|
ViewBag.Message = "File web.config presente";
|
|
// leggo il file di conf caricato...
|
|
System.Configuration.Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration("~/FileUpload/web.config");
|
|
|
|
if (sorgente != "" && sorgente != null)
|
|
{
|
|
// resetto tab import
|
|
memLayer.ML.taConfigTmp.reset(sorgente);
|
|
// carico dati!
|
|
var settings = rootWebConfig.AppSettings.Settings;
|
|
foreach (var item in settings.AllKeys)
|
|
{
|
|
memLayer.ML.taConfigTmp.insertQuery(sorgente, item, settings[item].Value, string.Format("{0}|{1}", sorgente, item));
|
|
}
|
|
// salvo in viewbag gli elenchi 0/1/2 (tutte, nuove, modificate)
|
|
|
|
using (var ctx = new MoonProEntities())
|
|
{
|
|
try
|
|
{
|
|
// esegue stored procedure come function, recuperando chiave desiderata...
|
|
var elConfig = ctx.ConfigTmp.ToList<ConfigTmp>();
|
|
ViewBag.elConfig = elConfig;
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
|
|
ViewBag.keyList = "CARICATO!";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ViewBag.Message = "Attenzione: nessun file presente!";
|
|
}
|
|
// VIEW!
|
|
return View((object)ViewBag.elConfig);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult UploadFile(HttpPostedFileBase file, string sorgente)
|
|
{
|
|
if (file != null && file.ContentLength > 0 && sorgente != "")
|
|
{
|
|
try
|
|
{
|
|
// forzo nome SEMPRE a web.config
|
|
//string path = Path.Combine(Server.MapPath("~/FileUpload"), Path.GetFileName(file.FileName).ToLower());
|
|
string path = Path.Combine(Server.MapPath("~/FileUpload"), "web.config");
|
|
file.SaveAs(path);
|
|
ViewBag.Message = "File Caricato!";
|
|
// ora processo import del sorgente selezionato...
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ViewBag.Message = "ERROR:" + ex.Message.ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ViewBag.Message = "Non è stato selezionato alcun file.";
|
|
}
|
|
return RedirectToAction("ConfigMan", "Home", new { sorgente });
|
|
}
|
|
|
|
|
|
// GET: Home/Download/Caller (ALL|ADM|IO|LAND|MON|SITE|TAB|CTRACK)
|
|
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");
|
|
done += UpdateMan.obj.downloadLatest(updateUrl("CTRACK"), localDownloadPath("CTRACK"), "CTRACK");
|
|
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 });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gestione QRCode utenti TAB
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ActionResult UserListQR(string id, string From, string Lenght)
|
|
{
|
|
int lenght = 0;
|
|
int from = 0;
|
|
int.TryParse(Lenght, out lenght);
|
|
int.TryParse(From, out from);
|
|
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>();
|
|
if (from + lenght > 0)
|
|
{
|
|
// seleziono sottoelenco SE ammissibile...
|
|
int numRec = elOperatori.Count;
|
|
lenght = lenght == 0 ? numRec : lenght;
|
|
from = from > numRec ? 0 : from;
|
|
if (from < numRec)
|
|
{
|
|
lenght = from + lenght < numRec ? lenght : numRec - from;
|
|
elOperatori = elOperatori.GetRange(from, lenght);
|
|
}
|
|
}
|
|
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"));
|
|
}
|
|
}
|
|
} |