Skip to content

Commit

Permalink
Merge pull request #1436 from sbwalker/dev
Browse files Browse the repository at this point in the history
separated updater from main solution
  • Loading branch information
sbwalker committed Jun 3, 2021
2 parents b5a81d8 + 060f764 commit ae2caac
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 63 deletions.
4 changes: 2 additions & 2 deletions Oqtane.Client/Modules/Admin/Upgrade/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
List<Package> packages = await PackageService.GetPackagesAsync("framework");
if (packages != null)
{
_package = packages.FirstOrDefault();
_package = packages.Where(item => item.PackageId.StartsWith(Constants.PackageId)).FirstOrDefault();
if (_package != null)
{
_upgradeavailable = (Version.Parse(_package.Version).CompareTo(Version.Parse(Constants.Version)) > 0);
Expand Down Expand Up @@ -89,7 +89,7 @@
try
{
await PackageService.DownloadPackageAsync(packageid, version, "Packages");
await PackageService.DownloadPackageAsync("Oqtane.Upgrade", version, "Packages");
await PackageService.DownloadPackageAsync(Constants.UpdaterPackageId, version, "Packages");
AddModuleMessage(Localizer["Framework Downloaded Successfully... Please Select Upgrade To Complete the Process"], MessageType.Success);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Oqtane.Upgrade</id>
<id>Oqtane.Updater</id>
<version>2.1.0</version>
<authors>Shaun Walker</authors>
<owners>.NET Foundation</owners>
Expand All @@ -14,10 +14,10 @@
<projectUrl>https://github.com/oqtane/oqtane.framework</projectUrl>
<releaseNotes>https://github.com/oqtane/oqtane.framework/releases/tag/v2.1.0</releaseNotes>
<icon>icon.png</icon>
<tags>oqtane upgrade</tags>
<tags>oqtane</tags>
</metadata>
<files>
<file src="..\Oqtane.Server\bin\Release\net5.0\Oqtane.Upgrade.*" target="lib\net5.0" />
<file src="..\Oqtane.Updater\bin\Release\net5.0\publish\*.*" target="lib\net5.0" />
<file src="icon.png" target="" />
</files>
</package>
6 changes: 4 additions & 2 deletions Oqtane.Package/release.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ copy /Y/B/V "..\Oqtane.Server\bin\Release\net5.0\System.Drawing.Common.dll" "..\
nuget.exe pack Oqtane.Client.nuspec
nuget.exe pack Oqtane.Server.nuspec
nuget.exe pack Oqtane.Shared.nuspec
nuget.exe pack Oqtane.Upgrade.nuspec
nuget.exe pack Oqtane.Framework.nuspec
del /F/Q/S "..\Oqtane.Server\bin\Release\net5.0\publish" > NUL
rmdir /Q/S "..\Oqtane.Server\bin\Release\net5.0\publish"
Expand All @@ -14,7 +13,10 @@ del "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.json"
ren "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.release.json" "appsettings.json"
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ".\install.ps1"
del "..\Oqtane.Server\bin\Release\net5.0\publish\appsettings.json"
del "..\Oqtane.Server\bin\Release\net5.0\publish\Oqtane.Upgrade.*"
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ".\upgrade.ps1"
dotnet clean -c Release ..\Oqtane.Updater.sln
dotnet build -c Release ..\Oqtane.Updater.sln
dotnet publish ..\Oqtane.Updater\Oqtane.Updater.csproj /p:Configuration=Release
nuget.exe pack Oqtane.Updater.nuspec
pause

22 changes: 13 additions & 9 deletions Oqtane.Server/Infrastructure/InstallationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,34 +264,38 @@ public void UpgradeFramework()
// ensure package version is greater than or equal to current framework version
if (packageversion != "" && Version.Parse(Constants.Version).CompareTo(Version.Parse(packageversion)) <= 0 && packageurl != "")
{
// install upgrade nuget package
// install Oqtane.Framework and Oqtane.Updater nuget packages
InstallPackages();
// download upgrade zip package
var client = new WebClient();
Uri uri = new Uri(packageurl);
client.DownloadFile(packageurl, Path.Combine(folder, uri.Segments[uri.Segments.Length - 1]));
// install upgrade zip package
FinishUpgrade();
string upgradepackage = Path.Combine(folder, uri.Segments[uri.Segments.Length - 1]);
client.DownloadFile(packageurl, upgradepackage);
// install Oqtane.Upgrade zip package
if (File.Exists(upgradepackage))
{
FinishUpgrade();
}
}
}
}
}

