automated framework update enhancement

This commit is contained in:
Shaun Walker
2019-10-30 17:03:09 -04:00
parent af423edb99
commit 0e09cdf20a
8 changed files with 266 additions and 2 deletions

View File

@ -279,7 +279,7 @@ namespace Oqtane.Controllers
public GenericResponse Upgrade()
{
var response = new GenericResponse { Success = true, Message = "" };
InstallationManager.InstallPackages("Framework", true);
InstallationManager.UpgradeFramework();
return response;
}
}

View File

@ -3,6 +3,7 @@
public interface IInstallationManager
{
void InstallPackages(string Folders, bool Restart);
void UpgradeFramework();
void RestartApplication();
}
}

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Hosting;
using System.Xml;
using Oqtane.Shared;
using System;
using System.Diagnostics;
namespace Oqtane.Infrastructure
{
@ -110,6 +111,98 @@ namespace Oqtane.Infrastructure
}
}
public void UpgradeFramework()
{
string folder = Path.Combine(environment.WebRootPath, "Framework");
if (Directory.Exists(folder))
{
string upgradepackage = "";
// iterate through packages
foreach (string packagename in Directory.GetFiles(folder, "Oqtane.Framework.*.nupkg"))
{
using (ZipArchive archive = ZipFile.OpenRead(packagename))
{
string frameworkversion = "";
// locate nuspec
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.ToLower().EndsWith(".nuspec"))
{
// open nuspec
XmlTextReader reader = new XmlTextReader(entry.Open());
reader.Namespaces = false; // remove namespace
XmlDocument doc = new XmlDocument();
doc.Load(reader);
// get framework version
XmlNode node = doc.SelectSingleNode("/package/metadata/version");
if (node != null)
{
frameworkversion = node.InnerText;
}
reader.Close();
}
}
// ensure package version is higher than current framework
if (frameworkversion != "" && Version.Parse(Constants.Version).CompareTo(Version.Parse(frameworkversion)) < 0)
{
upgradepackage = packagename;
}
else
{
File.Delete(packagename);
}
}
}
if (upgradepackage != "")
{
FinishUpgrade(upgradepackage);
}
}
}
private void FinishUpgrade(string packagename)
{
string folder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
// check if upgrade application exists
if (File.Exists(Path.Combine(folder, "Oqtane.Upgrade.exe")))
{
// unzip package
using (ZipArchive archive = ZipFile.OpenRead(packagename))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
string filename = Path.GetFileName(entry.FullName);
if (Path.GetExtension(filename) == ".dll")
{
entry.ExtractToFile(Path.Combine(Path.Combine(environment.WebRootPath, "Framework"), filename), true);
}
}
}
// delete package
File.Delete(packagename);
// run upgrade application
var process = new Process();
process.StartInfo.FileName = Path.Combine(folder, "Oqtane.Upgrade.exe");
process.StartInfo.Arguments = "";
process.StartInfo.ErrorDialog = false;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = false;
process.StartInfo.RedirectStandardError = false;
process.Start();
process.Dispose();
// stop application so upgrade application can proceed
RestartApplication();
}
}
public void RestartApplication()
{
HostApplicationLifetime.StopApplication();

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width">
<title>Oqtane</title>
<base href="/" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div>
<br /><br /><h1 align="center">Please Wait... Upgrade In Progress....</h1>
<img src="https://www.oqtane.org/Portals/0/oqtane.png" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);" />
</div>
</body>
</html>