mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Plugin features - Added PluginFeature attribute
Plugin features -Added PluginFeatureInfo to plugin features Web server - Moved REST APIs to plugins
This commit is contained in:
1 parent
46958338b9
commit
c1b0027231
18 files changed
+297
-183
No files matched your search
@@ -9,6 +9,7 @@ using Artemis.Core.DeviceProviders;
|
||||
using Artemis.Core.Ninject;
|
||||
using Artemis.Storage.Entities.Plugins;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Humanizer;
|
||||
using McMaster.NETCore.Plugins;
|
||||
using Ninject;
|
||||
using Ninject.Extensions.ChildKernel;
|
||||
@@ -342,6 +343,10 @@ namespace Artemis.Core.Services
|
||||
// Include Plugin as a parameter for the PluginSettingsProvider
|
||||
IParameter[] parameters = {new Parameter("Plugin", plugin, false)};
|
||||
PluginFeature instance = (PluginFeature) plugin.Kernel.Get(featureType, parameters);
|
||||
|
||||
// Get the PluginFeature attribute which contains extra info on the feature
|
||||
PluginFeatureAttribute? pluginFeatureAttribute = (PluginFeatureAttribute?) Attribute.GetCustomAttribute(featureType, typeof(PluginFeatureAttribute));
|
||||
instance.Info = new PluginFeatureInfo(instance, pluginFeatureAttribute);
|
||||
plugin.AddFeature(instance);
|
||||
|
||||
// Load the enabled state and if not found, default to true
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using EmbedIO;
|
||||
using EmbedIO.Routing;
|
||||
using EmbedIO.WebApi;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
internal class PluginsController : WebApiController
|
||||
{
|
||||
private readonly IWebServerService _webServerService;
|
||||
|
||||
public PluginsController(IWebServerService webServerService)
|
||||
{
|
||||
_webServerService = webServerService;
|
||||
}
|
||||
|
||||
[Route(HttpVerbs.Get, "/plugins/endpoints")]
|
||||
public IReadOnlyCollection<PluginEndPoint> GetPluginEndPoints()
|
||||
{
|
||||
return _webServerService.PluginsModule.PluginEndPoints;
|
||||
}
|
||||
|
||||
[Route(HttpVerbs.Get, "/plugins/endpoints/{plugin}/{endPoint}")]
|
||||
public PluginEndPoint GetPluginEndPoint(Guid plugin, string endPoint)
|
||||
{
|
||||
PluginEndPoint? pluginEndPoint = _webServerService.PluginsModule.PluginEndPoints.FirstOrDefault(e => e.PluginFeature.Plugin.Guid == plugin && e.Name == endPoint);
|
||||
if (pluginEndPoint == null)
|
||||
throw HttpException.NotFound();
|
||||
|
||||
return pluginEndPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,8 +52,6 @@ namespace Artemis.Core.Services
|
||||
.HandleHttpException((context, exception) => HandleHttpExceptionJson(context, exception))
|
||||
.HandleUnhandledException(JsonExceptionHandlerCallback);
|
||||
|
||||
// Add built-in core controllers to the API module
|
||||
apiModule.RegisterController(() => _kernel.Get<PluginsController>());
|
||||
// Add registered controllers to the API module
|
||||
foreach (WebApiControllerRegistration registration in _controllers)
|
||||
apiModule.RegisterController(registration.ControllerType, (Func<WebApiController>) registration.UntypedFactory);
|
||||
@@ -177,7 +175,8 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
context.Response.ContentType = MimeType.Json;
|
||||
await using TextWriter writer = context.OpenResponseText();
|
||||
await writer.WriteAsync(JsonConvert.SerializeObject(data));
|
||||
string json = JsonConvert.SerializeObject(data, new JsonSerializerSettings {PreserveReferencesHandling = PreserveReferencesHandling.Objects});
|
||||
await writer.WriteAsync(json);
|
||||
}
|
||||
|
||||
private async Task HandleHttpExceptionJson(IHttpContext context, IHttpException httpException)
|
||||
|
||||
Reference in new issue
Block a user