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">
|
<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>
|
<Label Class="col-sm-3" For="categories" HelpText="Comma delimited list of module categories" ResourceKey="Categories">Categories: </Label>
|
||||||
<div class="col-sm-9">
|
<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>
|
</div>
|
||||||
<div class="row mb-1 align-items-center">
|
<div class="row mb-1 align-items-center">
|
||||||
|
@ -294,7 +294,7 @@
|
|||||||
_containerType = PageState.Site.DefaultContainerType;
|
_containerType = PageState.Site.DefaultContainerType;
|
||||||
_allModuleDefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId);
|
_allModuleDefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId);
|
||||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(_category)).ToList();
|
_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;
|
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();
|
Type[] modulecontroltypes = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IModuleControl))).ToArray();
|
||||||
|
|
||||||
foreach (Type modulecontroltype in modulecontroltypes)
|
foreach (Type modulecontroltype in modulecontroltypes)
|
||||||
{
|
{
|
||||||
// Check if type should be ignored
|
// Check if type should be ignored
|
||||||
@ -299,12 +301,9 @@ namespace Oqtane.Repository
|
|||||||
int index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
int index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
// determine if this module implements IModule
|
// determine if this component is part of a module which implements IModule
|
||||||
Type moduletype = assembly
|
Type moduletype = moduletypes.FirstOrDefault(item => item.Namespace == modulecontroltype.Namespace);
|
||||||
.GetTypes()
|
|
||||||
.Where(item => item.Namespace != null)
|
|
||||||
.Where(item => item.Namespace == modulecontroltype.Namespace || item.Namespace.StartsWith(modulecontroltype.Namespace + "."))
|
|
||||||
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(IModule)));
|
|
||||||
if (moduletype != null)
|
if (moduletype != null)
|
||||||
{
|
{
|
||||||
// get property values from IModule
|
// get property values from IModule
|
||||||
@ -399,6 +398,22 @@ namespace Oqtane.Repository
|
|||||||
moduledefinitions[index] = moduledefinition;
|
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;
|
return moduledefinitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ using Oqtane.Shared;
|
|||||||
using Oqtane.Themes;
|
using Oqtane.Themes;
|
||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
using Oqtane.Migrations.Master;
|
using Oqtane.Migrations.Master;
|
||||||
|
using Oqtane.Modules;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -224,9 +225,11 @@ namespace Oqtane.Repository
|
|||||||
private List<Theme> LoadThemesFromAssembly(List<Theme> themes, Assembly assembly)
|
private List<Theme> LoadThemesFromAssembly(List<Theme> themes, Assembly assembly)
|
||||||
{
|
{
|
||||||
Theme theme;
|
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[] 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)
|
foreach (Type themeControlType in themeControlTypes)
|
||||||
{
|
{
|
||||||
// Check if type should be ignored
|
// Check if type should be ignored
|
||||||
@ -240,16 +243,9 @@ namespace Oqtane.Repository
|
|||||||
int index = themes.FindIndex(item => item.ThemeName == qualifiedThemeType);
|
int index = themes.FindIndex(item => item.ThemeName == qualifiedThemeType);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
// Find all types in the assembly with the same namespace root
|
// determine if this component is part of a theme which implements ITheme
|
||||||
themeTypes = assembly.GetTypes()
|
Type themetype = themeTypes.FirstOrDefault(item => item.Namespace == themeControlType.Namespace);
|
||||||
.Where(item => !item.IsOqtaneIgnore())
|
|
||||||
.Where(item => item.Namespace != null)
|
|
||||||
.Where(item => item.Namespace == themeControlType.Namespace || item.Namespace.StartsWith(themeControlType.Namespace + "."))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
// determine if this theme implements ITheme
|
|
||||||
Type themetype = themeTypes
|
|
||||||
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(ITheme)));
|
|
||||||
if (themetype != null)
|
if (themetype != null)
|
||||||
{
|
{
|
||||||
var themeobject = Activator.CreateInstance(themetype) as ITheme;
|
var themeobject = Activator.CreateInstance(themetype) as ITheme;
|
||||||
@ -285,6 +281,7 @@ namespace Oqtane.Repository
|
|||||||
}
|
}
|
||||||
theme = themes[index];
|
theme = themes[index];
|
||||||
|
|
||||||
|
// add theme control
|
||||||
var themecontrolobject = Activator.CreateInstance(themeControlType) as IThemeControl;
|
var themecontrolobject = Activator.CreateInstance(themeControlType) as IThemeControl;
|
||||||
theme.Themes.Add(
|
theme.Themes.Add(
|
||||||
new ThemeControl
|
new ThemeControl
|
||||||
@ -296,14 +293,12 @@ namespace Oqtane.Repository
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// containers
|
if (!theme.Containers.Any())
|
||||||
Type[] containertypes = themeTypes
|
|
||||||
.Where(item => item.GetInterfaces().Contains(typeof(IContainerControl))).ToArray();
|
|
||||||
foreach (Type containertype in containertypes)
|
|
||||||
{
|
{
|
||||||
var containerobject = Activator.CreateInstance(containertype) as IThemeControl;
|
// add container controls
|
||||||
if (theme.Containers.FirstOrDefault(item => item.TypeName == containertype.FullName + ", " + themeControlType.Assembly.GetName().Name) == null)
|
foreach (Type containertype in containerControlTypes.Where(item => item.Namespace == themeControlType.Namespace))
|
||||||
{
|
{
|
||||||
|
var containerobject = Activator.CreateInstance(containertype) as IThemeControl;
|
||||||
theme.Containers.Add(
|
theme.Containers.Add(
|
||||||
new ThemeControl
|
new ThemeControl
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user