assembly whitelist
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>2.1.11</Version>
|
||||
<Version>2.2.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Pilz.Text;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Pilz.Plugins;
|
||||
|
||||
@@ -18,7 +19,7 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
|
||||
|
||||
protected void OnCurrentAppDomainAssemblyLoad(object? sender, AssemblyLoadEventArgs args)
|
||||
{
|
||||
LoadPlugins(args.LoadedAssembly);
|
||||
LoadPlugins(args.LoadedAssembly, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -27,7 +28,7 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
|
||||
/// <param name="paths"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadPlugins(string[] paths, params object?[]? parameters)
|
||||
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadPlugins(string[] paths, object?[]? parameters)
|
||||
{
|
||||
var results = new List<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>>();
|
||||
|
||||
@@ -43,7 +44,7 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
|
||||
/// <param name="assemblies"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadPlugins(Assembly[] assemblies, params object?[]? parameters)
|
||||
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadPlugins(Assembly[] assemblies, object?[]? parameters)
|
||||
{
|
||||
var results = new List<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>>();
|
||||
|
||||
@@ -57,25 +58,30 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
|
||||
/// Loads plugins from already loaded assemblies for the current <see cref="AppDomain.CurrentDomain"/>.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadOwnPlugins(params object?[]? parameters)
|
||||
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadOwnPlugins(object?[]? parameters, string? whitelist)
|
||||
{
|
||||
return LoadOwnPlugins(false, parameters);
|
||||
return LoadOwnPlugins(false, parameters, whitelist);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads plugins from already loaded assemblies for the current <see cref="AppDomain.CurrentDomain"/>.
|
||||
/// </summary>
|
||||
/// <param name="listenAssemblyLoadContext">Do also load plugins from all yet not loaded assemblies by listening the event <see cref="AppDomain.AssemblyLoad"/></param>
|
||||
/// <param name="whitelist"></param>>.
|
||||
/// <param name="parameters"></param>>.
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadOwnPlugins(bool listenAssemblyLoadContext, params object?[]? parameters)
|
||||
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadOwnPlugins(bool listenAssemblyLoadContext, object?[]? parameters, string? whitelist)
|
||||
{
|
||||
var results = new List<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>>();
|
||||
|
||||
if (listenAssemblyLoadContext)
|
||||
AppDomain.CurrentDomain.AssemblyLoad += OnCurrentAppDomainAssemblyLoad;
|
||||
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies().AsEnumerable();
|
||||
if (!string.IsNullOrWhiteSpace(whitelist))
|
||||
assemblies = assemblies.Where(n => LikeOperator.IsLike(n.GetName().Name, whitelist));
|
||||
|
||||
foreach (var assembly in assemblies)
|
||||
results.Add(LoadPlugins(assembly, parameters));
|
||||
|
||||
return results;
|
||||
@@ -87,7 +93,7 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
|
||||
/// <param name="path"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
public virtual PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> LoadPlugin(string path, params object?[]? parameters)
|
||||
public virtual PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> LoadPlugin(string path, object?[]? parameters)
|
||||
{
|
||||
var result = new PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>();
|
||||
var loadContext = new PluginLoadContext(path);
|
||||
@@ -118,7 +124,7 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
|
||||
/// <param name="assembly"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
public virtual PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> LoadPlugins(Assembly assembly, params object?[]? parameters)
|
||||
public virtual PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> LoadPlugins(Assembly assembly, object?[]? parameters)
|
||||
{
|
||||
var result = new PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>
|
||||
{
|
||||
@@ -137,7 +143,7 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
|
||||
/// <typeparam name="TPlugin"></typeparam>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
public virtual PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> LoadPlugin<TPlugin>(params object?[]? parameters) where TPlugin : TPluginInterface
|
||||
public virtual PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> LoadPlugin<TPlugin>(object?[]? parameters) where TPlugin : TPluginInterface
|
||||
{
|
||||
var result = new PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>
|
||||
{
|
||||
@@ -149,12 +155,12 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
|
||||
return result;
|
||||
}
|
||||
|
||||
protected virtual void LoadPlugin(PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> result, params object?[]? parameters)
|
||||
protected virtual void LoadPlugin(PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> result, object?[]? parameters)
|
||||
{
|
||||
if (result.Assembly == null)
|
||||
result.Status = PluginLoadStatus.NoValidPlugin;
|
||||
else if (loadedPlugins.Any(n => n.Assembly == result.Assembly))
|
||||
result.Status = PluginLoadStatus.AlreadyLoaded;
|
||||
//else if (loadedPlugins.Any(n => n.Assembly == result.Assembly))
|
||||
// result.Status = PluginLoadStatus.AlreadyLoaded;
|
||||
else
|
||||
{
|
||||
foreach (var type in result.Assembly.GetTypes())
|
||||
@@ -165,7 +171,7 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
|
||||
result.Status = PluginLoadStatus.NoValidPlugin;
|
||||
}
|
||||
|
||||
protected virtual void LoadPlugin(PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> result, Type type, params object?[]? parameters)
|
||||
protected virtual void LoadPlugin(PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> result, Type type, object?[]? parameters)
|
||||
{
|
||||
if (loadedPlugins.Any(n => n.Plugin != null && n.Plugin.GetType() == type))
|
||||
result.Status = PluginLoadStatus.AlreadyLoaded;
|
||||
|
||||
Reference in New Issue
Block a user