Darthified code

This commit is contained in:
SpoinkyNL committed 2020-10-05 22:50:29 +02:00
1 parent 5b80c1e4fe
commit ae64db8a13
198 files changed
+1339 -1305

No files matched your search

@@ -74,7 +74,7 @@ namespace Artemis.Core.DataModelExpansions
if (_dynamicDataModels.ContainsValue(dynamicDataModel))
{
var existingKey = _dynamicDataModels.First(kvp => kvp.Value == dynamicDataModel).Key;
string existingKey = _dynamicDataModels.First(kvp => kvp.Value == dynamicDataModel).Key;
throw new ArtemisCoreException($"Cannot add a dynamic data model with key '{key}' " +
$"because the dynamic data model is already added with key '{existingKey}.");
}
@@ -111,8 +111,8 @@ namespace Artemis.Core.DataModelExpansions
/// <param name="dynamicDataModel">The dynamic data model to remove</param>
public void RemoveDynamicChild(DataModel dynamicDataModel)
{
var keys = _dynamicDataModels.Where(kvp => kvp.Value == dynamicDataModel).Select(kvp => kvp.Key).ToList();
foreach (var key in keys)
List<string> keys = _dynamicDataModels.Where(kvp => kvp.Value == dynamicDataModel).Select(kvp => kvp.Key).ToList();
foreach (string key in keys)
_dynamicDataModels.Remove(key);
}
@@ -124,17 +124,17 @@ namespace Artemis.Core.DataModelExpansions
/// <returns>If found, the dynamic data model otherwise <c>null</c></returns>
public T DynamicChild<T>(string key) where T : DataModel
{
_dynamicDataModels.TryGetValue(key, out var value);
_dynamicDataModels.TryGetValue(key, out DataModel value);
return value as T;
}
internal bool ContainsPath(string path)
{
var parts = path.Split('.');
var current = GetType();
foreach (var part in parts)
string[] parts = path.Split('.');
Type current = GetType();
foreach (string part in parts)
{
var property = current?.GetProperty(part);
PropertyInfo? property = current?.GetProperty(part);
current = property?.PropertyType;
if (property == null)
return false;
@@ -148,13 +148,13 @@ namespace Artemis.Core.DataModelExpansions
if (!ContainsPath(path))
return null;
var parts = path.Split('.');
var current = GetType();
string[] parts = path.Split('.');
Type current = GetType();
Type result = null;
foreach (var part in parts)
foreach (string part in parts)
{
var property = current.GetProperty(part);
PropertyInfo? property = current.GetProperty(part);
current = property.PropertyType;
result = property.PropertyType;
}
@@ -167,17 +167,17 @@ namespace Artemis.Core.DataModelExpansions
if (!ContainsPath(path))
return null;
var parts = path.Split('.');
var current = GetType();
string[] parts = path.Split('.');
Type current = GetType();
var index = 0;
foreach (var part in parts)
int index = 0;
foreach (string part in parts)
{
// Only return a type if the path CONTAINS a list, not if it points TO a list
if (index == parts.Length - 1)
return null;
var property = current.GetProperty(part);
PropertyInfo? property = current.GetProperty(part);
// For lists, look into the list type instead of the list itself
if (typeof(IList).IsAssignableFrom(property.PropertyType))
@@ -195,7 +195,7 @@ namespace Artemis.Core.DataModelExpansions
if (!ContainsPath(path))
return null;
var child = GetTypeAtPath(path);
Type child = GetTypeAtPath(path);
return child.GenericTypeArguments.Length > 0 ? child.GenericTypeArguments[0] : null;
}
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core.DataModelExpansions
{
@@ -25,7 +26,7 @@ namespace Artemis.Core.DataModelExpansions
/// <param name="propertyLambda">A lambda expression pointing to the property to ignore</param>
public void HideProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda)
{
var propertyInfo = ReflectionUtilities.GetPropertyInfo(DataModel, propertyLambda);
PropertyInfo propertyInfo = ReflectionUtilities.GetPropertyInfo(DataModel, propertyLambda);
if (!HiddenPropertiesList.Any(p => p.Equals(propertyInfo)))
HiddenPropertiesList.Add(propertyInfo);
}
@@ -37,7 +38,7 @@ namespace Artemis.Core.DataModelExpansions
/// <param name="propertyLambda">A lambda expression pointing to the property to stop ignoring</param>
public void ShowProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda)
{
var propertyInfo = ReflectionUtilities.GetPropertyInfo(DataModel, propertyLambda);
PropertyInfo propertyInfo = ReflectionUtilities.GetPropertyInfo(DataModel, propertyLambda);
HiddenPropertiesList.RemoveAll(p => p.Equals(propertyInfo));
}
@@ -54,7 +54,7 @@ namespace Artemis.Core.DeviceProviders
else if (e.RelativePath != null)
e.FinalPath = Path.Combine(PluginInfo.Directory.FullName, e.RelativePath);
var deviceInfo = ((IRGBDevice) sender).DeviceInfo;
IRGBDeviceInfo deviceInfo = ((IRGBDevice) sender).DeviceInfo;
if (e.FileName != null && !File.Exists(e.FinalPath))
{
Logger?.Information("Couldn't find a layout for device {deviceName}, model {deviceModel} at {filePath}",
@@ -62,7 +62,7 @@ namespace Artemis.Core.LayerBrushes
if (layer.LayerBrush != null)
throw new ArtemisCoreException("Layer already has an instantiated layer brush");
var brush = (BaseLayerBrush) LayerBrushProvider.PluginInfo.Kernel.Get(LayerBrushType);
BaseLayerBrush brush = (BaseLayerBrush) LayerBrushProvider.PluginInfo.Kernel.Get(LayerBrushType);
brush.Layer = layer;
brush.Descriptor = this;
brush.Initialize();
@@ -41,7 +41,7 @@ namespace Artemis.Core.LayerBrushes
if (!Enabled)
throw new ArtemisPluginException(PluginInfo, "Can only add a layer brush descriptor when the plugin is enabled");
var descriptor = new LayerBrushDescriptor(displayName, description, icon, typeof(T), this);
LayerBrushDescriptor descriptor = new LayerBrushDescriptor(displayName, description, icon, typeof(T), this);
_layerBrushDescriptors.Add(descriptor);
LayerBrushStore.Add(descriptor);
}
@@ -36,14 +36,14 @@ namespace Artemis.Core.LayerBrushes
if (Layer.General.ResizeMode == LayerResizeMode.Normal)
{
// Apply a translated version of the shape as the clipping mask
var shapePath = new SKPath(Layer.LayerShape.Path);
SKPath shapePath = new SKPath(Layer.LayerShape.Path);
Layer.IncludePathInTranslation(shapePath, true);
canvas.ClipPath(shapePath);
}
using var pointsPath = new SKPath();
using var ledPaint = new SKPaint();
foreach (var artemisLed in Layer.Leds)
using SKPath pointsPath = new SKPath();
using SKPaint ledPaint = new SKPaint();
foreach (ArtemisLed artemisLed in Layer.Leds)
{
pointsPath.AddPoly(new[]
{
@@ -53,18 +53,18 @@ namespace Artemis.Core.LayerBrushes
}
Layer.ExcludePathFromTranslation(pointsPath, true);
var points = pointsPath.Points;
for (var index = 0; index < Layer.Leds.Count; index++)
SKPoint[] points = pointsPath.Points;
for (int index = 0; index < Layer.Leds.Count; index++)
{
var artemisLed = Layer.Leds[index];
var renderPoint = points[index * 2 + 1];
ArtemisLed artemisLed = Layer.Leds[index];
SKPoint renderPoint = points[index * 2 + 1];
if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
continue;
// Let the brush determine the color
ledPaint.Color = GetColor(artemisLed, renderPoint);
var ledRectangle = SKRect.Create(
SKRect ledRectangle = SKRect.Create(
artemisLed.AbsoluteRenderRectangle.Left - Layer.Bounds.Left,
artemisLed.AbsoluteRenderRectangle.Top - Layer.Bounds.Top,
artemisLed.AbsoluteRenderRectangle.Width,
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Services;
using RGB.NET.Core;
@@ -39,8 +40,8 @@ namespace Artemis.Core.LayerBrushes
// TODO: This simply renders it on top of the rest, get a ZIndex based on layer position
LedGroup.ZIndex = 1;
var missingLeds = Layer.Leds.Where(l => !LedGroup.ContainsLed(l.RgbLed)).Select(l => l.RgbLed).ToList();
var extraLeds = LedGroup.GetLeds().Where(l => Layer.Leds.All(layerLed => layerLed.RgbLed != l)).ToList();
List<Led> missingLeds = Layer.Leds.Where(l => !LedGroup.ContainsLed(l.RgbLed)).Select(l => l.RgbLed).ToList();
List<Led> extraLeds = LedGroup.GetLeds().Where(l => Layer.Leds.All(layerLed => layerLed.RgbLed != l)).ToList();
LedGroup.AddLeds(missingLeds);
LedGroup.RemoveLeds(extraLeds);
LedGroup.Brush = GetBrush();
@@ -67,7 +67,7 @@ namespace Artemis.Core.LayerEffects
return;
}
var effect = (BaseLayerEffect) LayerEffectProvider.PluginInfo.Kernel.Get(LayerEffectType);
BaseLayerEffect effect = (BaseLayerEffect) LayerEffectProvider.PluginInfo.Kernel.Get(LayerEffectType);
effect.ProfileElement = renderElement;
effect.EntityId = entity.Id;
effect.Order = entity.Order;
@@ -83,7 +83,7 @@ namespace Artemis.Core.LayerEffects
private void CreatePlaceHolderInstance(RenderProfileElement renderElement, LayerEffectEntity entity)
{
var effect = new PlaceholderLayerEffect(entity, PlaceholderFor.Value) {ProfileElement = renderElement, Descriptor = this};
PlaceholderLayerEffect effect = new PlaceholderLayerEffect(entity, PlaceholderFor.Value) {ProfileElement = renderElement, Descriptor = this};
effect.Initialize();
renderElement.ActivateLayerEffect(effect);
}
@@ -41,7 +41,7 @@ namespace Artemis.Core.LayerEffects
if (!Enabled)
throw new ArtemisPluginException(PluginInfo, "Can only add a layer effect descriptor when the plugin is enabled");
var descriptor = new LayerEffectDescriptor(displayName, description, icon, typeof(T), this);
LayerEffectDescriptor descriptor = new LayerEffectDescriptor(displayName, description, icon, typeof(T), this);
_layerEffectDescriptors.Add(descriptor);
LayerEffectStore.Add(descriptor);
}
@@ -6,7 +6,7 @@ namespace Artemis.Core.LayerEffects.Placeholder
{
public static LayerEffectDescriptor Create(Guid missingPluginGuid)
{
var descriptor = new LayerEffectDescriptor("Missing effect", "This effect could not be loaded", "FileQuestion", null, Constants.EffectPlaceholderPlugin)
LayerEffectDescriptor descriptor = new LayerEffectDescriptor("Missing effect", "This effect could not be loaded", "FileQuestion", null, Constants.EffectPlaceholderPlugin)
{
PlaceholderFor = missingPluginGuid
};
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
@@ -37,7 +38,7 @@ namespace Artemis.Core.Modules
if (ProcessName == null && Location == null)
return false;
var processes = ProcessName != null ? Process.GetProcessesByName(ProcessName).Where(p => !p.HasExited) : Process.GetProcesses().Where(p => !p.HasExited);
IEnumerable<Process> processes = ProcessName != null ? Process.GetProcessesByName(ProcessName).Where(p => !p.HasExited) : Process.GetProcesses().Where(p => !p.HasExited);
return Location != null
? processes.Any(p => string.Equals(Path.GetDirectoryName(p.GetProcessFilename()), Location, StringComparison.CurrentCultureIgnoreCase))
: processes.Any();
@@ -46,7 +47,7 @@ namespace Artemis.Core.Modules
/// <inheritdoc />
public string GetUserFriendlyDescription()
{
var description = $"Requirement met when \"{ProcessName}.exe\" is running";
string description = $"Requirement met when \"{ProcessName}.exe\" is running";
if (Location != null)
description += $" from \"{Location}\"";
@@ -55,7 +55,7 @@ namespace Artemis.Core.Modules
/// <param name="propertyLambda">A lambda expression pointing to the property to ignore</param>
public void HideProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda)
{
var propertyInfo = ReflectionUtilities.GetPropertyInfo(DataModel, propertyLambda);
PropertyInfo propertyInfo = ReflectionUtilities.GetPropertyInfo(DataModel, propertyLambda);
if (!HiddenPropertiesList.Any(p => p.Equals(propertyInfo)))
HiddenPropertiesList.Add(propertyInfo);
}
@@ -67,7 +67,7 @@ namespace Artemis.Core.Modules
/// <param name="propertyLambda">A lambda expression pointing to the property to stop ignoring</param>
public void ShowProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda)
{
var propertyInfo = ReflectionUtilities.GetPropertyInfo(DataModel, propertyLambda);
PropertyInfo propertyInfo = ReflectionUtilities.GetPropertyInfo(DataModel, propertyLambda);
HiddenPropertiesList.RemoveAll(p => p.Equals(propertyInfo));
}
@@ -227,7 +227,7 @@ namespace Artemis.Core.Modules
{
base.Deactivate(isOverride);
var profile = ActiveProfile;
Profile profile = ActiveProfile;
ActiveProfile = null;
profile?.Dispose();
}
+1 -1
View File
@@ -75,7 +75,7 @@ namespace Artemis.Core
// Allow up to 15 seconds for plugins to activate.
// This means plugins that need more time should do their long running tasks in a background thread, which is intentional
// Little meh: Running this from a different thread could cause deadlocks
var enableTask = Task.Run(InternalEnablePlugin);
Task enableTask = Task.Run(InternalEnablePlugin);
if (!enableTask.Wait(TimeSpan.FromSeconds(15)))
throw new ArtemisPluginException(PluginInfo, "Plugin load timeout");
@@ -83,7 +83,7 @@ namespace Artemis.Core
if (!PluginInfo.Instance.Enabled)
return;
var interval = DateTime.Now - _lastEvent;
TimeSpan interval = DateTime.Now - _lastEvent;
_lastEvent = DateTime.Now;
// Modules don't always want to update, honor that
@@ -37,7 +37,7 @@ namespace Artemis.Core
if (_settingEntities.ContainsKey(name))
return (PluginSetting<T>) _settingEntities[name];
// Try to find in database
var settingEntity = _pluginRepository.GetSettingByNameAndGuid(name, _pluginInfo.Guid);
PluginSettingEntity settingEntity = _pluginRepository.GetSettingByNameAndGuid(name, _pluginInfo.Guid);
// If not found, create a new one
if (settingEntity == null)
{
@@ -45,7 +45,7 @@ namespace Artemis.Core
_pluginRepository.AddSetting(settingEntity);
}
var pluginSetting = new PluginSetting<T>(_pluginInfo, _pluginRepository, settingEntity);
PluginSetting<T> pluginSetting = new PluginSetting<T>(_pluginInfo, _pluginRepository, settingEntity);
// This overrides null with the default value, I'm not sure if that's desirable because you
// might expect something to go null and you might not