improve installationmanager

This commit is contained in:
Shaun Walker 2019-09-20 08:50:55 -04:00
parent 83a212e7e3
commit c3ff9ff12b
7 changed files with 52 additions and 42 deletions

View File

@ -129,7 +129,6 @@
List<ModuleDefinition> moduledefinitions; List<ModuleDefinition> moduledefinitions;
Dictionary<string, string> containers = new Dictionary<string, string>(); Dictionary<string, string> containers = new Dictionary<string, string>();
int pagemanagementmoduleid = -1; int pagemanagementmoduleid = -1;
string category = "";
string moduledefinitionname = ""; string moduledefinitionname = "";
string pane = ""; string pane = "";
string title = ""; string title = "";

View File

@ -12,12 +12,12 @@ namespace Oqtane.Controllers
public class ModuleDefinitionController : Controller public class ModuleDefinitionController : Controller
{ {
private readonly IModuleDefinitionRepository ModuleDefinitions; private readonly IModuleDefinitionRepository ModuleDefinitions;
private readonly IInstallation Installation; private readonly IInstallationManager InstallationManager;
public ModuleDefinitionController(IModuleDefinitionRepository ModuleDefinitions, IInstallation Installation) public ModuleDefinitionController(IModuleDefinitionRepository ModuleDefinitions, IInstallationManager InstallationManager)
{ {
this.ModuleDefinitions = ModuleDefinitions; this.ModuleDefinitions = ModuleDefinitions;
this.Installation = Installation; this.InstallationManager = InstallationManager;
} }
// GET: api/<controller> // GET: api/<controller>
@ -42,7 +42,7 @@ namespace Oqtane.Controllers
[Authorize(Roles = Constants.HostRole)] [Authorize(Roles = Constants.HostRole)]
public void InstallModules() public void InstallModules()
{ {
Installation.Install("Modules"); InstallationManager.InstallPackages("Modules");
} }
} }
} }

View File

@ -12,12 +12,12 @@ namespace Oqtane.Controllers
public class ThemeController : Controller public class ThemeController : Controller
{ {
private readonly IThemeRepository Themes; private readonly IThemeRepository Themes;
private readonly IInstallation Installation; private readonly IInstallationManager InstallationManager;
public ThemeController(IThemeRepository Themes, IInstallation Installation) public ThemeController(IThemeRepository Themes, IInstallationManager InstallationManager)
{ {
this.Themes = Themes; this.Themes = Themes;
this.Installation = Installation; this.InstallationManager = InstallationManager;
} }
// GET: api/<controller> // GET: api/<controller>
@ -31,7 +31,7 @@ namespace Oqtane.Controllers
[Authorize(Roles = Constants.HostRole)] [Authorize(Roles = Constants.HostRole)]
public void InstallThemes() public void InstallThemes()
{ {
Installation.Install("Themes"); InstallationManager.InstallPackages("Themes");
} }
} }
} }

View File

@ -1,7 +0,0 @@
namespace Oqtane.Infrastructure
{
public interface IInstallation
{
void Install(string Folders);
}
}

View File

@ -0,0 +1,7 @@
namespace Oqtane.Infrastructure
{
public interface IInstallationManager
{
void InstallPackages(string Folders);
}
}

View File

