diff --git a/.gitignore b/.gitignore index 29b72c2a9..26953347a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ msbuild.binlog .vscode/ *.binlog *.nupkg +*.nupkg.bak *.idea @@ -17,3 +18,6 @@ Oqtane.Server/Data/*.db /Oqtane.Server/Properties/PublishProfiles/FolderProfile.pubxml Oqtane.Server/Content +Oqtane.Server/wwwroot/Packages/**/assets.json + + diff --git a/Oqtane.Client/Installer/Installer.razor b/Oqtane.Client/Installer/Installer.razor index 9891fd089..dd1dcfec7 100644 --- a/Oqtane.Client/Installer/Installer.razor +++ b/Oqtane.Client/Installer/Installer.razor @@ -175,6 +175,7 @@ var config = new InstallConfig { DatabaseType = database.DBType, + DatabasePackage = database.Package, ConnectionString = connectionString, Aliases = uri.Authority, HostEmail = _hostEmail, diff --git a/Oqtane.Client/Modules/Admin/Sites/Add.razor b/Oqtane.Client/Modules/Admin/Sites/Add.razor index f21f7f1e2..da496c795 100644 --- a/Oqtane.Client/Modules/Admin/Sites/Add.razor +++ b/Oqtane.Client/Modules/Admin/Sites/Add.razor @@ -306,6 +306,7 @@ else { config.TenantName = _tenantName; config.DatabaseType = database.DBType; + config.DatabasePackage = database.Package; config.ConnectionString = connectionString; config.HostEmail = user.Email; config.HostPassword = _hostpassword; diff --git a/Oqtane.Database.MySQL/MySQLDatabase.cs b/Oqtane.Database.MySQL/MySQLDatabase.cs index 19d4de39d..2126399fc 100644 --- a/Oqtane.Database.MySQL/MySQLDatabase.cs +++ b/Oqtane.Database.MySQL/MySQLDatabase.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; using MySql.Data.MySqlClient; using MySql.EntityFrameworkCore.Metadata; +using Oqtane.Databases; using Oqtane.Shared; namespace Oqtane.Database.MySQL @@ -14,21 +15,15 @@ public class MySQLDatabase : OqtaneDatabaseBase private static string _name => "MySQL"; - private readonly static string _typeName; - static MySQLDatabase() { - var typeQualifiedName = typeof(MySQLDatabase).AssemblyQualifiedName; - - _typeName = typeQualifiedName.Substring(0, typeQualifiedName.IndexOf(", Version")); + Initialize(typeof(MySQLDatabase)); } public MySQLDatabase() :base(_name, _friendlyName) { } public override string Provider => "MySql.EntityFrameworkCore"; - public override string TypeName => _typeName; - public override OperationBuilder AddAutoIncrementColumn(ColumnsBuilder table, string name) { return table.Column(name: name, nullable: false).Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn); diff --git a/Oqtane.Database.MySQL/Oqtane.Database.MySQL.csproj b/Oqtane.Database.MySQL/Oqtane.Database.MySQL.csproj index cc1cd3065..218ae73e2 100644 --- a/Oqtane.Database.MySQL/Oqtane.Database.MySQL.csproj +++ b/Oqtane.Database.MySQL/Oqtane.Database.MySQL.csproj @@ -1,16 +1,32 @@ - - net5.0 - 9 - + + net5.0 + true + true + 1.0.0 + $(MSBuildProjectName).nuspec + $(MSBuildProjectName).$(Version).nupkg + true + - - - + + bin + - - - + + bin + + + + + + + + + + + + diff --git a/Oqtane.Database.MySQL/Oqtane.Database.MySQL.nuspec b/Oqtane.Database.MySQL/Oqtane.Database.MySQL.nuspec new file mode 100644 index 000000000..b8f1c17fd --- /dev/null +++ b/Oqtane.Database.MySQL/Oqtane.Database.MySQL.nuspec @@ -0,0 +1,25 @@ + + + + Oqtane.Database.MySQL + 1.0.0 + Shaun Walker + .NET Foundation + Oqtane MySQL Provider + Add support for MySQL to the Oqtane Framework + .NET Foundation + false + MIT + https://github.com/oqtane/oqtane.framework + https://www.oqtane.org/Portals/0/icon.jpg + oqtane + https://github.com/oqtane/oqtane.framework/releases/tag/v2.0.2 + Add support for MySQL to the Oqtane Framework + + + + + + + + \ No newline at end of file diff --git a/Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.csproj b/Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.csproj index 6f1c3507d..881153c50 100644 --- a/Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.csproj +++ b/Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.csproj @@ -1,18 +1,34 @@ - - 9 - net5.0 - + + net5.0 + true + true + 1.0.0 + $(MSBuildProjectName).nuspec + $(MSBuildProjectName).$(Version).nupkg + true + - - - - - + + bin + - - - + + bin + + + + + + + + + + + + + + diff --git a/Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.nuspec b/Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.nuspec new file mode 100644 index 000000000..db413608c --- /dev/null +++ b/Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.nuspec @@ -0,0 +1,26 @@ + + + + Oqtane.Database.PostgreSQL + 1.0.0 + Shaun Walker + .NET Foundation + Oqtane PostgreSQL Provider + Add support for PostgreSQL to the Oqtane Framework + .NET Foundation + false + MIT + https://github.com/oqtane/oqtane.framework + https://www.oqtane.org/Portals/0/icon.jpg + oqtane + https://github.com/oqtane/oqtane.framework/releases/tag/v2.0.2 + Add support for PostgreSQL to the Oqtane Framework + + + + + + + + + \ No newline at end of file diff --git a/Oqtane.Database.PostgreSQL/PostgreSQLDatabase.cs b/Oqtane.Database.PostgreSQL/PostgreSQLDatabase.cs index dbd1c953f..efc4a62b6 100644 --- a/Oqtane.Database.PostgreSQL/PostgreSQLDatabase.cs +++ b/Oqtane.Database.PostgreSQL/PostgreSQLDatabase.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; using Npgsql; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Oqtane.Databases; using Oqtane.Shared; namespace Oqtane.Database.PostgreSQL @@ -17,15 +18,11 @@ public class PostgreSQLDatabase : OqtaneDatabaseBase private static string _name => "PostgreSQL"; - private readonly static string _typeName; - private readonly INameRewriter _rewriter; static PostgreSQLDatabase() { - var typeQualifiedName = typeof(PostgreSQLDatabase).AssemblyQualifiedName; - - _typeName = typeQualifiedName.Substring(0, typeQualifiedName.IndexOf(", Version")); + Initialize(typeof(PostgreSQLDatabase)); } public PostgreSQLDatabase() : base(_name, _friendlyName) @@ -35,8 +32,6 @@ public PostgreSQLDatabase() : base(_name, _friendlyName) public override string Provider => "Npgsql.EntityFrameworkCore.PostgreSQL"; - public override string TypeName => _typeName; - public override OperationBuilder AddAutoIncrementColumn(ColumnsBuilder table, string name) { return table.Column(name: name, nullable: false).Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn); diff --git a/Oqtane.Database.SqlServer/LocalDbDatabase.cs b/Oqtane.Database.SqlServer/LocalDbDatabase.cs index be9ed7ce6..3e0716d3c 100644 --- a/Oqtane.Database.SqlServer/LocalDbDatabase.cs +++ b/Oqtane.Database.SqlServer/LocalDbDatabase.cs @@ -5,17 +5,11 @@ public class LocalDbDatabase : SqlServerDatabaseBase private static string _friendlyName => "Local Database"; private static string _name => "LocalDB"; - private readonly static string _typeName; - static LocalDbDatabase() { - var typeQualifiedName = typeof(LocalDbDatabase).AssemblyQualifiedName; - - _typeName = typeQualifiedName.Substring(0, typeQualifiedName.IndexOf(", Version")); + Initialize(typeof(LocalDbDatabase)); } public LocalDbDatabase() :base(_name, _friendlyName) { } - - public override string TypeName => _typeName; } } diff --git a/Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.csproj b/Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.csproj index c61607a7f..2765330b9 100644 --- a/Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.csproj +++ b/Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.csproj @@ -1,15 +1,33 @@ - - net5.0 - + + net5.0 + true + true + 1.0.0 + $(MSBuildProjectName).nuspec + $(MSBuildProjectName).$(Version).nupkg + true + - - - + + bin + - - - + + bin + + + + + + + + + + + + + diff --git a/Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.nuspec b/Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.nuspec new file mode 100644 index 000000000..2ebbb90c1 --- /dev/null +++ b/Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.nuspec @@ -0,0 +1,24 @@ + + + + Oqtane.Database.SqlServer + 1.0.0 + Shaun Walker + .NET Foundation + Oqtane SqlServer Provider + Add support for SqlServer to the Oqtane Framework + .NET Foundation + false + MIT + https://github.com/oqtane/oqtane.framework + https://www.oqtane.org/Portals/0/icon.jpg + oqtane + https://github.com/oqtane/oqtane.framework/releases/tag/v2.0.2 + Add support for SqlServer to the Oqtane Framework + + + + + + + \ No newline at end of file diff --git a/Oqtane.Database.SqlServer/SqlServerDatabase.cs b/Oqtane.Database.SqlServer/SqlServerDatabase.cs index 85dd54de5..69d48a7d3 100644 --- a/Oqtane.Database.SqlServer/SqlServerDatabase.cs +++ b/Oqtane.Database.SqlServer/SqlServerDatabase.cs @@ -6,17 +6,11 @@ public class SqlServerDatabase : SqlServerDatabaseBase private static string _name => "SqlServer"; - private readonly static string _typeName; - static SqlServerDatabase() { - var typeQualifiedName = typeof(SqlServerDatabase).AssemblyQualifiedName; - - _typeName = typeQualifiedName.Substring(0, typeQualifiedName.IndexOf(", Version")); + Initialize(typeof(SqlServerDatabase)); } public SqlServerDatabase() : base(_name, _friendlyName) { } - - public override string TypeName => _typeName; } } diff --git a/Oqtane.Database.SqlServer/SqlServerDatabaseBase.cs b/Oqtane.Database.SqlServer/SqlServerDatabaseBase.cs index 93fa1044a..1b18b1d18 100644 --- a/Oqtane.Database.SqlServer/SqlServerDatabaseBase.cs +++ b/Oqtane.Database.SqlServer/SqlServerDatabaseBase.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases; using Oqtane.Shared; namespace Oqtane.Database.SqlServer diff --git a/Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.csproj b/Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.csproj index 75f13dad7..1f30300bf 100644 --- a/Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.csproj +++ b/Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.csproj @@ -1,15 +1,33 @@ - - net5.0 - + + net5.0 + true + true + 1.0.0 + $(MSBuildProjectName).nuspec + $(MSBuildProjectName).$(Version).nupkg + true + - - - + + bin + - - - + + bin + + + + + + + + + + + + + diff --git a/Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.nuspec b/Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.nuspec new file mode 100644 index 000000000..d3a82f0d0 --- /dev/null +++ b/Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.nuspec @@ -0,0 +1,24 @@ + + + + Oqtane.Database.Sqlite + 1.0.0 + Shaun Walker + .NET Foundation + Oqtane Sqlite Provider + Add support for Sqlite to the Oqtane Framework + .NET Foundation + false + MIT + https://github.com/oqtane/oqtane.framework + https://www.oqtane.org/Portals/0/icon.jpg + oqtane + https://github.com/oqtane/oqtane.framework/releases/tag/v2.0.2 + Add support for Sqlite to the Oqtane Framework + + + + + + + \ No newline at end of file diff --git a/Oqtane.Database.Sqlite/SqliteDatabase.cs b/Oqtane.Database.Sqlite/SqliteDatabase.cs index 7f01db748..56c931514 100644 --- a/Oqtane.Database.Sqlite/SqliteDatabase.cs +++ b/Oqtane.Database.Sqlite/SqliteDatabase.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases; using Oqtane.Shared; namespace Oqtane.Database.Sqlite @@ -14,21 +15,15 @@ public class SqliteDatabase : OqtaneDatabaseBase private static string _name => "Sqlite"; - private readonly static string _typeName; - static SqliteDatabase() { - var typeQualifiedName = typeof(SqliteDatabase).AssemblyQualifiedName; - - _typeName = typeQualifiedName.Substring(0, typeQualifiedName.IndexOf(", Version")); + Initialize(typeof(SqliteDatabase)); } public SqliteDatabase() :base(_name, _friendlyName) { } public override string Provider => "Microsoft.EntityFrameworkCore.Sqlite"; - public override string TypeName => _typeName; - public override OperationBuilder AddAutoIncrementColumn(ColumnsBuilder table, string name) { return table.Column(name: name, nullable: false).Annotation("Sqlite:Autoincrement", true); diff --git a/Oqtane.Server/Controllers/DatabaseController.cs b/Oqtane.Server/Controllers/DatabaseController.cs index a49cf3fd8..bd3422e8d 100644 --- a/Oqtane.Server/Controllers/DatabaseController.cs +++ b/Oqtane.Server/Controllers/DatabaseController.cs @@ -20,35 +20,40 @@ public DatabaseController() { } Name = "LocalDB", FriendlyName = "Local Database", ControlType = "Oqtane.Installer.Controls.LocalDBConfig, Oqtane.Client", - DBType = "Oqtane.Database.SqlServer.LocalDbDatabase, Oqtane.Database.SqlServer" + DBType = "Oqtane.Database.SqlServer.LocalDbDatabase, Oqtane.Database.SqlServer", + Package = "Oqtane.Database.SqlServer" }, new() { Name = "SqlServer", FriendlyName = "SQL Server", ControlType = "Oqtane.Installer.Controls.SqlServerConfig, Oqtane.Client", - DBType = "Oqtane.Database.SqlServer.SqlServerDatabase, Oqtane.Database.SqlServer" + DBType = "Oqtane.Database.SqlServer.SqlServerDatabase, Oqtane.Database.SqlServer", + Package = "Oqtane.Database.SqlServer" }, new() { Name = "Sqlite", FriendlyName = "Sqlite", ControlType = "Oqtane.Installer.Controls.SqliteConfig, Oqtane.Client", - DBType = "Oqtane.Database.Sqlite.SqliteDatabase, Oqtane.Database.Sqlite" + DBType = "Oqtane.Database.Sqlite.SqliteDatabase, Oqtane.Database.Sqlite", + Package = "Oqtane.Database.Sqlite" }, new() { Name = "MySQL", FriendlyName = "MySQL", ControlType = "Oqtane.Installer.Controls.MySQLConfig, Oqtane.Client", - DBType = "Oqtane.Database.MySQL.MySQLDatabase, Oqtane.Database.MySQL" + DBType = "Oqtane.Database.MySQL.MySQLDatabase, Oqtane.Database.MySQL", + Package = "Oqtane.Database.MySQL" }, new() { Name = "PostgreSQL", FriendlyName = "PostgreSQL", - ControlType = "Oqtane.Installer.Controls.PostGreSQLConfig, Oqtane.Client", - DBType = "Oqtane.Database.PostgreSQL.PostgreSQLDatabase, Oqtane.Database.PostgreSQL" + ControlType = "Oqtane.Installer.Controls.PostgreSQLConfig, Oqtane.Client", + DBType = "Oqtane.Database.PostgreSQL.PostgreSQLDatabase, Oqtane.Database.PostgreSQL", + Package = "Oqtane.Database.PostgreSQL" } }; return databases; diff --git a/Oqtane.Server/Databases/Interfaces/IMultiDatabase.cs b/Oqtane.Server/Databases/Interfaces/IMultiDatabase.cs index b150f9e1d..b0092204d 100644 --- a/Oqtane.Server/Databases/Interfaces/IMultiDatabase.cs +++ b/Oqtane.Server/Databases/Interfaces/IMultiDatabase.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; namespace Oqtane.Repository.Databases.Interfaces diff --git a/Oqtane.Shared/Interfaces/IOqtaneDatabase.cs b/Oqtane.Server/Databases/Interfaces/IOqtaneDatabase.cs similarity index 92% rename from Oqtane.Shared/Interfaces/IOqtaneDatabase.cs rename to Oqtane.Server/Databases/Interfaces/IOqtaneDatabase.cs index 54ef2ffb2..47dc03da8 100644 --- a/Oqtane.Shared/Interfaces/IOqtaneDatabase.cs +++ b/Oqtane.Server/Databases/Interfaces/IOqtaneDatabase.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; using System.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; -using Oqtane.Models; -namespace Oqtane.Interfaces +namespace Oqtane.Databases.Interfaces { public interface IOqtaneDatabase { + public string AssemblyName { get; } + public string FriendlyName { get; } public string Name { get; } diff --git a/Oqtane.Shared/Shared/OqtaneDatabaseBase.cs b/Oqtane.Server/Databases/OqtaneDatabaseBase.cs similarity index 68% rename from Oqtane.Shared/Shared/OqtaneDatabaseBase.cs rename to Oqtane.Server/Databases/OqtaneDatabaseBase.cs index 631d355e6..ae32b7480 100644 --- a/Oqtane.Shared/Shared/OqtaneDatabaseBase.cs +++ b/Oqtane.Server/Databases/OqtaneDatabaseBase.cs @@ -1,29 +1,43 @@ using System; -using System.Collections.Generic; using System.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; -using Oqtane.Interfaces; -using Oqtane.Models; +using Oqtane.Databases.Interfaces; -namespace Oqtane.Shared +namespace Oqtane.Databases { public abstract class OqtaneDatabaseBase : IOqtaneDatabase { + private static string _assemblyName; + + private static string _typeName; + protected OqtaneDatabaseBase(string name, string friendlyName) { Name = name; FriendlyName = friendlyName; } - public string FriendlyName { get; } + protected static void Initialize(Type type) + { + var typeQualifiedName = type.AssemblyQualifiedName; + var assembly = type.Assembly; + var assemblyName = assembly.FullName; + + _typeName = typeQualifiedName.Substring(0, typeQualifiedName.IndexOf(", Version")); + _assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(", Version")); + } + + public string AssemblyName => _assemblyName; + + public string FriendlyName { get; } public string Name { get; } public abstract string Provider { get; } - public abstract string TypeName { get; } + public string TypeName => _typeName; public abstract OperationBuilder AddAutoIncrementColumn(ColumnsBuilder table, string name); diff --git a/Oqtane.Server/Extensions/DbContextOptionsBuilderExtensions.cs b/Oqtane.Server/Extensions/DbContextOptionsBuilderExtensions.cs index 1c14cc8ca..d6ecd06d9 100644 --- a/Oqtane.Server/Extensions/DbContextOptionsBuilderExtensions.cs +++ b/Oqtane.Server/Extensions/DbContextOptionsBuilderExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; using Microsoft.EntityFrameworkCore; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable ConvertToUsingDeclaration diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index def120af8..55f5eb8ac 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -101,26 +101,7 @@ private static void LoadAssemblies() if (!assemblies.Any(a => AssemblyName.ReferenceMatchesDefinition(assemblyName, a.GetName()))) { - try - { - var pdb = Path.ChangeExtension(dll.FullName, ".pdb"); - Assembly assembly = null; - - // load assembly ( and symbols ) from stream to prevent locking files ( as long as dependencies are in /bin they will load as well ) - if (File.Exists(pdb)) - { - assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName)), new MemoryStream(File.ReadAllBytes(pdb))); - } - else - { - assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName))); - } - Console.WriteLine($"Loaded : {assemblyName}"); - } - catch (Exception e) - { - Console.WriteLine($"Failed : {assemblyName}\n{e}"); - } + AssemblyLoadContext.Default.LoadOqtaneAssembly(dll, assemblyName); } } } diff --git a/Oqtane.Server/Infrastructure/DatabaseManager.cs b/Oqtane.Server/Infrastructure/DatabaseManager.cs index 196d36306..05dfadef7 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -3,12 +3,15 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.Loader; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; +using Oqtane.Databases.Interfaces; using Oqtane.Extensions; using Oqtane.Models; using Oqtane.Repository; @@ -28,14 +31,14 @@ public class DatabaseManager : IDatabaseManager { private readonly IConfigurationRoot _config; private readonly IServiceScopeFactory _serviceScopeFactory; + private readonly IWebHostEnvironment _environment; private readonly IMemoryCache _cache; - private IOqtaneDatabase _database; - - public DatabaseManager(IConfigurationRoot config, IServiceScopeFactory serviceScopeFactory, IMemoryCache cache) + public DatabaseManager(IConfigurationRoot config, IServiceScopeFactory serviceScopeFactory, IWebHostEnvironment environment, IMemoryCache cache) { _config = config; _serviceScopeFactory = serviceScopeFactory; + _environment = environment; _cache = cache; } @@ -175,6 +178,45 @@ public Installation Install(InstallConfig install) return result; } + private Installation InstallDatabase(InstallConfig install) + { + var result = new Installation {Success = false, Message = string.Empty}; + + try + { + //Rename bak extension + var packageFolderName = "Packages"; + var webRootPath = _environment.WebRootPath; + var packagesFolder = new DirectoryInfo(Path.Combine(webRootPath, packageFolderName)); + + // iterate through Nuget packages in source folder + foreach (var package in packagesFolder.GetFiles("*.nupkg.bak")) + { + if (package.Name.StartsWith(install.DatabasePackage)) + { + //rename file + var packageName = Path.Combine(package.DirectoryName, package.Name); + packageName = packageName.Substring(0, packageName.IndexOf(".bak")); + package.MoveTo(packageName, true); + } + } + + //Call InstallationManager to install Database Package + using (var scope = _serviceScopeFactory.CreateScope()) + { + var installationManager = scope.ServiceProvider.GetRequiredService(); + installationManager.InstallPackages(packageFolderName); + result.Success = true; + } + } + catch (Exception ex) + { + result.Message = ex.Message; + } + + return result; + } + private Installation CreateDatabase(InstallConfig install) { var result = new Installation { Success = false, Message = string.Empty }; @@ -183,11 +225,32 @@ private Installation CreateDatabase(InstallConfig install) { try { + var databaseType = install.DatabaseType; + + //Get database Type + var type = Type.GetType(databaseType); + + //Deploy the database components (if necessary) + if (type == null) + { + InstallDatabase(install); + + var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); + var assembliesFolder = new DirectoryInfo(assemblyPath); + var assemblyFile = new FileInfo($"{assembliesFolder}/{install.DatabasePackage}.dll"); + + AssemblyLoadContext.Default.LoadOqtaneAssembly(assemblyFile); + type = Type.GetType(databaseType); + } + + //Create database object from Type + var database = Activator.CreateInstance(type) as IOqtaneDatabase; + //create data directory if does not exist var dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory")?.ToString(); if (!Directory.Exists(dataDirectory)) Directory.CreateDirectory(dataDirectory ?? String.Empty); - var dbOptions = new DbContextOptionsBuilder().UseOqtaneDatabase(install.Database, NormalizeConnectionString(install.ConnectionString)).Options; + var dbOptions = new DbContextOptionsBuilder().UseOqtaneDatabase(database, NormalizeConnectionString(install.ConnectionString)).Options; using (var dbc = new DbContext(dbOptions)) { // create empty database if it does not exist @@ -585,14 +648,15 @@ private InstallationContext GetInstallationContext() { var connectionString = _config.GetConnectionString(SettingKeys.ConnectionStringKey); var databaseType = _config.GetSection(SettingKeys.DatabaseSection)[SettingKeys.DatabaseTypeKey]; - IOqtaneDatabase database = null; - if (!String.IsNullOrEmpty(databaseType)) + IOqtaneDatabase database = null; + if (!string.IsNullOrEmpty(databaseType)) { var type = Type.GetType(databaseType); database = Activator.CreateInstance(type) as IOqtaneDatabase; } + return new InstallationContext(database, connectionString); } diff --git a/Oqtane.Server/Migrations/01000000_InitializeMaster.cs b/Oqtane.Server/Migrations/01000000_InitializeMaster.cs index b6e3f964e..6c2b56a0f 100644 --- a/Oqtane.Server/Migrations/01000000_InitializeMaster.cs +++ b/Oqtane.Server/Migrations/01000000_InitializeMaster.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/01000000_InitializeTenant.cs b/Oqtane.Server/Migrations/01000000_InitializeTenant.cs index 66905b4be..af2c91140 100644 --- a/Oqtane.Server/Migrations/01000000_InitializeTenant.cs +++ b/Oqtane.Server/Migrations/01000000_InitializeTenant.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/01000100_AddAdditionalIndexesInMaster.cs b/Oqtane.Server/Migrations/01000100_AddAdditionalIndexesInMaster.cs index ef1380f73..ef2c2bf4a 100644 --- a/Oqtane.Server/Migrations/01000100_AddAdditionalIndexesInMaster.cs +++ b/Oqtane.Server/Migrations/01000100_AddAdditionalIndexesInMaster.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/01000100_AddAdditionalIndexesInTenant.cs b/Oqtane.Server/Migrations/01000100_AddAdditionalIndexesInTenant.cs index 4fbf88f74..3027fddd9 100644 --- a/Oqtane.Server/Migrations/01000100_AddAdditionalIndexesInTenant.cs +++ b/Oqtane.Server/Migrations/01000100_AddAdditionalIndexesInTenant.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/01000101_AddAdditionColumnToNotifications.cs b/Oqtane.Server/Migrations/01000101_AddAdditionColumnToNotifications.cs index a20389db6..5cb335811 100644 --- a/Oqtane.Server/Migrations/01000101_AddAdditionColumnToNotifications.cs +++ b/Oqtane.Server/Migrations/01000101_AddAdditionColumnToNotifications.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/01000201_DropColumnFromPage.cs b/Oqtane.Server/Migrations/01000201_DropColumnFromPage.cs index 276f62567..a56218b18 100644 --- a/Oqtane.Server/Migrations/01000201_DropColumnFromPage.cs +++ b/Oqtane.Server/Migrations/01000201_DropColumnFromPage.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02000001_AddColumnToProfileAndUpdatePage.cs b/Oqtane.Server/Migrations/02000001_AddColumnToProfileAndUpdatePage.cs index 8cad32c98..efef3645d 100644 --- a/Oqtane.Server/Migrations/02000001_AddColumnToProfileAndUpdatePage.cs +++ b/Oqtane.Server/Migrations/02000001_AddColumnToProfileAndUpdatePage.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02000101_UpdateIconColumnInPage.cs b/Oqtane.Server/Migrations/02000101_UpdateIconColumnInPage.cs index 36fa11af9..a9667af1c 100644 --- a/Oqtane.Server/Migrations/02000101_UpdateIconColumnInPage.cs +++ b/Oqtane.Server/Migrations/02000101_UpdateIconColumnInPage.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02000102_AddLanguageTable.cs b/Oqtane.Server/Migrations/02000102_AddLanguageTable.cs index 75f5b4dca..3060f049b 100644 --- a/Oqtane.Server/Migrations/02000102_AddLanguageTable.cs +++ b/Oqtane.Server/Migrations/02000102_AddLanguageTable.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02000103_UpdatePageAndAddColumnToSite.cs b/Oqtane.Server/Migrations/02000103_UpdatePageAndAddColumnToSite.cs index 9fca1d97f..cca26f392 100644 --- a/Oqtane.Server/Migrations/02000103_UpdatePageAndAddColumnToSite.cs +++ b/Oqtane.Server/Migrations/02000103_UpdatePageAndAddColumnToSite.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02000201_AddSiteGuidToSite.cs b/Oqtane.Server/Migrations/02000201_AddSiteGuidToSite.cs index d8cd94e76..31ddedff6 100644 --- a/Oqtane.Server/Migrations/02000201_AddSiteGuidToSite.cs +++ b/Oqtane.Server/Migrations/02000201_AddSiteGuidToSite.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02000202_UpdateDefaultContainerTypeInSitePage.cs b/Oqtane.Server/Migrations/02000202_UpdateDefaultContainerTypeInSitePage.cs index 3c6050387..85d367029 100644 --- a/Oqtane.Server/Migrations/02000202_UpdateDefaultContainerTypeInSitePage.cs +++ b/Oqtane.Server/Migrations/02000202_UpdateDefaultContainerTypeInSitePage.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02000203_DropDefaultLayoutInSite.cs b/Oqtane.Server/Migrations/02000203_DropDefaultLayoutInSite.cs index adda10796..9887f7ec5 100644 --- a/Oqtane.Server/Migrations/02000203_DropDefaultLayoutInSite.cs +++ b/Oqtane.Server/Migrations/02000203_DropDefaultLayoutInSite.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02010000_AddAppVersionsTableInTenant.cs b/Oqtane.Server/Migrations/02010000_AddAppVersionsTableInTenant.cs index 682c1b13c..bdad7cab0 100644 --- a/Oqtane.Server/Migrations/02010000_AddAppVersionsTableInTenant.cs +++ b/Oqtane.Server/Migrations/02010000_AddAppVersionsTableInTenant.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; @@ -58,7 +59,7 @@ DROP TABLE SchemaVersions migrationBuilder.Sql($@" INSERT INTO {appVersions}({version}, {appledDate}) - VALUES('02.01.00', '{DateTime.UtcNow:u}') + VALUES('02.01.00', '{DateTime.UtcNow.ToString("yyyy'-'MM'-'dd HH':'mm':'ss")}') "); } diff --git a/Oqtane.Server/Migrations/02010000_AddIndexesForForeignKeyInMaster.cs b/Oqtane.Server/Migrations/02010000_AddIndexesForForeignKeyInMaster.cs index c5fdd1b9e..04fc90bec 100644 --- a/Oqtane.Server/Migrations/02010000_AddIndexesForForeignKeyInMaster.cs +++ b/Oqtane.Server/Migrations/02010000_AddIndexesForForeignKeyInMaster.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02010001_AddDatabaseTypeColumnToTenant.cs b/Oqtane.Server/Migrations/02010001_AddDatabaseTypeColumnToTenant.cs index 73937171b..da4aba088 100644 --- a/Oqtane.Server/Migrations/02010001_AddDatabaseTypeColumnToTenant.cs +++ b/Oqtane.Server/Migrations/02010001_AddDatabaseTypeColumnToTenant.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/02010002_ChangeFolderNameAndPathColumnsSize.cs b/Oqtane.Server/Migrations/02010002_ChangeFolderNameAndPathColumnsSize.cs index 49762df35..9da73003d 100644 --- a/Oqtane.Server/Migrations/02010002_ChangeFolderNameAndPathColumnsSize.cs +++ b/Oqtane.Server/Migrations/02010002_ChangeFolderNameAndPathColumnsSize.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations.EntityBuilders; using Oqtane.Repository; diff --git a/Oqtane.Server/Migrations/EntityBuilders/AliasEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/AliasEntityBuilder.cs index 2e05d58ae..54c60ef37 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/AliasEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/AliasEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/AppVersionsEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/AppVersionsEntityBuilder.cs index 7c5581ff9..b6ac85ea6 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/AppVersionsEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/AppVersionsEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; namespace Oqtane.Migrations.EntityBuilders diff --git a/Oqtane.Server/Migrations/EntityBuilders/AspNetUserClaimsEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/AspNetUserClaimsEntityBuilder.cs index bf53614c6..90c4bcc24 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/AspNetUserClaimsEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/AspNetUserClaimsEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/AspNetUsersEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/AspNetUsersEntityBuilder.cs index dec56d2d5..2b57dc16c 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/AspNetUsersEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/AspNetUsersEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/AuditableBaseEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/AuditableBaseEntityBuilder.cs index cad1a9931..0f5cbf643 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/AuditableBaseEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/AuditableBaseEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable UnusedAutoPropertyAccessor.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/BaseEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/BaseEntityBuilder.cs index 77022a9fd..909593d03 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/BaseEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/BaseEntityBuilder.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable BuiltInTypeReferenceStyleForMemberAccess diff --git a/Oqtane.Server/Migrations/EntityBuilders/DeletableAuditableBaseEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/DeletableAuditableBaseEntityBuilder.cs index afe9627e4..a5308337a 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/DeletableAuditableBaseEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/DeletableAuditableBaseEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable UnusedAutoPropertyAccessor.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/DeletableBaseEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/DeletableBaseEntityBuilder.cs index 3ff98429c..c572481e9 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/DeletableBaseEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/DeletableBaseEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable UnusedAutoPropertyAccessor.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/FileEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/FileEntityBuilder.cs index f875fb0b2..ef27643c0 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/FileEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/FileEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/FolderEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/FolderEntityBuilder.cs index e8da5831b..318153e6c 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/FolderEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/FolderEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/JobEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/JobEntityBuilder.cs index 34cffd749..38327d764 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/JobEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/JobEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/JobLogEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/JobLogEntityBuilder.cs index f73f8aa08..1101bffcf 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/JobLogEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/JobLogEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/LanguageEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/LanguageEntityBuilder.cs index 44342abda..312dc5a68 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/LanguageEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/LanguageEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/LogEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/LogEntityBuilder.cs index f06feace6..ffae546f7 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/LogEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/LogEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/ModuleDefinitionsEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/ModuleDefinitionsEntityBuilder.cs index 7dad66459..fc313e5bd 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/ModuleDefinitionsEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/ModuleDefinitionsEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/ModuleEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/ModuleEntityBuilder.cs index 98ac75777..4f403aff2 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/ModuleEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/ModuleEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/NotificationEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/NotificationEntityBuilder.cs index 1a38a07c3..7b573b827 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/NotificationEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/NotificationEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/PageEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/PageEntityBuilder.cs index e9cf491ed..d47534836 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/PageEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/PageEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/PageModuleEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/PageModuleEntityBuilder.cs index 16ea23fba..a92394e7f 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/PageModuleEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/PageModuleEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/PermissionEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/PermissionEntityBuilder.cs index f5f21473c..f75ea1100 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/PermissionEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/PermissionEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/ProfileEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/ProfileEntityBuilder.cs index 593242a77..d8c83d460 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/ProfileEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/ProfileEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/RoleEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/RoleEntityBuilder.cs index 52feffa86..e52a6f7b2 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/RoleEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/RoleEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/SettingEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/SettingEntityBuilder.cs index 814149857..9396321ae 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/SettingEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/SettingEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/SiteEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/SiteEntityBuilder.cs index a78f20dbe..c403c40d3 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/SiteEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/SiteEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/TenantEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/TenantEntityBuilder.cs index 982010722..a6275136a 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/TenantEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/TenantEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/UserEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/UserEntityBuilder.cs index d070f0271..72d003513 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/UserEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/UserEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/EntityBuilders/UserRoleEntityBuilder.cs b/Oqtane.Server/Migrations/EntityBuilders/UserRoleEntityBuilder.cs index 9b112151a..04e4c4378 100644 --- a/Oqtane.Server/Migrations/EntityBuilders/UserRoleEntityBuilder.cs +++ b/Oqtane.Server/Migrations/EntityBuilders/UserRoleEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; // ReSharper disable MemberCanBePrivate.Global diff --git a/Oqtane.Server/Migrations/Framework/MultiDatabaseMigration.cs b/Oqtane.Server/Migrations/Framework/MultiDatabaseMigration.cs index 52c44623c..0951999df 100644 --- a/Oqtane.Server/Migrations/Framework/MultiDatabaseMigration.cs +++ b/Oqtane.Server/Migrations/Framework/MultiDatabaseMigration.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; using System.Linq; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; namespace Oqtane.Migrations { public abstract class MultiDatabaseMigration : Migration { - private readonly IOqtaneDatabase _databases; - protected MultiDatabaseMigration(IOqtaneDatabase database) { ActiveDatabase = database; diff --git a/Oqtane.Server/Migrations/Framework/MultiDatabaseMigrationsAssembly.cs b/Oqtane.Server/Migrations/Framework/MultiDatabaseMigrationsAssembly.cs index 73117e205..01aa9380a 100644 --- a/Oqtane.Server/Migrations/Framework/MultiDatabaseMigrationsAssembly.cs +++ b/Oqtane.Server/Migrations/Framework/MultiDatabaseMigrationsAssembly.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Internal; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Repository.Databases.Interfaces; diff --git a/Oqtane.Server/Modules/HtmlText/Manager/HtmlTextManager.cs b/Oqtane.Server/Modules/HtmlText/Manager/HtmlTextManager.cs index a741f8237..f36128415 100644 --- a/Oqtane.Server/Modules/HtmlText/Manager/HtmlTextManager.cs +++ b/Oqtane.Server/Modules/HtmlText/Manager/HtmlTextManager.cs @@ -61,11 +61,15 @@ public void ImportModule(Module module, string content, string version) public bool Install(Tenant tenant, string version) { + _tenantManager.SetTenant(tenant.TenantId); + return Migrate(new HtmlTextContext(_tenantManager, _accessor), tenant, MigrationType.Up); } public bool Uninstall(Tenant tenant) { + _tenantManager.SetTenant(tenant.TenantId); + return Migrate(new HtmlTextContext(_tenantManager, _accessor), tenant, MigrationType.Down); } } diff --git a/Oqtane.Server/Modules/HtmlText/Migrations/01000000_InitializeModule.cs b/Oqtane.Server/Modules/HtmlText/Migrations/01000000_InitializeModule.cs index da248e9d1..3e945473a 100644 --- a/Oqtane.Server/Modules/HtmlText/Migrations/01000000_InitializeModule.cs +++ b/Oqtane.Server/Modules/HtmlText/Migrations/01000000_InitializeModule.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations; using Oqtane.Modules.HtmlText.Migrations.EntityBuilders; diff --git a/Oqtane.Server/Modules/HtmlText/Migrations/EntityBuilders/HtmlTextEntityBuilder.cs b/Oqtane.Server/Modules/HtmlText/Migrations/EntityBuilders/HtmlTextEntityBuilder.cs index 0f9124854..6dd019df5 100644 --- a/Oqtane.Server/Modules/HtmlText/Migrations/EntityBuilders/HtmlTextEntityBuilder.cs +++ b/Oqtane.Server/Modules/HtmlText/Migrations/EntityBuilders/HtmlTextEntityBuilder.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Migrations; using Oqtane.Migrations.EntityBuilders; diff --git a/Oqtane.Server/Oqtane.Server.csproj b/Oqtane.Server/Oqtane.Server.csproj index 72f56074c..462f20ebb 100644 --- a/Oqtane.Server/Oqtane.Server.csproj +++ b/Oqtane.Server/Oqtane.Server.csproj @@ -32,21 +32,20 @@ + + all runtime; build; native; contentfiles; analyzers; buildtransitive + - - - - diff --git a/Oqtane.Server/Repository/Context/DBContextBase.cs b/Oqtane.Server/Repository/Context/DBContextBase.cs index d97865469..9590f02bb 100644 --- a/Oqtane.Server/Repository/Context/DBContextBase.cs +++ b/Oqtane.Server/Repository/Context/DBContextBase.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.Extensions.Configuration; +using Oqtane.Databases.Interfaces; using Oqtane.Extensions; using Oqtane.Infrastructure; using Oqtane.Interfaces; diff --git a/Oqtane.Server/Repository/Context/InstallationContext.cs b/Oqtane.Server/Repository/Context/InstallationContext.cs index d64bd5f06..502dc8cb1 100644 --- a/Oqtane.Server/Repository/Context/InstallationContext.cs +++ b/Oqtane.Server/Repository/Context/InstallationContext.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; +using Oqtane.Databases.Interfaces; using Oqtane.Extensions; using Oqtane.Interfaces; using Oqtane.Models; diff --git a/Oqtane.Server/Repository/Context/MasterDBContext.cs b/Oqtane.Server/Repository/Context/MasterDBContext.cs index 9520f9a14..7e11b43b6 100644 --- a/Oqtane.Server/Repository/Context/MasterDBContext.cs +++ b/Oqtane.Server/Repository/Context/MasterDBContext.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; using Oqtane.Models; using Microsoft.Extensions.Configuration; +using Oqtane.Databases.Interfaces; using Oqtane.Extensions; using Oqtane.Interfaces; using Oqtane.Migrations.Framework; diff --git a/Oqtane.Server/Repository/SqlRepository.cs b/Oqtane.Server/Repository/SqlRepository.cs index aad0700c4..71fa53834 100644 --- a/Oqtane.Server/Repository/SqlRepository.cs +++ b/Oqtane.Server/Repository/SqlRepository.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; +using Oqtane.Databases.Interfaces; using Oqtane.Interfaces; using Oqtane.Models; // ReSharper disable ConvertToUsingDeclaration diff --git a/Oqtane.Shared/Extensions/AssemblyExtensions.cs b/Oqtane.Shared/Extensions/AssemblyExtensions.cs index c6b39224b..db29c5e2b 100644 --- a/Oqtane.Shared/Extensions/AssemblyExtensions.cs +++ b/Oqtane.Shared/Extensions/AssemblyExtensions.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.Loader; using Oqtane.Modules; using Oqtane.Services; using Oqtane.Shared; @@ -72,6 +73,7 @@ public static IEnumerable GetOqtaneAssemblies(this AppDomain appDomain { return appDomain.GetAssemblies().Where(a => a.IsOqtaneAssembly()); } + public static IEnumerable GetOqtaneClientAssemblies(this AppDomain appDomain) { return appDomain.GetOqtaneAssemblies() @@ -80,7 +82,7 @@ public static IEnumerable GetOqtaneClientAssemblies(this AppDomain app } /// - /// Checks if type should be ignored by oqtane dynamic loader + /// Checks if type should be ignored by oqtane dynamic loader /// /// Checked type /// @@ -88,5 +90,44 @@ public static bool IsOqtaneIgnore(this Type type) { return Attribute.IsDefined(type, typeof(OqtaneIgnoreAttribute)) || type.IsAbstract || type.IsGenericType; } + + public static void LoadOqtaneAssembly(this AssemblyLoadContext loadContext, FileInfo dll) + { + AssemblyName assemblyName = null; + try + { + assemblyName = AssemblyName.GetAssemblyName(dll.FullName); + } + catch + { + Console.WriteLine($"Not Assembly : {dll.Name}"); + } + + loadContext.LoadOqtaneAssembly(dll, assemblyName); + } + + public static void LoadOqtaneAssembly(this AssemblyLoadContext loadContext, FileInfo dll, AssemblyName assemblyName) + { + try + { + var pdb = Path.ChangeExtension(dll.FullName, ".pdb"); + Assembly assembly = null; + + // load assembly ( and symbols ) from stream to prevent locking files ( as long as dependencies are in /bin they will load as well ) + if (File.Exists(pdb)) + { + assembly = loadContext.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName)), new MemoryStream(File.ReadAllBytes(pdb))); + } + else + { + assembly = loadContext.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName))); + } + Console.WriteLine($"Loaded : {assemblyName}"); + } + catch (Exception e) + { + Console.WriteLine($"Failed : {assemblyName}\n{e}"); + } + } } } diff --git a/Oqtane.Shared/Models/Database.cs b/Oqtane.Shared/Models/Database.cs index 7524d47ad..0ffb0ae5b 100644 --- a/Oqtane.Shared/Models/Database.cs +++ b/Oqtane.Shared/Models/Database.cs @@ -9,5 +9,7 @@ public class Database public string ControlType { get; set; } public string DBType { get; set; } + + public string Package { get; set; } } } diff --git a/Oqtane.Shared/Shared/InstallConfig.cs b/Oqtane.Shared/Shared/InstallConfig.cs index 26d66252a..7848c5220 100644 --- a/Oqtane.Shared/Shared/InstallConfig.cs +++ b/Oqtane.Shared/Shared/InstallConfig.cs @@ -1,29 +1,11 @@ -using System; -using Oqtane.Interfaces; namespace Oqtane.Shared { public class InstallConfig { - private IOqtaneDatabase _database; - public string ConnectionString { get; set; } public string DatabaseType { get; set; } - - public IOqtaneDatabase Database - { - get - { - if (_database == null) - { - var type = Type.GetType(DatabaseType); - _database = Activator.CreateInstance(type) as IOqtaneDatabase; - } - - return _database; - } - } - + public string DatabasePackage { get; set; } public string Aliases { get; set; } public string TenantName { get; set; } public bool IsNewTenant { get; set; }