cs-codex-dist-tests/Core/PluginManager.cs

69 lines
1.7 KiB
C#
Raw Normal View History

2023-09-12 08:31:55 +00:00
using FileUtils;
using KubernetesWorkflow;
2023-09-11 14:57:57 +00:00
using Logging;
2023-09-12 08:31:55 +00:00
using Utils;
2023-09-11 14:57:57 +00:00
2023-09-12 11:32:06 +00:00
namespace Core
2023-09-11 14:57:57 +00:00
{
2023-09-12 08:31:55 +00:00
public class PluginManager
2023-09-11 14:57:57 +00:00
{
private readonly List<IProjectPlugin> projectPlugins = new List<IProjectPlugin>();
2023-09-13 08:03:11 +00:00
public void InstantiatePlugins(Type[] pluginTypes, IPluginTools tools)
2023-09-11 14:57:57 +00:00
{
2023-09-12 08:31:55 +00:00
projectPlugins.Clear();
foreach (var pluginType in pluginTypes)
{
2023-09-13 08:03:11 +00:00
var plugin = (IProjectPlugin)Activator.CreateInstance(pluginType, args: tools)!;
2023-09-12 08:31:55 +00:00
projectPlugins.Add(plugin);
}
2023-09-11 14:57:57 +00:00
}
2023-09-13 08:03:11 +00:00
public void AnnouncePlugins()
2023-09-11 14:57:57 +00:00
{
2023-09-13 08:03:11 +00:00
foreach (var plugin in projectPlugins) plugin.Announce();
2023-09-11 14:57:57 +00:00
}
2023-09-13 08:03:11 +00:00
public void DecommissionPlugins()
2023-09-11 14:57:57 +00:00
{
2023-09-13 08:03:11 +00:00
foreach (var plugin in projectPlugins) plugin.Decommission();
2023-09-11 14:57:57 +00:00
}
2023-09-12 09:25:04 +00:00
public T GetPlugin<T>() where T : IProjectPlugin
{
return (T)projectPlugins.Single(p => p.GetType() == typeof(T));
}
2023-09-12 08:31:55 +00:00
}
2023-09-11 14:57:57 +00:00
public interface IProjectPlugin
{
2023-09-13 08:03:11 +00:00
void Announce();
void Decommission();
2023-09-12 08:31:55 +00:00
}
public interface IPluginTools : IWorkflowTool, ILogTool, IHttpFactoryTool, IFileTool
2023-09-13 08:03:11 +00:00
{
2023-09-12 08:31:55 +00:00
}
public interface IWorkflowTool
{
IStartupWorkflow CreateWorkflow(string? namespaceOverride = null);
2023-09-11 14:57:57 +00:00
}
2023-09-12 08:31:55 +00:00
public interface ILogTool
2023-09-11 14:57:57 +00:00
{
ILog GetLog();
2023-09-12 08:31:55 +00:00
}
public interface IHttpFactoryTool
{
Http CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null);
Http CreateHttp(Address address, string baseUrl, string? logAlias = null);
}
public interface IFileTool
{
IFileManager GetFileManager();
2023-09-11 14:57:57 +00:00
}
}