Removed the rest of CS Script and removed old plugin projects

This commit is contained in:
Robert Beekman committed 2019-04-10 16:05:19 +02:00
1 parent 4e565f9d76
commit 571a3fe168
47 files changed
+550 -846

No files matched your search

+1 -2
View File
@@ -1,5 +1,4 @@
using System.Linq;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Interfaces;
using Ninject.Extensions.Conventions;
using Ninject.Modules;
@@ -3,6 +3,7 @@ using System.Drawing;
using Artemis.Core.Plugins.Interfaces;
using Artemis.Core.ProfileElements;
using RGB.NET.Core;
using Stylet;
namespace Artemis.Core.Plugins.Abstract
{
@@ -10,9 +11,6 @@ namespace Artemis.Core.Plugins.Abstract
{
public Profile ActiveProfile { get; private set; }
/// <inheritdoc />
public abstract Type ViewModelType { get; }
/// <inheritdoc />
public abstract bool ExpandsMainDataModel { get; }
@@ -22,20 +20,6 @@ namespace Artemis.Core.Plugins.Abstract
// Load and activate the last active profile
}
public void ChangeActiveProfile(Profile profile)
{
lock (this)
{
if (profile == null)
throw new ArgumentNullException(nameof(profile));
ActiveProfile?.Deactivate();
ActiveProfile = profile;
ActiveProfile.Activate();
}
}
/// <inheritdoc />
public virtual void Update(double deltaTime)
{
@@ -56,9 +40,26 @@ namespace Artemis.Core.Plugins.Abstract
}
}
/// <inheritdoc />
public abstract IScreen GetMainViewModel();
/// <inheritdoc />
public void Dispose()
{
}
public void ChangeActiveProfile(Profile profile)
{
lock (this)
{
if (profile == null)
throw new ArgumentNullException(nameof(profile));
ActiveProfile?.Deactivate();
ActiveProfile = profile;
ActiveProfile.Activate();
}
}
}
}
@@ -20,6 +20,14 @@ namespace Artemis.Core.Plugins.Exceptions
PluginInfo = pluginInfo;
}
public ArtemisPluginException(string message) : base(message)
{
}
public ArtemisPluginException(string message, Exception inner) : base(message, inner)
{
}
public PluginInfo PluginInfo { get; }
}
}
@@ -2,6 +2,5 @@
{
public interface ILayerTypeConfiguration
{
}
}
@@ -1,6 +1,6 @@
using System;
using System.Drawing;
using System.Drawing;
using RGB.NET.Core;
using Stylet;
namespace Artemis.Core.Plugins.Interfaces
{
@@ -10,11 +10,6 @@ namespace Artemis.Core.Plugins.Interfaces
/// </summary>
public interface IModule : IPlugin
{
/// <summary>
/// The type of this module's view model
/// </summary>
Type ViewModelType { get; }
/// <summary>
/// Wether 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
@@ -34,5 +29,11 @@ namespace Artemis.Core.Plugins.Interfaces
/// <param name="surface">The RGB Surface to render to</param>
/// <param name="graphics"></param>
void Render(double deltaTime, RGBSurface surface, Graphics graphics);
/// <summary>
/// Called when the module's main view is being shown
/// </summary>
/// <returns></returns>
IScreen GetMainViewModel();
}
}
+9 -35
View File
@@ -1,21 +1,14 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Artemis.Core.Plugins.Exceptions;
using System.Collections.Generic;
using Artemis.Core.Plugins.Interfaces;
using Newtonsoft.Json;
using Ninject;
namespace Artemis.Core.Plugins.Models
{
public class PluginInfo
{
private static AppDomain _appDomain;
/// <summary>
/// The plugin's GUID
/// The plugins GUID
/// </summary>
public Guid Guid { get; set; }
@@ -28,42 +21,23 @@ namespace Artemis.Core.Plugins.Models
/// The version of the plugin
/// </summary>
public string Version { get; set; }
/// <summary>
/// The instantiated plugin, available after successful load
/// The main entry DLL, should contain a class implementing IPlugin
/// </summary>
[JsonIgnore]
public IPlugin Plugin { get; set; }
public string Main { get; set; }
/// <summary>
/// Full path to the plugin's current folder
/// </summary>
[JsonIgnore]
public string Folder { get; set; }
/// <summary>
/// Gets the view model of the module accompanying the provided plugin info
/// A references to the types implementing IPlugin, available after successful load
/// </summary>
/// <param name="kernel">The Ninject kernel to use for DI</param>
/// <returns></returns>
public IModuleViewModel GetModuleViewModel(IKernel kernel)
{
// Don't attempt to locate VMs for something other than a module
if (Plugin == null)
throw new ArtemisPluginException(this, "Cannot locate a view model for this plugin because it's not compiled.");
if (!(Plugin is IModule module))
throw new ArtemisPluginException(this, "Cannot locate a view model for this plugin as it's not a module.");
// Get the type from the module
var vmType = module.ViewModelType;
if (!typeof(IModuleViewModel).IsAssignableFrom(vmType))
throw new ArtemisPluginException(this, "ViewModel must implement IModuleViewModel.");
// Instantiate the ViewModel with Ninject
var vm = (IModuleViewModel) kernel.Get(vmType);
vm.PluginInfo = this;
return vm;
}
[JsonIgnore]
public List<IPlugin> Instances { get; set; }
public override string ToString()
{
@@ -61,10 +61,12 @@ namespace Artemis.Core.ProfileElements
public void UpdateLayerType(ILayerType layerType)
{
if (LayerType != null)
{
lock (LayerType)
{
LayerType.Dispose();
}
}
LayerType = layerType;
}
+24 -24
View File
@@ -7,39 +7,22 @@ namespace Artemis.Core.RGB.NET
{
public class DirectBitmap : IDisposable
{
public Bitmap Bitmap { get; private set; }
public Int32[] Bits { get; private set; }
public bool Disposed { get; private set; }
public int Height { get; private set; }
public int Width { get; private set; }
protected GCHandle BitsHandle { get; private set; }
public DirectBitmap(int width, int height)
{
Width = width;
Height = height;
Bits = new Int32[width * height];
Bits = new int[width * height];
BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject());
}
public void SetPixel(int x, int y, Color colour)
{
int index = x + (y * Width);
int col = colour.ToArgb();
public Bitmap Bitmap { get; }
public int[] Bits { get; }
public bool Disposed { get; private set; }
public int Height { get; }
public int Width { get; }
Bits[index] = col;
}
public Color GetPixel(int x, int y)
{
int index = x + (y * Width);
int col = Bits[index];
Color result = Color.FromArgb(col);
return result;
}
protected GCHandle BitsHandle { get; }
public void Dispose()
{
@@ -48,5 +31,22 @@ namespace Artemis.Core.RGB.NET
Bitmap.Dispose();
BitsHandle.Free();
}
public void SetPixel(int x, int y, Color colour)
{
var index = x + y * Width;
var col = colour.ToArgb();
Bits[index] = col;
}
public Color GetPixel(int x, int y)
{
var index = x + y * Width;
var col = Bits[index];
var result = Color.FromArgb(col);
return result;
}
}
}
@@ -1,5 +1,4 @@
using System.Drawing;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Groups;
using Color = RGB.NET.Core.Color;
@@ -17,7 +16,7 @@ namespace Artemis.Core.RGB.NET
// var height = ledGroup.GetLeds().Max(l => l.LedRectangle.Y + l.LedRectangle.Height);
var width = 500;
var height = 500;
_bitmap = new DirectBitmap((int) width, (int) height);
_bitmap = new DirectBitmap(width, height);
}
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
+4 -2
View File
@@ -48,8 +48,10 @@ namespace Artemis.Core.Services
{
try
{
var modules = _pluginService.Plugins.SelectMany(p => p.Instances).OfType<IModule>().ToList();
// Update all active modules
foreach (var module in _pluginService.Plugins.Select(p => p.Plugin).OfType<IModule>())
foreach (var module in modules)
module.Update(args.DeltaTime);
if (_rgbService.GraphicsDecorator == null)
@@ -60,7 +62,7 @@ namespace Artemis.Core.Services
{
g.Clear(Color.Red);
foreach (var module in _pluginService.Plugins.Select(p => p.Plugin).OfType<IModule>())
foreach (var module in modules)
module.Render(args.DeltaTime, _rgbService.Surface, g);
}
}
@@ -4,7 +4,6 @@ using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Plugins.Interfaces;
using Artemis.Core.Plugins.Models;
using Artemis.Core.ProfileElements;
namespace Artemis.Core.Services.Interfaces
{
@@ -25,18 +24,11 @@ namespace Artemis.Core.Services.Interfaces
/// </summary>
Task LoadPlugins();
/// <summary>
/// Gets the view model of the module accompanying the provided plugin info
/// </summary>
/// <param name="pluginInfo">The plugin info containing the module for which to load the view model</param>
Task<IModuleViewModel> GetModuleViewModel(PluginInfo pluginInfo);
/// <summary>
/// Occurs when a single plugin has loaded
/// </summary>
event EventHandler<PluginEventArgs> PluginLoaded;
/// <summary>
/// Occurs when loading all plugins has started
/// </summary>
+62 -48
View File
@@ -10,8 +10,8 @@ using Artemis.Core.Exceptions;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Interfaces;
using Artemis.Core.Plugins.Models;
using Artemis.Core.ProfileElements;
using Artemis.Core.Services.Interfaces;
using Newtonsoft.Json;
using Ninject;
using Ninject.Extensions.ChildKernel;
@@ -20,9 +20,8 @@ namespace Artemis.Core.Services
public class PluginService : IPluginService
{
private readonly IKernel _kernel;
private IKernel _childKernel;
private AppDomain _appDomain;
private readonly List<PluginInfo> _plugins;
private IKernel _childKernel;
public PluginService(IKernel kernel)
{
@@ -44,23 +43,70 @@ namespace Artemis.Core.Services
OnStartedLoadingPlugins();
UnloadPlugins();
// Create a child kernel and app domain that will only contain the plugins
_childKernel = new ChildKernel(_kernel);
_appDomain = AppDomain.CreateDomain("PluginAppDomain");
// Load the plugin assemblies into the app domain
var directory = new DirectoryInfo(Constants.DataFolder + "plugins");
foreach (var subDirectory in directory.EnumerateDirectories())
await Task.Run(() =>
{
// _appDomain.Load()
// _plugins.Add(new PluginInfo(subDirectory.FullName));
}
UnloadPlugins();
// Create a child kernel and app domain that will only contain the plugins
_childKernel = new ChildKernel(_kernel);
// Load the plugin assemblies into the plugin context
var directory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
foreach (var subDirectory in directory.EnumerateDirectories())
{
try
{
// Load the metadata
var metadataFile = Path.Combine(subDirectory.FullName, "plugin.json");
if (!File.Exists(metadataFile))
throw new ArtemisPluginException("Couldn't find the plugins metadata file at " + metadataFile);
// Locate the main entry
var pluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile));
var mainFile = Path.Combine(subDirectory.FullName, pluginInfo.Main);
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
var assembly = Assembly.LoadFile(mainFile);
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));
}
_plugins.Add(pluginInfo);
}
catch (Exception e)
{
throw new ArtemisPluginException("Failed to load plugin", e);
}
}
});
OnFinishedLoadedPlugins();
}
/// <inheritdoc />
public ILayerType GetLayerTypeByGuid(Guid layerTypeGuid)
{
var pluginInfo = _plugins.FirstOrDefault(p => p.Guid == layerTypeGuid);
if (pluginInfo == null)
return null;
var layerType = pluginInfo.Instances.SingleOrDefault(p => p is ILayerType);
if (layerType == null)
throw new ArtemisPluginException(pluginInfo, "Plugin is expected to implement exactly one ILayerType");
return (ILayerType) layerType;
}
public void Dispose()
{
UnloadPlugins();
}
private void UnloadPlugins()
{
_plugins.Clear();
@@ -70,38 +116,6 @@ namespace Artemis.Core.Services
_childKernel.Dispose();
_childKernel = null;
}
if (_appDomain != null)
{
AppDomain.Unload(_appDomain);
_appDomain = null;
}
}
/// <inheritdoc />
public async Task<IModuleViewModel> GetModuleViewModel(PluginInfo pluginInfo)
{
return await Task.Run(() => pluginInfo.GetModuleViewModel(_kernel));
}
/// <inheritdoc />
public ILayerType GetLayerTypeByGuid(Guid layerTypeGuid)
{
var pluginInfo = _plugins.FirstOrDefault(p => p.Guid == layerTypeGuid);
if (pluginInfo == null)
return null;
// Layer types are instantiated per layer so lets compile and return a new instance
if (!(pluginInfo.Plugin is ILayerType))
{
throw new ArtemisPluginException(pluginInfo, "Plugin is expected to implement ILayerType");
}
return (ILayerType) pluginInfo.Plugin;
}
public void Dispose()
{
UnloadPlugins();
}
#region Events
@@ -114,7 +128,7 @@ namespace Artemis.Core.Services
{
PluginLoaded?.Invoke(this, e);
}
private void OnStartedLoadingPlugins()
{
LoadingPlugins = true;
+1 -2
View File
@@ -14,7 +14,7 @@ namespace Artemis.Core.Services
public class RgbService : IRgbService, IDisposable
{
private readonly TimerUpdateTrigger _updateTrigger;
private List<IRGBDevice> _loadedDevices;
private readonly List<IRGBDevice> _loadedDevices;
public RgbService()
{
@@ -44,7 +44,6 @@ namespace Artemis.Core.Services
await Task.Run(() =>
{
// TODO SpoinkyNL 8-1-18: Keep settings into account
// This one doesn't work well without ASUS devices installed
// Surface.LoadDevices(AsusDeviceProvider.Instance);
+15 -6
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
@@ -27,7 +28,8 @@
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
@@ -51,7 +53,8 @@
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Scripting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Scripting" publicKeyToken="31bf3856ad364e35"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
@@ -67,7 +70,8 @@
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
@@ -83,7 +87,8 @@
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
</dependentAssembly>
<dependentAssembly>
@@ -91,7 +96,8 @@
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.1" newVersion="4.0.3.1" />
</dependentAssembly>
<dependentAssembly>
@@ -104,4 +110,7 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
+1
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.4.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net461" />