|
|
@@ -18,6 +18,8 @@ using System.Reflection;
|
|
|
using System.Net;
|
|
|
using System.IO;
|
|
|
using GreenTree.Nachtragsmanagement.Services.Configuration;
|
|
|
+using GreenTree.Nachtragsmanagement.Web.Extensions;
|
|
|
+using System.IO.Compression;
|
|
|
|
|
|
namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
{
|
|
|
@@ -493,27 +495,30 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
/// </summary>
|
|
|
public ActionResult ViewAppInfo()
|
|
|
{
|
|
|
- var assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
|
|
- .Select(a => new AssemblyDataModel
|
|
|
- {
|
|
|
- Name = a.GetName().Name,
|
|
|
- Version = a.GetName().Version.ToString(),
|
|
|
- Manufacturer =
|
|
|
- a.GetCustomAttributes<AssemblyCompanyAttribute>().Any()
|
|
|
- ? a.GetCustomAttributes<AssemblyCompanyAttribute>()
|
|
|
- .FirstOrDefault().Company
|
|
|
- : "Unbekannt"
|
|
|
- })
|
|
|
- .OrderBy(a => a.Manufacturer)
|
|
|
- .ThenBy(a => a.Name)
|
|
|
- .ToArray();
|
|
|
+ var model = new AppInfoDataModel
|
|
|
+ {
|
|
|
+ BaseDirectory = AppDomain.CurrentDomain.BaseDirectory,
|
|
|
+ IsUpdate = false
|
|
|
+ };
|
|
|
+
|
|
|
+ model.GetAssemblies();
|
|
|
|
|
|
+ return View("~/Views/Admin/AppInfo/View.cshtml", model);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Basic appInfo view function
|
|
|
+ /// </summary>
|
|
|
+ public ActionResult ViewUpdateSuccess()
|
|
|
+ {
|
|
|
var model = new AppInfoDataModel
|
|
|
{
|
|
|
- Assemblies = assemblies,
|
|
|
- BaseDirectory = AppDomain.CurrentDomain.BaseDirectory
|
|
|
+ BaseDirectory = AppDomain.CurrentDomain.BaseDirectory,
|
|
|
+ IsUpdate = true
|
|
|
};
|
|
|
|
|
|
+ model.GetAssemblies();
|
|
|
+
|
|
|
return View("~/Views/Admin/AppInfo/View.cshtml", model);
|
|
|
}
|
|
|
|
|
|
@@ -523,25 +528,112 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
|
|
|
[HttpPost]
|
|
|
public ActionResult CheckUpdate()
|
|
|
{
|
|
|
- var model = new AppUpdateDataModel
|
|
|
+ _logger.Information("Updateüberprüfung gestartet.");
|
|
|
+
|
|
|
+ try
|
|
|
{
|
|
|
- Package = "GreenTree.Nachtragsmanagement",
|
|
|
- CurrentVersion = AppendixVersion.CurrentVersion
|
|
|
- };
|
|
|
+ var model = new AppUpdateDataModel
|
|
|
+ {
|
|
|
+ Package = "GreenTree.Nachtragsmanagement",
|
|
|
+ CurrentVersion = AppendixVersion.CurrentVersion
|
|
|
+ };
|
|
|
|
|
|
- var wc = new WebClient();
|
|
|
+ var webResult = String.Empty;
|
|
|
|
|
|
- wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
|
|
|
- var webData = String.Format("Package={0}&CurrentVersion={1}", model.Package, model.CurrentVersion);
|
|
|
- var webResult = wc.UploadString(_configurationService.GetCurrentConfiguration().CheckUpdateUrl, webData);
|
|
|
+ using (var wc = new WebClient())
|
|
|
+ {
|
|
|
+ wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
|
|
|
+ var webData = String.Format("Package={0}&CurrentVersion={1}", model.Package, model.CurrentVersion);
|
|
|
+ webResult = wc.UploadString(_configurationService.GetCurrentConfiguration().CheckUpdateUrl, webData);
|
|
|
+ }
|
|
|
|
|
|
- var jsonResult = JsonConvert.DeserializeObject<JsonResult>(webResult);
|
|
|
- var result = JsonConvert.DeserializeObject<AppUpdateDataModel>(jsonResult.Data.ToString());
|
|
|
+ var jsonResult = JsonConvert.DeserializeObject<JsonResult>(webResult);
|
|
|
+ var result = JsonConvert.DeserializeObject<AppUpdateDataModel>(jsonResult.Data.ToString());
|
|
|
|
|
|
- return new JsonResult
|
|
|
+ if (result.IsUpdateAvailable)
|
|
|
+ _logger.Information(
|
|
|
+ String.Format(
|
|
|
+ "Es ist ein Update verfügbar (Aktuell: {0} - Neu: {1})!", AppendixVersion.CurrentVersion, result.UpdateVersion));
|
|
|
+ else
|
|
|
+ _logger.Information("Es kein Update verfügbar!");
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = result
|
|
|
+ };
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- Data = result
|
|
|
- };
|
|
|
+ _logger.Error("Fehler bei der Überprüfung eines Updates", ex);
|
|
|
+
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Update check
|
|
|
+ /// </summary>
|
|
|
+ [HttpPost]
|
|
|
+ public ActionResult Update()
|
|
|
+ {
|
|
|
+ _logger.Information("Update gestartet.");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var model = new AppUpdateDataModel
|
|
|
+ {
|
|
|
+ Package = "GreenTree.Nachtragsmanagement",
|
|
|
+ CurrentVersion = AppendixVersion.CurrentVersion
|
|
|
+ };
|
|
|
+
|
|
|
+ var currentConfig = _configurationService.GetCurrentConfiguration();
|
|
|
+
|
|
|
+ AppUpdateDataModel result;
|
|
|
+ string storePath;
|
|
|
+
|
|
|
+ using (var wc = new WebClient())
|
|
|
+ {
|
|
|
+ wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
|
|
|
+ var webData = String.Format("Package={0}&CurrentVersion={1}", model.Package, model.CurrentVersion);
|
|
|
+ var webResult = wc.UploadString(currentConfig.CheckUpdateUrl, webData);
|
|
|
+
|
|
|
+ var jsonResult = JsonConvert.DeserializeObject<JsonResult>(webResult);
|
|
|
+
|
|
|
+ result = JsonConvert.DeserializeObject<AppUpdateDataModel>(jsonResult.Data.ToString());
|
|
|
+
|
|
|
+ storePath = Path.Combine(Server.MapPath(currentConfig.UpdateStorePath), result.PackageFilename);
|
|
|
+
|
|
|
+ if (System.IO.File.Exists(storePath))
|
|
|
+ System.IO.File.Delete(storePath);
|
|
|
+
|
|
|
+ wc.DownloadFile(result.PackagePath, storePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ var hash = HashHelper.GetFileMd5(storePath);
|
|
|
+
|
|
|
+ if (hash != result.PackageMd5Hash)
|
|
|
+ return null;
|
|
|
+
|
|
|
+ var archive = ZipFile.Open(storePath, ZipArchiveMode.Read);
|
|
|
+ var applicationPath = Server.MapPath("/");
|
|
|
+
|
|
|
+ archive.ExtractToDirectory(applicationPath, true);
|
|
|
+
|
|
|
+ _logger.Information("Update erfolgreich durchgeführt - Anwendung wird neu gestartet!");
|
|
|
+
|
|
|
+ _webHelper.RestartAppDomain(true, "~/admin/viewupdatesuccess");
|
|
|
+
|
|
|
+ return new JsonResult
|
|
|
+ {
|
|
|
+ Data = "success"
|
|
|
+ };
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.Error("Fehler bei der Durchführung eines Updates", ex);
|
|
|
+
|
|
|
+ throw;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#endregion
|