improve installationmanager
This commit is contained in:
parent
83a212e7e3
commit
c3ff9ff12b
|
@ -129,7 +129,6 @@
|
|||
List<ModuleDefinition> moduledefinitions;
|
||||
Dictionary<string, string> containers = new Dictionary<string, string>();
|
||||
int pagemanagementmoduleid = -1;
|
||||
string category = "";
|
||||
string moduledefinitionname = "";
|
||||
string pane = "";
|
||||
string title = "";
|
||||
|
|
|
@ -12,12 +12,12 @@ namespace Oqtane.Controllers
|
|||
public class ModuleDefinitionController : Controller
|
||||
{
|
||||
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.Installation = Installation;
|
||||
this.InstallationManager = InstallationManager;
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
|
@ -42,7 +42,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.HostRole)]
|
||||
public void InstallModules()
|
||||
{
|
||||
Installation.Install("Modules");
|
||||
InstallationManager.InstallPackages("Modules");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,12 @@ namespace Oqtane.Controllers
|
|||
public class ThemeController : Controller
|
||||
{
|
||||
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.Installation = Installation;
|
||||
this.InstallationManager = InstallationManager;
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
|
@ -31,7 +31,7 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.HostRole)]
|
||||
public void InstallThemes()
|
||||
{
|
||||
Installation.Install("Themes");
|
||||
InstallationManager.InstallPackages("Themes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public interface IInstallation
|
||||
{
|
||||
void Install(string Folders);
|
||||
}
|
||||
}
|
7
Oqtane.Server/Infrastructure/IInstallationManager.cs
Normal file
7
Oqtane.Server/Infrastructure/IInstallationManager.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public interface IInstallationManager
|
||||
{
|
||||
void InstallPackages(string Folders);
|
||||
}
|
||||
}
|
|
@ -6,18 +6,18 @@ using Microsoft.AspNetCore.Hosting;
|
|||
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public class Installation : IInstallation
|
||||
public class InstallationManager : IInstallationManager
|
||||
{
|
||||
private readonly IHostApplicationLifetime HostApplicationLifetime;
|
||||
private readonly IWebHostEnvironment environment;
|
||||
|
||||
public Installation(IHostApplicationLifetime HostApplicationLifetime, IWebHostEnvironment environment)
|
||||
public InstallationManager(IHostApplicationLifetime HostApplicationLifetime, IWebHostEnvironment environment)
|
||||
{
|
||||
this.HostApplicationLifetime = HostApplicationLifetime;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public void Install(string Folders)
|
||||
public void InstallPackages(string Folders)
|
||||
{
|
||||
bool install = false;
|
||||
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
|
@ -26,6 +26,12 @@ namespace Oqtane.Infrastructure
|
|||
{
|
||||
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
|
||||
foreach (string packagename in Directory.GetFiles(folder, "*.nupkg"))
|
||||
{
|
|
@ -147,12 +147,12 @@ namespace Oqtane.Server
|
|||
|
||||
// register singleton scoped core services
|
||||
services.AddSingleton<IConfigurationRoot>(Configuration);
|
||||
services.AddSingleton<IInstallation, Installation>();
|
||||
services.AddSingleton<IInstallationManager, InstallationManager>();
|
||||
|
||||
// install any modules or themes
|
||||
ServiceProvider sp = services.BuildServiceProvider();
|
||||
var Installation = sp.GetRequiredService<IInstallation>();
|
||||
Installation.Install("Modules,Themes");
|
||||
var InstallationManager = sp.GetRequiredService<IInstallationManager>();
|
||||
InstallationManager.InstallPackages("Modules,Themes");
|
||||
|
||||
// register transient scoped core services
|
||||
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
|
||||
|
@ -329,6 +329,31 @@ namespace Oqtane.Server
|
|||
// register custom claims principal factory for role claims
|
||||
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
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
|
@ -361,26 +386,6 @@ namespace Oqtane.Server
|
|||
}
|
||||
|
||||
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
|
||||
assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
||||
|
|
Loading…
Reference in New Issue
Block a user