mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Moved from EF and SQLite to LiteDB
This commit is contained in:
1 parent
d4dd371a50
commit
66f7dc94c8
57 files changed
+379
-1279
No files matched your search
@@ -61,6 +61,9 @@
|
||||
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LiteDB, Version=4.1.4.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\LiteDB.4.1.4\lib\net40\LiteDB.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
@@ -129,6 +132,7 @@
|
||||
<Reference Include="System.Reflection.Metadata, Version=1.4.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reflection.Metadata.1.7.0-preview8.19405.3\lib\netstandard2.0\System.Reflection.Metadata.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0-preview8.19405.3\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -173,7 +177,7 @@
|
||||
<Compile Include="Plugins\Models\PluginSetting.cs" />
|
||||
<Compile Include="Plugins\Models\PluginSettings.cs" />
|
||||
<Compile Include="Models\Profile\Folder.cs" />
|
||||
<Compile Include="Models\Profile\Abstract\IProfileElement.cs" />
|
||||
<Compile Include="Models\Profile\Abstract\ProfileElement.cs" />
|
||||
<Compile Include="Models\Profile\Layer.cs" />
|
||||
<Compile Include="Models\Profile\Profile.cs" />
|
||||
<Compile Include="Ninject\CoreModule.cs" />
|
||||
|
||||
@@ -5,5 +5,6 @@ namespace Artemis.Core
|
||||
public static class Constants
|
||||
{
|
||||
public static readonly string DataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Artemis\\";
|
||||
public static readonly string ConnectionString = $"FileName={DataFolder}\\database.db;Mode=Exclusive";
|
||||
}
|
||||
}
|
||||
+25
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Abstract
|
||||
{
|
||||
@@ -35,5 +36,29 @@ namespace Artemis.Core.Models.Profile.Abstract
|
||||
/// Applies the profile element's properties to the underlying storage entity
|
||||
/// </summary>
|
||||
internal abstract void ApplyToEntity();
|
||||
|
||||
public List<Folder> GetAllFolders()
|
||||
{
|
||||
var folders = new List<Folder>();
|
||||
foreach (var childFolder in Children.Where(c => c is Folder).Cast<Folder>())
|
||||
{
|
||||
folders.Add(childFolder);
|
||||
folders.AddRange(childFolder.GetAllFolders());
|
||||
}
|
||||
|
||||
return folders;
|
||||
}
|
||||
|
||||
public List<Layer> GetAllLayers()
|
||||
{
|
||||
var folders = new List<Layer>();
|
||||
foreach (var childLayer in Children.Where(c => c is Layer).Cast<Layer>())
|
||||
{
|
||||
folders.Add(childLayer);
|
||||
folders.AddRange(childLayer.GetAllLayers());
|
||||
}
|
||||
|
||||
return folders;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
@@ -11,7 +13,7 @@ namespace Artemis.Core.Models.Profile
|
||||
public Folder(Profile profile, Folder folder, string name)
|
||||
{
|
||||
FolderEntity = new FolderEntity();
|
||||
Guid = System.Guid.NewGuid().ToString();
|
||||
EntityId = Guid.NewGuid();
|
||||
|
||||
Profile = profile;
|
||||
ParentFolder = folder;
|
||||
@@ -22,22 +24,22 @@ namespace Artemis.Core.Models.Profile
|
||||
public Folder(Profile profile, Folder folder, FolderEntity folderEntity, IPluginService pluginService)
|
||||
{
|
||||
FolderEntity = folderEntity;
|
||||
Guid = folderEntity.Guid;
|
||||
EntityId = folderEntity.Id;
|
||||
|
||||
Profile = profile;
|
||||
ParentFolder = folder;
|
||||
Children = new List<ProfileElement>();
|
||||
|
||||
// Load child folders
|
||||
foreach (var childFolder in folderEntity.Folders)
|
||||
foreach (var childFolder in Profile.ProfileEntity.Folders.Where(f => f.ParentId == EntityId))
|
||||
folder.Children.Add(new Folder(profile, this, childFolder, pluginService));
|
||||
// Load child layers
|
||||
foreach (var childLayer in folderEntity.Layers)
|
||||
foreach (var childLayer in Profile.ProfileEntity.Layers.Where(f => f.ParentId == EntityId))
|
||||
folder.Children.Add(new Layer(profile, this, childLayer, pluginService));
|
||||
}
|
||||
|
||||
internal FolderEntity FolderEntity { get; set; }
|
||||
internal string Guid { get; set; }
|
||||
internal Guid EntityId { get; set; }
|
||||
|
||||
public Profile Profile { get; }
|
||||
public Folder ParentFolder { get; }
|
||||
@@ -59,25 +61,15 @@ namespace Artemis.Core.Models.Profile
|
||||
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
FolderEntity.Guid = Guid;
|
||||
FolderEntity.Id = EntityId;
|
||||
FolderEntity.ParentId = ParentFolder?.EntityId ?? new Guid();
|
||||
|
||||
FolderEntity.Order = Order;
|
||||
FolderEntity.Name = Name;
|
||||
|
||||
foreach (var profileElement in Children)
|
||||
{
|
||||
profileElement.ApplyToEntity();
|
||||
// Add missing children
|
||||
if (profileElement is Folder folder)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else if (profileElement is Layer layer)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
FolderEntity.ProfileId = Profile.EntityId;
|
||||
|
||||
// Remove extra childen
|
||||
}
|
||||
// TODO: conditions
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
@@ -14,7 +13,7 @@ namespace Artemis.Core.Models.Profile
|
||||
internal Layer(Profile profile, Folder folder, string name)
|
||||
{
|
||||
LayerEntity = new LayerEntity();
|
||||
Guid = System.Guid.NewGuid().ToString();
|
||||
EntityId = Guid.NewGuid();
|
||||
|
||||
Profile = profile;
|
||||
ParentFolder = folder;
|
||||
@@ -24,15 +23,15 @@ namespace Artemis.Core.Models.Profile
|
||||
internal Layer(Profile profile, Folder folder, LayerEntity layerEntity, IPluginService pluginService)
|
||||
{
|
||||
LayerEntity = layerEntity;
|
||||
Guid = layerEntity.Guid;
|
||||
EntityId = layerEntity.Id;
|
||||
|
||||
Profile = profile;
|
||||
ParentFolder = folder;
|
||||
LayerType = pluginService.GetLayerTypeByGuid(System.Guid.Parse(layerEntity.LayerTypeGuid));
|
||||
LayerType = pluginService.GetLayerTypeByGuid(layerEntity.LayerTypeGuid);
|
||||
}
|
||||
|
||||
internal LayerEntity LayerEntity { get; set; }
|
||||
internal string Guid { get; set; }
|
||||
internal Guid EntityId { get; set; }
|
||||
|
||||
public Profile Profile { get; }
|
||||
public Folder ParentFolder { get; }
|
||||
@@ -64,12 +63,16 @@ namespace Artemis.Core.Models.Profile
|
||||
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
LayerEntity.Guid = Guid;
|
||||
LayerEntity.Id = EntityId;
|
||||
LayerEntity.ParentId = ParentFolder?.EntityId ?? new Guid();
|
||||
LayerEntity.LayerTypeGuid = LayerType?.PluginInfo.Guid ?? new Guid();
|
||||
|
||||
LayerEntity.Order = Order;
|
||||
LayerEntity.Name = Name;
|
||||
LayerEntity.LayerTypeGuid = LayerType?.PluginInfo.Guid.ToString();
|
||||
|
||||
// TODO: Settings
|
||||
LayerEntity.ProfileId = Profile.EntityId;
|
||||
|
||||
// TODO: LEDs, conditions, elements
|
||||
}
|
||||
|
||||
public void UpdateLayerType(LayerType layerType)
|
||||
|
||||
@@ -6,7 +6,7 @@ using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Profile.Abstract;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
@@ -14,8 +14,8 @@ namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
internal Profile(PluginInfo pluginInfo, string name)
|
||||
{
|
||||
ProfileEntity = new ProfileEntity {RootFolder = new FolderEntity()};
|
||||
Guid = System.Guid.NewGuid().ToString();
|
||||
ProfileEntity = new ProfileEntity();
|
||||
EntityId = Guid.NewGuid();
|
||||
|
||||
PluginInfo = pluginInfo;
|
||||
Name = name;
|
||||
@@ -26,20 +26,24 @@ namespace Artemis.Core.Models.Profile
|
||||
internal Profile(PluginInfo pluginInfo, ProfileEntity profileEntity, IPluginService pluginService)
|
||||
{
|
||||
ProfileEntity = profileEntity;
|
||||
Guid = profileEntity.Guid;
|
||||
EntityId = profileEntity.Id;
|
||||
|
||||
PluginInfo = pluginInfo;
|
||||
Name = profileEntity.Name;
|
||||
|
||||
// Populate the profile starting at the root, the rest is populated recursively
|
||||
Children = new List<ProfileElement> {new Folder(this, null, profileEntity.RootFolder, pluginService)};
|
||||
var rootFolder = profileEntity.Folders.FirstOrDefault(f => f.ParentId == new Guid());
|
||||
if (rootFolder == null)
|
||||
Children = new List<ProfileElement> {new Folder(this, null, "Root folder")};
|
||||
else
|
||||
Children = new List<ProfileElement> {new Folder(this, null, rootFolder, pluginService)};
|
||||
}
|
||||
|
||||
public PluginInfo PluginInfo { get; }
|
||||
public bool IsActivated { get; private set; }
|
||||
|
||||
internal ProfileEntity ProfileEntity { get; set; }
|
||||
internal string Guid { get; set; }
|
||||
public Guid EntityId { get; set; }
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
@@ -67,13 +71,22 @@ namespace Artemis.Core.Models.Profile
|
||||
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
ProfileEntity.Guid = Guid;
|
||||
ProfileEntity.Id = EntityId;
|
||||
ProfileEntity.PluginGuid = PluginInfo.Guid;
|
||||
ProfileEntity.Name = Name;
|
||||
ProfileEntity.IsActive = IsActivated;
|
||||
|
||||
var rootFolder = Children.Single();
|
||||
foreach (var profileElement in Children)
|
||||
profileElement.ApplyToEntity();
|
||||
|
||||
ProfileEntity.Folders.Clear();
|
||||
ProfileEntity.Folders.AddRange(GetAllFolders().Select(f => f.FolderEntity));
|
||||
|
||||
ProfileEntity.Layers.Clear();
|
||||
ProfileEntity.Layers.AddRange(GetAllLayers().Select(f => f.LayerEntity));
|
||||
}
|
||||
|
||||
|
||||
internal void Activate()
|
||||
{
|
||||
lock (this)
|
||||
@@ -95,7 +108,7 @@ namespace Artemis.Core.Models.Profile
|
||||
OnDeactivated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{nameof(Order)}: {Order}, {nameof(Name)}: {Name}, {nameof(PluginInfo)}: {PluginInfo}";
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -3,6 +3,7 @@ using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using LiteDB;
|
||||
using Ninject.Activation;
|
||||
using Ninject.Extensions.Conventions;
|
||||
using Ninject.Modules;
|
||||
@@ -37,6 +38,8 @@ namespace Artemis.Core.Ninject
|
||||
.Configure(c => c.When(HasAccessToProtectedService).InSingletonScope());
|
||||
});
|
||||
|
||||
Kernel.Bind<LiteRepository>().ToMethod(t => new LiteRepository(Constants.ConnectionString)).InSingletonScope();
|
||||
|
||||
// Bind all repositories as singletons
|
||||
Kernel.Bind(x =>
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Storage.Entities;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Newtonsoft.Json;
|
||||
@@ -71,20 +70,7 @@ namespace Artemis.Core.Plugins.Models
|
||||
return;
|
||||
|
||||
_pluginSettingEntity.Value = JsonConvert.SerializeObject(Value);
|
||||
_pluginSettingRepository.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the setting asynchronously
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task SaveAsync()
|
||||
{
|
||||
if (!HasChanged)
|
||||
return;
|
||||
|
||||
_pluginSettingEntity.Value = JsonConvert.SerializeObject(Value);
|
||||
await _pluginSettingRepository.SaveAsync();
|
||||
_pluginSettingRepository.Save(_pluginSettingEntity);
|
||||
}
|
||||
|
||||
public event EventHandler<EventArgs> SettingChanged;
|
||||
|
||||
@@ -43,7 +43,6 @@ namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
settingEntity = new PluginSettingEntity {Name = name, PluginGuid = _pluginInfo.Guid, Value = JsonConvert.SerializeObject(defaultValue)};
|
||||
_pluginSettingRepository.Add(settingEntity);
|
||||
_pluginSettingRepository.Save();
|
||||
}
|
||||
|
||||
var pluginSetting = new PluginSetting<T>(_pluginInfo, _pluginSettingRepository, settingEntity);
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
var surfaceConfig = _surfaceService.ActiveSurface;
|
||||
if (surfaceConfig != null)
|
||||
_logger.Information("Initialized with active surface entity {surfaceConfig}-{guid}", surfaceConfig.Name, surfaceConfig.Guid);
|
||||
_logger.Information("Initialized with active surface entity {surfaceConfig}-{guid}", surfaceConfig.Name, surfaceConfig.EntityId);
|
||||
else
|
||||
_logger.Information("Initialized without an active surface entity");
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
@@ -8,7 +7,7 @@ namespace Artemis.Core.Services.Storage.Interfaces
|
||||
{
|
||||
public interface IProfileService : IArtemisService
|
||||
{
|
||||
Task<ICollection<Profile>> GetProfiles(ProfileModule module);
|
||||
Task<Profile> GetActiveProfile(ProfileModule module);
|
||||
List<Profile> GetProfiles(ProfileModule module);
|
||||
Profile GetActiveProfile(ProfileModule module);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.Storage.Repositories;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
@@ -14,17 +16,17 @@ namespace Artemis.Core.Services.Storage
|
||||
public class ProfileService : IProfileService
|
||||
{
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly ProfileRepository _profileRepository;
|
||||
private readonly IProfileRepository _profileRepository;
|
||||
|
||||
internal ProfileService(IPluginService pluginService)
|
||||
internal ProfileService(IPluginService pluginService, IProfileRepository profileRepository)
|
||||
{
|
||||
_pluginService = pluginService;
|
||||
_profileRepository = new ProfileRepository();
|
||||
_profileRepository = profileRepository;
|
||||
}
|
||||
|
||||
public async Task<ICollection<Profile>> GetProfiles(ProfileModule module)
|
||||
public List<Profile> GetProfiles(ProfileModule module)
|
||||
{
|
||||
var profileEntities = await _profileRepository.GetByPluginGuidAsync(module.PluginInfo.Guid);
|
||||
var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid);
|
||||
var profiles = new List<Profile>();
|
||||
foreach (var profileEntity in profileEntities)
|
||||
profiles.Add(new Profile(module.PluginInfo, profileEntity, _pluginService));
|
||||
@@ -32,23 +34,23 @@ namespace Artemis.Core.Services.Storage
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public async Task<Profile> GetActiveProfile(ProfileModule module)
|
||||
public Profile GetActiveProfile(ProfileModule module)
|
||||
{
|
||||
var profileEntity = await _profileRepository.GetActiveProfileByPluginGuidAsync(module.PluginInfo.Guid);
|
||||
var profileEntity = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid).FirstOrDefault(p => p.IsActive);
|
||||
if (profileEntity == null)
|
||||
return null;
|
||||
|
||||
return new Profile(module.PluginInfo, profileEntity, _pluginService);
|
||||
}
|
||||
|
||||
public async Task<Profile> CreateProfile(ProfileModule module, string name)
|
||||
public Profile CreateProfile(ProfileModule module, string name)
|
||||
{
|
||||
var profile = new Profile(module.PluginInfo, name);
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
public async Task UpdateProfile(Profile profile, bool includeChildren)
|
||||
public void UpdateProfile(Profile profile, bool includeChildren)
|
||||
{
|
||||
profile.ApplyToEntity();
|
||||
if (includeChildren)
|
||||
|
||||
@@ -57,6 +57,8 @@ namespace Artemis.Core.Services.Storage
|
||||
lock (_surfaceConfigurations)
|
||||
{
|
||||
_surfaceRepository.Add(configuration.SurfaceEntity);
|
||||
_surfaceConfigurations.Add(configuration);
|
||||
|
||||
UpdateSurfaceConfiguration(configuration, true);
|
||||
return configuration;
|
||||
}
|
||||
@@ -78,9 +80,9 @@ namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
configuration.IsActive = configuration == ActiveSurface;
|
||||
configuration.ApplyToEntity();
|
||||
}
|
||||
|
||||
_surfaceRepository.Save();
|
||||
_surfaceRepository.Save(configuration.SurfaceEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the active surface entity to the devices
|
||||
@@ -102,13 +104,13 @@ namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
foreach (var deviceConfiguration in surface.Devices)
|
||||
{
|
||||
deviceConfiguration.ApplyToConfiguration();
|
||||
deviceConfiguration.ApplyToEntity();
|
||||
if (surface.IsActive)
|
||||
deviceConfiguration.ApplyToRgbDevice();
|
||||
}
|
||||
}
|
||||
|
||||
_surfaceRepository.Save();
|
||||
_surfaceRepository.Save(surface.SurfaceEntity);
|
||||
_rgbService.UpdateGraphicsDecorator();
|
||||
OnSurfaceConfigurationUpdated(new SurfaceConfigurationEventArgs(surface));
|
||||
}
|
||||
@@ -122,10 +124,9 @@ namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
var entity = surface.SurfaceEntity;
|
||||
surface.Destroy();
|
||||
_surfaceConfigurations.Remove(surface);
|
||||
|
||||
_surfaceConfigurations.Remove(surface);
|
||||
_surfaceRepository.Remove(entity);
|
||||
_surfaceRepository.Save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +177,7 @@ namespace Artemis.Core.Services.Storage
|
||||
private void AddDeviceIfMissing(IRGBDevice rgbDevice, Surface surface)
|
||||
{
|
||||
var deviceHashCode = rgbDevice.GetDeviceHashCode();
|
||||
var device = surface.Devices.FirstOrDefault(d => d.Configuration.DeviceHashCode == deviceHashCode);
|
||||
var device = surface.Devices.FirstOrDefault(d => d.DeviceEntity.DeviceHashCode == deviceHashCode);
|
||||
|
||||
if (device != null)
|
||||
return;
|
||||
|
||||
@@ -28,8 +28,7 @@
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a"
|
||||
culture="neutral" />
|
||||
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
@@ -53,8 +52,7 @@
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Scripting" publicKeyToken="31bf3856ad364e35"
|
||||
culture="neutral" />
|
||||
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Scripting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
@@ -70,8 +68,7 @@
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a"
|
||||
culture="neutral" />
|
||||
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
@@ -87,8 +84,7 @@
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a"
|
||||
culture="neutral" />
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
@@ -96,8 +92,7 @@
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51"
|
||||
culture="neutral" />
|
||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.1" newVersion="4.0.3.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="AppDomainToolkit" version="1.0.4.3" targetFramework="net461" />
|
||||
<package id="Ben.Demystifier" version="0.1.4" targetFramework="net472" />
|
||||
<package id="Castle.Core" version="4.4.0" targetFramework="net461" />
|
||||
<package id="LiteDB" version="4.1.4" targetFramework="net472" />
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net472" />
|
||||
<package id="Ninject" version="3.3.4" targetFramework="net461" />
|
||||
<package id="Ninject.Extensions.ChildKernel" version="3.3.0" targetFramework="net461" />
|
||||
|
||||
Reference in new issue
Block a user