add support for Library modules and optimize usage of reflection during startup
This commit is contained in:
parent
bfa891f0ca
commit
7b94f8f105
@ -32,7 +32,7 @@
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="categories" HelpText="Comma delimited list of module categories" ResourceKey="Categories">Categories: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="categories" class="form-control" @bind="@_categories" maxlength="200" required />
|
||||
<input id="categories" class="form-control" @bind="@_categories" maxlength="200" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
|
@ -294,7 +294,7 @@
|
||||
_containerType = PageState.Site.DefaultContainerType;
|
||||
_allModuleDefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId);
|
||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(_category)).ToList();
|
||||
_categories = _allModuleDefinitions.SelectMany(m => m.Categories.Split(',')).Distinct().ToList();
|
||||
_categories = _allModuleDefinitions.SelectMany(m => m.Categories.Split(',', StringSplitOptions.RemoveEmptyEntries)).Distinct().Where(item => item != "Library").ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,9 @@ namespace Oqtane.Repository
|
||||
{
|
||||
ModuleDefinition moduledefinition;
|
||||
|
||||
Type[] moduletypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IModule))).ToArray();
|
||||
Type[] modulecontroltypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IModuleControl))).ToArray();
|
||||
|
||||
foreach (Type modulecontroltype in modulecontroltypes)
|
||||
{
|
||||
// Check if type should be ignored
|
||||
@ -299,12 +301,9 @@ namespace Oqtane.Repository
|
||||
int index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
||||
if (index == -1)
|
||||
{
|
||||
// determine if this module implements IModule
|
||||
Type moduletype = assembly
|
||||
.GetTypes()
|
||||
.Where(item => item.Namespace != null)
|
||||
.Where(item => item.Namespace == modulecontroltype.Namespace || item.Namespace.StartsWith(modulecontroltype.Namespace + "."))
|
||||
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(IModule)));
|
||||
// determine if this component is part of a module which implements IModule
|
||||
Type moduletype = moduletypes.FirstOrDefault(item => item.Namespace == modulecontroltype.Namespace);
|
||||
|
||||
if (moduletype != null)
|
||||
{
|
||||
// get property values from IModule
|
||||
@ -399,6 +398,22 @@ namespace Oqtane.Repository
|
||||
moduledefinitions[index] = moduledefinition;
|
||||
}
|
||||
|
||||
// process modules without UI components
|
||||
foreach (var moduletype in moduletypes.Where(m1 => !modulecontroltypes.Any(m2 => m1.Namespace == m2.Namespace)))
|
||||
{
|
||||
// get property values from IModule
|
||||
var moduleobject = Activator.CreateInstance(moduletype) as IModule;
|
||||
moduledefinition = moduleobject.ModuleDefinition;
|
||||
moduledefinition.ModuleDefinitionName = moduletype.Namespace + ", " + moduletype.Assembly.GetName().Name;
|
||||
moduledefinition.AssemblyName = assembly.GetName().Name;
|
||||
moduledefinition.Categories = "Library";
|
||||
moduledefinition.PermissionList = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.Utilize, RoleNames.Host, true)
|
||||
};
|
||||
moduledefinitions.Add(moduledefinition);
|
||||
}
|
||||
|
||||
return moduledefinitions;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ using Oqtane.Shared;
|
||||
using Oqtane.Themes;
|
||||
using System.Reflection.Metadata;
|
||||
using Oqtane.Migrations.Master;
|
||||
using Oqtane.Modules;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
@ -224,9 +225,11 @@ namespace Oqtane.Repository
|
||||
private List<Theme> LoadThemesFromAssembly(List<Theme> themes, Assembly assembly)
|
||||
{
|
||||
Theme theme;
|
||||
List<Type> themeTypes = new List<Type>();
|
||||
|
||||
Type[] themeTypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(ITheme))).ToArray();
|
||||
Type[] themeControlTypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IThemeControl))).ToArray();
|
||||
Type[] containerControlTypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IContainerControl))).ToArray();
|
||||
|
||||
foreach (Type themeControlType in themeControlTypes)
|
||||
{
|
||||
// Check if type should be ignored
|
||||
@ -240,16 +243,9 @@ namespace Oqtane.Repository
|
||||
int index = themes.FindIndex(item => item.ThemeName == qualifiedThemeType);
|
||||
if (index == -1)
|
||||
{
|
||||
// Find all types in the assembly with the same namespace root
|
||||
themeTypes = assembly.GetTypes()
|
||||
.Where(item => !item.IsOqtaneIgnore())
|
||||
.Where(item => item.Namespace != null)
|
||||
.Where(item => item.Namespace == themeControlType.Namespace || item.Namespace.StartsWith(themeControlType.Namespace + "."))
|
||||
.ToList();
|
||||
// determine if this component is part of a theme which implements ITheme
|
||||
Type themetype = themeTypes.FirstOrDefault(item => item.Namespace == themeControlType.Namespace);
|
||||
|
||||
// determine if this theme implements ITheme
|
||||
Type themetype = themeTypes
|
||||
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(ITheme)));
|
||||
if (themetype != null)
|
||||
{
|
||||
var themeobject = Activator.CreateInstance(themetype) as ITheme;
|
||||
@ -285,6 +281,7 @@ namespace Oqtane.Repository
|
||||
}
|
||||
theme = themes[index];
|
||||
|
||||
// add theme control
|
||||
var themecontrolobject = Activator.CreateInstance(themeControlType) as IThemeControl;
|
||||
theme.Themes.Add(
|
||||
new ThemeControl
|
||||
@ -296,14 +293,12 @@ namespace Oqtane.Repository
|
||||
}
|
||||
);
|
||||
|
||||
// containers
|
||||
Type[] containertypes = themeTypes
|
||||
.Where(item => item.GetInterfaces().Contains(typeof(IContainerControl))).ToArray();
|
||||
foreach (Type containertype in containertypes)
|
||||
if (!theme.Containers.Any())
|
||||
{
|
||||
var containerobject = Activator.CreateInstance(containertype) as IThemeControl;
|
||||
if (theme.Containers.FirstOrDefault(item => item.TypeName == containertype.FullName + ", " + themeControlType.Assembly.GetName().Name) == null)
|
||||
// add container controls
|
||||
foreach (Type containertype in containerControlTypes.Where(item => item.Namespace == themeControlType.Namespace))
|
||||
{
|
||||
var containerobject = Activator.CreateInstance(containertype) as IThemeControl;
|
||||
theme.Containers.Add(
|
||||
new ThemeControl
|
||||
{
|
||||
|
Reference in New Issue
Block a user