private void FinishUpgrade()
{
// check if upgrade application exists
string Upgrader = "Oqtane.Upgrade.dll";
// check if updater application exists
string Updater = Constants.UpdaterPackageId + ".dll";
string folder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
if (folder == null || !File.Exists(Path.Combine(folder, Upgrader))) return;
if (folder == null || !File.Exists(Path.Combine(folder, Updater))) return;

// run upgrade application
// run updater application
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo
{
WorkingDirectory = folder,
FileName = "dotnet",
Arguments = Path.Combine(folder, Upgrader) + " \"" + _environment.ContentRootPath + "\" \"" + _environment.WebRootPath + "\"",
Arguments = Path.Combine(folder, Updater) + " \"" + _environment.ContentRootPath + "\" \"" + _environment.WebRootPath + "\"",
UseShellExecute = false,
ErrorDialog = false,
CreateNoWindow = true,
Expand Down
6 changes: 0 additions & 6 deletions Oqtane.Server/Oqtane.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,12 @@
<ItemGroup>
<ProjectReference Include="..\Oqtane.Client\Oqtane.Client.csproj" />
<ProjectReference Include="..\Oqtane.Shared\Oqtane.Shared.csproj" />
<ProjectReference Include="..\Oqtane.Upgrade\Oqtane.Upgrade.csproj" />
</ItemGroup>
<ItemGroup>
<UpgradeFiles Include="$(ProjectDir)bin\Release\net5.0\Oqtane.Upgrade.deps.json" />
<UpgradeFiles Include="$(ProjectDir)bin\Release\net5.0\Oqtane.Upgrade.dll" />
<UpgradeFiles Include="$(ProjectDir)bin\Release\net5.0\Oqtane.Upgrade.pdb" />
<UpgradeFiles Include="$(ProjectDir)bin\Release\net5.0\Oqtane.Upgrade.runtimeconfig.json" />
<ModuleTemplateFiles Include="$(ProjectDir)wwwroot\Modules\Templates\**\*.*" />
<ThemeTemplateFiles Include="$(ProjectDir)wwwroot\Themes\Templates\**\*.*" />
</ItemGroup>
<Target Name="AddPayloadsFolder" AfterTargets="Publish">
<Copy SourceFiles="@(UpgradeFiles)" DestinationFiles="@(UpgradeFiles->'$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
<Copy SourceFiles="@(ModuleTemplateFiles)" DestinationFiles="@(ModuleTemplateFiles->'$(PublishDir)wwwroot\Modules\Templates\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
<Copy SourceFiles="@(ThemeTemplateFiles)" DestinationFiles="@(ThemeTemplateFiles->'$(PublishDir)wwwroot\Themes\Templates\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
</Target></Project>
3 changes: 2 additions & 1 deletion Oqtane.Shared/Shared/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace Oqtane.Shared {

public class Constants {
public const string PackageId = "Oqtane.Framework";
public static readonly string Version = "2.1.0";
public const string ReleaseVersions = "1.0.0,1.0.1,1.0.2,1.0.3,1.0.4,2.0.0,2.0.1,2.0.2,2.1.0";
public const string PackageId = "Oqtane.Framework";
public const string UpdaterPackageId = "Oqtane.Updater";

public const string DefaultDBType = "Oqtane.Database.SqlServer.SqlServerDatabase, Oqtane.Database.SqlServer";

Expand Down
32 changes: 32 additions & 0 deletions Oqtane.Updater.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28822.285
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{77EECA8C-B58E-469E-B8C5-D543AFC9A654}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Updater", "Oqtane.Updater\Oqtane.Updater.csproj", "{2E8C6889-37CF-4C8D-88B1-505547F25098}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1FB11796-35DE-4AED-9A52-17733557FCC4}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\Oqtane.Server\bin\Release\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\Oqtane.Server\bin\Debug\</OutputPath>
</PropertyGroup>

</Project>
52 changes: 25 additions & 27 deletions Oqtane.Upgrade/Program.cs → Oqtane.Updater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
using System.IO.Compression;
using System.Threading;

namespace Oqtane.Upgrade
namespace Oqtane.Updater
{
class Program
{
/// <summary>
/// This console application is responsible for extracting the contents of a previously downloaded Oqtane Upgrade package
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
// requires 2 arguments - the ContentRootPath and the WebRootPath of the site
Expand All @@ -22,11 +26,12 @@ static void Main(string[] args)
string contentrootfolder = args[0];
string webrootfolder = args[1];
string deployfolder = Path.Combine(contentrootfolder, "Packages");
string backupfolder = Path.Combine(contentrootfolder, "Backup");

if (Directory.Exists(deployfolder))
{
string packagename = "";
string[] packages = Directory.GetFiles(deployfolder, "Oqtane.Framework.*.nupkg");
string[] packages = Directory.GetFiles(deployfolder, "Oqtane.Upgrade.*.zip");
if (packages.Length > 0)
{
packagename = packages[packages.Length - 1]; // use highest version
Expand All @@ -40,7 +45,7 @@ static void Main(string[] args)
File.Copy(Path.Combine(webrootfolder, "app_offline.bak"), Path.Combine(contentrootfolder, "app_offline.htm"), true);
}

// get list of files in package
// get list of files in package with local paths
List<string> files = new List<string>();
using (ZipArchive archive = ZipFile.OpenRead(packagename))
{
Expand All @@ -55,18 +60,22 @@ static void Main(string[] args)
{
try
{
// create backup
//clear out backup folder
if (Directory.Exists(backupfolder))
{
Directory.Delete(backupfolder, true);
}
Directory.CreateDirectory(backupfolder);

// backup files
foreach (string file in files)
{
if (File.Exists(file))
string filename = Path.Combine(backupfolder, file.Replace(contentrootfolder, ""));
if (!Directory.Exists(Path.GetDirectoryName(filename)))
{
// remove previous backup if it exists
if (File.Exists(file + ".bak"))
{
File.Delete(file + ".bak");
}
File.Move(file, file + ".bak");
Directory.CreateDirectory(Path.GetDirectoryName(filename));
}
File.Copy(file, filename);
}

// extract files
Expand Down Expand Up @@ -96,14 +105,7 @@ static void Main(string[] args)
if (success)
{
// clean up backup
foreach (string file in files)
{
if (File.Exists(file + ".bak"))
{
File.Delete(file + ".bak");
}
}

Directory.Delete(backupfolder, true);
// delete package
File.Delete(packagename);
}
Expand All @@ -112,15 +114,11 @@ static void Main(string[] args)
// 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);
}
string filename = Path.Combine(backupfolder, file.Replace(contentrootfolder, ""));
File.Copy(filename, file);
}
// clean up backup
Directory.Delete(backupfolder, true);
}
}
catch (Exception ex)
Expand Down
6 changes: 0 additions & 6 deletions Oqtane.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Client", "Oqtane.Cli
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Shared", "Oqtane.Shared\Oqtane.Shared.csproj", "{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Upgrade", "Oqtane.Upgrade\Oqtane.Upgrade.csproj", "{2E8C6889-37CF-4C8D-88B1-505547F25098}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oqtane.Test", "Oqtane.Test\Oqtane.Test.csproj", "{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{77EECA8C-B58E-469E-B8C5-D543AFC9A654}"
Expand Down Expand Up @@ -38,10 +36,6 @@ Global
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19D67A9D-3F2E-41BD-80E6-0B50CA83C3AE}.Release|Any CPU.Build.0 = Release|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E8C6889-37CF-4C8D-88B1-505547F25098}.Release|Any CPU.Build.0 = Release|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Debug|Any CPU.Build.0 = Debug|Any CPU
{823B556D-8D4E-4BB8-A65A-C4EB5E7E7424}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

0 comments on commit ae2caac

Please sign in to comment.