1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Merge pull request #235 from DarthAffe/SmallImprovements

Small improvements
This commit is contained in:
DarthAffe 2021-09-06 01:18:43 +02:00 committed by GitHub
commit 5fc2e34f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 21 deletions

View File

@ -14,7 +14,7 @@ namespace RGB.NET.Core
private readonly List<T> _decorators = new(); private readonly List<T> _decorators = new();
/// <inheritdoc /> /// <inheritdoc />
public IReadOnlyCollection<T> Decorators { get; } public IReadOnlyList<T> Decorators { get; }
#endregion #endregion

View File

@ -20,7 +20,7 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets a readonly-list of all <see cref="IDecorator"/> attached to this <see cref="IDecoratable{T}"/>. /// Gets a readonly-list of all <see cref="IDecorator"/> attached to this <see cref="IDecoratable{T}"/>.
/// </summary> /// </summary>
IReadOnlyCollection<T> Decorators { get; } IReadOnlyList<T> Decorators { get; }
/// <summary> /// <summary>
/// Adds an <see cref="IDecorator"/> to the <see cref="IDecoratable"/>. /// Adds an <see cref="IDecorator"/> to the <see cref="IDecoratable"/>.

View File

@ -30,7 +30,7 @@ namespace RGB.NET.Core
protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = new(); protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = new();
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList()); public IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)>(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList());
#endregion #endregion

View File

@ -2,7 +2,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace RGB.NET.Core namespace RGB.NET.Core
{ {
@ -31,7 +30,7 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets a collection <see cref="IDeviceUpdateTrigger"/> registered to this device provider. /// Gets a collection <see cref="IDeviceUpdateTrigger"/> registered to this device provider.
/// </summary> /// </summary>
ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers { get; } IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers { get; }
#endregion #endregion

View File

@ -26,20 +26,15 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets a readonly list containing all loaded <see cref="IRGBDevice"/>. /// Gets a readonly list containing all loaded <see cref="IRGBDevice"/>.
/// This collection should be locked when enumerated in a multi-threaded application.
/// </summary> /// </summary>
public IEnumerable<IRGBDevice> Devices public IReadOnlyList<IRGBDevice> Devices { get; }
{
get
{
lock (_devices)
return new ReadOnlyCollection<IRGBDevice>(_devices);
}
}
/// <summary> /// <summary>
/// Gets a readonly list containing all registered <see cref="IUpdateTrigger"/>. /// Gets a readonly list containing all registered <see cref="IUpdateTrigger"/>.
/// This collection should be locked when enumerated in a multi-threaded application.
/// </summary> /// </summary>
public IEnumerable<IUpdateTrigger> UpdateTriggers => new ReadOnlyCollection<IUpdateTrigger>(_updateTriggers); public IReadOnlyList<IUpdateTrigger> UpdateTriggers { get; }
/// <summary> /// <summary>
/// Gets a copy of the <see cref="Rectangle"/> representing this <see cref="RGBSurface"/>. /// Gets a copy of the <see cref="Rectangle"/> representing this <see cref="RGBSurface"/>.
@ -53,7 +48,7 @@ namespace RGB.NET.Core
{ {
get get
{ {
lock (_devices) lock (Devices)
return _devices.SelectMany(x => x); return _devices.SelectMany(x => x);
} }
} }
@ -124,6 +119,9 @@ namespace RGB.NET.Core
public RGBSurface() public RGBSurface()
{ {
_deltaTimeCounter = Stopwatch.StartNew(); _deltaTimeCounter = Stopwatch.StartNew();
Devices = new ReadOnlyCollection<IRGBDevice>(_devices);
UpdateTriggers = new ReadOnlyCollection<IUpdateTrigger>(_updateTriggers);
} }
#endregion #endregion
@ -146,8 +144,8 @@ namespace RGB.NET.Core
bool render = customData["render"] as bool? ?? true; bool render = customData["render"] as bool? ?? true;
bool updateDevices = customData["updateDevices"] as bool? ?? true; bool updateDevices = customData["updateDevices"] as bool? ?? true;
lock (_updateTriggers) lock (UpdateTriggers)
lock (_devices) lock (Devices)
{ {
OnUpdating(updateTrigger, customData); OnUpdating(updateTrigger, customData);
@ -178,7 +176,7 @@ namespace RGB.NET.Core
public void Dispose() public void Dispose()
{ {
List<IRGBDevice> devices; List<IRGBDevice> devices;
lock (_devices) lock (Devices)
devices = new List<IRGBDevice>(_devices); devices = new List<IRGBDevice>(_devices);
foreach (IRGBDevice device in devices) foreach (IRGBDevice device in devices)
@ -267,7 +265,7 @@ namespace RGB.NET.Core
/// <param name="device">The <see cref="IRGBDevice"/> to attach.</param> /// <param name="device">The <see cref="IRGBDevice"/> to attach.</param>
public void Attach(IRGBDevice device) public void Attach(IRGBDevice device)
{ {
lock (_devices) lock (Devices)
{ {
if (string.IsNullOrWhiteSpace(device.DeviceInfo.DeviceName)) throw new RGBDeviceException($"The device '{device.DeviceInfo.Manufacturer} {device.DeviceInfo.Model}' has no valid name."); if (string.IsNullOrWhiteSpace(device.DeviceInfo.DeviceName)) throw new RGBDeviceException($"The device '{device.DeviceInfo.Manufacturer} {device.DeviceInfo.Model}' has no valid name.");
if (device.Surface != null) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is already attached to a surface."); if (device.Surface != null) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is already attached to a surface.");
@ -287,7 +285,7 @@ namespace RGB.NET.Core
/// <returns><c>true</c> if the <see cref="IRGBDevice"/> could be detached; <c>false</c> otherwise.</returns> /// <returns><c>true</c> if the <see cref="IRGBDevice"/> could be detached; <c>false</c> otherwise.</returns>
public void Detach(IRGBDevice device) public void Detach(IRGBDevice device)
{ {
lock (_devices) lock (Devices)
{ {
if (!_devices.Contains(device)) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is not attached to this surface."); if (!_devices.Contains(device)) throw new RGBSurfaceException($"The device '{device.DeviceInfo.DeviceName}' is not attached to this surface.");
@ -314,7 +312,7 @@ namespace RGB.NET.Core
private void UpdateSurfaceRectangle() private void UpdateSurfaceRectangle()
{ {
lock (_devices) lock (Devices)
{ {
Rectangle devicesRectangle = new(_devices.Select(d => d.Boundary)); Rectangle devicesRectangle = new(_devices.Select(d => d.Boundary));
Boundary = Boundary.SetSize(new Size(devicesRectangle.Location.X + devicesRectangle.Size.Width, devicesRectangle.Location.Y + devicesRectangle.Size.Height)); Boundary = Boundary.SetSize(new Size(devicesRectangle.Location.X + devicesRectangle.Size.Width, devicesRectangle.Location.Y + devicesRectangle.Size.Height));