Fixed plugin binding and reworked some interfaces to abstract classes

This commit is contained in:
SpoinkyNL committed 2019-04-11 19:52:28 +02:00
1 parent 571a3fe168
commit 3689db9325
17 files changed
+88 -82

No files matched your search

+1 -2
View File
@@ -102,6 +102,7 @@
<Compile Include="Events\DeviceEventArgs.cs" />
<Compile Include="Exceptions\ArtemisCoreException.cs" />
<Compile Include="Models\DataModelDescription.cs" />
<Compile Include="Plugins\Abstract\ModuleDataModel.cs" />
<Compile Include="Plugins\Abstract\ModuleViewModel.cs" />
<Compile Include="Plugins\Abstract\ProfileModule.cs" />
<Compile Include="Plugins\Exceptions\ArtemisPluginException.cs" />
@@ -110,8 +111,6 @@
<Compile Include="Plugins\Interfaces\ILayerType.cs" />
<Compile Include="Plugins\Interfaces\ILayerTypeConfiguration.cs" />
<Compile Include="Plugins\Interfaces\IModule.cs" />
<Compile Include="Plugins\Interfaces\IModuleDataModel.cs" />
<Compile Include="Plugins\Interfaces\IModuleViewModel.cs" />
<Compile Include="Plugins\Interfaces\IPlugin.cs" />
<Compile Include="Plugins\Models\PluginInfo.cs" />
<Compile Include="ProfileElements\Folder.cs" />
@@ -0,0 +1,15 @@
using Artemis.Core.Plugins.Interfaces;
using Stylet;
namespace Artemis.Core.Plugins.Abstract
{
public abstract class ModuleDataModel
{
protected ModuleDataModel(IModule module)
{
Module = module;
}
public IModule Module { get; }
}
}
@@ -4,8 +4,13 @@ using Stylet;
namespace Artemis.Core.Plugins.Abstract
{
public abstract class ModuleViewModel : Screen, IModuleViewModel
public abstract class ModuleViewModel : Screen
{
public PluginInfo PluginInfo { get; set; }
protected ModuleViewModel(IModule module)
{
Module = module;
}
public IModule Module { get; }
}
}
@@ -11,6 +11,9 @@ namespace Artemis.Core.Plugins.Abstract
{
public Profile ActiveProfile { get; private set; }
/// <inheritdoc />
public abstract string DisplayName { get; }
/// <inheritdoc />
public abstract bool ExpandsMainDataModel { get; }
@@ -11,7 +11,12 @@ namespace Artemis.Core.Plugins.Interfaces
public interface IModule : IPlugin
{
/// <summary>
/// Wether or not this module expands upon the main data model. If set to true any data in main data model can be
/// The modules display name that's shown in the menu
/// </summary>
string DisplayName { get; }
/// <summary>
/// Whether or not this module expands upon the main data model. If set to true any data in main data model can be
/// accessed by profiles in this module
/// </summary>
bool ExpandsMainDataModel { get; }
@@ -1,6 +0,0 @@
namespace Artemis.Core.Plugins.Interfaces
{
public interface IModuleDataModel
{
}
}
@@ -1,14 +0,0 @@
using Artemis.Core.Plugins.Models;
using Stylet;
namespace Artemis.Core.Plugins.Interfaces
{
/// <inheritdoc />
/// <summary>
/// Allows you to create a view model for a module
/// </summary>
public interface IModuleViewModel : IScreen
{
PluginInfo PluginInfo { get; set; }
}
}
@@ -7,6 +7,11 @@ namespace Artemis.Core.Plugins.Models
{
public class PluginInfo
{
public PluginInfo()
{
Instances = new List<IPlugin>();
}
/// <summary>
/// The plugins GUID
/// </summary>
+19 -3
View File
@@ -68,12 +68,28 @@ namespace Artemis.Core.Services
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
var assembly = Assembly.LoadFile(mainFile);
Assembly assembly;
try
{
assembly = Assembly.LoadFile(mainFile);
}
catch (Exception e)
{
throw new ArtemisPluginException(pluginInfo, "Failed to load the plugins assembly", e);
}
var pluginTypes = assembly.GetTypes().Where(t => typeof(IPlugin).IsAssignableFrom(t)).ToArray();
foreach (var pluginType in pluginTypes)
{
_childKernel.Bind(pluginType).To<IPlugin>().InSingletonScope();
pluginInfo.Instances.Add((IPlugin) _childKernel.Get(pluginType));
_childKernel.Bind<IPlugin>().To(pluginType).InSingletonScope();
try
{
pluginInfo.Instances.Add((IPlugin) _childKernel.Get(pluginType));
}
catch (Exception e)
{
throw new ArtemisPluginException(pluginInfo, "Failed to instantiate the plugin", e);
}
}
_plugins.Add(pluginInfo);