@ -6,18 +6,18 @@ using Microsoft.AspNetCore.Hosting;
namespace Oqtane.Infrastructure namespace Oqtane.Infrastructure
{ {
public class Installation : IInstallation public class InstallationManager : IInstallationManager
{ {
private readonly IHostApplicationLifetime HostApplicationLifetime; private readonly IHostApplicationLifetime HostApplicationLifetime;
private readonly IWebHostEnvironment environment; private readonly IWebHostEnvironment environment;
public Installation(IHostApplicationLifetime HostApplicationLifetime, IWebHostEnvironment environment) public InstallationManager(IHostApplicationLifetime HostApplicationLifetime, IWebHostEnvironment environment)
{ {
this.HostApplicationLifetime = HostApplicationLifetime; this.HostApplicationLifetime = HostApplicationLifetime;
this.environment = environment; this.environment = environment;
} }
public void Install(string Folders) public void InstallPackages(string Folders)
{ {
bool install = false; bool install = false;
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
@ -26,6 +26,12 @@ namespace Oqtane.Infrastructure
{ {
string folder = Path.Combine(environment.WebRootPath, Folder); string folder = Path.Combine(environment.WebRootPath, Folder);
// create folder if it does not exist
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
// iterate through theme packages // iterate through theme packages
foreach (string packagename in Directory.GetFiles(folder, "*.nupkg")) foreach (string packagename in Directory.GetFiles(folder, "*.nupkg"))
{ {

View File

@ -147,12 +147,12 @@ namespace Oqtane.Server
// register singleton scoped core services // register singleton scoped core services
services.AddSingleton<IConfigurationRoot>(Configuration); services.AddSingleton<IConfigurationRoot>(Configuration);
services.AddSingleton<IInstallation, Installation>(); services.AddSingleton<IInstallationManager, InstallationManager>();
// install any modules or themes // install any modules or themes
ServiceProvider sp = services.BuildServiceProvider(); ServiceProvider sp = services.BuildServiceProvider();
var Installation = sp.GetRequiredService<IInstallation>(); var InstallationManager = sp.GetRequiredService<IInstallationManager>();
Installation.Install("Modules,Themes"); InstallationManager.InstallPackages("Modules,Themes");
// register transient scoped core services // register transient scoped core services
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>(); services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
@ -329,6 +329,31 @@ namespace Oqtane.Server
// register custom claims principal factory for role claims // register custom claims principal factory for role claims
services.AddTransient<IUserClaimsPrincipalFactory<IdentityUser>, ClaimsPrincipalFactory<IdentityUser>>(); services.AddTransient<IUserClaimsPrincipalFactory<IdentityUser>, ClaimsPrincipalFactory<IdentityUser>>();
services.AddSingleton<IInstallationManager, InstallationManager>();
// install any modules or themes
ServiceProvider sp = services.BuildServiceProvider();
var InstallationManager = sp.GetRequiredService<IInstallationManager>();
InstallationManager.InstallPackages("Modules,Themes");
// register transient scoped core services
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
services.AddTransient<IThemeRepository, ThemeRepository>();
services.AddTransient<IUserPermissions, UserPermissions>();
services.AddTransient<ITenantResolver, TenantResolver>();
services.AddTransient<IAliasRepository, AliasRepository>();
services.AddTransient<ITenantRepository, TenantRepository>();
services.AddTransient<ISiteRepository, SiteRepository>();
services.AddTransient<IPageRepository, PageRepository>();
services.AddTransient<IModuleRepository, ModuleRepository>();
services.AddTransient<IPageModuleRepository, PageModuleRepository>();
services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<IProfileRepository, ProfileRepository>();
services.AddTransient<IRoleRepository, RoleRepository>();
services.AddTransient<IUserRoleRepository, UserRoleRepository>();
services.AddTransient<IPermissionRepository, PermissionRepository>();
services.AddTransient<ISettingRepository, SettingRepository>();
// get list of loaded assemblies // get list of loaded assemblies
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
@ -362,26 +387,6 @@ namespace Oqtane.Server
services.AddMvc().AddModuleAssemblies(moduleassemblies).AddNewtonsoftJson(); services.AddMvc().AddModuleAssemblies(moduleassemblies).AddNewtonsoftJson();
// register singleton scoped core services
services.AddSingleton<IConfigurationRoot>(Configuration);
// register transient scoped core services
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
services.AddTransient<IThemeRepository, ThemeRepository>();
services.AddTransient<IUserPermissions, UserPermissions>();
services.AddTransient<ITenantResolver, TenantResolver>();
services.AddTransient<IAliasRepository, AliasRepository>();
services.AddTransient<ITenantRepository, TenantRepository>();
services.AddTransient<ISiteRepository, SiteRepository>();
services.AddTransient<IPageRepository, PageRepository>();
services.AddTransient<IModuleRepository, ModuleRepository>();
services.AddTransient<IPageModuleRepository, PageModuleRepository>();
services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<IRoleRepository, RoleRepository>();
services.AddTransient<IUserRoleRepository, UserRoleRepository>();
services.AddTransient<IPermissionRepository, PermissionRepository>();
services.AddTransient<ISettingRepository, SettingRepository>();
// dynamically register module services, contexts, and repository classes // dynamically register module services, contexts, and repository classes
assemblies = AppDomain.CurrentDomain.GetAssemblies() assemblies = AppDomain.CurrentDomain.GetAssemblies()
.Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module.")).ToArray(); .Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module.")).ToArray();