Code cleanup

This commit is contained in:
Robert committed 2019-11-13 19:57:23 +01:00
1 parent 44eaa6ac40
commit 5340e6c6d4
70 files changed
+492 -488

No files matched your search

@@ -8,7 +8,7 @@ namespace Artemis.Core.Extensions
{
if (type == null)
return false;
return type.BaseType?.GetGenericTypeDefinition() == genericType;
}
}
@@ -3,7 +3,6 @@ using System.Drawing;
using Artemis.Core.Models.Profile.Interfaces;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities;
using RGB.NET.Core;
namespace Artemis.Core.Models.Profile
{
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Drawing;
using RGB.NET.Core;
namespace Artemis.Core.Models.Profile.Interfaces
{
@@ -6,7 +6,6 @@ using Artemis.Core.Models.Profile.Interfaces;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities;
using RGB.NET.Core;
namespace Artemis.Core.Models.Profile
{
+2 -4
View File
@@ -1,13 +1,11 @@
using System;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Abstract;
using Artemis.Storage.Entities;
using RGB.NET.Core;
using Point = RGB.NET.Core.Point;
using Rectangle = System.Drawing.Rectangle;
namespace Artemis.Core.Models.Surface
@@ -104,12 +102,12 @@ namespace Artemis.Core.Models.Surface
foreach (var led in Leds)
led.CalculateRenderRectangle();
var path = new GraphicsPath();
path.AddRectangles(Leds.Select(l => l.AbsoluteRenderRectangle).ToArray());
RenderPath = path;
}
internal void Destroy()
{
Configuration = null;
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Extensions;
using Artemis.Storage.Entities;
using RGB.NET.Core;
+1 -4
View File
@@ -1,9 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.IO;
using Artemis.Core.Exceptions;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Repositories.Interfaces;
using Ninject.Activation;
+2 -3
View File
@@ -8,8 +8,8 @@ namespace Artemis.Core.Ninject
private static readonly ILogger _logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithDemystifiedStackTraces()
.WriteTo.File("Logs/Artemis log-.txt",
rollingInterval: RollingInterval.Day,
.WriteTo.File("Logs/Artemis log-.txt",
rollingInterval: RollingInterval.Day,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext:l}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
@@ -19,7 +19,6 @@ namespace Artemis.Core.Ninject
if (requestingType != null)
return _logger.ForContext(requestingType);
return _logger;
}
}
}
@@ -25,6 +25,5 @@ namespace Artemis.Core.Ninject
return _instance;
}
}
}
+2 -2
View File
@@ -12,13 +12,13 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary>
public abstract class Device : Plugin
{
public IRGBDeviceProvider DeviceProvider { get; }
protected Device(PluginInfo pluginInfo, IRGBDeviceProvider deviceProvider) : base(pluginInfo)
{
DeviceProvider = deviceProvider ?? throw new ArgumentNullException(nameof(deviceProvider));
}
public IRGBDeviceProvider DeviceProvider { get; }
protected void ResolveAbsolutePath(Type type, object sender, ResolvePathEventArgs e)
{
@@ -2,7 +2,6 @@
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Models;
using RGB.NET.Core;
namespace Artemis.Core.Plugins.Abstract
{
@@ -2,8 +2,6 @@
using System.Drawing;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Models;
using RGB.NET.Core;
using Stylet;
namespace Artemis.Core.Plugins.Abstract
{
+6 -7
View File
@@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using Artemis.Core.Plugins.Models;
namespace Artemis.Core.Plugins.Abstract
@@ -17,6 +16,12 @@ namespace Artemis.Core.Plugins.Abstract
public PluginInfo PluginInfo { get; internal set; }
/// <inheritdoc />
/// <summary>
/// Called when the plugin is unloaded, clean up any unmanaged resources here
/// </summary>
public abstract void Dispose();
/// <summary>
/// Called when the plugin is activated
/// </summary>
@@ -26,11 +31,5 @@ namespace Artemis.Core.Plugins.Abstract
/// 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();
}
}
@@ -3,7 +3,6 @@ using System.Drawing;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Models;
using RGB.NET.Core;
namespace Artemis.Core.Plugins.Abstract
{
@@ -1,10 +1,8 @@
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Artemis.Storage.Entities;
using Artemis.Storage.Repositories.Interfaces;
using Newtonsoft.Json;
using Stylet;
namespace Artemis.Core.Plugins.Models
{
+1
View File
@@ -50,6 +50,7 @@ namespace Artemis.Core.RGB.NET
return result;
}
return Color.Black;
}
}
+10 -11
View File
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
@@ -101,6 +100,16 @@ namespace Artemis.Core.Services
OnFrameRendered(new FrameRenderedEventArgs(_rgbService.GraphicsDecorator.GetBitmap(), _rgbService.Surface));
}
protected virtual void OnFrameRendering(FrameRenderingEventArgs e)
{
FrameRendering?.Invoke(this, e);
}
protected virtual void OnFrameRendered(FrameRenderedEventArgs e)
{
FrameRendered?.Invoke(this, e);
}
#region Events
public event EventHandler Initialized;
@@ -114,15 +123,5 @@ namespace Artemis.Core.Services
}
#endregion
protected virtual void OnFrameRendering(FrameRenderingEventArgs e)
{
FrameRendering?.Invoke(this, e);
}
protected virtual void OnFrameRendered(FrameRenderedEventArgs e)
{
FrameRendered?.Invoke(this, e);
}
}
}
@@ -1,6 +1,5 @@
using Artemis.Core.Models;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Interfaces;
namespace Artemis.Core.Services.Interfaces
{
@@ -74,7 +74,7 @@ namespace Artemis.Core.Services.Interfaces
#region Events
/// <summary>
/// Occurs when built-in plugins are being loaded
/// Occurs when built-in plugins are being loaded
/// </summary>
event EventHandler CopyingBuildInPlugins;
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Events;
using Artemis.Core.Models.Surface;
using Artemis.Core.RGB.NET;
using RGB.NET.Core;
+5 -8
View File
@@ -63,19 +63,18 @@ namespace Artemis.Core.Services
// Find the matching plugin in the plugin folder
var match = pluginDirectory.EnumerateDirectories().FirstOrDefault(d => d.Name == subDirectory.Name);
if (match == null)
{
CopyBuiltInPlugin(subDirectory);
}
else
{
var metadataFile = Path.Combine(match.FullName, "plugin.json");
if (!File.Exists(metadataFile))
{
_logger.Information("Copying missing built-in plugin {name} version: {version}",
_logger.Information("Copying missing built-in plugin {name} version: {version}",
builtInPluginInfo.Name, builtInPluginInfo.Version);
CopyBuiltInPlugin(subDirectory);
}
else
{
try
{
// Compare versions, copy if the same when debugging
@@ -83,7 +82,7 @@ namespace Artemis.Core.Services
#if DEBUG
if (builtInPluginInfo.Version >= pluginInfo.Version)
{
_logger.Information("Copying updated built-in plugin {name} version: {version} (old version: {oldVersion})",
_logger.Information("Copying updated built-in plugin {name} version: {version} (old version: {oldVersion})",
builtInPluginInfo.Name, builtInPluginInfo.Version, pluginInfo.Version);
CopyBuiltInPlugin(subDirectory);
}
@@ -100,6 +99,7 @@ namespace Artemis.Core.Services
{
throw new ArtemisPluginException("Failed read plugin metadata needed to install built-in plugin", e);
}
}
}
}
}
@@ -128,10 +128,7 @@ namespace Artemis.Core.Services
{
// Load the metadata
var metadataFile = Path.Combine(subDirectory.FullName, "plugin.json");
if (!File.Exists(metadataFile))
{
_logger.Warning(new ArtemisPluginException("Couldn't find the plugins metadata file at " + metadataFile), "Plugin exception");
}
if (!File.Exists(metadataFile)) _logger.Warning(new ArtemisPluginException("Couldn't find the plugins metadata file at " + metadataFile), "Plugin exception");
// Locate the main entry
var pluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile));
+3 -8
View File
@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Events;
using Artemis.Core.Plugins.Models;
using Artemis.Core.RGB.NET;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage;
using RGB.NET.Brushes;
using RGB.NET.Core;
using RGB.NET.Groups;
@@ -20,10 +18,10 @@ namespace Artemis.Core.Services
{
private readonly List<IRGBDevice> _loadedDevices;
private readonly ILogger _logger;
private readonly TimerUpdateTrigger _updateTrigger;
private ListLedGroup _background;
private readonly PluginSetting<double> _renderScaleSetting;
private readonly PluginSetting<int> _targetFrameRateSetting;
private readonly TimerUpdateTrigger _updateTrigger;
private ListLedGroup _background;
internal RgbService(ILogger logger, ISettingsService settingsService)
{
@@ -40,7 +38,6 @@ namespace Artemis.Core.Services
_loadedDevices = new List<IRGBDevice>();
_updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / _targetFrameRateSetting.Value};
Surface.RegisterUpdateTrigger(_updateTrigger);
}
/// <inheritdoc />
@@ -68,9 +65,7 @@ namespace Artemis.Core.Services
OnDeviceLoaded(new DeviceEventArgs(surfaceDevice));
}
else
{
OnDeviceReloaded(new DeviceEventArgs(surfaceDevice));
}
}
}
@@ -91,7 +86,7 @@ namespace Artemis.Core.Services
{
_updateTrigger.UpdateFrequency = 1.0 / _targetFrameRateSetting.Value;
}
private void SurfaceOnException(ExceptionEventArgs args)
{
_logger.Warning("Surface threw e");
@@ -17,11 +17,11 @@ namespace Artemis.Core.Services.Storage
public class SurfaceService : ISurfaceService
{
private readonly ILogger _logger;
private readonly IRgbService _rgbService;
private readonly IPluginService _pluginService;
private readonly PluginSetting<double> _renderScaleSetting;
private readonly IRgbService _rgbService;
private readonly List<Surface> _surfaceConfigurations;
private readonly ISurfaceRepository _surfaceRepository;
private readonly PluginSetting<double> _renderScaleSetting;
internal SurfaceService(ILogger logger, ISurfaceRepository surfaceRepository, IRgbService rgbService, IPluginService pluginService, ISettingsService settingsService)
{
@@ -128,27 +128,6 @@ namespace Artemis.Core.Services.Storage
}
}
#region Event handlers
private void RgbServiceOnDeviceLoaded(object sender, DeviceEventArgs e)
{
lock (_surfaceConfigurations)
{
foreach (var surfaceConfiguration in _surfaceConfigurations)
AddDeviceIfMissing(e.Device, surfaceConfiguration);
}
UpdateSurfaceConfiguration(ActiveSurface, true);
}
private void RenderScaleSettingOnSettingChanged(object sender, EventArgs e)
{
foreach (var surfaceConfiguration in SurfaceConfigurations)
surfaceConfiguration.UpdateScale(_renderScaleSetting.Value);
}
#endregion
#region Repository
private void LoadFromRepository()
@@ -225,6 +204,27 @@ namespace Artemis.Core.Services.Storage
#endregion
#region Event handlers
private void RgbServiceOnDeviceLoaded(object sender, DeviceEventArgs e)
{
lock (_surfaceConfigurations)
{
foreach (var surfaceConfiguration in _surfaceConfigurations)
AddDeviceIfMissing(e.Device, surfaceConfiguration);
}
UpdateSurfaceConfiguration(ActiveSurface, true);
}
private void RenderScaleSettingOnSettingChanged(object sender, EventArgs e)
{
foreach (var surfaceConfiguration in SurfaceConfigurations)
surfaceConfiguration.UpdateScale(_renderScaleSetting.Value);
}
#endregion
#region Events
public event EventHandler<SurfaceConfigurationEventArgs> ActiveSurfaceConfigurationChanged;
+12 -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.5.0" newVersion="4.0.5.0" />
</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>
@@ -107,4 +113,4 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
</configuration>
+1
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AppDomainToolkit" version="1.0.4.3" targetFramework="net461" />
<package id="Ben.Demystifier" version="0.1.4" targetFramework="net472" />