mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Fully implemented the surface service which contains all storage logic
This commit is contained in:
1 parent
4e2afad268
commit
91cd23dadf
8 files changed
+284
-117
No files matched your search
@@ -1,19 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
public class SurfaceConfiguration
|
||||
{
|
||||
internal SurfaceConfiguration()
|
||||
internal SurfaceConfiguration(string name)
|
||||
{
|
||||
SurfaceEntity = new SurfaceEntity();
|
||||
Guid = System.Guid.NewGuid().ToString();
|
||||
|
||||
Name = name;
|
||||
IsActive = false;
|
||||
DeviceConfigurations = new List<SurfaceDeviceConfiguration>();
|
||||
|
||||
ApplyToEntity();
|
||||
}
|
||||
|
||||
internal SurfaceConfiguration(SurfaceEntity surfaceEntity)
|
||||
{
|
||||
SurfaceEntity = surfaceEntity;
|
||||
Guid = surfaceEntity.Guid;
|
||||
|
||||
Name = surfaceEntity.Name;
|
||||
IsActive = surfaceEntity.IsActive;
|
||||
DeviceConfigurations = new List<SurfaceDeviceConfiguration>();
|
||||
@@ -24,9 +32,27 @@ namespace Artemis.Core.Models.Surface
|
||||
DeviceConfigurations.Add(new SurfaceDeviceConfiguration(position, this));
|
||||
}
|
||||
|
||||
internal SurfaceEntity SurfaceEntity { get; set; }
|
||||
internal string Guid { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public bool IsActive { get; internal set; }
|
||||
public List<SurfaceDeviceConfiguration> DeviceConfigurations { get; internal set; }
|
||||
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
SurfaceEntity.Guid = Guid;
|
||||
SurfaceEntity.Name = Name;
|
||||
SurfaceEntity.IsActive = IsActive;
|
||||
}
|
||||
|
||||
internal void Destroy()
|
||||
{
|
||||
SurfaceEntity = null;
|
||||
|
||||
foreach (var deviceConfiguration in DeviceConfigurations)
|
||||
deviceConfiguration.Destroy();
|
||||
DeviceConfigurations.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,102 @@
|
||||
using Artemis.Storage.Entities;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Models.Surface
|
||||
{
|
||||
public class SurfaceDeviceConfiguration
|
||||
{
|
||||
internal SurfaceDeviceConfiguration(int deviceId, IRGBDeviceInfo deviceInfo, SurfaceConfiguration surface)
|
||||
internal SurfaceDeviceConfiguration(IRGBDevice device, int deviceId, SurfaceConfiguration surface)
|
||||
{
|
||||
PositionEntity = new SurfacePositionEntity();
|
||||
Guid = System.Guid.NewGuid().ToString();
|
||||
|
||||
Device = device;
|
||||
DeviceId = deviceId;
|
||||
DeviceName = deviceInfo.DeviceName;
|
||||
DeviceModel = deviceInfo.Model;
|
||||
DeviceManufacturer = deviceInfo.Manufacturer;
|
||||
DeviceName = device.DeviceInfo.DeviceName;
|
||||
DeviceModel = device.DeviceInfo.Model;
|
||||
DeviceManufacturer = device.DeviceInfo.Manufacturer;
|
||||
|
||||
X = device.Location.X;
|
||||
Y = device.Location.Y;
|
||||
Rotation = 0;
|
||||
ZIndex = 1;
|
||||
|
||||
Surface = surface;
|
||||
|
||||
ApplyToEntity();
|
||||
}
|
||||
|
||||
internal SurfaceDeviceConfiguration(SurfacePositionEntity position, SurfaceConfiguration surfaceConfiguration)
|
||||
internal SurfaceDeviceConfiguration(SurfacePositionEntity positionEntity, SurfaceConfiguration surfaceConfiguration)
|
||||
{
|
||||
Guid = position.Guid;
|
||||
PositionEntity = positionEntity;
|
||||
Guid = positionEntity.Guid;
|
||||
|
||||
DeviceId = position.DeviceId;
|
||||
DeviceName = position.DeviceName;
|
||||
DeviceModel = position.DeviceModel;
|
||||
DeviceManufacturer = position.DeviceManufacturer;
|
||||
DeviceId = positionEntity.DeviceId;
|
||||
DeviceName = positionEntity.DeviceName;
|
||||
DeviceModel = positionEntity.DeviceModel;
|
||||
DeviceManufacturer = positionEntity.DeviceManufacturer;
|
||||
|
||||
X = position.X;
|
||||
Y = position.Y;
|
||||
Rotation = position.Rotation;
|
||||
ZIndex = position.ZIndex;
|
||||
X = positionEntity.X;
|
||||
Y = positionEntity.Y;
|
||||
Rotation = positionEntity.Rotation;
|
||||
ZIndex = positionEntity.ZIndex;
|
||||
|
||||
Surface = surfaceConfiguration;
|
||||
}
|
||||
|
||||
internal string Guid { get; set; }
|
||||
|
||||
public int DeviceId { get; set; }
|
||||
public string DeviceName { get; set; }
|
||||
public string DeviceModel { get; set; }
|
||||
public string DeviceManufacturer { get; set; }
|
||||
internal SurfacePositionEntity PositionEntity { get; set; }
|
||||
internal string Guid { get; }
|
||||
|
||||
public IRGBDevice Device { get; private set; }
|
||||
public int DeviceId { get; }
|
||||
public string DeviceName { get; }
|
||||
public string DeviceModel { get; }
|
||||
public string DeviceManufacturer { get; }
|
||||
|
||||
public double X { get; set; }
|
||||
public double Y { get; set; }
|
||||
public double Rotation { get; set; }
|
||||
public int ZIndex { get; set; }
|
||||
|
||||
public SurfaceConfiguration Surface { get; internal set; }
|
||||
public SurfaceConfiguration Surface { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Applies the configuration to the device
|
||||
/// </summary>
|
||||
public void ApplyToDevice()
|
||||
{
|
||||
Device.Location = new Point(X, Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Must be called when saving to the database
|
||||
/// </summary>
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
PositionEntity.Guid = Guid;
|
||||
PositionEntity.SurfaceId = Surface.Guid;
|
||||
|
||||
PositionEntity.DeviceId = DeviceId;
|
||||
PositionEntity.DeviceName = DeviceName;
|
||||
PositionEntity.DeviceModel = DeviceModel;
|
||||
PositionEntity.DeviceManufacturer = DeviceManufacturer;
|
||||
|
||||
PositionEntity.X = X;
|
||||
PositionEntity.Y = Y;
|
||||
PositionEntity.Rotation = Rotation;
|
||||
PositionEntity.ZIndex = ZIndex;
|
||||
|
||||
// Ensure the position entity is in the surface entity's' collection of positions
|
||||
if (Surface.SurfaceEntity.SurfacePositions.All(p => p.Guid != Guid))
|
||||
Surface.SurfaceEntity.SurfacePositions.Add(PositionEntity);
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
PositionEntity = null;
|
||||
Device = null;
|
||||
Surface = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user