mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Moved from EF and SQLite to LiteDB
This commit is contained in:
1 parent
296414001b
commit
2fb2e5444c
57 files changed
+379
-1279
No files matched your search
@@ -4,7 +4,7 @@ using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Storage.Entities;
|
||||
using Artemis.Storage.Entities.Surface;
|
||||
using RGB.NET.Core;
|
||||
using Rectangle = System.Drawing.Rectangle;
|
||||
|
||||
@@ -17,26 +17,23 @@ namespace Artemis.Core.Models.Surface
|
||||
RgbDevice = rgbDevice;
|
||||
Plugin = plugin;
|
||||
Surface = surface;
|
||||
Configuration = new DeviceEntity();
|
||||
DeviceEntity = new DeviceEntity();
|
||||
Leds = rgbDevice.Select(l => new DeviceLed(l, this)).ToList().AsReadOnly();
|
||||
|
||||
Rotation = 0;
|
||||
ZIndex = 1;
|
||||
|
||||
ApplyToConfiguration();
|
||||
ApplyToEntity();
|
||||
CalculateRenderRectangle();
|
||||
}
|
||||
|
||||
internal Device(IRGBDevice rgbDevice, Plugin plugin, Surface surface, DeviceEntity configuration)
|
||||
internal Device(IRGBDevice rgbDevice, Plugin plugin, Surface surface, DeviceEntity deviceEntity)
|
||||
{
|
||||
RgbDevice = rgbDevice;
|
||||
Plugin = plugin;
|
||||
Surface = surface;
|
||||
Configuration = configuration;
|
||||
DeviceEntity = deviceEntity;
|
||||
Leds = rgbDevice.Select(l => new DeviceLed(l, this)).ToList().AsReadOnly();
|
||||
|
||||
Rotation = configuration.Rotation;
|
||||
ZIndex = configuration.ZIndex;
|
||||
}
|
||||
|
||||
public Rectangle RenderRectangle { get; private set; }
|
||||
@@ -45,46 +42,43 @@ namespace Artemis.Core.Models.Surface
|
||||
public IRGBDevice RgbDevice { get; private set; }
|
||||
public Plugin Plugin { get; }
|
||||
public Surface Surface { get; private set; }
|
||||
public DeviceEntity Configuration { get; private set; }
|
||||
public DeviceEntity DeviceEntity { get; private set; }
|
||||
public ReadOnlyCollection<DeviceLed> Leds { get; set; }
|
||||
|
||||
public double X
|
||||
{
|
||||
get => Configuration.X;
|
||||
set => Configuration.X = value;
|
||||
get => DeviceEntity.X;
|
||||
set => DeviceEntity.X = value;
|
||||
}
|
||||
|
||||
public double Y
|
||||
{
|
||||
get => Configuration.Y;
|
||||
set => Configuration.Y = value;
|
||||
get => DeviceEntity.Y;
|
||||
set => DeviceEntity.Y = value;
|
||||
}
|
||||
|
||||
public double Rotation
|
||||
{
|
||||
get => Configuration.Rotation;
|
||||
set => Configuration.Rotation = value;
|
||||
get => DeviceEntity.Rotation;
|
||||
set => DeviceEntity.Rotation = value;
|
||||
}
|
||||
|
||||
public int ZIndex
|
||||
{
|
||||
get => Configuration.ZIndex;
|
||||
set => Configuration.ZIndex = value;
|
||||
get => DeviceEntity.ZIndex;
|
||||
set => DeviceEntity.ZIndex = value;
|
||||
}
|
||||
|
||||
internal void ApplyToConfiguration()
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
Configuration.SurfaceId = Surface.Guid;
|
||||
Configuration.DeviceHashCode = RgbDevice.GetDeviceHashCode();
|
||||
// Other properties are mapped computed
|
||||
|
||||
// Ensure the position configuration is in the surface configuration's' collection of positions
|
||||
if (Surface.SurfaceEntity.DeviceEntities.All(p => p.Guid != Configuration.Guid))
|
||||
Surface.SurfaceEntity.DeviceEntities.Add(Configuration);
|
||||
DeviceEntity.DeviceHashCode = RgbDevice.GetDeviceHashCode();
|
||||
}
|
||||
|
||||
internal void ApplyToRgbDevice()
|
||||
{
|
||||
RgbDevice.Location = new Point(Configuration.X, Configuration.Y);
|
||||
RgbDevice.Location = new Point(DeviceEntity.X, DeviceEntity.Y);
|
||||
CalculateRenderRectangle();
|
||||
}
|
||||
|
||||
@@ -110,7 +104,7 @@ namespace Artemis.Core.Models.Surface
|
||||
|
||||
internal void Destroy()
|
||||
{
|
||||
Configuration = null;
|
||||
DeviceEntity = null;
|
||||
RgbDevice = null;
|
||||
Surface = null;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Storage.Entities;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Surface;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
@@ -10,12 +11,14 @@ namespace Artemis.Core.Models.Surface
|
||||
internal Surface(RGBSurface rgbSurface, string name, double scale)
|
||||
{
|
||||
SurfaceEntity = new SurfaceEntity {DeviceEntities = new List<DeviceEntity>()};
|
||||
Guid = System.Guid.NewGuid().ToString();
|
||||
EntityId = Guid.NewGuid();
|
||||
|
||||
Name = name;
|
||||
Scale = scale;
|
||||
RgbSurface = rgbSurface;
|
||||
IsActive = false;
|
||||
|
||||
// Devices are not populated here but as they are detected
|
||||
Devices = new List<Device>();
|
||||
|
||||
ApplyToEntity();
|
||||
@@ -24,13 +27,15 @@ namespace Artemis.Core.Models.Surface
|
||||
internal Surface(RGBSurface rgbSurface, SurfaceEntity surfaceEntity, double scale)
|
||||
{
|
||||
SurfaceEntity = surfaceEntity;
|
||||
Guid = surfaceEntity.Guid;
|
||||
EntityId = surfaceEntity.Id;
|
||||
|
||||
RgbSurface = rgbSurface;
|
||||
Scale = scale;
|
||||
Name = surfaceEntity.Name;
|
||||
IsActive = surfaceEntity.IsActive;
|
||||
Devices = new List<Device>();
|
||||
|
||||
// Devices are not populated here but as they are detected
|
||||
Devices = new List<Device>();
|
||||
}
|
||||
|
||||
public RGBSurface RgbSurface { get; }
|
||||
@@ -40,13 +45,20 @@ namespace Artemis.Core.Models.Surface
|
||||
public List<Device> Devices { get; internal set; }
|
||||
|
||||
internal SurfaceEntity SurfaceEntity { get; set; }
|
||||
internal string Guid { get; set; }
|
||||
internal Guid EntityId { get; set; }
|
||||
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
SurfaceEntity.Guid = Guid;
|
||||
SurfaceEntity.Id = EntityId;
|
||||
SurfaceEntity.Name = Name;
|
||||
SurfaceEntity.IsActive = IsActive;
|
||||
|
||||
// Add missing device entities, don't remove old ones in case they come back later
|
||||
foreach (var deviceEntity in Devices.Select(d => d.DeviceEntity).ToList())
|
||||
{
|
||||
if (!SurfaceEntity.DeviceEntities.Contains(deviceEntity))
|
||||
SurfaceEntity.DeviceEntities.Add(deviceEntity);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Destroy()
|
||||
|
||||
Reference in new issue
Block a user