diff --git a/Oqtane.Client/Modules/Admin/Upgrade/Index.razor b/Oqtane.Client/Modules/Admin/Upgrade/Index.razor index bded103d..c723d0e6 100644 --- a/Oqtane.Client/Modules/Admin/Upgrade/Index.razor +++ b/Oqtane.Client/Modules/Admin/Upgrade/Index.razor @@ -12,7 +12,7 @@ @if (_upgradeavailable) { - @("Framework") @_package.Version + } else { diff --git a/Oqtane.Package/release.cmd b/Oqtane.Package/release.cmd index 5eba1aae..d70e92ff 100644 --- a/Oqtane.Package/release.cmd +++ b/Oqtane.Package/release.cmd @@ -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 diff --git a/Oqtane.Server/Infrastructure/InstallationManager.cs b/Oqtane.Server/Infrastructure/InstallationManager.cs index 74f38f33..c39978b7 100644 --- a/Oqtane.Server/Infrastructure/InstallationManager.cs +++ b/Oqtane.Server/Infrastructure/InstallationManager.cs @@ -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() diff --git a/Oqtane.Server/Oqtane.Server.csproj b/Oqtane.Server/Oqtane.Server.csproj index 0e172b84..cfc40988 100644 --- a/Oqtane.Server/Oqtane.Server.csproj +++ b/Oqtane.Server/Oqtane.Server.csproj @@ -22,9 +22,6 @@ - - - @@ -53,4 +50,12 @@ - + + + + + + + + + diff --git a/Oqtane.Server/wwwroot/app_offline.bak b/Oqtane.Server/wwwroot/app_offline.bak index d26d5e2b..e4ec3791 100644 --- a/Oqtane.Server/wwwroot/app_offline.bak +++ b/Oqtane.Server/wwwroot/app_offline.bak @@ -9,8 +9,8 @@
-

Please Wait... Upgrade In Progress....

- +

+

Please Wait... Upgrade In Progress....

diff --git a/Oqtane.Upgrade/Program.cs b/Oqtane.Upgrade/Program.cs index d8515e81..10a55ad4 100644 --- a/Oqtane.Upgrade/Program.cs +++ b/Oqtane.Upgrade/Program.cs @@ -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 {