mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-11-22 02:12:22 +00:00
Rename module entity to plugin in the code
This commit is contained in:
parent
01a7589417
commit
fdf85d5055
@ -1,5 +1,5 @@
|
||||
using Zirconium.Core.Modules;
|
||||
using Zirconium.Core.Modules.Interfaces;
|
||||
using Zirconium.Core.Plugins;
|
||||
using Zirconium.Core.Plugins.Interfaces;
|
||||
using Zirconium.Core.Logging;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
@ -10,8 +10,8 @@ namespace Zirconium.Core
|
||||
public Config Config;
|
||||
public SessionManager SessionManager { get; }
|
||||
public Router Router { get; }
|
||||
public ModuleManager ModuleManager { get; }
|
||||
public IHostModuleAPI HostModuleAPI { get; }
|
||||
public PluginManager PluginManager { get; }
|
||||
public IPluginHostAPI PluginHostAPI { get; }
|
||||
public AuthManager AuthManager { get; }
|
||||
private WebSocketServer _websocketServer;
|
||||
|
||||
@ -22,10 +22,10 @@ namespace Zirconium.Core
|
||||
_websocketServer.AddWebSocketService<ConnectionHandler>(config.Websocket.Endpoint, () => new ConnectionHandler(this));
|
||||
SessionManager = new SessionManager();
|
||||
Router = new Router(this);
|
||||
HostModuleAPI = new HostModuleAPI(this, Router);
|
||||
PluginHostAPI = new PluginHostAPI(this, Router);
|
||||
AuthManager = new AuthManager(this);
|
||||
ModuleManager = new ModuleManager(HostModuleAPI);
|
||||
ModuleManager.LoadModules(config.PluginsDirPath, config.EnabledPlugins);
|
||||
PluginManager = new PluginManager(PluginHostAPI);
|
||||
PluginManager.LoadPlugins(config.PluginsDirPath, config.EnabledPlugins);
|
||||
Log.Info("Zirconium is initialized successfully");
|
||||
}
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
namespace Zirconium.Core.Modules.Interfaces
|
||||
{
|
||||
public interface IModuleAPI
|
||||
{
|
||||
void Initialize(IHostModuleAPI hostModuleAPI);
|
||||
string GetModuleUniqueName();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using Zirconium.Core.Models;
|
||||
|
||||
namespace Zirconium.Core.Modules.Interfaces
|
||||
namespace Zirconium.Core.Plugins.Interfaces
|
||||
{
|
||||
public interface IC2SMessageHandler {
|
||||
string GetHandlingMessageType();
|
@ -1,6 +1,6 @@
|
||||
using Zirconium.Core.Models;
|
||||
|
||||
namespace Zirconium.Core.Modules.Interfaces
|
||||
namespace Zirconium.Core.Plugins.Interfaces
|
||||
{
|
||||
public interface ICoreEventHandler
|
||||
{
|
8
src/Zirconium/Core/Plugins/Interfaces/IPluginAPI.cs
Normal file
8
src/Zirconium/Core/Plugins/Interfaces/IPluginAPI.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Zirconium.Core.Plugins.Interfaces
|
||||
{
|
||||
public interface IPluginAPI
|
||||
{
|
||||
void Initialize(IPluginHostAPI hostModuleAPI);
|
||||
string GetPluginUniqueName();
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using Zirconium.Core.Models;
|
||||
|
||||
namespace Zirconium.Core.Modules.Interfaces
|
||||
namespace Zirconium.Core.Plugins.Interfaces
|
||||
{
|
||||
public interface IHostModuleAPI
|
||||
public interface IPluginHostAPI
|
||||
{
|
||||
void Hook(IC2SMessageHandler handler);
|
||||
void HookCoreEvent(ICoreEventHandler handler);
|
||||
@ -13,7 +13,7 @@ namespace Zirconium.Core.Modules.Interfaces
|
||||
string[] GetServerDomains();
|
||||
string GetServerID();
|
||||
void SendMessage(ConnectionInfo connInfo, BaseMessage message);
|
||||
dynamic GetSettings(IModuleAPI plugin);
|
||||
dynamic GetSettings(IPluginAPI plugin);
|
||||
dynamic GetSettings(string pluginName);
|
||||
}
|
||||
}
|
@ -2,16 +2,16 @@ using System.Collections.Generic;
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Zirconium.Core.Models;
|
||||
using Zirconium.Core.Modules.Interfaces;
|
||||
using Zirconium.Core.Plugins.Interfaces;
|
||||
|
||||
namespace Zirconium.Core.Modules
|
||||
namespace Zirconium.Core.Plugins
|
||||
{
|
||||
public class HostModuleAPI : IHostModuleAPI
|
||||
public class PluginHostAPI : IPluginHostAPI
|
||||
{
|
||||
private App _app;
|
||||
private Router _router;
|
||||
|
||||
public HostModuleAPI(App app, Router router)
|
||||
public PluginHostAPI(App app, Router router)
|
||||
{
|
||||
_router = router;
|
||||
_app = app;
|
||||
@ -37,9 +37,9 @@ namespace Zirconium.Core.Modules
|
||||
return _app.Config.ServerID;
|
||||
}
|
||||
|
||||
public dynamic GetSettings(IModuleAPI plugin)
|
||||
public dynamic GetSettings(IPluginAPI plugin)
|
||||
{
|
||||
return _app.Config.Plugins.GetValueOrDefault(plugin.GetModuleUniqueName(), null);
|
||||
return _app.Config.Plugins.GetValueOrDefault(plugin.GetPluginUniqueName(), null);
|
||||
}
|
||||
|
||||
public dynamic GetSettings(string pluginName)
|
@ -5,25 +5,25 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using McMaster.NETCore.Plugins;
|
||||
using Zirconium.Core.Models;
|
||||
using Zirconium.Core.Modules.Interfaces;
|
||||
using Zirconium.Core.Plugins.Interfaces;
|
||||
|
||||
namespace Zirconium.Core.Modules
|
||||
namespace Zirconium.Core.Plugins
|
||||
{
|
||||
// Class which responsible for module managing (loading, initializing) and module lifetime cycle
|
||||
public class ModuleManager
|
||||
// Class which responsible for plugin managing (loading, initializing) and plugin lifetime cycle
|
||||
public class PluginManager
|
||||
{
|
||||
private IList<IModuleAPI> _modules;
|
||||
private IHostModuleAPI _hostModuleAPI;
|
||||
private Mutex _moduleMutex;
|
||||
private IList<IPluginAPI> _plugins;
|
||||
private IPluginHostAPI _pluginHostAPI;
|
||||
private Mutex _pluginsMutex;
|
||||
|
||||
public ModuleManager(IHostModuleAPI hostModuleAPI)
|
||||
public PluginManager(IPluginHostAPI hostModuleAPI)
|
||||
{
|
||||
_hostModuleAPI = hostModuleAPI;
|
||||
_modules = new List<IModuleAPI>();
|
||||
_moduleMutex = new Mutex();
|
||||
_pluginHostAPI = hostModuleAPI;
|
||||
_plugins = new List<IPluginAPI>();
|
||||
_pluginsMutex = new Mutex();
|
||||
}
|
||||
|
||||
public void LoadModules(string folderPath, string[] enabledModules)
|
||||
public void LoadPlugins(string folderPath, string[] enabledPlugins)
|
||||
{
|
||||
var loaders = new List<PluginLoader>();
|
||||
if (folderPath == "")
|
||||
@ -36,7 +36,7 @@ namespace Zirconium.Core.Modules
|
||||
foreach (var dir in Directory.GetDirectories(folderPath))
|
||||
{
|
||||
var dirName = Path.GetFileName(dir);
|
||||
if (enabledModules.Where(x => x == dirName).FirstOrDefault() == null) {
|
||||
if (enabledPlugins.Where(x => x == dirName).FirstOrDefault() == null) {
|
||||
continue;
|
||||
}
|
||||
var pluginDll = Path.Combine(dir, dirName + ".dll");
|
||||
@ -47,8 +47,8 @@ namespace Zirconium.Core.Modules
|
||||
var loader = PluginLoader.CreateFromAssemblyFile(
|
||||
pluginDll,
|
||||
sharedTypes: new[] {
|
||||
typeof(IModuleAPI),
|
||||
typeof(IHostModuleAPI),
|
||||
typeof(IPluginAPI),
|
||||
typeof(IPluginHostAPI),
|
||||
typeof(IC2SMessageHandler),
|
||||
typeof(ICoreEventHandler),
|
||||
typeof(BaseMessage),
|
||||
@ -65,13 +65,13 @@ namespace Zirconium.Core.Modules
|
||||
foreach (var pluginType in loader
|
||||
.LoadDefaultAssembly()
|
||||
.GetTypes()
|
||||
.Where(t => typeof(IModuleAPI).IsAssignableFrom(t) && !t.IsAbstract))
|
||||
.Where(t => typeof(IPluginAPI).IsAssignableFrom(t) && !t.IsAbstract))
|
||||
{
|
||||
// This assumes the implementation of IPlugin has a parameterless constructor
|
||||
IModuleAPI module = (IModuleAPI)Activator.CreateInstance(pluginType);
|
||||
Logging.Log.Debug($"Created module instance '{module.GetModuleUniqueName()}'.");
|
||||
module.Initialize(_hostModuleAPI);
|
||||
_modules.Add(module);
|
||||
IPluginAPI plugin = (IPluginAPI)Activator.CreateInstance(pluginType);
|
||||
Logging.Log.Debug($"Created plugin instance '{plugin.GetPluginUniqueName()}'.");
|
||||
plugin.Initialize(_pluginHostAPI);
|
||||
_plugins.Add(plugin);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Zirconium.Core.Models;
|
||||
using Zirconium.Core.Modules.Interfaces;
|
||||
using Zirconium.Core.Plugins.Interfaces;
|
||||
using Zirconium.Utils;
|
||||
using Zirconium.Core.Logging;
|
||||
using Newtonsoft.Json;
|
||||
|
@ -1,15 +1,15 @@
|
||||
using Newtonsoft.Json;
|
||||
using Zirconium.Core.Logging;
|
||||
using Zirconium.Core.Models;
|
||||
using Zirconium.Core.Modules.Interfaces;
|
||||
using Zirconium.Core.Plugins.Interfaces;
|
||||
|
||||
namespace HelloWorldPlugin
|
||||
{
|
||||
internal class HelloWorldPlugin : IModuleAPI
|
||||
internal class HelloWorldPlugin : IPluginAPI
|
||||
{
|
||||
public string GetModuleUniqueName() => "HelloWorldPlugin";
|
||||
public string GetPluginUniqueName() => "HelloWorldPlugin";
|
||||
|
||||
public void Initialize(IHostModuleAPI hostModuleAPI)
|
||||
public void Initialize(IPluginHostAPI hostModuleAPI)
|
||||
{
|
||||
var handler = new C2SHandler(hostModuleAPI);
|
||||
hostModuleAPI.Hook(handler);
|
||||
@ -19,9 +19,9 @@ namespace HelloWorldPlugin
|
||||
|
||||
internal class C2SHandler : IC2SMessageHandler
|
||||
{
|
||||
private IHostModuleAPI hostModuleAPI;
|
||||
private IPluginHostAPI hostModuleAPI;
|
||||
|
||||
public C2SHandler(IHostModuleAPI hostModuleAPI) {
|
||||
public C2SHandler(IPluginHostAPI hostModuleAPI) {
|
||||
this.hostModuleAPI = hostModuleAPI;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user