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

@ -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();