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