mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Code style - Omit the type in a new expressions
This commit is contained in:
1 parent
099f56f4fe
commit
10e6cdc54b
117 files changed
+251
-252
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user