mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Changed plugins to abstract classes
This commit is contained in:
parent
083119dae2
commit
bfc320c0ac
@ -109,13 +109,14 @@
|
||||
<Compile Include="Plugins\Abstract\ModuleViewModel.cs" />
|
||||
<Compile Include="Plugins\Abstract\ProfileModule.cs" />
|
||||
<Compile Include="Plugins\Exceptions\ArtemisPluginException.cs" />
|
||||
<Compile Include="Plugins\Interfaces\IDataModelExpansion.cs" />
|
||||
<Compile Include="Plugins\Interfaces\IDevice.cs" />
|
||||
<Compile Include="Plugins\Interfaces\ILayerType.cs" />
|
||||
<Compile Include="Plugins\Abstract\DataModelExpansion.cs" />
|
||||
<Compile Include="Plugins\Abstract\Device.cs" />
|
||||
<Compile Include="Plugins\Abstract\LayerType.cs" />
|
||||
<Compile Include="Plugins\Interfaces\ILayerTypeConfiguration.cs" />
|
||||
<Compile Include="Plugins\Interfaces\IModule.cs" />
|
||||
<Compile Include="Plugins\Interfaces\IPlugin.cs" />
|
||||
<Compile Include="Plugins\Abstract\Module.cs" />
|
||||
<Compile Include="Plugins\Abstract\Plugin.cs" />
|
||||
<Compile Include="Plugins\Models\PluginInfo.cs" />
|
||||
<Compile Include="Plugins\Models\PluginSettings.cs" />
|
||||
<Compile Include="ProfileElements\Folder.cs" />
|
||||
<Compile Include="ProfileElements\Interfaces\IProfileElement.cs" />
|
||||
<Compile Include="ProfileElements\Layer.cs" />
|
||||
@ -134,6 +135,7 @@
|
||||
<Compile Include="Services\Interfaces\IPluginService.cs" />
|
||||
<Compile Include="Events\PluginEventArgs.cs" />
|
||||
<Compile Include="Services\PluginService.cs" />
|
||||
<Compile Include="Services\SettingsService.cs" />
|
||||
<Compile Include="Services\StorageService.cs" />
|
||||
<Compile Include="UtilitiesRemoveMe.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
17
src/Artemis.Core/Plugins/Abstract/DataModelExpansion.cs
Normal file
17
src/Artemis.Core/Plugins/Abstract/DataModelExpansion.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Artemis.Core.Plugins.Models;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to expand the application-wide datamodel
|
||||
/// </summary>
|
||||
public abstract class DataModelExpansion : Plugin
|
||||
{
|
||||
protected DataModelExpansion(PluginInfo pluginInfo) : base(pluginInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public abstract void Update(double deltaTime);
|
||||
}
|
||||
}
|
||||
15
src/Artemis.Core/Plugins/Abstract/Device.cs
Normal file
15
src/Artemis.Core/Plugins/Abstract/Device.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Artemis.Core.Plugins.Models;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to implement your own RGB device
|
||||
/// </summary>
|
||||
public abstract class Device : Plugin
|
||||
{
|
||||
protected Device(PluginInfo pluginInfo) : base(pluginInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,24 +1,29 @@
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.ProfileElements;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Plugins.Interfaces
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to create your own layer type
|
||||
/// </summary>
|
||||
public interface ILayerType : IPlugin
|
||||
public abstract class LayerType : Plugin
|
||||
{
|
||||
protected LayerType(PluginInfo pluginInfo) : base(pluginInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the layer type
|
||||
/// </summary>
|
||||
/// <param name="layer"></param>
|
||||
void Update(Layer layer);
|
||||
public abstract void Update(Layer layer);
|
||||
|
||||
/// <summary>
|
||||
/// Renders the layer type
|
||||
/// </summary>
|
||||
void Render(Layer device, RGBSurface surface, Graphics graphics);
|
||||
public abstract void Render(Layer device, RGBSurface surface, Graphics graphics);
|
||||
}
|
||||
}
|
||||
@ -1,31 +1,36 @@
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Core.Plugins.Interfaces
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to add support for new games/applications
|
||||
/// </summary>
|
||||
public interface IModule : IPlugin
|
||||
public abstract class Module : Plugin
|
||||
{
|
||||
protected Module(PluginInfo pluginInfo) : base(pluginInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The modules display name that's shown in the menu
|
||||
/// </summary>
|
||||
string DisplayName { get; }
|
||||
public string DisplayName { get; protected set; }
|
||||
|
||||
/// <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; }
|
||||
public bool ExpandsMainDataModel { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame when the module must update
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Time since the last update</param>
|
||||
void Update(double deltaTime);
|
||||
public abstract void Update(double deltaTime);
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame when the module must render
|
||||
@ -33,12 +38,12 @@ namespace Artemis.Core.Plugins.Interfaces
|
||||
/// <param name="deltaTime">Time since the last render</param>
|
||||
/// <param name="surface">The RGB Surface to render to</param>
|
||||
/// <param name="graphics"></param>
|
||||
void Render(double deltaTime, RGBSurface surface, Graphics graphics);
|
||||
public abstract void Render(double deltaTime, RGBSurface surface, Graphics graphics);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the module's main view is being shown
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IScreen GetMainViewModel();
|
||||
public abstract IScreen GetMainViewModel();
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,12 @@
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
public abstract class ModuleDataModel
|
||||
{
|
||||
protected ModuleDataModel(IModule module)
|
||||
protected ModuleDataModel(Module module)
|
||||
{
|
||||
Module = module;
|
||||
}
|
||||
|
||||
public IModule Module { get; }
|
||||
public Module Module { get; }
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,14 @@
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Stylet;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
public abstract class ModuleViewModel : Screen
|
||||
{
|
||||
protected ModuleViewModel(IModule module)
|
||||
protected ModuleViewModel(Module module)
|
||||
{
|
||||
Module = module;
|
||||
}
|
||||
|
||||
public IModule Module { get; }
|
||||
public Module Module { get; }
|
||||
}
|
||||
}
|
||||
35
src/Artemis.Core/Plugins/Abstract/Plugin.cs
Normal file
35
src/Artemis.Core/Plugins/Abstract/Plugin.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// This is the base plugin type, use the other interfaces such as Module to create plugins
|
||||
/// </summary>
|
||||
public abstract class Plugin : IDisposable
|
||||
{
|
||||
internal Plugin(PluginInfo pluginInfo)
|
||||
{
|
||||
PluginInfo = pluginInfo;
|
||||
}
|
||||
|
||||
public PluginInfo PluginInfo { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is activated
|
||||
/// </summary>
|
||||
public abstract void EnablePlugin();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is deactivated
|
||||
/// </summary>
|
||||
public abstract void DisablePlugin();
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Called when the plugin is unloaded, clean up any unmanaged resources here
|
||||
/// </summary>
|
||||
public abstract void Dispose();
|
||||
}
|
||||
}
|
||||
@ -1,25 +1,21 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.ProfileElements;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
public abstract class ProfileModule : IModule
|
||||
public abstract class ProfileModule : Module
|
||||
{
|
||||
protected ProfileModule(PluginInfo pluginInfo) : base(pluginInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public Profile ActiveProfile { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract string DisplayName { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract bool ExpandsMainDataModel { get; }
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(double deltaTime)
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
@ -29,7 +25,7 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Render(double deltaTime, RGBSurface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, RGBSurface surface, Graphics graphics)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
@ -38,18 +34,6 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract IScreen GetMainViewModel();
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract void EnablePlugin();
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract void DisablePlugin();
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract void Dispose();
|
||||
|
||||
public void ChangeActiveProfile(Profile profile)
|
||||
{
|
||||
lock (this)
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
namespace Artemis.Core.Plugins.Interfaces
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to expand the application-wide datamodel
|
||||
/// </summary>
|
||||
public interface IDataModelExpansion : IPlugin
|
||||
{
|
||||
void Update(double deltaTime);
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
namespace Artemis.Core.Plugins.Interfaces
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to implement your own RGB device
|
||||
/// </summary>
|
||||
public interface IDevice : IPlugin
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Plugins.Interfaces
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// This is the base plugin type, use the other interfaces such as IModule to create plugins
|
||||
/// </summary>
|
||||
public interface IPlugin : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the plugin is activated
|
||||
/// </summary>
|
||||
void EnablePlugin();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is deactivated
|
||||
/// </summary>
|
||||
void DisablePlugin();
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using AppDomainToolkit;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core.Plugins.Models
|
||||
@ -15,40 +15,40 @@ namespace Artemis.Core.Plugins.Models
|
||||
/// <summary>
|
||||
/// The plugins GUID
|
||||
/// </summary>
|
||||
public Guid Guid { get; set; }
|
||||
public Guid Guid { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the plugin
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
public string Name { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The version of the plugin
|
||||
/// </summary>
|
||||
public string Version { get; set; }
|
||||
public string Version { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The main entry DLL, should contain a class implementing IPlugin
|
||||
/// The main entry DLL, should contain a class implementing Plugin
|
||||
/// </summary>
|
||||
public string Main { get; set; }
|
||||
public string Main { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The plugins root directory
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public DirectoryInfo Directory { get; set; }
|
||||
public DirectoryInfo Directory { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// A reference to the type implementing IPlugin, available after successful load
|
||||
/// A reference to the type implementing Plugin, available after successful load
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public IPlugin Instance { get; set; }
|
||||
public Plugin Instance { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the user enabled the plugin or not
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool Enabled { get; set; }
|
||||
public bool Enabled { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The AppDomain context of this plugin
|
||||
|
||||
26
src/Artemis.Core/Plugins/Models/PluginSettings.cs
Normal file
26
src/Artemis.Core/Plugins/Models/PluginSettings.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Artemis.Storage.Repositories;
|
||||
|
||||
namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
public class PluginSettings
|
||||
{
|
||||
private readonly PluginInfo _pluginInfo;
|
||||
private readonly SettingRepository _settingRepository;
|
||||
|
||||
internal PluginSettings(PluginInfo pluginInfo, SettingRepository settingRepository)
|
||||
{
|
||||
_pluginInfo = pluginInfo;
|
||||
_settingRepository = settingRepository;
|
||||
}
|
||||
|
||||
public bool HasSettingChanged(string settingName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool HasAnySettingChanged()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.ProfileElements.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
@ -18,7 +19,7 @@ namespace Artemis.Core.ProfileElements
|
||||
}
|
||||
|
||||
public Profile Profile { get; }
|
||||
public ILayerType LayerType { get; private set; }
|
||||
public LayerType LayerType { get; private set; }
|
||||
public ILayerTypeConfiguration LayerTypeConfiguration { get; set; }
|
||||
public List<IProfileElement> Children { get; set; }
|
||||
public int Order { get; set; }
|
||||
@ -58,13 +59,15 @@ namespace Artemis.Core.ProfileElements
|
||||
return layer;
|
||||
}
|
||||
|
||||
public void UpdateLayerType(ILayerType layerType)
|
||||
public void UpdateLayerType(LayerType layerType)
|
||||
{
|
||||
if (LayerType != null)
|
||||
{
|
||||
lock (LayerType)
|
||||
{
|
||||
LayerType.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
LayerType = layerType;
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
25
src/Artemis.Core/Services/SettingsService.cs
Normal file
25
src/Artemis.Core/Services/SettingsService.cs
Normal file
@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,28 +1,28 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.ProfileElements;
|
||||
using QRCoder;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Plugins.LayerTypes.Brush
|
||||
{
|
||||
public class BrushLayerType : ILayerType
|
||||
public class BrushLayerType : LayerType
|
||||
{
|
||||
public void Dispose()
|
||||
public BrushLayerType(PluginInfo pluginInfo) : base(pluginInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public void EnablePlugin()
|
||||
public override void EnablePlugin()
|
||||
{
|
||||
var qrGenerator = new QRCodeGenerator();
|
||||
}
|
||||
|
||||
public void DisablePlugin()
|
||||
public override void DisablePlugin()
|
||||
{
|
||||
}
|
||||
|
||||
public void Update(Layer layer)
|
||||
public override void Update(Layer layer)
|
||||
{
|
||||
var config = layer.LayerTypeConfiguration as BrushConfiguration;
|
||||
if (config == null)
|
||||
@ -31,7 +31,11 @@ namespace Artemis.Plugins.LayerTypes.Brush
|
||||
// Update the brush
|
||||
}
|
||||
|
||||
public void Render(Layer device, RGBSurface surface, Graphics graphics)
|
||||
public override void Render(Layer device, RGBSurface surface, Graphics graphics)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ namespace Artemis.Plugins.Modules.General
|
||||
{
|
||||
public class GeneralDataModel : ModuleDataModel
|
||||
{
|
||||
public GeneralDataModel(IModule module) : base(module)
|
||||
public GeneralDataModel(Module module) : base(module)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Plugins.Modules.General.ViewModels;
|
||||
using QRCoder;
|
||||
@ -13,26 +13,33 @@ using Rectangle = System.Drawing.Rectangle;
|
||||
|
||||
namespace Artemis.Plugins.Modules.General
|
||||
{
|
||||
public class GeneralModule : IModule
|
||||
public class GeneralModule : Module
|
||||
{
|
||||
private readonly RGBSurface _surface;
|
||||
private Dictionary<Led, Color> _colors;
|
||||
|
||||
public GeneralModule(IRgbService rgbService)
|
||||
public GeneralModule(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo)
|
||||
{
|
||||
var rgbService1 = rgbService;
|
||||
_surface = rgbService1.Surface;
|
||||
_colors = new Dictionary<Led, Color>();
|
||||
DisplayName = "General";
|
||||
ExpandsMainDataModel = true;
|
||||
|
||||
rgbService1.FinishedLoadedDevices += (sender, args) => PopulateColors();
|
||||
_surface = rgbService.Surface;
|
||||
_colors = new Dictionary<Led, Color>();
|
||||
|
||||
rgbService.FinishedLoadedDevices += (sender, args) => PopulateColors();
|
||||
}
|
||||
|
||||
public string DisplayName => "General";
|
||||
public override void EnablePlugin()
|
||||
{
|
||||
var qrGenerator = new QRCodeGenerator();
|
||||
PopulateColors();
|
||||
}
|
||||
|
||||
// True since the main data model is all this module shows
|
||||
public bool ExpandsMainDataModel => true;
|
||||
public override void DisablePlugin()
|
||||
{
|
||||
}
|
||||
|
||||
public void Update(double deltaTime)
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
if (_colors == null)
|
||||
return;
|
||||
@ -41,7 +48,7 @@ namespace Artemis.Plugins.Modules.General
|
||||
UpdateLedColor(surfaceLed, deltaTime);
|
||||
}
|
||||
|
||||
public void Render(double deltaTime, RGBSurface surface, Graphics graphics)
|
||||
public override void Render(double deltaTime, RGBSurface surface, Graphics graphics)
|
||||
{
|
||||
foreach (var surfaceLed in _surface.Leds)
|
||||
{
|
||||
@ -55,26 +62,16 @@ namespace Artemis.Plugins.Modules.General
|
||||
}
|
||||
}
|
||||
|
||||
public IScreen GetMainViewModel()
|
||||
public override IScreen GetMainViewModel()
|
||||
{
|
||||
return new GeneralViewModel(this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public override void Dispose()
|
||||
{
|
||||
_colors = null;
|
||||
}
|
||||
|
||||
public void EnablePlugin()
|
||||
{
|
||||
var qrGenerator = new QRCodeGenerator();
|
||||
PopulateColors();
|
||||
}
|
||||
|
||||
public void DisablePlugin()
|
||||
{
|
||||
}
|
||||
|
||||
private void UpdateLedColor(Led led, double deltaTime)
|
||||
{
|
||||
if (_colors.ContainsKey(led))
|
||||
|
||||
@ -5,7 +5,7 @@ namespace Artemis.Plugins.Modules.General.ViewModels
|
||||
{
|
||||
public class GeneralViewModel : ModuleViewModel
|
||||
{
|
||||
public GeneralViewModel(IModule module) : base(module)
|
||||
public GeneralViewModel(Module module) : base(module)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Artemis.Storage.Entities
|
||||
{
|
||||
@ -7,6 +8,8 @@ namespace Artemis.Storage.Entities
|
||||
[Key]
|
||||
public string Name { get; set; }
|
||||
|
||||
public Guid PluginGuid { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
||||
@ -11,10 +11,10 @@ namespace Artemis.Storage.Migrations
|
||||
"Folders",
|
||||
table => new
|
||||
{
|
||||
Guid = table.Column<string>(nullable: false),
|
||||
Guid = table.Column<string>(),
|
||||
FolderEntityGuid = table.Column<string>(nullable: true),
|
||||
Name = table.Column<string>(nullable: true),
|
||||
Order = table.Column<int>(nullable: false)
|
||||
Order = table.Column<int>()
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -31,7 +31,7 @@ namespace Artemis.Storage.Migrations
|
||||
"Settings",
|
||||
table => new
|
||||
{
|
||||
Name = table.Column<string>(nullable: false),
|
||||
Name = table.Column<string>(),
|
||||
Value = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table => { table.PrimaryKey("PK_Settings", x => x.Name); });
|
||||
@ -40,10 +40,10 @@ namespace Artemis.Storage.Migrations
|
||||
"Layers",
|
||||
table => new
|
||||
{
|
||||
Guid = table.Column<string>(nullable: false),
|
||||
Guid = table.Column<string>(),
|
||||
FolderEntityGuid = table.Column<string>(nullable: true),
|
||||
Name = table.Column<string>(nullable: true),
|
||||
Order = table.Column<int>(nullable: false)
|
||||
Order = table.Column<int>()
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -60,11 +60,11 @@ namespace Artemis.Storage.Migrations
|
||||
"Profiles",
|
||||
table => new
|
||||
{
|
||||
Guid = table.Column<string>(nullable: false),
|
||||
Guid = table.Column<string>(),
|
||||
Name = table.Column<string>(nullable: true),
|
||||
PluginGuid = table.Column<Guid>(nullable: false),
|
||||
PluginGuid = table.Column<Guid>(),
|
||||
RootFolderGuid = table.Column<string>(nullable: true),
|
||||
RootFolderId = table.Column<int>(nullable: false)
|
||||
RootFolderId = table.Column<int>()
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -81,7 +81,7 @@ namespace Artemis.Storage.Migrations
|
||||
"LayerSettings",
|
||||
table => new
|
||||
{
|
||||
Guid = table.Column<string>(nullable: false),
|
||||
Guid = table.Column<string>(),
|
||||
LayerEntityGuid = table.Column<string>(nullable: true),
|
||||
Name = table.Column<string>(nullable: true),
|
||||
Value = table.Column<string>(nullable: true)
|
||||
@ -101,9 +101,9 @@ namespace Artemis.Storage.Migrations
|
||||
"Leds",
|
||||
table => new
|
||||
{
|
||||
Guid = table.Column<string>(nullable: false),
|
||||
Guid = table.Column<string>(),
|
||||
LayerGuid = table.Column<string>(nullable: true),
|
||||
LayerId = table.Column<int>(nullable: false),
|
||||
LayerId = table.Column<int>(),
|
||||
LedName = table.Column<string>(nullable: true),
|
||||
LimitedToDevice = table.Column<string>(nullable: true)
|
||||
},
|
||||
@ -122,9 +122,9 @@ namespace Artemis.Storage.Migrations
|
||||
"Keypoints",
|
||||
table => new
|
||||
{
|
||||
Guid = table.Column<string>(nullable: false),
|
||||
Guid = table.Column<string>(),
|
||||
LayerSettingEntityGuid = table.Column<string>(nullable: true),
|
||||
Time = table.Column<int>(nullable: false),
|
||||
Time = table.Column<int>(),
|
||||
Value = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
|
||||
193
src/Artemis.Storage/Migrations/20190415185618_SettingsPluginGuid.Designer.cs
generated
Normal file
193
src/Artemis.Storage/Migrations/20190415185618_SettingsPluginGuid.Designer.cs
generated
Normal file
@ -0,0 +1,193 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Artemis.Storage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
[DbContext(typeof(StorageContext))]
|
||||
[Migration("20190415185618_SettingsPluginGuid")]
|
||||
partial class SettingsPluginGuid
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("FolderEntityGuid");
|
||||
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<int>("Order");
|
||||
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("FolderEntityGuid");
|
||||
|
||||
b.ToTable("Folders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("LayerSettingEntityGuid");
|
||||
|
||||
b.Property<int>("Time");
|
||||
|
||||
b.Property<string>("Value");
|
||||
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("LayerSettingEntityGuid");
|
||||
|
||||
b.ToTable("Keypoints");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("FolderEntityGuid");
|
||||
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<int>("Order");
|
||||
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("FolderEntityGuid");
|
||||
|
||||
b.ToTable("Layers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("LayerEntityGuid");
|
||||
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<string>("Value");
|
||||
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("LayerEntityGuid");
|
||||
|
||||
b.ToTable("LayerSettings");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("LayerGuid");
|
||||
|
||||
b.Property<int>("LayerId");
|
||||
|
||||
b.Property<string>("LedName");
|
||||
|
||||
b.Property<string>("LimitedToDevice");
|
||||
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("LayerGuid");
|
||||
|
||||
b.ToTable("Leds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<Guid>("PluginGuid");
|
||||
|
||||
b.Property<string>("RootFolderGuid");
|
||||
|
||||
b.Property<int>("RootFolderId");
|
||||
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("RootFolderGuid");
|
||||
|
||||
b.ToTable("Profiles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.SettingEntity", b =>
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<Guid>("PluginGuid");
|
||||
|
||||
b.Property<string>("Value");
|
||||
|
||||
b.HasKey("Name");
|
||||
|
||||
b.HasIndex("Name", "PluginGuid");
|
||||
|
||||
b.ToTable("Settings");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.FolderEntity")
|
||||
.WithMany("Folders")
|
||||
.HasForeignKey("FolderEntityGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.LayerSettingEntity")
|
||||
.WithMany("Keypoints")
|
||||
.HasForeignKey("LayerSettingEntityGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.FolderEntity")
|
||||
.WithMany("Layers")
|
||||
.HasForeignKey("FolderEntityGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.LayerEntity")
|
||||
.WithMany("Settings")
|
||||
.HasForeignKey("LayerEntityGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.LayerEntity", "Layer")
|
||||
.WithMany("Leds")
|
||||
.HasForeignKey("LayerGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.FolderEntity", "RootFolder")
|
||||
.WithMany()
|
||||
.HasForeignKey("RootFolderGuid");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public partial class SettingsPluginGuid : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "PluginGuid",
|
||||
table: "Settings",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Settings_Name_PluginGuid",
|
||||
table: "Settings",
|
||||
columns: new[] { "Name", "PluginGuid" });
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Settings_Name_PluginGuid",
|
||||
table: "Settings");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PluginGuid",
|
||||
table: "Settings");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,186 +1,191 @@
|
||||
// <auto-generated />
|
||||
|
||||
using System;
|
||||
using Artemis.Storage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
[DbContext(typeof(StorageContext))]
|
||||
internal class StorageContextModelSnapshot : ModelSnapshot
|
||||
partial class StorageContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "2.0.2-rtm-10011");
|
||||
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("FolderEntityGuid");
|
||||
b.Property<string>("FolderEntityGuid");
|
||||
|
||||
b.Property<string>("Name");
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<int>("Order");
|
||||
b.Property<int>("Order");
|
||||
|
||||
b.HasKey("Guid");
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("FolderEntityGuid");
|
||||
b.HasIndex("FolderEntityGuid");
|
||||
|
||||
b.ToTable("Folders");
|
||||
});
|
||||
b.ToTable("Folders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("LayerSettingEntityGuid");
|
||||
b.Property<string>("LayerSettingEntityGuid");
|
||||
|
||||
b.Property<int>("Time");
|
||||
b.Property<int>("Time");
|
||||
|
||||
b.Property<string>("Value");
|
||||
b.Property<string>("Value");
|
||||
|
||||
b.HasKey("Guid");
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("LayerSettingEntityGuid");
|
||||
b.HasIndex("LayerSettingEntityGuid");
|
||||
|
||||
b.ToTable("Keypoints");
|
||||
});
|
||||
b.ToTable("Keypoints");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("FolderEntityGuid");
|
||||
b.Property<string>("FolderEntityGuid");
|
||||
|
||||
b.Property<string>("Name");
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<int>("Order");
|
||||
b.Property<int>("Order");
|
||||
|
||||
b.HasKey("Guid");
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("FolderEntityGuid");
|
||||
b.HasIndex("FolderEntityGuid");
|
||||
|
||||
b.ToTable("Layers");
|
||||
});
|
||||
b.ToTable("Layers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("LayerEntityGuid");
|
||||
b.Property<string>("LayerEntityGuid");
|
||||
|
||||
b.Property<string>("Name");
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<string>("Value");
|
||||
b.Property<string>("Value");
|
||||
|
||||
b.HasKey("Guid");
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("LayerEntityGuid");
|
||||
b.HasIndex("LayerEntityGuid");
|
||||
|
||||
b.ToTable("LayerSettings");
|
||||
});
|
||||
b.ToTable("LayerSettings");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("LayerGuid");
|
||||
b.Property<string>("LayerGuid");
|
||||
|
||||
b.Property<int>("LayerId");
|
||||
b.Property<int>("LayerId");
|
||||
|
||||
b.Property<string>("LedName");
|
||||
b.Property<string>("LedName");
|
||||
|
||||
b.Property<string>("LimitedToDevice");
|
||||
b.Property<string>("LimitedToDevice");
|
||||
|
||||
b.HasKey("Guid");
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("LayerGuid");
|
||||
b.HasIndex("LayerGuid");
|
||||
|
||||
b.ToTable("Leds");
|
||||
});
|
||||
b.ToTable("Leds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b =>
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
{
|
||||
b.Property<string>("Guid")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Name");
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.Property<Guid>("PluginGuid");
|
||||
b.Property<Guid>("PluginGuid");
|
||||
|
||||
b.Property<string>("RootFolderGuid");
|
||||
b.Property<string>("RootFolderGuid");
|
||||
|
||||
b.Property<int>("RootFolderId");
|
||||
b.Property<int>("RootFolderId");
|
||||
|
||||
b.HasKey("Guid");
|
||||
b.HasKey("Guid");
|
||||
|
||||
b.HasIndex("RootFolderGuid");
|
||||
b.HasIndex("RootFolderGuid");
|
||||
|
||||
b.ToTable("Profiles");
|
||||
});
|
||||
b.ToTable("Profiles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.SettingEntity", b =>
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.ValueGeneratedOnAdd();
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Value");
|
||||
b.Property<Guid>("PluginGuid");
|
||||
|
||||
b.HasKey("Name");
|
||||
b.Property<string>("Value");
|
||||
|
||||
b.ToTable("Settings");
|
||||
});
|
||||
b.HasKey("Name");
|
||||
|
||||
b.HasIndex("Name", "PluginGuid");
|
||||
|
||||
b.ToTable("Settings");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.FolderEntity")
|
||||
.WithMany("Folders")
|
||||
.HasForeignKey("FolderEntityGuid");
|
||||
});
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.FolderEntity")
|
||||
.WithMany("Folders")
|
||||
.HasForeignKey("FolderEntityGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.LayerSettingEntity")
|
||||
.WithMany("Keypoints")
|
||||
.HasForeignKey("LayerSettingEntityGuid");
|
||||
});
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.LayerSettingEntity")
|
||||
.WithMany("Keypoints")
|
||||
.HasForeignKey("LayerSettingEntityGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.FolderEntity")
|
||||
.WithMany("Layers")
|
||||
.HasForeignKey("FolderEntityGuid");
|
||||
});
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.FolderEntity")
|
||||
.WithMany("Layers")
|
||||
.HasForeignKey("FolderEntityGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.LayerEntity")
|
||||
.WithMany("Settings")
|
||||
.HasForeignKey("LayerEntityGuid");
|
||||
});
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.LayerEntity")
|
||||
.WithMany("Settings")
|
||||
.HasForeignKey("LayerEntityGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.LayerEntity", "Layer")
|
||||
.WithMany("Leds")
|
||||
.HasForeignKey("LayerGuid");
|
||||
});
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.LayerEntity", "Layer")
|
||||
.WithMany("Leds")
|
||||
.HasForeignKey("LayerGuid");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b =>
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.FolderEntity", "RootFolder")
|
||||
.WithMany()
|
||||
.HasForeignKey("RootFolderGuid");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
{
|
||||
b.HasOne("Artemis.Storage.Entities.FolderEntity", "RootFolder")
|
||||
.WithMany()
|
||||
.HasForeignKey("RootFolderGuid");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
src/Artemis.Storage/Repositories/SettingRepository.cs
Normal file
44
src/Artemis.Storage/Repositories/SettingRepository.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Storage.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Artemis.Storage.Repositories
|
||||
{
|
||||
public class SettingRepository
|
||||
{
|
||||
private readonly StorageContext _dbContext;
|
||||
|
||||
public SettingRepository()
|
||||
{
|
||||
_dbContext = new StorageContext();
|
||||
}
|
||||
|
||||
public IQueryable<SettingEntity> GetAll()
|
||||
{
|
||||
return _dbContext.Settings;
|
||||
}
|
||||
|
||||
public async Task<List<SettingEntity>> GetByPluginGuid(Guid pluginGuid)
|
||||
{
|
||||
return await _dbContext.Settings.Where(p => p.PluginGuid == pluginGuid).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<SettingEntity> GetByNameAndPluginGuid(string name, Guid pluginGuid)
|
||||
{
|
||||
return await _dbContext.Settings.FirstOrDefaultAsync(p => p.Name == name && p.PluginGuid == pluginGuid);
|
||||
}
|
||||
|
||||
public async Task<SettingEntity> GetByName(string name)
|
||||
{
|
||||
return await _dbContext.Settings.FirstOrDefaultAsync(p => p.Name == name);
|
||||
}
|
||||
|
||||
public async Task SaveAsync()
|
||||
{
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -12,5 +12,11 @@ namespace Artemis.Storage
|
||||
{
|
||||
optionsBuilder.UseSqlite("Data Source=Storage.db");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<SettingEntity>().HasIndex(s => new {s.Name, s.PluginGuid});
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.ViewModels.Interfaces;
|
||||
@ -28,8 +29,8 @@ namespace Artemis.UI.ViewModels
|
||||
ActiveItem = _artemisViewModels.First(v => v.GetType() == typeof(HomeViewModel));
|
||||
|
||||
// Sync up with the plugin service
|
||||
Modules = new BindableCollection<IModule>();
|
||||
Modules.AddRange(_pluginService.GetPluginsOfType<IModule>());
|
||||
Modules = new BindableCollection<Module>();
|
||||
Modules.AddRange(_pluginService.GetPluginsOfType<Module>());
|
||||
|
||||
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
|
||||
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
|
||||
@ -37,10 +38,10 @@ namespace Artemis.UI.ViewModels
|
||||
PropertyChanged += OnSelectedPageChanged;
|
||||
}
|
||||
|
||||
public IObservableCollection<IModule> Modules { get; set; }
|
||||
public IObservableCollection<Module> Modules { get; set; }
|
||||
public bool MenuOpen { get; set; }
|
||||
public ListBoxItem SelectedPage { get; set; }
|
||||
public IModule SelectedModule { get; set; }
|
||||
public Module SelectedModule { get; set; }
|
||||
|
||||
public async Task NavigateToSelectedModule()
|
||||
{
|
||||
@ -66,7 +67,7 @@ namespace Artemis.UI.ViewModels
|
||||
Modules.Remove(existing);
|
||||
}
|
||||
|
||||
if (e.PluginInfo.Instance is IModule module)
|
||||
if (e.PluginInfo.Instance is Module module)
|
||||
Modules.Add(module);
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
xmlns:vms="clr-namespace:Artemis.UI.ViewModels"
|
||||
xmlns:models="clr-namespace:Artemis.Core.Plugins.Models;assembly=Artemis.Core"
|
||||
xmlns:interfaces="clr-namespace:Artemis.Core.Plugins.Interfaces;assembly=Artemis.Core"
|
||||
xmlns:abstract="clr-namespace:Artemis.Core.Plugins.Abstract;assembly=Artemis.Core"
|
||||
mc:Ignorable="d"
|
||||
GlowBrush="{DynamicResource AccentColorBrush}"
|
||||
FontFamily="{StaticResource DefaultFont}"
|
||||
@ -127,7 +128,7 @@
|
||||
SelectedItem="{Binding SelectedModule}"
|
||||
DockPanel.Dock="Top">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="interfaces:IModule">
|
||||
<DataTemplate DataType="abstract:Module">
|
||||
<DockPanel HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Margin="0">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user