mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Changed plugins to abstract classes
This commit is contained in:
1 parent
083119dae2
commit
bfc320c0ac
36 files changed
+657
-300
No files matched your search
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Color = System.Drawing.Color;
|
||||
@@ -47,7 +47,7 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
var modules = _pluginService.GetPluginsOfType<IModule>();
|
||||
var modules = _pluginService.GetPluginsOfType<Module>();
|
||||
|
||||
// Update all active modules
|
||||
foreach (var module in modules)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
@@ -15,13 +16,13 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// Add an expansion to the datamodel to be available for use after the next update
|
||||
/// </summary>
|
||||
/// <param name="dataModelExpansion"></param>
|
||||
void AddExpansion(IDataModelExpansion dataModelExpansion);
|
||||
void AddExpansion(DataModelExpansion dataModelExpansion);
|
||||
|
||||
/// <summary>
|
||||
/// Remove a previously added expansion so that it is no longer available and updated
|
||||
/// </summary>
|
||||
/// <param name="dataModelExpansion"></param>
|
||||
void RemoveExpansion(IDataModelExpansion dataModelExpansion);
|
||||
void RemoveExpansion(DataModelExpansion dataModelExpansion);
|
||||
|
||||
/// <summary>
|
||||
/// Generates a data model description for the main datamodel including all it's expansions
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
@@ -40,7 +40,7 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin you want to find the plugin info for</param>
|
||||
/// <returns>The plugins PluginInfo</returns>
|
||||
PluginInfo GetPluginInfo(IPlugin plugin);
|
||||
PluginInfo GetPluginInfo(Plugin plugin);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin info of all loaded plugins
|
||||
@@ -53,14 +53,14 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="layerTypeGuid">The GUID of the layer type to find</param>
|
||||
/// <returns>An instance of the layer type</returns>
|
||||
ILayerType GetLayerTypeByGuid(Guid layerTypeGuid);
|
||||
LayerType GetLayerTypeByGuid(Guid layerTypeGuid);
|
||||
|
||||
/// <summary>
|
||||
/// Finds all enabled <see cref="IPlugin" /> instances of type <see cref="T" />
|
||||
/// Finds all enabled <see cref="Plugin" /> instances of type <see cref="T" />
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Either <see cref="IPlugin" /> or a plugin type implementing <see cref="IPlugin" /></typeparam>
|
||||
/// <typeparam name="T">Either <see cref="Plugin" /> or a plugin type implementing <see cref="Plugin" /></typeparam>
|
||||
/// <returns>Returns a list of plug instances of type <see cref="T" /></returns>
|
||||
List<T> GetPluginsOfType<T>() where T : IPlugin;
|
||||
List<T> GetPluginsOfType<T>() where T : Plugin;
|
||||
|
||||
#region Events
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
|
||||
@@ -9,14 +10,14 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
public class MainDataModelService : IMainDataModelService
|
||||
{
|
||||
private readonly List<IDataModelExpansion> _dataModelExpansions;
|
||||
private readonly List<DataModelExpansion> _dataModelExpansions;
|
||||
|
||||
public MainDataModelService()
|
||||
{
|
||||
_dataModelExpansions = new List<IDataModelExpansion>();
|
||||
_dataModelExpansions = new List<DataModelExpansion>();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<IDataModelExpansion> DataModelExpansions
|
||||
public ReadOnlyCollection<DataModelExpansion> DataModelExpansions
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -37,7 +38,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public void AddExpansion(IDataModelExpansion dataModelExpansion)
|
||||
public void AddExpansion(DataModelExpansion dataModelExpansion)
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
@@ -46,7 +47,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveExpansion(IDataModelExpansion dataModelExpansion)
|
||||
public void RemoveExpansion(DataModelExpansion dataModelExpansion)
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
|
||||
@@ -5,13 +5,14 @@ using System.Linq;
|
||||
using AppDomainToolkit;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Exceptions;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Newtonsoft.Json;
|
||||
using Ninject;
|
||||
using Ninject.Extensions.ChildKernel;
|
||||
using Ninject.Parameters;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
@@ -88,10 +89,7 @@ namespace Artemis.Core.Services
|
||||
lock (_plugins)
|
||||
{
|
||||
// Unload all plugins
|
||||
while (_plugins.Count > 0)
|
||||
{
|
||||
UnloadPlugin(_plugins[0]);
|
||||
}
|
||||
while (_plugins.Count > 0) UnloadPlugin(_plugins[0]);
|
||||
|
||||
// Dispose the child kernel and therefore any leftover plugins instantiated with it
|
||||
if (_childKernel != null)
|
||||
@@ -119,7 +117,7 @@ namespace Artemis.Core.Services
|
||||
if (!File.Exists(mainFile))
|
||||
throw new ArtemisPluginException(pluginInfo, "Couldn't find the plugins main entry at " + mainFile);
|
||||
|
||||
// Load the plugin, all types implementing IPlugin and register them with DI
|
||||
// Load the plugin, all types implementing Plugin and register them with DI
|
||||
var setupInfo = new AppDomainSetup
|
||||
{
|
||||
ApplicationName = pluginInfo.Guid.ToString(),
|
||||
@@ -137,18 +135,19 @@ namespace Artemis.Core.Services
|
||||
throw new ArtemisPluginException(pluginInfo, "Failed to load the plugins assembly", e);
|
||||
}
|
||||
|
||||
// Get the IPlugin implementation from the main assembly and if there is only one, instantiate it
|
||||
// Get the Plugin implementation from the main assembly and if there is only one, instantiate it
|
||||
var mainAssembly = pluginInfo.Context.Domain.GetAssemblies().First(a => a.Location == mainFile);
|
||||
var pluginTypes = mainAssembly.GetTypes().Where(t => typeof(IPlugin).IsAssignableFrom(t)).ToList();
|
||||
var pluginTypes = mainAssembly.GetTypes().Where(t => typeof(Plugin).IsAssignableFrom(t)).ToList();
|
||||
if (pluginTypes.Count > 1)
|
||||
throw new ArtemisPluginException(pluginInfo, $"Plugin contains {pluginTypes.Count} implementations of IPlugin, only 1 allowed");
|
||||
throw new ArtemisPluginException(pluginInfo, $"Plugin contains {pluginTypes.Count} implementations of Plugin, only 1 allowed");
|
||||
if (pluginTypes.Count == 0)
|
||||
throw new ArtemisPluginException(pluginInfo, "Plugin contains no implementation of IPlugin");
|
||||
throw new ArtemisPluginException(pluginInfo, "Plugin contains no implementation of Plugin");
|
||||
|
||||
var pluginType = pluginTypes.Single();
|
||||
try
|
||||
{
|
||||
pluginInfo.Instance = (IPlugin) _childKernel.Get(pluginType);
|
||||
var constructorArguments = new ConstructorArgument("pluginInfo", pluginInfo);
|
||||
pluginInfo.Instance = (Plugin) _childKernel.Get(pluginType, constraint: null, constructorArguments);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -179,7 +178,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
_childKernel.Unbind(pluginInfo.Instance.GetType());
|
||||
|
||||
|
||||
pluginInfo.Instance.Dispose();
|
||||
pluginInfo.Context.Dispose();
|
||||
_plugins.Remove(pluginInfo);
|
||||
@@ -189,7 +188,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public PluginInfo GetPluginInfo(IPlugin plugin)
|
||||
public PluginInfo GetPluginInfo(Plugin plugin)
|
||||
{
|
||||
lock (_plugins)
|
||||
{
|
||||
@@ -204,20 +203,20 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ILayerType GetLayerTypeByGuid(Guid layerTypeGuid)
|
||||
public LayerType GetLayerTypeByGuid(Guid layerTypeGuid)
|
||||
{
|
||||
var pluginInfo = _plugins.FirstOrDefault(p => p.Guid == layerTypeGuid);
|
||||
if (pluginInfo == null)
|
||||
return null;
|
||||
|
||||
if (!(pluginInfo.Instance is ILayerType layerType))
|
||||
throw new ArtemisPluginException(pluginInfo, "Plugin is expected to implement exactly one ILayerType");
|
||||
if (!(pluginInfo.Instance is LayerType layerType))
|
||||
throw new ArtemisPluginException(pluginInfo, "Plugin is expected to implement exactly one LayerType");
|
||||
|
||||
return layerType;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<T> GetPluginsOfType<T>() where T : IPlugin
|
||||
public List<T> GetPluginsOfType<T>() where T : Plugin
|
||||
{
|
||||
lock (_plugins)
|
||||
{
|
||||
|
||||
@@ -68,9 +68,7 @@ namespace Artemis.Core.Services
|
||||
OnDeviceLoaded(new DeviceEventArgs(surfaceDevice));
|
||||
}
|
||||
else
|
||||
{
|
||||
OnDeviceReloaded(new DeviceEventArgs(surfaceDevice));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Repositories;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
public class SettingsService : ISettingsService
|
||||
{
|
||||
private SettingRepository _settingRepository;
|
||||
|
||||
public SettingsService()
|
||||
{
|
||||
_settingRepository = new SettingRepository();
|
||||
}
|
||||
|
||||
public PluginSettings GetPluginSettings(PluginInfo pluginInfo)
|
||||
{
|
||||
return new PluginSettings(pluginInfo, _settingRepository);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISettingsService : IArtemisService
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user