Code style - Omit the type in a new expressions

This commit is contained in:
SpoinkyNL committed 2020-12-18 17:54:01 +01:00
1 parent 099f56f4fe
commit 10e6cdc54b
117 files changed
+251 -252

No files matched your search

+6 -6
View File
@@ -35,7 +35,7 @@ namespace Artemis.Core
/// <summary>
/// The plugin info used by core components of Artemis
/// </summary>
public static readonly PluginInfo CorePluginInfo = new PluginInfo
public static readonly PluginInfo CorePluginInfo = new()
{
Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core", Version = new Version(2, 0)
};
@@ -43,16 +43,16 @@ namespace Artemis.Core
/// <summary>
/// The plugin used by core components of Artemis
/// </summary>
public static readonly Plugin CorePlugin = new Plugin(CorePluginInfo, new DirectoryInfo(ApplicationFolder), null);
public static readonly Plugin CorePlugin = new(CorePluginInfo, new DirectoryInfo(ApplicationFolder), null);
internal static readonly CorePluginFeature CorePluginFeature = new CorePluginFeature {Plugin = CorePlugin};
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new EffectPlaceholderPlugin {Plugin = CorePlugin};
internal static readonly CorePluginFeature CorePluginFeature = new() {Plugin = CorePlugin};
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new() {Plugin = CorePlugin};
internal static JsonSerializerSettings JsonConvertSettings = new JsonSerializerSettings
internal static JsonSerializerSettings JsonConvertSettings = new()
{
Converters = new List<JsonConverter> {new SKColorConverter(), new ForgivingIntConverter()}
};
internal static JsonSerializerSettings JsonConvertTypedSettings = new JsonSerializerSettings
internal static JsonSerializerSettings JsonConvertTypedSettings = new()
{
TypeNameHandling = TypeNameHandling.All,
Converters = new List<JsonConverter> { new SKColorConverter(), new ForgivingIntConverter() }
@@ -84,7 +84,7 @@ namespace Artemis.Core
IEnumerable<TSource> _()
{
HashSet<TKey> knownKeys = new HashSet<TKey>(comparer);
HashSet<TKey> knownKeys = new(comparer);
foreach (TSource element in source)
{
if (knownKeys.Add(keySelector(element)))
@@ -19,7 +19,7 @@ namespace Artemis.Core
public static string GetProcessFilename(this Process p)
{
int capacity = 2000;
StringBuilder builder = new StringBuilder(capacity);
StringBuilder builder = new(capacity);
IntPtr ptr = OpenProcess(ProcessAccessFlags.QueryLimitedInformation, false, p.Id);
if (!QueryFullProcessImageName(ptr, 0, builder, ref capacity)) return string.Empty;
@@ -8,7 +8,7 @@ namespace Artemis.Core
{
public static string GetDeviceIdentifier(this IRGBDevice rgbDevice)
{
StringBuilder builder = new StringBuilder();
StringBuilder builder = new();
builder.Append(rgbDevice.DeviceInfo.DeviceName);
builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.Manufacturer);
@@ -16,7 +16,7 @@ namespace Artemis.Core
/// <returns>The RGB.NET color</returns>
public static Color ToRgbColor(this SKColor color)
{
return new Color(color.Alpha, color.Red, color.Green, color.Blue);
return new(color.Alpha, color.Red, color.Green, color.Blue);
}
/// <summary>
@@ -49,7 +49,7 @@ namespace Artemis.Core
/// <returns>The sum of the two colors</returns>
public static SKColor Sum(this SKColor a, SKColor b)
{
return new SKColor(
return new(
ClampToByte(a.Red + b.Red),
ClampToByte(a.Green + b.Green),
ClampToByte(a.Blue + b.Blue),
@@ -11,7 +11,7 @@ namespace Artemis.Core
/// </summary>
public static class TypeExtensions
{
private static readonly Dictionary<Type, List<Type>> PrimitiveTypeConversions = new Dictionary<Type, List<Type>>
private static readonly Dictionary<Type, List<Type>> PrimitiveTypeConversions = new()
{
{typeof(decimal), new List<Type> {typeof(sbyte), typeof(byte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(char)}},
{typeof(double), new List<Type> {typeof(sbyte), typeof(byte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(char), typeof(float)}},
@@ -24,7 +24,7 @@ namespace Artemis.Core
{typeof(short), new List<Type> {typeof(byte)}}
};
private static readonly Dictionary<Type, string> TypeKeywords = new Dictionary<Type, string>
private static readonly Dictionary<Type, string> TypeKeywords = new()
{
{typeof(bool), "bool"},
{typeof(byte), "byte"},
@@ -34,7 +34,7 @@ namespace Artemis.Core
return Stops.OrderBy(c => c.Position).Select(c => c.Color).ToArray();
List<SKColor> colors = Stops.OrderBy(c => c.Position).Select(c => c.Color).ToList();
List<SKColor> result = new List<SKColor>();
List<SKColor> result = new();
for (int i = 0; i <= timesToRepeat; i++)
result.AddRange(colors);
@@ -57,7 +57,7 @@ namespace Artemis.Core
// Create stops and a list of divided stops
List<float> stops = Stops.OrderBy(c => c.Position).Select(c => c.Position / (timesToRepeat + 1)).ToList();
List<float> result = new List<float>();
List<float> result = new();
// For each repeat cycle, add the base stops to the end result
for (int i = 0; i <= timesToRepeat; i++)
@@ -120,7 +120,7 @@ namespace Artemis.Core
public static ColorGradient GetUnicornBarf()
{
const int amount = 8;
ColorGradient gradient = new ColorGradient();
ColorGradient gradient = new();
for (int i = 0; i <= amount; i++)
{
@@ -11,7 +11,7 @@ namespace Artemis.Core
/// </summary>
public abstract class DataModelConditionPart : IDisposable
{
private readonly List<DataModelConditionPart> _children = new List<DataModelConditionPart>();
private readonly List<DataModelConditionPart> _children = new();
/// <summary>
/// Gets the parent of this part
@@ -153,7 +153,7 @@ namespace Artemis.Core
return;
// Ensure the list path is valid and points to a list
DataModelPath eventPath = new DataModelPath(null, Entity.EventPath);
DataModelPath eventPath = new(null, Entity.EventPath);
// Can't check this on an invalid list, if it becomes valid later lets hope for the best
if (eventPath.IsValid && !PointsToEvent(eventPath))
return;
@@ -177,7 +177,7 @@ namespace Artemis.Core
return;
// Ensure the list path is valid and points to a list
DataModelPath listPath = new DataModelPath(null, Entity.ListPath);
DataModelPath listPath = new(null, Entity.ListPath);
Type listType = listPath.GetPropertyType()!;
// Can't check this on an invalid list, if it becomes valid later lets hope for the best
if (listPath.IsValid && !PointsToList(listPath))
@@ -11,7 +11,7 @@ namespace Artemis.Core
/// </summary>
public class ConditionalDataBinding<TLayerProperty, TProperty> : IDataBindingMode<TLayerProperty, TProperty>
{
private readonly List<DataBindingCondition<TLayerProperty, TProperty>> _conditions = new List<DataBindingCondition<TLayerProperty, TProperty>>();
private readonly List<DataBindingCondition<TLayerProperty, TProperty>> _conditions = new();
private bool _disposed;
internal ConditionalDataBinding(DataBinding<TLayerProperty, TProperty> dataBinding, ConditionalDataBindingEntity entity)
@@ -81,7 +81,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("ConditionalDataBinding");
DataBindingCondition<TLayerProperty, TProperty> condition = new DataBindingCondition<TLayerProperty, TProperty>(this);
DataBindingCondition<TLayerProperty, TProperty> condition = new(this);
_conditions.Add(condition);
ApplyOrder();
@@ -10,7 +10,7 @@ namespace Artemis.Core
/// </summary>
public class DirectDataBinding<TLayerProperty, TProperty> : IDataBindingMode<TLayerProperty, TProperty>
{
private readonly List<DataBindingModifier<TLayerProperty, TProperty>> _modifiers = new List<DataBindingModifier<TLayerProperty, TProperty>>();
private readonly List<DataBindingModifier<TLayerProperty, TProperty>> _modifiers = new();
private bool _disposed;
internal DirectDataBinding(DataBinding<TLayerProperty, TProperty> dataBinding, DirectDataBindingEntity entity)
@@ -156,7 +156,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("DirectDataBinding");
DataBindingModifier<TLayerProperty, TProperty> modifier = new DataBindingModifier<TLayerProperty, TProperty>(this, type);
DataBindingModifier<TLayerProperty, TProperty> modifier = new(this, type);
_modifiers.Add(modifier);
ApplyOrder();
@@ -47,7 +47,7 @@ namespace Artemis.Core
/// <para>Always empty if <see cref="TrackHistory" /> is <see langword="false" /></para>
/// </summary>
[DataModelProperty(Description = "The arguments of the last time this event triggered")]
public Queue<T> EventArgumentsHistory { get; } = new Queue<T>(20);
public Queue<T> EventArgumentsHistory { get; } = new(20);
/// <summary>
/// Trigger the event with the given <paramref name="eventArgs" />
@@ -157,14 +157,14 @@ namespace Artemis.Core
/// <para>Always empty if <see cref="TrackHistory" /> is <see langword="false" /></para>
/// </summary>
[DataModelProperty(Description = "The arguments of the last time this event triggered")]
public Queue<DataModelEventArgs> EventArgumentsHistory { get; } = new Queue<DataModelEventArgs>(20);
public Queue<DataModelEventArgs> EventArgumentsHistory { get; } = new(20);
/// <summary>
/// Trigger the event
/// </summary>
public void Trigger()
{
DataModelEventArgs eventArgs = new DataModelEventArgs {TriggerTime = DateTime.Now};
DataModelEventArgs eventArgs = new() {TriggerTime = DateTime.Now};
LastEventArguments = eventArgs;
LastTrigger = DateTime.Now;
@@ -192,7 +192,7 @@ namespace Artemis.Core
if (Target == null)
return;
DataModelPathSegment startSegment = new DataModelPathSegment(this, "target", "target");
DataModelPathSegment startSegment = new(this, "target", "target");
startSegment.Node = _segments.AddFirst(startSegment);
// On an empty path don't bother processing segments
+2 -2
View File
@@ -68,7 +68,7 @@ namespace Artemis.Core
/// <inheritdoc />
public override List<ILayerProperty> GetAllLayerProperties()
{
List<ILayerProperty> result = new List<ILayerProperty>();
List<ILayerProperty> result = new();
foreach (BaseLayerEffect layerEffect in LayerEffects)
if (layerEffect.BaseProperties != null)
result.AddRange(layerEffect.BaseProperties.GetAllLayerProperties());
@@ -151,7 +151,7 @@ namespace Artemis.Core
if (Disposed)
throw new ObjectDisposedException("Folder");
SKPath path = new SKPath {FillType = SKPathFillType.Winding};
SKPath path = new() {FillType = SKPathFillType.Winding};
foreach (ProfileElement child in Children)
if (child is RenderProfileElement effectChild && effectChild.Path != null)
path.AddPath(effectChild.Path);
+5 -5
View File
@@ -125,7 +125,7 @@ namespace Artemis.Core
/// <inheritdoc />
public override List<ILayerProperty> GetAllLayerProperties()
{
List<ILayerProperty> result = new List<ILayerProperty>();
List<ILayerProperty> result = new();
result.AddRange(General.GetAllLayerProperties());
result.AddRange(Transform.GetAllLayerProperties());
if (LayerBrush?.BaseProperties != null)
@@ -221,7 +221,7 @@ namespace Artemis.Core
LayerEntity.Leds.Clear();
foreach (ArtemisLed artemisLed in Leds)
{
LedEntity ledEntity = new LedEntity
LedEntity ledEntity = new()
{
DeviceIdentifier = artemisLed.Device.RgbDevice.GetDeviceIdentifier(),
LedName = artemisLed.RgbLed.Id.ToString()
@@ -336,7 +336,7 @@ namespace Artemis.Core
Renderer.Paint.BlendMode = General.BlendMode.CurrentValue;
Renderer.Paint.Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f));
using SKPath renderPath = new SKPath();
using SKPath renderPath = new();
if (General.ShapeType.CurrentValue == LayerShapeType.Rectangle)
renderPath.AddRect(Renderer.Path.Bounds);
else
@@ -415,7 +415,7 @@ namespace Artemis.Core
}
else
{
SKPath path = new SKPath {FillType = SKPathFillType.Winding};
SKPath path = new() {FillType = SKPathFillType.Winding};
foreach (ArtemisLed artemisLed in Leds)
path.AddRect(artemisLed.AbsoluteRectangle);
@@ -569,7 +569,7 @@ namespace Artemis.Core
if (Disposed)
throw new ObjectDisposedException("Layer");
List<ArtemisLed> leds = new List<ArtemisLed>();
List<ArtemisLed> leds = new();
// Get the surface LEDs for this layer
List<ArtemisLed> availableLeds = surface.Devices.SelectMany(d => d.Leds).ToList();
@@ -292,7 +292,7 @@ namespace Artemis.Core
if (value == null)
return null;
LayerPropertyKeyframe<T> keyframe = new LayerPropertyKeyframe<T>(
LayerPropertyKeyframe<T> keyframe = new(
CoreJson.DeserializeObject<T>(keyframeEntity.Value)!, keyframeEntity.Position, (Easings.Functions) keyframeEntity.EasingFunction, this
);
AddKeyframe(keyframe);
@@ -366,9 +366,9 @@ namespace Artemis.Core
#region Data bindings
// ReSharper disable InconsistentNaming
internal readonly List<IDataBindingRegistration> _dataBindingRegistrations = new List<IDataBindingRegistration>();
internal readonly List<IDataBindingRegistration> _dataBindingRegistrations = new();
internal readonly List<IDataBinding> _dataBindings = new List<IDataBinding>();
internal readonly List<IDataBinding> _dataBindings = new();
// ReSharper restore InconsistentNaming
/// <summary>
@@ -444,7 +444,7 @@ namespace Artemis.Core
if (dataBindingRegistration.DataBinding != null)
throw new ArtemisCoreException("Provided data binding registration already has an enabled data binding");
DataBinding<T, TProperty> dataBinding = new DataBinding<T, TProperty>(dataBindingRegistration);
DataBinding<T, TProperty> dataBinding = new(dataBindingRegistration);
_dataBindings.Add(dataBinding);
OnDataBindingEnabled(new LayerPropertyEventArgs<T>(dataBinding.LayerProperty));
@@ -66,7 +66,7 @@ namespace Artemis.Core
/// <inheritdoc />
public KeyframeEntity GetKeyframeEntity()
{
return new KeyframeEntity
return new()
{
Value = CoreJson.SerializeObject(Value),
Position = Position,
@@ -113,7 +113,7 @@ namespace Artemis.Core
if (!PropertiesInitialized)
return new List<ILayerProperty>();
List<ILayerProperty> result = new List<ILayerProperty>(LayerProperties);
List<ILayerProperty> result = new(LayerProperties);
foreach (LayerPropertyGroup layerPropertyGroup in LayerPropertyGroups)
result.AddRange(layerPropertyGroup.GetAllLayerProperties());
@@ -14,7 +14,7 @@ namespace Artemis.Core
/// <inheritdoc />
public override void CalculateRenderProperties()
{
SKPath path = new SKPath();
SKPath path = new();
path.AddOval(SKRect.Create(Layer.Bounds.Width, Layer.Bounds.Height));
Path = path;
}
@@ -14,7 +14,7 @@ namespace Artemis.Core
/// <inheritdoc />
public override void CalculateRenderProperties()
{
SKPath path = new SKPath();
SKPath path = new();
path.AddRect(SKRect.Create(Layer.Bounds.Width, Layer.Bounds.Height));
Path = path;
}
+3 -3
View File
@@ -12,7 +12,7 @@ namespace Artemis.Core
/// </summary>
public sealed class Profile : ProfileElement
{
private readonly object _lock = new object();
private readonly object _lock = new();
private bool _isActivated;
internal Profile(ProfileModule module, string name) : base(null!)
@@ -26,7 +26,7 @@ namespace Artemis.Core
UndoStack = new Stack<string>();
RedoStack = new Stack<string>();
Folder _ = new Folder(this, "Root folder");
Folder _ = new(this, "Root folder");
Save();
}
@@ -168,7 +168,7 @@ namespace Artemis.Core
FolderEntity? rootFolder = ProfileEntity.Folders.FirstOrDefault(f => f.ParentId == EntityId);
if (rootFolder == null)
{
Folder _ = new Folder(this, "Root folder");
Folder _ = new(this, "Root folder");
}
else
{
@@ -189,7 +189,7 @@ namespace Artemis.Core
if (Disposed)
throw new ObjectDisposedException(GetType().Name);
List<Folder> folders = new List<Folder>();
List<Folder> folders = new();
foreach (Folder childFolder in Children.Where(c => c is Folder).Cast<Folder>())
{
// Add all folders in this element
@@ -210,7 +210,7 @@ namespace Artemis.Core
if (Disposed)
throw new ObjectDisposedException(GetType().Name);
List<Layer> layers = new List<Layer>();
List<Layer> layers = new();
// Add all layers in this element
layers.AddRange(Children.Where(c => c is Layer).Cast<Layer>());
@@ -67,7 +67,7 @@ namespace Artemis.Core
RenderElementEntity.LayerEffects.Clear();
foreach (BaseLayerEffect layerEffect in LayerEffects)
{
LayerEffectEntity layerEffectEntity = new LayerEffectEntity
LayerEffectEntity layerEffectEntity = new()
{
Id = layerEffect.EntityId,
ProviderId = layerEffect.Descriptor?.PlaceholderFor ?? layerEffect.ProviderId,
@@ -208,7 +208,7 @@ namespace Artemis.Core
if (descriptor == null)
throw new ArgumentNullException(nameof(descriptor));
LayerEffectEntity entity = new LayerEffectEntity
LayerEffectEntity entity = new()
{
Id = Guid.NewGuid(),
Enabled = true,
+1 -1
View File
@@ -12,7 +12,7 @@ namespace Artemis.Core
public class Timeline : CorePropertyChanged, IStorageModel
{
private const int MaxExtraTimelines = 15;
private readonly object _lock = new object();
private readonly object _lock = new();
/// <summary>
/// Creates a new instance of the <see cref="Timeline" /> class
@@ -288,7 +288,7 @@ namespace Artemis.Core
foreach (ArtemisLed led in Leds)
led.CalculateRectangles();
SKPath path = new SKPath {FillType = SKPathFillType.Winding};
SKPath path = new() {FillType = SKPathFillType.Winding};
foreach (ArtemisLed artemisLed in Leds)
path.AddRect(artemisLed.AbsoluteRectangle);
@@ -12,8 +12,8 @@ namespace Artemis.Core
/// </summary>
public class ArtemisSurface : CorePropertyChanged
{
private List<ArtemisDevice> _devices = new List<ArtemisDevice>();
private ReadOnlyDictionary<Led, ArtemisLed> _ledMap = new ReadOnlyDictionary<Led, ArtemisLed>(new Dictionary<Led, ArtemisLed>());
private List<ArtemisDevice> _devices = new();
private ReadOnlyDictionary<Led, ArtemisLed> _ledMap = new(new Dictionary<Led, ArtemisLed>());
private bool _isActive;
private string _name;
+1 -1
View File
@@ -8,7 +8,7 @@ namespace Artemis.Core.Ninject
{
internal class LoggerProvider : Provider<ILogger>
{
internal static readonly LoggingLevelSwitch LoggingLevelSwitch = new LoggingLevelSwitch(LogEventLevel.Verbose);
internal static readonly LoggingLevelSwitch LoggingLevelSwitch = new(LogEventLevel.Verbose);
private static readonly ILogger Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
@@ -9,7 +9,7 @@ namespace Artemis.Core.Ninject
// TODO: Investigate if this can't just be set as a constant on the plugin child kernel
internal class PluginSettingsProvider : Provider<PluginSettings>
{
private static readonly List<PluginSettings> PluginSettings = new List<PluginSettings>();
private static readonly List<PluginSettings> PluginSettings = new();
private readonly IPluginRepository _pluginRepository;
private readonly IPluginManagementService _pluginManagementService;
@@ -41,7 +41,7 @@ namespace Artemis.Core.Ninject
if (existingSettings != null)
return existingSettings;
PluginSettings? settings = new PluginSettings(plugin, _pluginRepository);
PluginSettings? settings = new(plugin, _pluginRepository);
PluginSettings.Add(settings);
return settings;
}
@@ -13,7 +13,7 @@ namespace Artemis.Core.DataModelExpansions
/// </summary>
public abstract class DataModel
{
private readonly Dictionary<string, DataModel> _dynamicDataModels = new Dictionary<string, DataModel>();
private readonly Dictionary<string, DataModel> _dynamicDataModels = new();
/// <summary>
/// Creates a new instance of the <see cref="DataModel" /> class
@@ -47,7 +47,7 @@ namespace Artemis.Core.DataModelExpansions
/// Gets an read-only dictionary of all dynamic data models
/// </summary>
[DataModelIgnore]
public ReadOnlyDictionary<string, DataModel> DynamicDataModels => new ReadOnlyDictionary<string, DataModel>(_dynamicDataModels);
public ReadOnlyDictionary<string, DataModel> DynamicDataModels => new(_dynamicDataModels);
/// <summary>
/// Returns a read-only collection of all properties in this datamodel that are to be ignored
@@ -13,7 +13,7 @@ namespace Artemis.Core.DataModelExpansions
/// <summary>
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new();
/// <summary>
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
@@ -41,7 +41,7 @@ namespace Artemis.Core.DataModelExpansions
/// <returns></returns>
public virtual DataModelPropertyAttribute GetDataModelDescription()
{
return new DataModelPropertyAttribute {Name = Plugin.Info.Name, Description = Plugin.Info.Description};
return new() {Name = Plugin.Info.Name, Description = Plugin.Info.Description};
}
}
}
@@ -34,7 +34,7 @@ namespace Artemis.Core.DeviceProviders
[Inject]
public ILogger? Logger { get; set; }
internal Dictionary<IRGBDevice, string> DeviceLayoutPaths { get; set; } = new Dictionary<IRGBDevice, string>();
internal Dictionary<IRGBDevice, string> DeviceLayoutPaths { get; set; } = new();
/// <inheritdoc />
public override void Disable()
@@ -41,7 +41,7 @@ namespace Artemis.Core.LayerBrushes
if (!IsEnabled)
throw new ArtemisPluginException(Plugin, "Can only add a layer brush descriptor when the plugin is enabled");
LayerBrushDescriptor descriptor = new LayerBrushDescriptor(displayName, description, icon, typeof(T), this);
LayerBrushDescriptor descriptor = new(displayName, description, icon, typeof(T), this);
_layerBrushDescriptors.Add(descriptor);
LayerBrushStore.Add(descriptor);
}
@@ -34,8 +34,8 @@ namespace Artemis.Core.LayerBrushes
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
canvas.SetMatrix(canvas.TotalMatrix.PreConcat(Layer.GetTransformMatrix(true, false, false, true).Invert()));
using SKPath pointsPath = new SKPath();
using SKPaint ledPaint = new SKPaint();
using SKPath pointsPath = new();
using SKPaint ledPaint = new();
foreach (ArtemisLed artemisLed in Layer.Leds)
{
pointsPath.AddPoly(new[]
@@ -87,7 +87,7 @@ namespace Artemis.Core.LayerEffects
{
if (PlaceholderFor == null)
throw new ArtemisCoreException("Cannot create a placeholder instance using a layer effect descriptor that is not a placeholder for anything");
PlaceholderLayerEffect effect = new PlaceholderLayerEffect(entity, PlaceholderFor)
PlaceholderLayerEffect effect = new(entity, PlaceholderFor)
{
ProfileElement = renderElement,
Descriptor = this
@@ -41,7 +41,7 @@ namespace Artemis.Core.LayerEffects
if (!IsEnabled)
throw new ArtemisPluginFeatureException(this, "Can only add a layer effect descriptor when the plugin is enabled");
LayerEffectDescriptor descriptor = new LayerEffectDescriptor(displayName, description, icon, typeof(T), this);
LayerEffectDescriptor descriptor = new(displayName, description, icon, typeof(T), this);
_layerEffectDescriptors.Add(descriptor);
LayerEffectStore.Add(descriptor);
}
@@ -4,7 +4,7 @@
{
public static LayerEffectDescriptor Create(string missingProviderId)
{
LayerEffectDescriptor descriptor = new LayerEffectDescriptor("Missing effect", "This effect could not be loaded", "FileQuestion", null, Constants.EffectPlaceholderPlugin)
LayerEffectDescriptor descriptor = new("Missing effect", "This effect could not be loaded", "FileQuestion", null, Constants.EffectPlaceholderPlugin)
{
PlaceholderFor = missingProviderId
};
+2 -2
View File
@@ -42,7 +42,7 @@ namespace Artemis.Core.Modules
/// <returns></returns>
public virtual DataModelPropertyAttribute GetDataModelDescription()
{
return new DataModelPropertyAttribute {Name = Plugin.Info.Name, Description = Plugin.Info.Description};
return new() {Name = Plugin.Info.Name, Description = Plugin.Info.Description};
}
internal override void InternalEnable()
@@ -98,7 +98,7 @@ namespace Artemis.Core.Modules
/// A list of activation requirements
/// <para>Note: if empty the module is always activated</para>
/// </summary>
public List<IModuleActivationRequirement> ActivationRequirements { get; } = new List<IModuleActivationRequirement>();
public List<IModuleActivationRequirement> ActivationRequirements { get; } = new();
/// <summary>
/// Gets or sets the activation requirement mode, defaults to <see cref="ActivationRequirementType.Any" />
@@ -46,7 +46,7 @@ namespace Artemis.Core.Modules
/// <returns></returns>
public virtual DataModelPropertyAttribute GetDataModelDescription()
{
return new DataModelPropertyAttribute {Name = Plugin.Info.Name, Description = Plugin.Info.Description};
return new() {Name = Plugin.Info.Name, Description = Plugin.Info.Description};
}
/// <summary>
@@ -94,8 +94,8 @@ namespace Artemis.Core.Modules
/// <summary>
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
private readonly object _lock = new object();
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new();
private readonly object _lock = new();
/// <summary>
/// Creates a new instance of the <see cref="ProfileModule" /> class
@@ -54,7 +54,7 @@ namespace Artemis.Core
_pluginRepository.AddSetting(settingEntity);
}
PluginSetting<T> pluginSetting = new PluginSetting<T>(Plugin, _pluginRepository, settingEntity);
PluginSetting<T> pluginSetting = new(Plugin, _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
@@ -13,7 +13,7 @@ namespace Artemis.Core
private DateTime _lastEvent;
private Timer? _timer;
private bool _disposed;
private readonly object _lock = new object();
private readonly object _lock = new();
internal TimedUpdateRegistration(PluginFeature feature, TimeSpan interval, Action<double> action)
{
+2 -2
View File
@@ -45,7 +45,7 @@ namespace Artemis.Core
public Rectangle RenderedRectangle { get; private set; }
/// <inheritdoc />
public Dictionary<BrushRenderTarget, Color> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, Color>();
public Dictionary<BrushRenderTarget, Color> RenderedTargets { get; } = new();
/// <summary>
/// Gets or sets the desired scale of the bitmap brush
@@ -155,7 +155,7 @@ namespace Artemis.Core
}
}
Color pixel = new Color(a / sampleSize, r / sampleSize, g / sampleSize, b / sampleSize);
Color pixel = new(a / sampleSize, r / sampleSize, g / sampleSize, b / sampleSize);
ArtemisDevice? artemisDevice = Surface?.GetArtemisLed(renderTarget.Led)?.Device;
if (artemisDevice is not null)
@@ -29,7 +29,7 @@ namespace Artemis.Core.Services
if ((amount & (amount - 1)) != 0)
throw new ArgumentException("Must be power of two", nameof(amount));
Queue<ColorCube> cubes = new Queue<ColorCube>(amount);
Queue<ColorCube> cubes = new(amount);
cubes.Enqueue(new ColorCube(colors));
while (cubes.Count < amount)
+5 -5
View File
@@ -32,10 +32,10 @@ namespace Artemis.Core.Services
private readonly PluginSetting<double> _renderScale;
private readonly IRgbService _rgbService;
private readonly ISurfaceService _surfaceService;
private readonly List<Exception> _updateExceptions = new List<Exception>();
private List<BaseDataModelExpansion> _dataModelExpansions = new List<BaseDataModelExpansion>();
private readonly List<Exception> _updateExceptions = new();
private List<BaseDataModelExpansion> _dataModelExpansions = new();
private DateTime _lastExceptionLog;
private List<Module> _modules = new List<Module>();
private List<Module> _modules = new();
// ReSharper disable UnusedParameter.Local - Storage migration and module service are injected early to ensure it runs before anything else
public CoreService(IKernel kernel, ILogger logger, StorageMigrationService _, ISettingsService settingsService, IPluginManagementService pluginManagementService,
@@ -112,7 +112,7 @@ namespace Artemis.Core.Services
public void PlayIntroAnimation()
{
IntroAnimation intro = new IntroAnimation(_logger, _profileService, _surfaceService);
IntroAnimation intro = new(_logger, _profileService, _surfaceService);
// Draw a white overlay over the device
void DrawOverlay(object? sender, FrameRenderingEventArgs args)
@@ -183,7 +183,7 @@ namespace Artemis.Core.Services
return;
// Render all active modules
using SKCanvas canvas = new SKCanvas(_rgbService.BitmapBrush.Bitmap);
using SKCanvas canvas = new(_rgbService.BitmapBrush.Bitmap);
canvas.Scale((float) _renderScale.Value);
canvas.Clear(new SKColor(0, 0, 0));
if (!ModuleRenderingDisabled)
+1 -1
View File
@@ -16,7 +16,7 @@ namespace Artemis.Core.Services
private void BlinkDevice(ArtemisDevice device, int blinkCount)
{
// Create a LED group way at the top
ListLedGroup ledGroup = new ListLedGroup(device.Leds.Select(l => l.RgbLed))
ListLedGroup ledGroup = new(device.Leds.Select(l => l.RgbLed))
{
Brush = new SolidColorBrush(new Color(255, 255, 255)),
ZIndex = 999
@@ -5,7 +5,7 @@ namespace Artemis.Core.Services
{
internal static class InputKeyUtilities
{
internal static readonly Dictionary<KeyboardKey, LedId> KeyboardKeyLedIdMap = new Dictionary<KeyboardKey, LedId>
internal static readonly Dictionary<KeyboardKey, LedId> KeyboardKeyLedIdMap = new()
{
{KeyboardKey.None, LedId.Keyboard_Custom1},
{KeyboardKey.Cancel, LedId.Keyboard_Custom2},
@@ -182,7 +182,7 @@ namespace Artemis.Core.Services
{KeyboardKey.NumPadEnter, LedId.Keyboard_NumEnter}
};
internal static readonly Dictionary<MouseButton, LedId> MouseButtonLedIdMap = new Dictionary<MouseButton, LedId>
internal static readonly Dictionary<MouseButton, LedId> MouseButtonLedIdMap = new()
{
{MouseButton.Left, LedId.Mouse1},
{MouseButton.Middle, LedId.Mouse2},
@@ -34,7 +34,7 @@ namespace Artemis.Core.Services
#region Providers
private readonly List<InputProvider> _inputProviders = new List<InputProvider>();
private readonly List<InputProvider> _inputProviders = new();
public void AddInputProvider(InputProvider inputProvider)
{
@@ -63,8 +63,8 @@ namespace Artemis.Core.Services
#region Identification
private readonly Dictionary<Tuple<InputProvider, object>, ArtemisDevice> _deviceCache = new Dictionary<Tuple<InputProvider, object>, ArtemisDevice>();
private List<ArtemisDevice> _devices = new List<ArtemisDevice>();
private readonly Dictionary<Tuple<InputProvider, object>, ArtemisDevice> _deviceCache = new();
private List<ArtemisDevice> _devices = new();
private ArtemisDevice? _cachedFallbackKeyboard;
private ArtemisDevice? _cachedFallbackMouse;
private ArtemisDevice? _identifyingDevice;
@@ -180,8 +180,8 @@ namespace Artemis.Core.Services
#region Keyboard
private readonly Dictionary<ArtemisDevice, HashSet<KeyboardKey>> _pressedKeys = new Dictionary<ArtemisDevice, HashSet<KeyboardKey>>();
private readonly Dictionary<ArtemisDevice, KeyboardModifierKey> _keyboardModifier = new Dictionary<ArtemisDevice, KeyboardModifierKey>();
private readonly Dictionary<ArtemisDevice, HashSet<KeyboardKey>> _pressedKeys = new();
private readonly Dictionary<ArtemisDevice, KeyboardModifierKey> _keyboardModifier = new();
private KeyboardModifierKey _globalModifiers;
private void InputProviderOnKeyboardDataReceived(object? sender, InputProviderKeyboardEventArgs e)
@@ -199,7 +199,7 @@ namespace Artemis.Core.Services
led = e.Device.GetLed(ledId);
// Create the UpDown event args because it can be used for every event
ArtemisKeyboardKeyUpDownEventArgs eventArgs = new ArtemisKeyboardKeyUpDownEventArgs(e.Device, led, e.Key, keyboardModifierKey, e.IsDown);
ArtemisKeyboardKeyUpDownEventArgs eventArgs = new(e.Device, led, e.Key, keyboardModifierKey, e.IsDown);
OnKeyboardKeyUpDown(eventArgs);
if (e.IsDown)
OnKeyboardKeyDown(eventArgs);
@@ -289,7 +289,7 @@ namespace Artemis.Core.Services
led = e.Device.Leds.FirstOrDefault(l => l.RgbLed.Id == ledId);
// Create the UpDown event args because it can be used for every event
ArtemisMouseButtonUpDownEventArgs eventArgs = new ArtemisMouseButtonUpDownEventArgs(e.Device, led, e.Button, e.IsDown);
ArtemisMouseButtonUpDownEventArgs eventArgs = new(e.Device, led, e.Button, e.IsDown);
OnMouseButtonUpDown(eventArgs);
if (e.IsDown)
OnMouseButtonDown(eventArgs);
+4 -4
View File
@@ -14,7 +14,7 @@ namespace Artemis.Core.Services
{
internal class ModuleService : IModuleService
{
private static readonly SemaphoreSlim ActiveModuleSemaphore = new SemaphoreSlim(1, 1);
private static readonly SemaphoreSlim ActiveModuleSemaphore = new(1, 1);
private readonly ILogger _logger;
private readonly IModuleRepository _moduleRepository;
private readonly IPluginManagementService _pluginManagementService;
@@ -28,7 +28,7 @@ namespace Artemis.Core.Services
_profileService = profileService;
_pluginManagementService.PluginFeatureEnabled += OnPluginFeatureEnabled;
Timer activationUpdateTimer = new Timer(2000);
Timer activationUpdateTimer = new(2000);
activationUpdateTimer.Start();
activationUpdateTimer.Elapsed += ActivationUpdateTimerOnElapsed;
@@ -204,11 +204,11 @@ namespace Artemis.Core.Services
return;
}
Stopwatch stopwatch = new Stopwatch();
Stopwatch stopwatch = new();
stopwatch.Start();
List<Module> modules = _pluginManagementService.GetFeaturesOfType<Module>().ToList();
List<Task> tasks = new List<Task>();
List<Task> tasks = new();
foreach (Module module in modules)
lock (module)
{
@@ -38,7 +38,7 @@ namespace Artemis.Core.Services
private void CopyBuiltInPlugin(FileInfo zipFileInfo, ZipArchive zipArchive)
{
DirectoryInfo pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins", Path.GetFileNameWithoutExtension(zipFileInfo.Name)));
DirectoryInfo pluginDirectory = new(Path.Combine(Constants.DataFolder, "plugins", Path.GetFileNameWithoutExtension(zipFileInfo.Name)));
bool createLockFile = File.Exists(Path.Combine(pluginDirectory.FullName, "artemis.lock"));
// Remove the old directory if it exists
@@ -58,10 +58,10 @@ namespace Artemis.Core.Services
public void CopyBuiltInPlugins()
{
OnCopyingBuildInPlugins();
DirectoryInfo pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
DirectoryInfo pluginDirectory = new(Path.Combine(Constants.DataFolder, "plugins"));
// Iterate built-in plugins
DirectoryInfo builtInPluginDirectory = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "Plugins"));
DirectoryInfo builtInPluginDirectory = new(Path.Combine(Directory.GetCurrentDirectory(), "Plugins"));
if (!builtInPluginDirectory.Exists)
{
_logger.Warning("No built-in plugins found at {pluginDir}, skipping CopyBuiltInPlugins", builtInPluginDirectory.FullName);
@@ -76,7 +76,7 @@ namespace Artemis.Core.Services
if (metaDataFileEntry == null)
throw new ArtemisPluginException("Couldn't find a plugin.json in " + zipFile.FullName);
using StreamReader reader = new StreamReader(metaDataFileEntry.Open());
using StreamReader reader = new(metaDataFileEntry.Open());
PluginInfo builtInPluginInfo = CoreJson.DeserializeObject<PluginInfo>(reader.ReadToEnd())!;
// Find the matching plugin in the plugin folder
@@ -151,7 +151,7 @@ namespace Artemis.Core.Services
public Plugin? GetCallingPlugin()
{
StackTrace stackTrace = new StackTrace(); // get call stack
StackTrace stackTrace = new(); // get call stack
StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
foreach (StackFrame stackFrame in stackFrames)
@@ -183,7 +183,7 @@ namespace Artemis.Core.Services
UnloadPlugins();
// Load the plugin assemblies into the plugin context
DirectoryInfo pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
DirectoryInfo pluginDirectory = new(Path.Combine(Constants.DataFolder, "plugins"));
foreach (DirectoryInfo subDirectory in pluginDirectory.EnumerateDirectories())
{
try
@@ -238,7 +238,7 @@ namespace Artemis.Core.Services
}
// Load the entity and fall back on creating a new one
Plugin plugin = new Plugin(pluginInfo, directory, _pluginRepository.GetPluginByGuid(pluginInfo.Guid));
Plugin plugin = new(pluginInfo, directory, _pluginRepository.GetPluginByGuid(pluginInfo.Guid));
OnPluginLoading(new PluginEventArgs(plugin));
// Locate the main assembly entry
@@ -17,7 +17,7 @@ namespace Artemis.Core.Services.Models
internal static SurfaceArrangement GetDefaultArrangement()
{
SurfaceArrangement arrangement = new SurfaceArrangement();
SurfaceArrangement arrangement = new();
SurfaceArrangementType keypad = arrangement.AddType(RGBDeviceType.Keypad, 1);
keypad.AddConfiguration(new SurfaceArrangementConfiguration(null, HorizontalArrangementPosition.Equal, VerticalArrangementPosition.Equal, 20));
@@ -71,7 +71,7 @@ namespace Artemis.Core.Services.Models
private SurfaceArrangementType AddType(RGBDeviceType type, int zIndex)
{
SurfaceArrangementType surfaceArrangementType = new SurfaceArrangementType(this, type, zIndex);
SurfaceArrangementType surfaceArrangementType = new(this, type, zIndex);
Types.Add(surfaceArrangementType);
return surfaceArrangementType;
}
@@ -46,7 +46,7 @@ namespace Artemis.Core.Services.Models
}
// If nothing applied fall back to just basing on whatever is the furthers to the right
SurfaceArrangementConfiguration fallback = new SurfaceArrangementConfiguration(
SurfaceArrangementConfiguration fallback = new(
null,
HorizontalArrangementPosition.Right,
VerticalArrangementPosition.Equal,
@@ -33,8 +33,8 @@ namespace Artemis.Core.Services
_surfaceService.SurfaceConfigurationUpdated += OnSurfaceConfigurationUpdated;
}
public JsonSerializerSettings MementoSettings { get; set; } = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
public JsonSerializerSettings ExportSettings { get; set; } = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented};
public JsonSerializerSettings MementoSettings { get; set; } = new() {TypeNameHandling = TypeNameHandling.All};
public JsonSerializerSettings ExportSettings { get; set; } = new() {TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented};
public ProfileDescriptor? GetLastActiveProfile(ProfileModule module)
{
@@ -78,7 +78,7 @@ namespace Artemis.Core.Services
public ProfileDescriptor CreateProfileDescriptor(ProfileModule module, string name)
{
ProfileEntity profileEntity = new ProfileEntity {Id = Guid.NewGuid(), Name = name, ModuleId = module.Id};
ProfileEntity profileEntity = new() {Id = Guid.NewGuid(), Name = name, ModuleId = module.Id};
_profileRepository.Add(profileEntity);
return new ProfileDescriptor(module, profileEntity);
@@ -107,7 +107,7 @@ namespace Artemis.Core.Services
if (profileEntity == null)
throw new ArtemisCoreException($"Cannot find profile named: {profileDescriptor.Name} ID: {profileDescriptor.Id}");
Profile profile = new Profile(profileDescriptor.ProfileModule, profileEntity);
Profile profile = new(profileDescriptor.ProfileModule, profileEntity);
InstantiateProfile(profile);
profileDescriptor.ProfileModule.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
@@ -122,7 +122,7 @@ namespace Artemis.Core.Services
return;
ProfileEntity entity = _profileRepository.Get(module.ActiveProfile.EntityId);
Profile profile = new Profile(module, entity);
Profile profile = new(module, entity);
InstantiateProfile(profile);
module.ChangeActiveProfile(null, _surfaceService.ActiveSurface);
@@ -138,7 +138,7 @@ namespace Artemis.Core.Services
if (profileEntity == null)
throw new ArtemisCoreException($"Cannot find profile named: {profileDescriptor.Name} ID: {profileDescriptor.Id}");
Profile profile = new Profile(profileDescriptor.ProfileModule, profileEntity);
Profile profile = new(profileDescriptor.ProfileModule, profileEntity);
InstantiateProfile(profile);
void ActivatingProfileSurfaceUpdate(object? sender, SurfaceConfigurationEventArgs e)
@@ -40,7 +40,7 @@ namespace Artemis.Core.Services
public ArtemisSurface CreateSurfaceConfiguration(string name)
{
// Create a blank config
ArtemisSurface configuration = new ArtemisSurface(_rgbService.Surface, name);
ArtemisSurface configuration = new(_rgbService.Surface, name);
// Add all current devices
foreach (IRGBDevice rgbDevice in _rgbService.LoadedDevices)
@@ -134,7 +134,7 @@ namespace Artemis.Core.Services
foreach (SurfaceEntity surfaceEntity in configs)
{
// Create the surface entity
ArtemisSurface surfaceConfiguration = new ArtemisSurface(_rgbService.Surface, surfaceEntity);
ArtemisSurface surfaceConfiguration = new(_rgbService.Surface, surfaceEntity);
foreach (DeviceEntity position in surfaceEntity.DeviceEntities)
{
IRGBDevice? device = _rgbService.Surface.Devices.FirstOrDefault(d => d.GetDeviceIdentifier() == position.DeviceIdentifier);
@@ -6,7 +6,7 @@ namespace Artemis.Core
{
internal class ConditionOperatorStore
{
private static readonly List<ConditionOperatorRegistration> Registrations = new List<ConditionOperatorRegistration>();
private static readonly List<ConditionOperatorRegistration> Registrations = new();
public static ConditionOperatorRegistration Add(BaseConditionOperator conditionOperator)
{
@@ -6,7 +6,7 @@ namespace Artemis.Core
{
internal class DataBindingModifierTypeStore
{
private static readonly List<DataBindingModifierTypeRegistration> Registrations = new List<DataBindingModifierTypeRegistration>();
private static readonly List<DataBindingModifierTypeRegistration> Registrations = new();
public static DataBindingModifierTypeRegistration Add(BaseDataBindingModifierType modifierType)
{
+1 -1
View File
@@ -7,7 +7,7 @@ namespace Artemis.Core
{
internal class DataModelStore
{
private static readonly List<DataModelRegistration> Registrations = new List<DataModelRegistration>();
private static readonly List<DataModelRegistration> Registrations = new();
public static DataModelRegistration Add(DataModel dataModel)
{
+1 -1
View File
@@ -7,7 +7,7 @@ namespace Artemis.Core
{
internal class LayerBrushStore
{
private static readonly List<LayerBrushRegistration> Registrations = new List<LayerBrushRegistration>();
private static readonly List<LayerBrushRegistration> Registrations = new();
public static LayerBrushRegistration Add(LayerBrushDescriptor descriptor)
{
+1 -1
View File
@@ -7,7 +7,7 @@ namespace Artemis.Core
{
internal class LayerEffectStore
{
private static readonly List<LayerEffectRegistration> Registrations = new List<LayerEffectRegistration>();
private static readonly List<LayerEffectRegistration> Registrations = new();
public static LayerEffectRegistration Add(LayerEffectDescriptor descriptor)
{
@@ -37,7 +37,7 @@ namespace Artemis.Core
if (restart)
arguments = "-Command \"& {Start-Sleep -s " + delay + "; (Get-Process 'Artemis.UI').kill(); Start-Process -FilePath '" + Process.GetCurrentProcess().MainModule!.FileName + "'}\"";
ProcessStartInfo info = new ProcessStartInfo
ProcessStartInfo info = new()
{
Arguments = arguments,
WindowStyle = ProcessWindowStyle.Hidden,
@@ -59,7 +59,7 @@ namespace Artemis.Core
/// <returns>The process created to open the URL</returns>
public static Process? OpenUrl(string url)
{
ProcessStartInfo processInfo = new ProcessStartInfo
ProcessStartInfo processInfo = new()
{
FileName = url,
UseShellExecute = true
@@ -87,7 +87,7 @@ namespace Artemis.Core
// On Windows, ensure everyone has permission (important when running as admin)
DirectorySecurity security = dataDirectory.GetAccessControl();
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
SecurityIdentifier everyone = new(WellKnownSidType.WorldSid, null);
security.AddAccessRule(new FileSystemAccessRule(
everyone,
FileSystemRights.Modify | FileSystemRights.Synchronize,
+1 -1
View File
@@ -47,7 +47,7 @@ namespace Artemis.Core
LedName = l.RgbLed.Id.ToString()
}));
Profile profile = new Profile(new DummyModule(), profileEntity);
Profile profile = new(new DummyModule(), profileEntity);
profile.Activate(_surfaceService.ActiveSurface);
_profileService.InstantiateProfile(profile);