Core port - Targeting .NET Core 3.1!

Core port - Updated projects to new project layout
Core port - Changed the way devices are identified to be consistent across different frameworks
Core port - Updated plugin system to no longer use AppDomain but AssemblyLoadContext (through McMaster.NETCore.Plugins)
Core port - Renamed a few events to keep Fody from getting confused
This commit is contained in:
SpoinkyNL committed 2020-02-22 18:38:32 +01:00
1 parent 29a75b7ad8
commit a79c56eaa1
61 files changed
+537 -2031

No files matched your search

+8 -13
View File
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using AppDomainToolkit;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Extensions;
@@ -11,6 +10,7 @@ using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using McMaster.NETCore.Plugins;
using Newtonsoft.Json;
using Ninject;
using Ninject.Extensions.ChildKernel;
@@ -198,17 +198,15 @@ namespace Artemis.Core.Services
throw new ArtemisPluginException(pluginInfo, "Couldn't find the plugins main entry at " + mainFile);
// Load the plugin, all types implementing Plugin and register them with DI
var setupInfo = new AppDomainSetup
pluginInfo.PluginLoader = PluginLoader.CreateFromAssemblyFile(mainFile, configure =>
{
ApplicationName = pluginInfo.Guid.ToString(),
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
PrivateBinPath = pluginInfo.Directory.FullName
};
pluginInfo.Context = AppDomainContext.Create(setupInfo);
configure.IsUnloadable = true;
configure.PreferSharedTypes = true;
});
try
{
pluginInfo.Context.LoadAssemblyWithReferences(LoadMethod.LoadFrom, mainFile);
pluginInfo.Assembly = pluginInfo.PluginLoader.LoadDefaultAssembly();
}
catch (Exception e)
{
@@ -217,12 +215,9 @@ namespace Artemis.Core.Services
// Get the Plugin implementation from the main assembly and if there is only one, instantiate it
List<Type> pluginTypes;
var mainAssembly = pluginInfo.Context.Domain.GetAssemblies().FirstOrDefault(a => a.Location == mainFile);
if (mainAssembly == null)
throw new ArtemisPluginException(pluginInfo, "Found no supported assembly in the plugins main file");
try
{
pluginTypes = mainAssembly.GetTypes().Where(t => typeof(Plugin).IsAssignableFrom(t)).ToList();
pluginTypes = pluginInfo.Assembly.GetTypes().Where(t => typeof(Plugin).IsAssignableFrom(t)).ToList();
}
catch (ReflectionTypeLoadException e)
{
@@ -275,7 +270,7 @@ namespace Artemis.Core.Services
_childKernel.Unbind(pluginInfo.Instance.GetType());
pluginInfo.Instance.Dispose();
pluginInfo.Context.Dispose();
pluginInfo.PluginLoader.Dispose();
_plugins.Remove(pluginInfo);
OnPluginUnloaded(new PluginEventArgs(pluginInfo));
@@ -47,7 +47,7 @@ namespace Artemis.Core.Services.Storage.Interfaces
/// <summary>
/// Occurs when the active device entity has been changed
/// </summary>
event EventHandler<SurfaceConfigurationEventArgs> ActiveSurfaceConfigurationChanged;
event EventHandler<SurfaceConfigurationEventArgs> ActiveSurfaceConfigurationSelected;
/// <summary>
/// Occurs when a surface configuration has been updated
@@ -33,7 +33,7 @@ namespace Artemis.Core.Services.Storage
_layerService = layerService;
_profileRepository = profileRepository;
_surfaceService.ActiveSurfaceConfigurationChanged += OnActiveSurfaceConfigurationChanged;
_surfaceService.ActiveSurfaceConfigurationSelected += OnActiveSurfaceConfigurationSelected;
_surfaceService.SurfaceConfigurationUpdated += OnSurfaceConfigurationUpdated;
_pluginService.PluginLoaded += OnPluginLoaded;
}
@@ -196,7 +196,7 @@ namespace Artemis.Core.Services.Storage
#region Event handlers
private void OnActiveSurfaceConfigurationChanged(object sender, SurfaceConfigurationEventArgs e)
private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e)
{
ActiveProfilesPopulateLeds(e.Surface);
}
@@ -139,7 +139,7 @@ namespace Artemis.Core.Services.Storage
var surfaceConfiguration = new ArtemisSurface(_rgbService.Surface, surfaceEntity, _renderScaleSetting.Value);
foreach (var position in surfaceEntity.DeviceEntities)
{
var device = _rgbService.Surface.Devices.FirstOrDefault(d => d.GetDeviceHashCode() == position.DeviceHashCode);
var device = _rgbService.Surface.Devices.FirstOrDefault(d => d.GetDeviceIdentifier() == position.DeviceIdentifier);
if (device != null)
{
var plugin = _pluginService.GetDevicePlugin(device);
@@ -174,14 +174,14 @@ namespace Artemis.Core.Services.Storage
private void AddDeviceIfMissing(IRGBDevice rgbDevice, ArtemisSurface surface)
{
var deviceHashCode = rgbDevice.GetDeviceHashCode();
var device = surface.Devices.FirstOrDefault(d => d.DeviceEntity.DeviceHashCode == deviceHashCode);
var deviceIdentifier = rgbDevice.GetDeviceIdentifier();
var device = surface.Devices.FirstOrDefault(d => d.DeviceEntity.DeviceIdentifier == deviceIdentifier);
if (device != null)
return;
// Find an existing device config and use that
var existingDeviceConfig = surface.SurfaceEntity.DeviceEntities.FirstOrDefault(d => d.DeviceHashCode == deviceHashCode);
var existingDeviceConfig = surface.SurfaceEntity.DeviceEntities.FirstOrDefault(d => d.DeviceIdentifier == deviceIdentifier);
if (existingDeviceConfig != null)
{
var plugin = _pluginService.GetDevicePlugin(rgbDevice);
@@ -193,7 +193,7 @@ namespace Artemis.Core.Services.Storage
_logger.Information(
"No device config found for {deviceInfo}, device hash: {deviceHashCode}. Adding a new entry.",
rgbDevice.DeviceInfo,
deviceHashCode
deviceIdentifier
);
var plugin = _pluginService.GetDevicePlugin(rgbDevice);
device = new ArtemisDevice(rgbDevice, plugin, surface);
@@ -230,12 +230,12 @@ namespace Artemis.Core.Services.Storage
#region Events
public event EventHandler<SurfaceConfigurationEventArgs> ActiveSurfaceConfigurationChanged;
public event EventHandler<SurfaceConfigurationEventArgs> ActiveSurfaceConfigurationSelected;
public event EventHandler<SurfaceConfigurationEventArgs> SurfaceConfigurationUpdated;
protected virtual void OnActiveSurfaceConfigurationChanged(SurfaceConfigurationEventArgs e)
{
ActiveSurfaceConfigurationChanged?.Invoke(this, e);
ActiveSurfaceConfigurationSelected?.Invoke(this, e);
}
protected virtual void OnSurfaceConfigurationUpdated(SurfaceConfigurationEventArgs e)