Set up loading of plugins.

This commit is contained in:
benbierens 2023-09-20 13:56:01 +02:00
parent 8cde69a483
commit 5b2557b3f4
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
5 changed files with 56 additions and 20 deletions

View File

@ -59,20 +59,4 @@
}
}
}
public interface IProjectPlugin
{
void Announce();
void Decommission();
}
public interface IHasLogPrefix
{
string LogPrefix { get; }
}
public interface IHasMetadata
{
void AddMetadata(IAddMetadata metadata);
}
}

View File

@ -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
{
/// <summary>
/// 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.
/// </summary>
public static void Load<T>() where T : IProjectPlugin
{
var type = typeof(T);
FrameworkAssert.That(type != null, $"Unable to load plugin.");
}
}
}

View File

@ -5,6 +5,14 @@ namespace ContinuousTests
{
public class EntryPointFactory
{
public EntryPointFactory()
{
ProjectPlugin.Load<CodexPlugin.CodexPlugin>();
ProjectPlugin.Load<CodexContractsPlugin.CodexContractsPlugin>();
ProjectPlugin.Load<GethPlugin.GethPlugin>();
ProjectPlugin.Load<MetricsPlugin.MetricsPlugin>();
}
public EntryPoint CreateEntryPoint(string kubeConfigFile, string dataFilePath, string customNamespace, ILog log)
{
var kubeConfig = GetKubeConfig(kubeConfigFile);

View File

@ -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<ICodexNode> onlineCodexNodes = new List<ICodexNode>();
public CodexDistTest()
{
ProjectPlugin.Load<CodexPlugin.CodexPlugin>();
ProjectPlugin.Load<CodexContractsPlugin.CodexContractsPlugin>();
ProjectPlugin.Load<GethPlugin.GethPlugin>();
ProjectPlugin.Load<MetricsPlugin.MetricsPlugin>();
}
public ICodexNode AddCodex()
{
return AddCodex(s => { });

View File

@ -18,7 +18,11 @@ namespace CodexNetDeployer
{
this.config = config;
peerConnectivityChecker = new PeerConnectivityChecker();
ProjectPlugin.Load<CodexPlugin.CodexPlugin>();
ProjectPlugin.Load<CodexContractsPlugin.CodexContractsPlugin>();
ProjectPlugin.Load<GethPlugin.GethPlugin>();
ProjectPlugin.Load<MetricsPlugin.MetricsPlugin>();
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)
{