implementation of [OqtaneIgnore] class attribute in controls
This commit is contained in:
parent
6586883979
commit
47f17a589f
|
@ -1,6 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@if (_visible)
|
@if (_visible)
|
||||||
{
|
{
|
||||||
<div class="app-admin-modal">
|
<div class="app-admin-modal">
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@inject IUserService UserService
|
@inject IUserService UserService
|
||||||
|
|
||||||
@if (_authorized)
|
@if (_authorized)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
@if (_text != string.Empty)
|
@if (_text != string.Empty)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@inject IFolderService FolderService
|
@inject IFolderService FolderService
|
||||||
@inject IFileService FileService
|
@inject IFileService FileService
|
||||||
@inject IJSRuntime JsRuntime
|
@inject IJSRuntime JsRuntime
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
@if (!string.IsNullOrEmpty(HelpText))
|
@if (!string.IsNullOrEmpty(HelpText))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
@if (!string.IsNullOrEmpty(_message))
|
@if (!string.IsNullOrEmpty(_message))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@typeparam TableItem
|
@typeparam TableItem
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@if(Format == "Table")
|
@if(Format == "Table")
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@inject IRoleService RoleService
|
@inject IRoleService RoleService
|
||||||
@inject IUserService UserService
|
@inject IUserService UserService
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@inject IJSRuntime JsRuntime
|
@inject IJSRuntime JsRuntime
|
||||||
|
|
||||||
@if (_filemanagervisible)
|
@if (_filemanagervisible)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
@if (Name == Parent.ActiveTab)
|
@if (Name == Parent.ActiveTab)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
<CascadingValue Value="this">
|
<CascadingValue Value="this">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
|
|
|
@ -82,7 +82,6 @@ namespace Oqtane.Services
|
||||||
var result = await response.Content.ReadFromJsonAsync<TResult>();
|
var result = await response.Content.ReadFromJsonAsync<TResult>();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +120,8 @@ namespace Oqtane.Services
|
||||||
if (response.StatusCode != HttpStatusCode.NoContent && response.StatusCode != HttpStatusCode.NotFound)
|
if (response.StatusCode != HttpStatusCode.NoContent && response.StatusCode != HttpStatusCode.NotFound)
|
||||||
{
|
{
|
||||||
//TODO: Log errors here
|
//TODO: Log errors here
|
||||||
|
|
||||||
|
Console.WriteLine($"Request: {response.RequestMessage.RequestUri}");
|
||||||
Console.WriteLine($"Response status: {response.StatusCode} {response.ReasonPhrase}");
|
Console.WriteLine($"Response status: {response.StatusCode} {response.ReasonPhrase}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@inherits ThemeControlBase
|
@inherits ThemeControlBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
@if (BreadCrumbPages.Any())
|
@if (BreadCrumbPages.Any())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@using Oqtane.Enums
|
@using Oqtane.Enums
|
||||||
@inherits ThemeControlBase
|
@inherits ThemeControlBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject IUserService UserService
|
@inject IUserService UserService
|
||||||
@inject IModuleDefinitionService ModuleDefinitionService
|
@inject IModuleDefinitionService ModuleDefinitionService
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@inherits LoginBase
|
@inherits LoginBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
<Authorizing>
|
<Authorizing>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@inherits ThemeControlBase
|
@inherits ThemeControlBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
@if (PageState.Site.LogoFileId != null)
|
@if (PageState.Site.LogoFileId != null)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@inherits MenuBase
|
@inherits MenuBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@if (MenuPages.Any())
|
@if (MenuPages.Any())
|
||||||
{
|
{
|
||||||
<div class="app-menu">
|
<div class="app-menu">
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@inherits MenuBase
|
@inherits MenuBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@if (MenuPages.Any())
|
@if (MenuPages.Any())
|
||||||
{
|
{
|
||||||
<div class="app-menu">
|
<div class="app-menu">
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@inherits ModuleActionsBase
|
@inherits ModuleActionsBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
@if (PageState.EditMode && !PageState.Page.EditMode && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions))
|
@if (PageState.EditMode && !PageState.Page.EditMode && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@inherits ContainerBase
|
@inherits ContainerBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
|
|
||||||
@((MarkupString)title)
|
@((MarkupString)title)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@inherits ThemeControlBase
|
@inherits ThemeControlBase
|
||||||
|
@attribute [OqtaneIgnore]
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace System.Reflection
|
namespace System.Reflection
|
||||||
|
@ -31,5 +33,20 @@ namespace System.Reflection
|
||||||
return assembly.GetTypes()
|
return assembly.GetTypes()
|
||||||
.Where(t => t.GetInterfaces().Contains(interfaceType));
|
.Where(t => t.GetInterfaces().Contains(interfaceType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsOqtaneAssembly(this Assembly assembly)
|
||||||
|
{
|
||||||
|
return assembly.FullName != null && (assembly.FullName.Contains("oqtane.", StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsOqtaneAssembly(this FileInfo fileInfo)
|
||||||
|
{
|
||||||
|
return (fileInfo.Name.Contains("oqtane.", StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<Assembly> GetOqtaneAssemblies(this AppDomain appDomain)
|
||||||
|
{
|
||||||
|
return appDomain.GetAssemblies().Where(a => a.IsOqtaneAssembly());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||||
|
|
||||||
|
@ -16,10 +17,11 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
}
|
}
|
||||||
|
|
||||||
// load MVC application parts from module assemblies
|
// load MVC application parts from module assemblies
|
||||||
foreach (var assembly in OqtaneServiceCollectionExtensions.GetOqtaneModuleAssemblies())
|
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||||
|
foreach (var assembly in assemblies)
|
||||||
{
|
{
|
||||||
// check if assembly contains MVC Controllers
|
// check if assembly contains MVC Controllers
|
||||||
if (assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(Controller))).ToArray().Length > 0)
|
if (assembly.GetTypes().Any(t => t.IsSubclassOf(typeof(Controller))))
|
||||||
{
|
{
|
||||||
var partFactory = ApplicationPartFactory.GetApplicationPartFactory(assembly);
|
var partFactory = ApplicationPartFactory.GetApplicationPartFactory(assembly);
|
||||||
foreach (var part in partFactory.GetApplicationParts(assembly))
|
foreach (var part in partFactory.GetApplicationParts(assembly))
|
||||||
|
|
|
@ -5,67 +5,35 @@ using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Oqtane.Extensions;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
using Oqtane.Modules;
|
using Oqtane.Modules;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace Microsoft.Extensions.DependencyInjection
|
namespace Microsoft.Extensions.DependencyInjection
|
||||||
{
|
{
|
||||||
public static class OqtaneServiceCollectionExtensions
|
public static class OqtaneServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
private static readonly IList<Assembly> OqtaneModuleAssemblies = new List<Assembly>();
|
public static IServiceCollection AddOqtaneParts(this IServiceCollection services)
|
||||||
|
|
||||||
private static Assembly[] Assemblies => AppDomain.CurrentDomain.GetAssemblies();
|
|
||||||
|
|
||||||
internal static IEnumerable<Assembly> GetOqtaneModuleAssemblies() => OqtaneModuleAssemblies;
|
|
||||||
|
|
||||||
public static IServiceCollection AddOqtaneModules(this IServiceCollection services)
|
|
||||||
{
|
{
|
||||||
if (services is null)
|
LoadAssemblies();
|
||||||
{
|
services.AddOqtaneServices();
|
||||||
throw new ArgumentNullException(nameof(services));
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadAssemblies("Module");
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddOqtaneThemes(this IServiceCollection services)
|
private static IServiceCollection AddOqtaneServices(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
if (services is null)
|
if (services is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(services));
|
throw new ArgumentNullException(nameof(services));
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadAssemblies("Theme");
|
var hostedServiceType = typeof(IHostedService);
|
||||||
|
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IServiceCollection AddOqtaneSiteTemplates(this IServiceCollection services)
|
|
||||||
{
|
|
||||||
if (services is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(services));
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadAssemblies("SiteTemplate");
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IServiceCollection AddOqtaneServices(this IServiceCollection services)
|
|
||||||
{
|
|
||||||
if (services is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(services));
|
|
||||||
}
|
|
||||||
|
|
||||||
// dynamically register module services, contexts, and repository classes
|
|
||||||
var assemblies = Assemblies.Where(item => item.FullName != null && (item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module."))).ToArray();
|
|
||||||
foreach (var assembly in assemblies)
|
foreach (var assembly in assemblies)
|
||||||
{
|
{
|
||||||
|
// dynamically register module services, contexts, and repository classes
|
||||||
var implementationTypes = assembly.GetInterfaces<IService>();
|
var implementationTypes = assembly.GetInterfaces<IService>();
|
||||||
foreach (var implementationType in implementationTypes)
|
foreach (var implementationType in implementationTypes)
|
||||||
{
|
{
|
||||||
|
@ -75,22 +43,8 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
services.AddScoped(serviceType ?? implementationType, implementationType);
|
services.AddScoped(serviceType ?? implementationType, implementationType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return services;
|
// dynamically register hosted services
|
||||||
}
|
|
||||||
|
|
||||||
public static IServiceCollection AddOqtaneHostedServices(this IServiceCollection services)
|
|
||||||
{
|
|
||||||
if (services is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(services));
|
|
||||||
}
|
|
||||||
|
|
||||||
// dynamically register hosted services
|
|
||||||
var hostedServiceType = typeof(IHostedService);
|
|
||||||
foreach (var assembly in Assemblies)
|
|
||||||
{
|
|
||||||
var serviceTypes = assembly.GetTypes(hostedServiceType);
|
var serviceTypes = assembly.GetTypes(hostedServiceType);
|
||||||
foreach (var serviceType in serviceTypes)
|
foreach (var serviceType in serviceTypes)
|
||||||
{
|
{
|
||||||
|
@ -104,34 +58,50 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LoadAssemblies(string pattern)
|
private static void LoadAssemblies()
|
||||||
{
|
{
|
||||||
var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||||
if (assemblyPath == null) return;
|
if (assemblyPath == null) return;
|
||||||
|
|
||||||
var assembliesFolder = new DirectoryInfo(assemblyPath);
|
var assembliesFolder = new DirectoryInfo(assemblyPath);
|
||||||
|
|
||||||
|
|
||||||
// iterate through Oqtane assemblies in /bin ( filter is narrow to optimize loading process )
|
// iterate through Oqtane assemblies in /bin ( filter is narrow to optimize loading process )
|
||||||
foreach (var dll in assembliesFolder.EnumerateFiles($"*.{pattern}.*.dll"))
|
foreach (var dll in assembliesFolder.EnumerateFiles($"*.dll", SearchOption.TopDirectoryOnly).Where(f => f.IsOqtaneAssembly()))
|
||||||
{
|
{
|
||||||
// check if assembly is already loaded
|
AssemblyName assemblyName;
|
||||||
var assembly = Assemblies.FirstOrDefault(a =>!a.IsDynamic && a.Location == dll.FullName);
|
try
|
||||||
if (assembly == null)
|
|
||||||
{
|
{
|
||||||
// load assembly ( and symbols ) from stream to prevent locking files ( as long as dependencies are in /bin they will load as well )
|
assemblyName = AssemblyName.GetAssemblyName(dll.FullName);
|
||||||
string pdb = dll.FullName.Replace(".dll", ".pdb");
|
}
|
||||||
if (File.Exists(pdb))
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Not Assembly : {dll.Name}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
|
if (!assemblies.Any(a => AssemblyName.ReferenceMatchesDefinition(assemblyName, a.GetName())))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName)), new MemoryStream(File.ReadAllBytes(pdb)));
|
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}");
|
||||||
}
|
}
|
||||||
else
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(dll.FullName)));
|
Console.WriteLine($"Failed : {assemblyName}\n{e}");
|
||||||
}
|
|
||||||
if (pattern == "Module")
|
|
||||||
{
|
|
||||||
// build a list of module assemblies
|
|
||||||
OqtaneModuleAssemblies.Add(assembly);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
Oqtane.Server/Extensions/StringExtensions.cs
Normal file
17
Oqtane.Server/Extensions/StringExtensions.cs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Oqtane.Extensions
|
||||||
|
{
|
||||||
|
public static class StringExtensions
|
||||||
|
{
|
||||||
|
public static bool StartWithAnyOf(this string s, IEnumerable<string> list)
|
||||||
|
{
|
||||||
|
if (s == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return list.Any(f => s.StartsWith(f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -75,6 +75,7 @@ namespace Oqtane.Repository
|
||||||
// get module assemblies
|
// get module assemblies
|
||||||
_moduleDefinitions = LoadModuleDefinitionsFromAssemblies();
|
_moduleDefinitions = LoadModuleDefinitionsFromAssemblies();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ModuleDefinition> moduleDefinitions = _moduleDefinitions;
|
List<ModuleDefinition> moduleDefinitions = _moduleDefinitions;
|
||||||
|
|
||||||
List<Permission> permissions = new List<Permission>();
|
List<Permission> permissions = new List<Permission>();
|
||||||
|
@ -94,7 +95,7 @@ namespace Oqtane.Repository
|
||||||
if (moduledef == null)
|
if (moduledef == null)
|
||||||
{
|
{
|
||||||
// new module definition
|
// new module definition
|
||||||
moduledef = new ModuleDefinition { ModuleDefinitionName = moduledefinition.ModuleDefinitionName };
|
moduledef = new ModuleDefinition {ModuleDefinitionName = moduledefinition.ModuleDefinitionName};
|
||||||
_db.ModuleDefinition.Add(moduledef);
|
_db.ModuleDefinition.Add(moduledef);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
if (siteId != -1)
|
if (siteId != -1)
|
||||||
|
@ -109,18 +110,22 @@ namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
moduledefinition.Name = moduledef.Name;
|
moduledefinition.Name = moduledef.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(moduledef.Description))
|
if (!string.IsNullOrEmpty(moduledef.Description))
|
||||||
{
|
{
|
||||||
moduledefinition.Description = moduledef.Description;
|
moduledefinition.Description = moduledef.Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(moduledef.Categories))
|
if (!string.IsNullOrEmpty(moduledef.Categories))
|
||||||
{
|
{
|
||||||
moduledefinition.Categories = moduledef.Categories;
|
moduledefinition.Categories = moduledef.Categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(moduledef.Version))
|
if (!string.IsNullOrEmpty(moduledef.Version))
|
||||||
{
|
{
|
||||||
moduledefinition.Version = moduledef.Version;
|
moduledefinition.Version = moduledef.Version;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (siteId != -1)
|
if (siteId != -1)
|
||||||
{
|
{
|
||||||
if (permissions.Count == 0)
|
if (permissions.Count == 0)
|
||||||
|
@ -139,9 +144,11 @@ namespace Oqtane.Repository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove module definition from list as it is already synced
|
// remove module definition from list as it is already synced
|
||||||
moduledefs.Remove(moduledef);
|
moduledefs.Remove(moduledef);
|
||||||
}
|
}
|
||||||
|
|
||||||
moduledefinition.ModuleDefinitionId = moduledef.ModuleDefinitionId;
|
moduledefinition.ModuleDefinitionId = moduledef.ModuleDefinitionId;
|
||||||
moduledefinition.SiteId = siteId;
|
moduledefinition.SiteId = siteId;
|
||||||
moduledefinition.CreatedBy = moduledef.CreatedBy;
|
moduledefinition.CreatedBy = moduledef.CreatedBy;
|
||||||
|
@ -157,6 +164,7 @@ namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
_permissions.DeletePermissions(siteId, EntityNames.ModuleDefinition, moduledefinition.ModuleDefinitionId);
|
_permissions.DeletePermissions(siteId, EntityNames.ModuleDefinition, moduledefinition.ModuleDefinitionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
_db.ModuleDefinition.Remove(moduledefinition); // delete
|
_db.ModuleDefinition.Remove(moduledefinition); // delete
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
|
@ -168,12 +176,12 @@ namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
List<ModuleDefinition> moduleDefinitions = new List<ModuleDefinition>();
|
List<ModuleDefinition> moduleDefinitions = new List<ModuleDefinition>();
|
||||||
// iterate through Oqtane module assemblies
|
// iterate through Oqtane module assemblies
|
||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||||
.Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module.")).ToArray();
|
|
||||||
foreach (Assembly assembly in assemblies)
|
foreach (Assembly assembly in assemblies)
|
||||||
{
|
{
|
||||||
moduleDefinitions = LoadModuleDefinitionsFromAssembly(moduleDefinitions, assembly);
|
moduleDefinitions = LoadModuleDefinitionsFromAssembly(moduleDefinitions, assembly);
|
||||||
}
|
}
|
||||||
|
|
||||||
return moduleDefinitions;
|
return moduleDefinitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,84 +191,92 @@ namespace Oqtane.Repository
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (modulecontroltype.Name != "ModuleBase" && !modulecontroltype.Namespace.EndsWith(".Controls"))
|
// Check if type should be ignored
|
||||||
|
if (modulecontroltype.Name == "ModuleBase"
|
||||||
|
|| modulecontroltype.IsGenericType
|
||||||
|
|| Attribute.IsDefined(modulecontroltype, typeof(OqtaneIgnoreAttribute))
|
||||||
|
) continue;
|
||||||
|
|
||||||
|
string[] typename = modulecontroltype.AssemblyQualifiedName?.Split(',').Select(item => item.Trim()).ToArray();
|
||||||
|
string[] segments = typename[0].Split('.');
|
||||||
|
Array.Resize(ref segments, segments.Length - 1);
|
||||||
|
string moduleType = string.Join(".", segments);
|
||||||
|
string qualifiedModuleType = moduleType + ", " + typename[1];
|
||||||
|
|
||||||
|
int index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
||||||
|
if (index == -1)
|
||||||
{
|
{
|
||||||
string[] typename = modulecontroltype.AssemblyQualifiedName?.Split(',').Select(item => item.Trim()).ToArray();
|
// determine if this module implements IModule
|
||||||
string[] segments = typename[0].Split('.');
|
Type moduletype = assembly
|
||||||
Array.Resize(ref segments, segments.Length - 1);
|
.GetTypes()
|
||||||
string moduleType = string.Join(".", segments);
|
.Where(item => item.Namespace != null)
|
||||||
string qualifiedModuleType = moduleType + ", " + typename[1];
|
.Where(item => item.Namespace.StartsWith(moduleType))
|
||||||
|
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(IModule)));
|
||||||
int index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
if (moduletype != null)
|
||||||
if (index == -1)
|
|
||||||
{
|
{
|
||||||
// determine if this module implements IModule
|
// get property values from IModule
|
||||||
Type moduletype = assembly
|
var moduleobject = Activator.CreateInstance(moduletype);
|
||||||
.GetTypes()
|
moduledefinition = (ModuleDefinition) moduletype.GetProperty("ModuleDefinition").GetValue(moduleobject);
|
||||||
.Where(item => item.Namespace != null)
|
|
||||||
.Where(item => item.Namespace.StartsWith(moduleType))
|
|
||||||
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(IModule)));
|
|
||||||
if (moduletype != null)
|
|
||||||
{
|
|
||||||
// get property values from IModule
|
|
||||||
var moduleobject = Activator.CreateInstance(moduletype);
|
|
||||||
moduledefinition = (ModuleDefinition)moduletype.GetProperty("ModuleDefinition").GetValue(moduleobject);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// set default property values
|
|
||||||
moduledefinition = new ModuleDefinition
|
|
||||||
{
|
|
||||||
Name = moduleType.Substring(moduleType.LastIndexOf(".") + 1),
|
|
||||||
Description = "Manage " + moduleType.Substring(moduleType.LastIndexOf(".") + 1),
|
|
||||||
Categories = ((qualifiedModuleType.StartsWith("Oqtane.Modules.Admin.")) ? "Admin" : "")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// set internal properties
|
|
||||||
moduledefinition.ModuleDefinitionName = qualifiedModuleType;
|
|
||||||
moduledefinition.Version = ""; // will be populated from database
|
|
||||||
moduledefinition.ControlTypeTemplate = moduleType + "." + Constants.ActionToken + ", " + typename[1];
|
|
||||||
moduledefinition.AssemblyName = assembly.GetName().Name;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(moduledefinition.Categories))
|
|
||||||
{
|
|
||||||
moduledefinition.Categories = "Common";
|
|
||||||
}
|
|
||||||
if (moduledefinition.Categories == "Admin")
|
|
||||||
{
|
|
||||||
moduledefinition.Permissions = new List<Permission>
|
|
||||||
{
|
|
||||||
new Permission(PermissionNames.Utilize, Constants.AdminRole, true)
|
|
||||||
}.EncodePermissions();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
moduledefinition.Permissions = new List<Permission>
|
|
||||||
{
|
|
||||||
new Permission(PermissionNames.Utilize, Constants.AdminRole, true),
|
|
||||||
new Permission(PermissionNames.Utilize, Constants.RegisteredRole, true)
|
|
||||||
}.EncodePermissions();
|
|
||||||
}
|
|
||||||
moduledefinitions.Add(moduledefinition);
|
|
||||||
index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
|
||||||
}
|
}
|
||||||
moduledefinition = moduledefinitions[index];
|
else
|
||||||
// actions
|
|
||||||
var modulecontrolobject = Activator.CreateInstance(modulecontroltype);
|
|
||||||
string actions = (string)modulecontroltype.GetProperty("Actions")?.GetValue(modulecontrolobject);
|
|
||||||
if (!string.IsNullOrEmpty(actions))
|
|
||||||
{
|
{
|
||||||
foreach (string action in actions.Split(','))
|
// set default property values
|
||||||
|
moduledefinition = new ModuleDefinition
|
||||||
{
|
{
|
||||||
moduledefinition.ControlTypeRoutes += (action + "=" + modulecontroltype.FullName + ", " + typename[1] + ";");
|
Name = moduleType.Substring(moduleType.LastIndexOf(".") + 1),
|
||||||
}
|
Description = "Manage " + moduleType.Substring(moduleType.LastIndexOf(".") + 1),
|
||||||
|
Categories = ((qualifiedModuleType.StartsWith("Oqtane.Modules.Admin.")) ? "Admin" : "")
|
||||||
|
};
|
||||||
}
|
}
|
||||||
moduledefinitions[index] = moduledefinition;
|
|
||||||
|
// set internal properties
|
||||||
|
moduledefinition.ModuleDefinitionName = qualifiedModuleType;
|
||||||
|
moduledefinition.Version = ""; // will be populated from database
|
||||||
|
moduledefinition.ControlTypeTemplate = moduleType + "." + Constants.ActionToken + ", " + typename[1];
|
||||||
|
moduledefinition.AssemblyName = assembly.GetName().Name;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(moduledefinition.Categories))
|
||||||
|
{
|
||||||
|
moduledefinition.Categories = "Common";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (moduledefinition.Categories == "Admin")
|
||||||
|
{
|
||||||
|
moduledefinition.Permissions = new List<Permission>
|
||||||
|
{
|
||||||
|
new Permission(PermissionNames.Utilize, Constants.AdminRole, true)
|
||||||
|
}.EncodePermissions();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moduledefinition.Permissions = new List<Permission>
|
||||||
|
{
|
||||||
|
new Permission(PermissionNames.Utilize, Constants.AdminRole, true),
|
||||||
|
new Permission(PermissionNames.Utilize, Constants.RegisteredRole, true)
|
||||||
|
}.EncodePermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"Registering module: {moduledefinition.ModuleDefinitionName}");
|
||||||
|
moduledefinitions.Add(moduledefinition);
|
||||||
|
index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moduledefinition = moduledefinitions[index];
|
||||||
|
// actions
|
||||||
|
var modulecontrolobject = Activator.CreateInstance(modulecontroltype);
|
||||||
|
string actions = (string) modulecontroltype.GetProperty("Actions")?.GetValue(modulecontrolobject);
|
||||||
|
if (!string.IsNullOrEmpty(actions))
|
||||||
|
{
|
||||||
|
foreach (string action in actions.Split(','))
|
||||||
|
{
|
||||||
|
moduledefinition.ControlTypeRoutes += (action + "=" + modulecontroltype.FullName + ", " + typename[1] + ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
moduledefinitions[index] = moduledefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
return moduledefinitions;
|
return moduledefinitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace Oqtane.Repository
|
||||||
List<SiteTemplate> siteTemplates = new List<SiteTemplate>();
|
List<SiteTemplate> siteTemplates = new List<SiteTemplate>();
|
||||||
|
|
||||||
// iterate through Oqtane site template assemblies
|
// iterate through Oqtane site template assemblies
|
||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||||
.Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".SiteTemplate.")).ToArray();
|
|
||||||
foreach (Assembly assembly in assemblies)
|
foreach (Assembly assembly in assemblies)
|
||||||
{
|
{
|
||||||
siteTemplates = LoadSiteTemplatesFromAssembly(siteTemplates, assembly);
|
siteTemplates = LoadSiteTemplatesFromAssembly(siteTemplates, assembly);
|
||||||
|
|
|
@ -31,8 +31,7 @@ namespace Oqtane.Repository
|
||||||
List<Theme> themes = new List<Theme>();
|
List<Theme> themes = new List<Theme>();
|
||||||
|
|
||||||
// iterate through Oqtane theme assemblies
|
// iterate through Oqtane theme assemblies
|
||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||||
.Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Theme.")).ToArray();
|
|
||||||
foreach (Assembly assembly in assemblies)
|
foreach (Assembly assembly in assemblies)
|
||||||
{
|
{
|
||||||
themes = LoadThemesFromAssembly(themes, assembly);
|
themes = LoadThemesFromAssembly(themes, assembly);
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace Oqtane
|
||||||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddMvc().AddNewtonsoftJson();
|
|
||||||
services.AddServerSideBlazor();
|
services.AddServerSideBlazor();
|
||||||
|
|
||||||
// setup HttpClient for server side in a client side compatible fashion ( with auth cookie )
|
// setup HttpClient for server side in a client side compatible fashion ( with auth cookie )
|
||||||
|
@ -188,16 +188,13 @@ namespace Oqtane
|
||||||
services.AddTransient<IUpgradeManager, UpgradeManager>();
|
services.AddTransient<IUpgradeManager, UpgradeManager>();
|
||||||
|
|
||||||
// load the external assemblies into the app domain
|
// load the external assemblies into the app domain
|
||||||
services.AddOqtaneModules();
|
services.AddOqtaneParts();
|
||||||
services.AddOqtaneThemes();
|
|
||||||
services.AddOqtaneSiteTemplates();
|
|
||||||
|
|
||||||
services.AddMvc()
|
services.AddMvc()
|
||||||
.AddOqtaneApplicationParts() // register any Controllers from custom modules
|
.AddOqtaneApplicationParts() // register any Controllers from custom modules
|
||||||
.AddNewtonsoftJson();
|
.AddNewtonsoftJson();
|
||||||
|
|
||||||
services.AddOqtaneServices();
|
|
||||||
services.AddOqtaneHostedServices();
|
|
||||||
|
|
||||||
services.AddSwaggerGen(c =>
|
services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
|
|
9
Oqtane.Shared/Shared/OqtaneIgnoreAttribute.cs
Normal file
9
Oqtane.Shared/Shared/OqtaneIgnoreAttribute.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Oqtane.Shared
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class OqtaneIgnoreAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user