Merge pull request #667 from sbwalker/master
Improvements to System Update
This commit is contained in:
commit
5fb602f733
@ -12,7 +12,7 @@
|
||||
@if (_upgradeavailable)
|
||||
{
|
||||
<ModuleMessage Type="MessageType.Info" Message="Select The Upgrade Button To Install a New Framework Version"></ModuleMessage>
|
||||
@("Framework") @_package.Version <button type="button" class="btn btn-success" @onclick=@(async () => await Download(Constants.PackageId, Constants.Version))>Upgrade</button>
|
||||
<button type="button" class="btn btn-success" @onclick=@(async () => await Download(Constants.PackageId, @_package.Version))>Upgrade To @_package.Version</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
DEL "*.nupkg"
|
||||
del "*.nupkg"
|
||||
dotnet clean -c Release ..\Oqtane.sln
|
||||
dotnet build -c Release ..\Oqtane.sln
|
||||
dotnet publish ..\Oqtane.Server\Oqtane.Server.csproj /p:Configuration=Release
|
||||
nuget.exe pack Oqtane.Framework.nuspec
|
||||
nuget.exe pack Oqtane.Client.nuspec
|
||||
nuget.exe pack Oqtane.Server.nuspec
|
||||
|
@ -186,6 +186,7 @@ namespace Oqtane.Infrastructure
|
||||
packageversion = node.InnerText;
|
||||
}
|
||||
reader.Close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,28 +203,26 @@ namespace Oqtane.Infrastructure
|
||||
private void FinishUpgrade()
|
||||
{
|
||||
// check if upgrade application exists
|
||||
string Upgrader = "Oqtane.Upgrade.dll";
|
||||
string folder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||
if (folder == null || !File.Exists(Path.Combine(folder, "Oqtane.Upgrade.exe"))) return;
|
||||
if (folder == null || !File.Exists(Path.Combine(folder, Upgrader))) return;
|
||||
|
||||
// run upgrade application
|
||||
var process = new Process
|
||||
using (var process = new Process())
|
||||
{
|
||||
StartInfo =
|
||||
process.StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = Path.Combine(folder, "Oqtane.Upgrade.exe"),
|
||||
Arguments = "\"" + _environment.ContentRootPath + "\" \"" + _environment.WebRootPath + "\"",
|
||||
ErrorDialog = false,
|
||||
WorkingDirectory = folder,
|
||||
FileName = "dotnet",
|
||||
Arguments = Path.Combine(folder, Upgrader) + " \"" + _environment.ContentRootPath + "\" \"" + _environment.WebRootPath + "\"",
|
||||
UseShellExecute = false,
|
||||
ErrorDialog = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = false,
|
||||
RedirectStandardError = false
|
||||
}
|
||||
};
|
||||
process.Start();
|
||||
};
|
||||
process.Start();
|
||||
process.Dispose();
|
||||
|
||||
// stop application so upgrade application can proceed
|
||||
RestartApplication();
|
||||
}
|
||||
|
||||
public void RestartApplication()
|
||||
|
@ -22,9 +22,6 @@
|
||||
<Content Remove="wwwroot\Modules\Templates\**" />
|
||||
<EmbeddedResource Remove="wwwroot\Modules\Templates\**" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Scripts\Tenant.01.00.02.01.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Scripts\Master.00.00.00.00.sql" />
|
||||
<EmbeddedResource Include="Scripts\Master.00.09.00.00.sql" />
|
||||
@ -53,4 +50,12 @@
|
||||
<ProjectReference Include="..\Oqtane.Client\Oqtane.Client.csproj" />
|
||||
<ProjectReference Include="..\Oqtane.Shared\Oqtane.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
<ItemGroup>
|
||||
<UpgradeFiles Include="$(ProjectDir)bin\Release\netcoreapp3.1\Oqtane.Upgrade.dll" />
|
||||
<UpgradeFiles Include="$(ProjectDir)bin\Release\netcoreapp3.1\Oqtane.Upgrade.runtimeconfig.json" />
|
||||
<TemplateFiles Include="$(ProjectDir)wwwroot\Modules\Templates\**\*.*" />
|
||||
</ItemGroup>
|
||||
<Target Name="AddPayloadsFolder" AfterTargets="Publish">
|
||||
<Copy SourceFiles="@(UpgradeFiles)" DestinationFiles="@(UpgradeFiles->'$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
|
||||
<Copy SourceFiles="@(TemplateFiles)" DestinationFiles="@(TemplateFiles->'$(PublishDir)wwwroot\Modules\Templates\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
|
||||
</Target></Project>
|
||||
|
@ -9,8 +9,8 @@
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<br /><br /><h1 align="center">Please Wait... Upgrade In Progress....</h1>
|
||||
<img src="https://www.oqtane.org/Portals/0/oqtane-black.png" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);" />
|
||||
<br /><br />
|
||||
<h1 align="center">Please Wait... Upgrade In Progress....</h1>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -11,12 +11,13 @@ namespace Oqtane.Upgrade
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// requires 2 arguments - the ContentRootPath and the WebRootPath of the site
|
||||
|
||||
// for testing purposes set Oqtane.Upgrade as startup project and modify values below
|
||||
//Array.Resize(ref args, 2);
|
||||
//args[0] = @"C:\yourpath\oqtane.framework\Oqtane.Server";
|
||||
//args[1] = @"C:\yourpath\oqtane.framework\Oqtane.Server\wwwroot";
|
||||
|
||||
// requires 2 arguments - the contentrootpath and the webrootpath of the site
|
||||
if (args.Length == 2)
|
||||
{
|
||||
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
@ -47,14 +48,19 @@ namespace Oqtane.Upgrade
|
||||
{
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
switch (Path.GetDirectoryName(entry.FullName).Split('\\')[0])
|
||||
string filename = Path.GetFileName(entry.FullName);
|
||||
if (!string.IsNullOrEmpty(filename))
|
||||
{
|
||||
case "lib":
|
||||
files.Add(Path.Combine(binfolder, Path.GetFileName(entry.FullName)));
|
||||
break;
|
||||
case "wwwroot":
|
||||
files.Add(Path.Combine(webrootfolder, entry.FullName.Replace("wwwroot/", "").Replace("/","\\")));
|
||||
break;
|
||||
// use top level folder to determine location to extract files
|
||||
switch (Path.GetDirectoryName(entry.FullName).Split(Path.DirectorySeparatorChar)[0])
|
||||
{
|
||||
case "lib":
|
||||
files.Add(Path.Combine(binfolder, filename));
|
||||
break;
|
||||
case "wwwroot":
|
||||
files.Add(Path.Combine(webrootfolder, entry.FullName.Replace("wwwroot/", "").Replace("/", Path.DirectorySeparatorChar.ToString())));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -62,74 +68,97 @@ namespace Oqtane.Upgrade
|
||||
// ensure files are not locked
|
||||
if (CanAccessFiles(files))
|
||||
{
|
||||
// create backup
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (File.Exists(file + ".bak"))
|
||||
{
|
||||
File.Delete(file + ".bak");
|
||||
}
|
||||
File.Move(file, file + ".bak");
|
||||
}
|
||||
|
||||
// extract files
|
||||
bool success = true;
|
||||
try
|
||||
{
|
||||
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
||||
{
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
string filename = "";
|
||||
switch (Path.GetDirectoryName(entry.FullName).Split('\\')[0])
|
||||
{
|
||||
case "lib":
|
||||
filename = Path.Combine(binfolder, Path.GetFileName(entry.FullName));
|
||||
break;
|
||||
case "wwwroot":
|
||||
filename = Path.Combine(webrootfolder, entry.FullName.Replace("wwwroot/", "").Replace("/", "\\"));
|
||||
break;
|
||||
}
|
||||
if (files.Contains(filename))
|
||||
{
|
||||
entry.ExtractToFile(filename, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
// an error occurred extracting a file
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
// clean up backup
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (File.Exists(file + ".bak"))
|
||||
{
|
||||
File.Delete(file + ".bak");
|
||||
}
|
||||
}
|
||||
|
||||
// delete package
|
||||
File.Delete(packagename);
|
||||
}
|
||||
else
|
||||
{
|
||||
// restore on failure
|
||||
// create backup
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (File.Exists(file))
|
||||
{
|
||||
File.Delete(file);
|
||||
// remove previous backup if it exists
|
||||
if (File.Exists(file + ".bak"))
|
||||
{
|
||||
File.Delete(file + ".bak");
|
||||
}
|
||||
File.Move(file, file + ".bak");
|
||||
}
|
||||
}
|
||||
|
||||
// extract files
|
||||
bool success = true;
|
||||
try
|
||||
{
|
||||
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
||||
{
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
string filename = Path.GetFileName(entry.FullName);
|
||||
if (!string.IsNullOrEmpty(filename))
|
||||
{
|
||||
// use top level folder to determine location to extract files
|
||||
switch (Path.GetDirectoryName(entry.FullName).Split(Path.DirectorySeparatorChar)[0])
|
||||
{
|
||||
case "lib":
|
||||
filename = Path.Combine(binfolder, filename);
|
||||
break;
|
||||
case "wwwroot":
|
||||
filename = Path.Combine(webrootfolder, entry.FullName.Replace("wwwroot/", "").Replace("/", Path.DirectorySeparatorChar.ToString()));
|
||||
break;
|
||||
}
|
||||
if (files.Contains(filename))
|
||||
{
|
||||
entry.ExtractToFile(filename, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// an error occurred extracting a file
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
// clean up backup
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (File.Exists(file + ".bak"))
|
||||
{
|
||||
File.Delete(file + ".bak");
|
||||
}
|
||||
}
|
||||
|
||||
// delete package
|
||||
File.Delete(packagename);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Update Not Successful: Error Extracting Files From Package");
|
||||
|
||||
// restore on failure
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (File.Exists(file))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
if (File.Exists(file + ".bak"))
|
||||
{
|
||||
File.Move(file + ".bak", file);
|
||||
}
|
||||
}
|
||||
File.Move(file + ".bak", file);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Update Not Successful: " + ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Upgrade Not Successful: Some Files Are Locked");
|
||||
}
|
||||
|
||||
// bring the app back online
|
||||
@ -138,7 +167,19 @@ namespace Oqtane.Upgrade
|
||||
File.Delete(Path.Combine(contentrootfolder, "app_offline.htm"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Framework Upgrade Package Not Found");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Framework Upgrade Folder " + deployfolder + " Does Not Exist");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Missing ContentRootPath and WebRootPath Parameters");
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,8 +199,15 @@ namespace Oqtane.Upgrade
|
||||
{
|
||||
try
|
||||
{
|
||||
stream = File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||
locked = false;
|
||||
if (File.Exists(filepath))
|
||||
{
|
||||
stream = File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||
locked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
locked = false;
|
||||
}
|
||||
}
|
||||
catch // file is locked by another process
|
||||
{
|
||||
|
Reference in New Issue
Block a user