automated framework update enhancement
This commit is contained in:
@ -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();
|
||||
|
Reference in New Issue
Block a user