Code cleanup

This commit is contained in:
Robert committed 2019-11-13 14:08:26 +01:00
1 parent 0d02e144ba
commit da4b691717
70 files changed
+492 -488

No files matched your search

+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;