From 5b2557b3f40e642136bacd7ab3621631ff12a8fb Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 20 Sep 2023 13:56:01 +0200 Subject: [PATCH] Set up loading of plugins. --- Framework/Core/PluginManager.cs | 16 --------- Framework/Core/ProjectPlugin.cs | 34 +++++++++++++++++++ .../CodexContinuousTests/EntryPointFactory.cs | 8 +++++ Tests/CodexTests/CodexDistTest.cs | 10 +++++- Tools/CodexNetDeployer/Deployer.cs | 8 +++-- 5 files changed, 56 insertions(+), 20 deletions(-) create mode 100644 Framework/Core/ProjectPlugin.cs diff --git a/Framework/Core/PluginManager.cs b/Framework/Core/PluginManager.cs index 69ee4bb..7de080f 100644 --- a/Framework/Core/PluginManager.cs +++ b/Framework/Core/PluginManager.cs @@ -59,20 +59,4 @@ } } } - - public interface IProjectPlugin - { - void Announce(); - void Decommission(); - } - - public interface IHasLogPrefix - { - string LogPrefix { get; } - } - - public interface IHasMetadata - { - void AddMetadata(IAddMetadata metadata); - } } diff --git a/Framework/Core/ProjectPlugin.cs b/Framework/Core/ProjectPlugin.cs new file mode 100644 index 0000000..72f3c16 --- /dev/null +++ b/Framework/Core/ProjectPlugin.cs @@ -0,0 +1,34 @@ +using Utils; + +namespace Core +{ + public interface IProjectPlugin + { + void Announce(); + void Decommission(); + } + + public interface IHasLogPrefix + { + string LogPrefix { get; } + } + + public interface IHasMetadata + { + void AddMetadata(IAddMetadata metadata); + } + + public static class ProjectPlugin + { + /// + /// On some platforms and in some cases, not all required plugin assemblies are automatically loaded into the app domain. + /// In this case, the runtime needs a slight push to load it before the EntryPoint class is instantiated. + /// Used ProjectPlugin.Load<>() before you create an EntryPoint to ensure all plugins you want to use are loaded. + /// + public static void Load() where T : IProjectPlugin + { + var type = typeof(T); + FrameworkAssert.That(type != null, $"Unable to load plugin."); + } + } +} diff --git a/Tests/CodexContinuousTests/EntryPointFactory.cs b/Tests/CodexContinuousTests/EntryPointFactory.cs index f61d22e..90b92b4 100644 --- a/Tests/CodexContinuousTests/EntryPointFactory.cs +++ b/Tests/CodexContinuousTests/EntryPointFactory.cs @@ -5,6 +5,14 @@ namespace ContinuousTests { public class EntryPointFactory { + public EntryPointFactory() + { + ProjectPlugin.Load(); + ProjectPlugin.Load(); + ProjectPlugin.Load(); + ProjectPlugin.Load(); + } + public EntryPoint CreateEntryPoint(string kubeConfigFile, string dataFilePath, string customNamespace, ILog log) { var kubeConfig = GetKubeConfig(kubeConfigFile); diff --git a/Tests/CodexTests/CodexDistTest.cs b/Tests/CodexTests/CodexDistTest.cs index 2af737d..32c6ec2 100644 --- a/Tests/CodexTests/CodexDistTest.cs +++ b/Tests/CodexTests/CodexDistTest.cs @@ -1,10 +1,10 @@ using CodexContractsPlugin; using CodexPlugin; +using Core; using DistTestCore; using DistTestCore.Helpers; using GethPlugin; using NUnit.Framework.Constraints; -using Utils; namespace Tests { @@ -12,6 +12,14 @@ namespace Tests { private readonly List onlineCodexNodes = new List(); + public CodexDistTest() + { + ProjectPlugin.Load(); + ProjectPlugin.Load(); + ProjectPlugin.Load(); + ProjectPlugin.Load(); + } + public ICodexNode AddCodex() { return AddCodex(s => { }); diff --git a/Tools/CodexNetDeployer/Deployer.cs b/Tools/CodexNetDeployer/Deployer.cs index ee9ff9a..f06e91c 100644 --- a/Tools/CodexNetDeployer/Deployer.cs +++ b/Tools/CodexNetDeployer/Deployer.cs @@ -18,7 +18,11 @@ namespace CodexNetDeployer { this.config = config; peerConnectivityChecker = new PeerConnectivityChecker(); - + + ProjectPlugin.Load(); + ProjectPlugin.Load(); + ProjectPlugin.Load(); + ProjectPlugin.Load(); entryPoint = CreateEntryPoint(new NullLog()); } @@ -27,8 +31,6 @@ namespace CodexNetDeployer var ep = CreateEntryPoint(new ConsoleLog()); Log("Using plugins:" + Environment.NewLine); - ep.Announce(); - Log(""); var metadata = ep.GetPluginMetadata(); foreach (var entry in metadata) {