diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index 7a774b98b..451d434f7 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -61,6 +61,9 @@ ..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll + + ..\packages\LiteDB.4.1.4\lib\net40\LiteDB.dll + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll @@ -129,6 +132,7 @@ ..\packages\System.Reflection.Metadata.1.7.0-preview8.19405.3\lib\netstandard2.0\System.Reflection.Metadata.dll + ..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0-preview8.19405.3\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll @@ -173,7 +177,7 @@ - + diff --git a/src/Artemis.Core/Constants.cs b/src/Artemis.Core/Constants.cs index ad65affd1..6f55fa4d1 100644 --- a/src/Artemis.Core/Constants.cs +++ b/src/Artemis.Core/Constants.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"; } } \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/Abstract/IProfileElement.cs b/src/Artemis.Core/Models/Profile/Abstract/ProfileElement.cs similarity index 61% rename from src/Artemis.Core/Models/Profile/Abstract/IProfileElement.cs rename to src/Artemis.Core/Models/Profile/Abstract/ProfileElement.cs index 963ce31a8..ac41df902 100644 --- a/src/Artemis.Core/Models/Profile/Abstract/IProfileElement.cs +++ b/src/Artemis.Core/Models/Profile/Abstract/ProfileElement.cs @@ -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 /// internal abstract void ApplyToEntity(); + + public List GetAllFolders() + { + var folders = new List(); + foreach (var childFolder in Children.Where(c => c is Folder).Cast()) + { + folders.Add(childFolder); + folders.AddRange(childFolder.GetAllFolders()); + } + + return folders; + } + + public List GetAllLayers() + { + var folders = new List(); + foreach (var childLayer in Children.Where(c => c is Layer).Cast()) + { + folders.Add(childLayer); + folders.AddRange(childLayer.GetAllLayers()); + } + + return folders; + } } } \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/Folder.cs b/src/Artemis.Core/Models/Profile/Folder.cs index c90dd1a05..7b57b90e5 100644 --- a/src/Artemis.Core/Models/Profile/Folder.cs +++ b/src/Artemis.Core/Models/Profile/Folder.cs @@ -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(); // 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() diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 7bea7cb2c..b1f5b3380 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -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) diff --git a/src/Artemis.Core/Models/Profile/Profile.cs b/src/Artemis.Core/Models/Profile/Profile.cs index 27af026da..9569b2372 100644 --- a/src/Artemis.Core/Models/Profile/Profile.cs +++ b/src/Artemis.Core/Models/Profile/Profile.cs @@ -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 {new Folder(this, null, profileEntity.RootFolder, pluginService)}; + var rootFolder = profileEntity.Folders.FirstOrDefault(f => f.ParentId == new Guid()); + if (rootFolder == null) + Children = new List {new Folder(this, null, "Root folder")}; + else + Children = new List {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}"; diff --git a/src/Artemis.Core/Models/Surface/Device.cs b/src/Artemis.Core/Models/Surface/Device.cs index 0977939ca..00d6ca386 100644 --- a/src/Artemis.Core/Models/Surface/Device.cs +++ b/src/Artemis.Core/Models/Surface/Device.cs @@ -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 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; } diff --git a/src/Artemis.Core/Models/Surface/Surface.cs b/src/Artemis.Core/Models/Surface/Surface.cs index 19a14327c..035275c5e 100644 --- a/src/Artemis.Core/Models/Surface/Surface.cs +++ b/src/Artemis.Core/Models/Surface/Surface.cs @@ -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()}; - 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(); 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(); + + // Devices are not populated here but as they are detected + Devices = new List(); } public RGBSurface RgbSurface { get; } @@ -40,13 +45,20 @@ namespace Artemis.Core.Models.Surface public List 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() diff --git a/src/Artemis.Core/Ninject/CoreModule.cs b/src/Artemis.Core/Ninject/CoreModule.cs index fcdbf289c..521866a3c 100644 --- a/src/Artemis.Core/Ninject/CoreModule.cs +++ b/src/Artemis.Core/Ninject/CoreModule.cs @@ -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().ToMethod(t => new LiteRepository(Constants.ConnectionString)).InSingletonScope(); + // Bind all repositories as singletons Kernel.Bind(x => { diff --git a/src/Artemis.Core/Plugins/Models/PluginSetting.cs b/src/Artemis.Core/Plugins/Models/PluginSetting.cs index a532559b2..8f64bc71b 100644 --- a/src/Artemis.Core/Plugins/Models/PluginSetting.cs +++ b/src/Artemis.Core/Plugins/Models/PluginSetting.cs @@ -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(); - } - - /// - /// Saves the setting asynchronously - /// - /// - public async Task SaveAsync() - { - if (!HasChanged) - return; - - _pluginSettingEntity.Value = JsonConvert.SerializeObject(Value); - await _pluginSettingRepository.SaveAsync(); + _pluginSettingRepository.Save(_pluginSettingEntity); } public event EventHandler SettingChanged; diff --git a/src/Artemis.Core/Plugins/Models/PluginSettings.cs b/src/Artemis.Core/Plugins/Models/PluginSettings.cs index f495c9e08..8c1851f35 100644 --- a/src/Artemis.Core/Plugins/Models/PluginSettings.cs +++ b/src/Artemis.Core/Plugins/Models/PluginSettings.cs @@ -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(_pluginInfo, _pluginSettingRepository, settingEntity); diff --git a/src/Artemis.Core/Services/CoreService.cs b/src/Artemis.Core/Services/CoreService.cs index 2e1bdd5ac..6094f49d2 100644 --- a/src/Artemis.Core/Services/CoreService.cs +++ b/src/Artemis.Core/Services/CoreService.cs @@ -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"); diff --git a/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs b/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs index 65db1b113..a40aa2666 100644 --- a/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs +++ b/src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs @@ -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> GetProfiles(ProfileModule module); - Task GetActiveProfile(ProfileModule module); + List GetProfiles(ProfileModule module); + Profile GetActiveProfile(ProfileModule module); } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs index a95c0e945..54d42d150 100644 --- a/src/Artemis.Core/Services/Storage/ProfileService.cs +++ b/src/Artemis.Core/Services/Storage/ProfileService.cs @@ -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> GetProfiles(ProfileModule module) + public List GetProfiles(ProfileModule module) { - var profileEntities = await _profileRepository.GetByPluginGuidAsync(module.PluginInfo.Guid); + var profileEntities = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid); var profiles = new List(); 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 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 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) diff --git a/src/Artemis.Core/Services/Storage/SurfaceService.cs b/src/Artemis.Core/Services/Storage/SurfaceService.cs index 9ab0d4c90..82ff82963 100644 --- a/src/Artemis.Core/Services/Storage/SurfaceService.cs +++ b/src/Artemis.Core/Services/Storage/SurfaceService.cs @@ -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; diff --git a/src/Artemis.Core/app.config b/src/Artemis.Core/app.config index 99b0b360c..32dcf9823 100644 --- a/src/Artemis.Core/app.config +++ b/src/Artemis.Core/app.config @@ -28,8 +28,7 @@ - + @@ -53,8 +52,7 @@ - + @@ -70,8 +68,7 @@ - + @@ -87,8 +84,7 @@ - + @@ -96,8 +92,7 @@ - + diff --git a/src/Artemis.Core/packages.config b/src/Artemis.Core/packages.config index 88478609d..f7b7e8272 100644 --- a/src/Artemis.Core/packages.config +++ b/src/Artemis.Core/packages.config @@ -1,9 +1,9 @@  - + diff --git a/src/Artemis.Plugins.Devices.Corsair/app.config b/src/Artemis.Plugins.Devices.Corsair/app.config index 9a8f47c0a..9b3e8ff8d 100644 --- a/src/Artemis.Plugins.Devices.Corsair/app.config +++ b/src/Artemis.Plugins.Devices.Corsair/app.config @@ -16,8 +16,7 @@ - + diff --git a/src/Artemis.Plugins.Devices.Logitech/Artemis.Plugins.Devices.Logitech.csproj b/src/Artemis.Plugins.Devices.Logitech/Artemis.Plugins.Devices.Logitech.csproj index 8bf88eab9..492b0902e 100644 --- a/src/Artemis.Plugins.Devices.Logitech/Artemis.Plugins.Devices.Logitech.csproj +++ b/src/Artemis.Plugins.Devices.Logitech/Artemis.Plugins.Devices.Logitech.csproj @@ -65,6 +65,7 @@ + PreserveNewest diff --git a/src/Artemis.Plugins.Devices.Logitech/app.config b/src/Artemis.Plugins.Devices.Logitech/app.config new file mode 100644 index 000000000..e995f3d3b --- /dev/null +++ b/src/Artemis.Plugins.Devices.Logitech/app.config @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.Plugins.LayerTypes.Brush/app.config b/src/Artemis.Plugins.LayerTypes.Brush/app.config index c31f9a979..0edb16ded 100644 --- a/src/Artemis.Plugins.LayerTypes.Brush/app.config +++ b/src/Artemis.Plugins.LayerTypes.Brush/app.config @@ -16,8 +16,7 @@ - + diff --git a/src/Artemis.Plugins.Modules.General/app.config b/src/Artemis.Plugins.Modules.General/app.config index c31f9a979..0edb16ded 100644 --- a/src/Artemis.Plugins.Modules.General/app.config +++ b/src/Artemis.Plugins.Modules.General/app.config @@ -16,8 +16,7 @@ - + diff --git a/src/Artemis.Storage/Artemis.Storage.csproj b/src/Artemis.Storage/Artemis.Storage.csproj index a26324489..384f835dc 100644 --- a/src/Artemis.Storage/Artemis.Storage.csproj +++ b/src/Artemis.Storage/Artemis.Storage.csproj @@ -6,12 +6,7 @@ 7 - - - - - - + diff --git a/src/Artemis.Storage/Entities/DeviceEntity.cs b/src/Artemis.Storage/Entities/DeviceEntity.cs deleted file mode 100644 index e6df74a4d..000000000 --- a/src/Artemis.Storage/Entities/DeviceEntity.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Artemis.Storage.Entities -{ - public class DeviceEntity - { - public DeviceEntity() - { - Guid = System.Guid.NewGuid().ToString(); - } - - [Key] - public string Guid { get; set; } - - public int DeviceHashCode { get; set; } - public double X { get; set; } - public double Y { get; set; } - public double Rotation { get; set; } - public int ZIndex { get; set; } - - public string SurfaceId { get; set; } - public virtual SurfaceEntity Surface { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/FolderEntity.cs b/src/Artemis.Storage/Entities/FolderEntity.cs deleted file mode 100644 index 1beb882f4..000000000 --- a/src/Artemis.Storage/Entities/FolderEntity.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Artemis.Storage.Entities -{ - [Table("Folders")] - public class FolderEntity - { - [Key] - public string Guid { get; set; } - - public int Order { get; set; } - public string Name { get; set; } - - public virtual ICollection Folders { get; set; } - public virtual ICollection Layers { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/KeypointEntity.cs b/src/Artemis.Storage/Entities/KeypointEntity.cs deleted file mode 100644 index 5ef4a7cf9..000000000 --- a/src/Artemis.Storage/Entities/KeypointEntity.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Artemis.Storage.Entities -{ - [Table("Keypoints")] - public class KeypointEntity - { - [Key] - public string Guid { get; set; } - - public int Time { get; set; } - public string Value { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/LayerEntity.cs b/src/Artemis.Storage/Entities/LayerEntity.cs deleted file mode 100644 index c91056bd5..000000000 --- a/src/Artemis.Storage/Entities/LayerEntity.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Artemis.Storage.Entities -{ - [Table("Layers")] - public class LayerEntity - { - [Key] - public string Guid { get; set; } - - public virtual ICollection Leds { get; set; } - public virtual ICollection Settings { get; set; } - - public int Order { get; set; } - public string Name { get; set; } - public string LayerTypeGuid { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/LayerSettingEntity.cs b/src/Artemis.Storage/Entities/LayerSettingEntity.cs deleted file mode 100644 index 250da711f..000000000 --- a/src/Artemis.Storage/Entities/LayerSettingEntity.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Artemis.Storage.Entities -{ - [Table("LayerSettings")] - public class LayerSettingEntity - { - [Key] - public string Guid { get; set; } - - public string Name { get; set; } - public string Value { get; set; } - - public ICollection Keypoints { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/LedEntity.cs b/src/Artemis.Storage/Entities/LedEntity.cs deleted file mode 100644 index 69886bb32..000000000 --- a/src/Artemis.Storage/Entities/LedEntity.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Artemis.Storage.Entities -{ - [Table("Leds")] - public class LedEntity - { - [Key] - public string Guid { get; set; } - - public string LedName { get; set; } - public string LimitedToDevice { get; set; } - - public string LayerId { get; set; } - public virtual LayerEntity Layer { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/PluginSettingEntity.cs b/src/Artemis.Storage/Entities/PluginSettingEntity.cs index ba73fd031..7b63df153 100644 --- a/src/Artemis.Storage/Entities/PluginSettingEntity.cs +++ b/src/Artemis.Storage/Entities/PluginSettingEntity.cs @@ -4,9 +4,10 @@ namespace Artemis.Storage.Entities { public class PluginSettingEntity { + public Guid Id { get; set; } public Guid PluginGuid { get; set; } - public string Name { get; set; } + public string Name { get; set; } public string Value { get; set; } } } \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/FolderEntity.cs b/src/Artemis.Storage/Entities/Profile/FolderEntity.cs new file mode 100644 index 000000000..bfa677765 --- /dev/null +++ b/src/Artemis.Storage/Entities/Profile/FolderEntity.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using LiteDB; + +namespace Artemis.Storage.Entities.Profile +{ + public class FolderEntity + { + public Guid Id { get; set; } + public Guid ParentId { get; set; } + + public int Order { get; set; } + public string Name { get; set; } + + public List Conditions { get; set; } + + [BsonRef("ProfileEntity")] + public ProfileEntity Profile { get; set; } + + public Guid ProfileId { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/LayerElementEntity.cs b/src/Artemis.Storage/Entities/Profile/LayerElementEntity.cs new file mode 100644 index 000000000..4c0145ef6 --- /dev/null +++ b/src/Artemis.Storage/Entities/Profile/LayerElementEntity.cs @@ -0,0 +1,9 @@ +using System; + +namespace Artemis.Storage.Entities.Profile +{ + public class LayerElementEntity + { + public Guid Id { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/LayerEntity.cs b/src/Artemis.Storage/Entities/Profile/LayerEntity.cs new file mode 100644 index 000000000..337c7c4d5 --- /dev/null +++ b/src/Artemis.Storage/Entities/Profile/LayerEntity.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using LiteDB; + +namespace Artemis.Storage.Entities.Profile +{ + public class LayerEntity + { + public Guid Id { get; set; } + public Guid ParentId { get; set; } + public Guid LayerTypeGuid { get; set; } + + public int Order { get; set; } + public string Name { get; set; } + + public List Leds { get; set; } + public List Condition { get; set; } + public List Elements { get; set; } + + [BsonRef("ProfileEntity")] + public ProfileEntity Profile { get; set; } + + public Guid ProfileId { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/LedEntity.cs b/src/Artemis.Storage/Entities/Profile/LedEntity.cs new file mode 100644 index 000000000..ad2238511 --- /dev/null +++ b/src/Artemis.Storage/Entities/Profile/LedEntity.cs @@ -0,0 +1,12 @@ +using System; + +namespace Artemis.Storage.Entities.Profile +{ + public class LedEntity + { + public Guid Id { get; set; } + + public string LedName { get; set; } + public string LimitedToDevice { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/ProfileConditionEntity.cs b/src/Artemis.Storage/Entities/Profile/ProfileConditionEntity.cs new file mode 100644 index 000000000..99ca1dbe3 --- /dev/null +++ b/src/Artemis.Storage/Entities/Profile/ProfileConditionEntity.cs @@ -0,0 +1,9 @@ +using System; + +namespace Artemis.Storage.Entities.Profile +{ + public class ProfileConditionEntity + { + public Guid Id { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/ProfileEntity.cs b/src/Artemis.Storage/Entities/Profile/ProfileEntity.cs new file mode 100644 index 000000000..4ab95fec1 --- /dev/null +++ b/src/Artemis.Storage/Entities/Profile/ProfileEntity.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace Artemis.Storage.Entities.Profile +{ + public class ProfileEntity + { + public Guid Id { get; set; } + public Guid PluginGuid { get; set; } + + public string Name { get; set; } + public bool IsActive { get; set; } + + public List Folders { get; set; } + public List Layers { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/ProfileEntity.cs b/src/Artemis.Storage/Entities/ProfileEntity.cs deleted file mode 100644 index cfe8a98ec..000000000 --- a/src/Artemis.Storage/Entities/ProfileEntity.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; - -namespace Artemis.Storage.Entities -{ - public class ProfileEntity - { - [Key] - public string Guid { get; set; } - - public Guid PluginGuid { get; set; } - - public string Name { get; set; } - public bool IsActive { get; set; } - - public int RootFolderId { get; set; } - public virtual FolderEntity RootFolder { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/SettingEntity.cs b/src/Artemis.Storage/Entities/SettingEntity.cs deleted file mode 100644 index a095b6ed7..000000000 --- a/src/Artemis.Storage/Entities/SettingEntity.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Artemis.Storage.Entities -{ - public class SettingEntity - { - public string Name { get; set; } - public string Value { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs new file mode 100644 index 000000000..3175ce23c --- /dev/null +++ b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs @@ -0,0 +1,15 @@ +using System; + +namespace Artemis.Storage.Entities.Surface +{ + public class DeviceEntity + { + public Guid Id { get; set; } + + public int DeviceHashCode { get; set; } + public double X { get; set; } + public double Y { get; set; } + public double Rotation { get; set; } + public int ZIndex { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Surface/SurfaceEntity.cs b/src/Artemis.Storage/Entities/Surface/SurfaceEntity.cs new file mode 100644 index 000000000..2ff49e492 --- /dev/null +++ b/src/Artemis.Storage/Entities/Surface/SurfaceEntity.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace Artemis.Storage.Entities.Surface +{ + public class SurfaceEntity + { + public Guid Id { get; set; } + + public string Name { get; set; } + public bool IsActive { get; set; } + + public List DeviceEntities { get; set; } + } +} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/SurfaceEntity.cs b/src/Artemis.Storage/Entities/SurfaceEntity.cs deleted file mode 100644 index 3afb05b0d..000000000 --- a/src/Artemis.Storage/Entities/SurfaceEntity.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace Artemis.Storage.Entities -{ - public class SurfaceEntity - { - public SurfaceEntity() - { - Guid = System.Guid.NewGuid().ToString(); - } - - [Key] - public string Guid { get; set; } - - public string Name { get; set; } - public bool IsActive { get; set; } - - public virtual ICollection DeviceEntities { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Migrations/20191028171528_InitialCreate.Designer.cs b/src/Artemis.Storage/Migrations/20191028171528_InitialCreate.Designer.cs deleted file mode 100644 index 3e71f340f..000000000 --- a/src/Artemis.Storage/Migrations/20191028171528_InitialCreate.Designer.cs +++ /dev/null @@ -1,245 +0,0 @@ -// -using System; -using Artemis.Storage; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Artemis.Storage.Migrations -{ - [DbContext(typeof(StorageContext))] - [Migration("20191028171528_InitialCreate")] - partial class InitialCreate - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "2.2.4-servicing-10062"); - - modelBuilder.Entity("Artemis.Storage.Entities.DeviceEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("DeviceHashCode"); - - b.Property("Rotation"); - - b.Property("SurfaceId"); - - b.Property("X"); - - b.Property("Y"); - - b.Property("ZIndex"); - - b.HasKey("Guid"); - - b.HasIndex("SurfaceId"); - - b.ToTable("DeviceEntity"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("FolderEntityGuid"); - - b.Property("Name"); - - b.Property("Order"); - - b.HasKey("Guid"); - - b.HasIndex("FolderEntityGuid"); - - b.ToTable("Folders"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("LayerSettingEntityGuid"); - - b.Property("Time"); - - b.Property("Value"); - - b.HasKey("Guid"); - - b.HasIndex("LayerSettingEntityGuid"); - - b.ToTable("Keypoints"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("FolderEntityGuid"); - - b.Property("Name"); - - b.Property("Order"); - - b.HasKey("Guid"); - - b.HasIndex("FolderEntityGuid"); - - b.ToTable("Layers"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("LayerEntityGuid"); - - b.Property("Name"); - - b.Property("Value"); - - b.HasKey("Guid"); - - b.HasIndex("LayerEntityGuid"); - - b.ToTable("LayerSettings"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("LayerId"); - - b.Property("LedName"); - - b.Property("LimitedToDevice"); - - b.HasKey("Guid"); - - b.HasIndex("LayerId"); - - b.ToTable("Leds"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.PluginSettingEntity", b => - { - b.Property("Name"); - - b.Property("PluginGuid"); - - b.Property("Value"); - - b.HasKey("Name", "PluginGuid"); - - b.ToTable("PluginSettings"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("Name"); - - b.Property("PluginGuid"); - - b.Property("RootFolderGuid"); - - b.Property("RootFolderId"); - - b.HasKey("Guid"); - - b.HasIndex("RootFolderGuid"); - - b.ToTable("Profiles"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.SettingEntity", b => - { - b.Property("Name") - .ValueGeneratedOnAdd(); - - b.Property("Value"); - - b.HasKey("Name"); - - b.ToTable("Settings"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.SurfaceEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("IsActive"); - - b.Property("Name"); - - b.HasKey("Guid"); - - b.ToTable("Surfaces"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.DeviceEntity", b => - { - b.HasOne("Artemis.Storage.Entities.SurfaceEntity", "Surface") - .WithMany("DeviceEntities") - .HasForeignKey("SurfaceId"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b => - { - b.HasOne("Artemis.Storage.Entities.FolderEntity") - .WithMany("Folders") - .HasForeignKey("FolderEntityGuid"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b => - { - b.HasOne("Artemis.Storage.Entities.LayerSettingEntity") - .WithMany("Keypoints") - .HasForeignKey("LayerSettingEntityGuid"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b => - { - b.HasOne("Artemis.Storage.Entities.FolderEntity") - .WithMany("Layers") - .HasForeignKey("FolderEntityGuid"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b => - { - b.HasOne("Artemis.Storage.Entities.LayerEntity") - .WithMany("Settings") - .HasForeignKey("LayerEntityGuid"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b => - { - b.HasOne("Artemis.Storage.Entities.LayerEntity", "Layer") - .WithMany("Leds") - .HasForeignKey("LayerId"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b => - { - b.HasOne("Artemis.Storage.Entities.FolderEntity", "RootFolder") - .WithMany() - .HasForeignKey("RootFolderGuid"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Artemis.Storage/Migrations/20191028171528_InitialCreate.cs b/src/Artemis.Storage/Migrations/20191028171528_InitialCreate.cs deleted file mode 100644 index 65f4611a1..000000000 --- a/src/Artemis.Storage/Migrations/20191028171528_InitialCreate.cs +++ /dev/null @@ -1,252 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Artemis.Storage.Migrations -{ - public partial class InitialCreate : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - "Folders", - table => new - { - Guid = table.Column(), - Order = table.Column(), - Name = table.Column(nullable: true), - FolderEntityGuid = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Folders", x => x.Guid); - table.ForeignKey( - "FK_Folders_Folders_FolderEntityGuid", - x => x.FolderEntityGuid, - "Folders", - "Guid", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - "PluginSettings", - table => new - { - PluginGuid = table.Column(), - Name = table.Column(), - Value = table.Column(nullable: true) - }, - constraints: table => { table.PrimaryKey("PK_PluginSettings", x => new {x.Name, x.PluginGuid}); }); - - migrationBuilder.CreateTable( - "Settings", - table => new - { - Name = table.Column(), - Value = table.Column(nullable: true) - }, - constraints: table => { table.PrimaryKey("PK_Settings", x => x.Name); }); - - migrationBuilder.CreateTable( - "Surfaces", - table => new - { - Guid = table.Column(), - Name = table.Column(nullable: true), - IsActive = table.Column() - }, - constraints: table => { table.PrimaryKey("PK_Surfaces", x => x.Guid); }); - - migrationBuilder.CreateTable( - "Layers", - table => new - { - Guid = table.Column(), - Order = table.Column(), - Name = table.Column(nullable: true), - FolderEntityGuid = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Layers", x => x.Guid); - table.ForeignKey( - "FK_Layers_Folders_FolderEntityGuid", - x => x.FolderEntityGuid, - "Folders", - "Guid", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - "Profiles", - table => new - { - Guid = table.Column(), - PluginGuid = table.Column(), - Name = table.Column(nullable: true), - RootFolderId = table.Column(), - RootFolderGuid = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Profiles", x => x.Guid); - table.ForeignKey( - "FK_Profiles_Folders_RootFolderGuid", - x => x.RootFolderGuid, - "Folders", - "Guid", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - "DeviceEntity", - table => new - { - Guid = table.Column(), - DeviceHashCode = table.Column(), - X = table.Column(), - Y = table.Column(), - Rotation = table.Column(), - ZIndex = table.Column(), - SurfaceId = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_DeviceEntity", x => x.Guid); - table.ForeignKey( - "FK_DeviceEntity_Surfaces_SurfaceId", - x => x.SurfaceId, - "Surfaces", - "Guid", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - "LayerSettings", - table => new - { - Guid = table.Column(), - Name = table.Column(nullable: true), - Value = table.Column(nullable: true), - LayerEntityGuid = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_LayerSettings", x => x.Guid); - table.ForeignKey( - "FK_LayerSettings_Layers_LayerEntityGuid", - x => x.LayerEntityGuid, - "Layers", - "Guid", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - "Leds", - table => new - { - Guid = table.Column(), - LedName = table.Column(nullable: true), - LimitedToDevice = table.Column(nullable: true), - LayerId = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Leds", x => x.Guid); - table.ForeignKey( - "FK_Leds_Layers_LayerId", - x => x.LayerId, - "Layers", - "Guid", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - "Keypoints", - table => new - { - Guid = table.Column(), - Time = table.Column(), - Value = table.Column(nullable: true), - LayerSettingEntityGuid = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Keypoints", x => x.Guid); - table.ForeignKey( - "FK_Keypoints_LayerSettings_LayerSettingEntityGuid", - x => x.LayerSettingEntityGuid, - "LayerSettings", - "Guid", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateIndex( - "IX_DeviceEntity_SurfaceId", - "DeviceEntity", - "SurfaceId"); - - migrationBuilder.CreateIndex( - "IX_Folders_FolderEntityGuid", - "Folders", - "FolderEntityGuid"); - - migrationBuilder.CreateIndex( - "IX_Keypoints_LayerSettingEntityGuid", - "Keypoints", - "LayerSettingEntityGuid"); - - migrationBuilder.CreateIndex( - "IX_Layers_FolderEntityGuid", - "Layers", - "FolderEntityGuid"); - - migrationBuilder.CreateIndex( - "IX_LayerSettings_LayerEntityGuid", - "LayerSettings", - "LayerEntityGuid"); - - migrationBuilder.CreateIndex( - "IX_Leds_LayerId", - "Leds", - "LayerId"); - - migrationBuilder.CreateIndex( - "IX_Profiles_RootFolderGuid", - "Profiles", - "RootFolderGuid"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - "DeviceEntity"); - - migrationBuilder.DropTable( - "Keypoints"); - - migrationBuilder.DropTable( - "Leds"); - - migrationBuilder.DropTable( - "PluginSettings"); - - migrationBuilder.DropTable( - "Profiles"); - - migrationBuilder.DropTable( - "Settings"); - - migrationBuilder.DropTable( - "Surfaces"); - - migrationBuilder.DropTable( - "LayerSettings"); - - migrationBuilder.DropTable( - "Layers"); - - migrationBuilder.DropTable( - "Folders"); - } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Migrations/StorageContextModelSnapshot.cs b/src/Artemis.Storage/Migrations/StorageContextModelSnapshot.cs deleted file mode 100644 index e41900c32..000000000 --- a/src/Artemis.Storage/Migrations/StorageContextModelSnapshot.cs +++ /dev/null @@ -1,242 +0,0 @@ -// - -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; - -namespace Artemis.Storage.Migrations -{ - [DbContext(typeof(StorageContext))] - internal class StorageContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "2.2.4-servicing-10062"); - - modelBuilder.Entity("Artemis.Storage.Entities.DeviceEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("DeviceHashCode"); - - b.Property("Rotation"); - - b.Property("SurfaceId"); - - b.Property("X"); - - b.Property("Y"); - - b.Property("ZIndex"); - - b.HasKey("Guid"); - - b.HasIndex("SurfaceId"); - - b.ToTable("DeviceEntity"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("FolderEntityGuid"); - - b.Property("Name"); - - b.Property("Order"); - - b.HasKey("Guid"); - - b.HasIndex("FolderEntityGuid"); - - b.ToTable("Folders"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("LayerSettingEntityGuid"); - - b.Property("Time"); - - b.Property("Value"); - - b.HasKey("Guid"); - - b.HasIndex("LayerSettingEntityGuid"); - - b.ToTable("Keypoints"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("FolderEntityGuid"); - - b.Property("Name"); - - b.Property("Order"); - - b.HasKey("Guid"); - - b.HasIndex("FolderEntityGuid"); - - b.ToTable("Layers"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("LayerEntityGuid"); - - b.Property("Name"); - - b.Property("Value"); - - b.HasKey("Guid"); - - b.HasIndex("LayerEntityGuid"); - - b.ToTable("LayerSettings"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("LayerId"); - - b.Property("LedName"); - - b.Property("LimitedToDevice"); - - b.HasKey("Guid"); - - b.HasIndex("LayerId"); - - b.ToTable("Leds"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.PluginSettingEntity", b => - { - b.Property("Name"); - - b.Property("PluginGuid"); - - b.Property("Value"); - - b.HasKey("Name", "PluginGuid"); - - b.ToTable("PluginSettings"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("Name"); - - b.Property("PluginGuid"); - - b.Property("RootFolderGuid"); - - b.Property("RootFolderId"); - - b.HasKey("Guid"); - - b.HasIndex("RootFolderGuid"); - - b.ToTable("Profiles"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.SettingEntity", b => - { - b.Property("Name") - .ValueGeneratedOnAdd(); - - b.Property("Value"); - - b.HasKey("Name"); - - b.ToTable("Settings"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.SurfaceEntity", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd(); - - b.Property("IsActive"); - - b.Property("Name"); - - b.HasKey("Guid"); - - b.ToTable("Surfaces"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.DeviceEntity", b => - { - b.HasOne("Artemis.Storage.Entities.SurfaceEntity", "Surface") - .WithMany("DeviceEntities") - .HasForeignKey("SurfaceId"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b => - { - b.HasOne("Artemis.Storage.Entities.FolderEntity") - .WithMany("Folders") - .HasForeignKey("FolderEntityGuid"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b => - { - b.HasOne("Artemis.Storage.Entities.LayerSettingEntity") - .WithMany("Keypoints") - .HasForeignKey("LayerSettingEntityGuid"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b => - { - b.HasOne("Artemis.Storage.Entities.FolderEntity") - .WithMany("Layers") - .HasForeignKey("FolderEntityGuid"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b => - { - b.HasOne("Artemis.Storage.Entities.LayerEntity") - .WithMany("Settings") - .HasForeignKey("LayerEntityGuid"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b => - { - b.HasOne("Artemis.Storage.Entities.LayerEntity", "Layer") - .WithMany("Leds") - .HasForeignKey("LayerId"); - }); - - modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b => - { - b.HasOne("Artemis.Storage.Entities.FolderEntity", "RootFolder") - .WithMany() - .HasForeignKey("RootFolderGuid"); - }); -#pragma warning restore 612, 618 - } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Repositories/Interfaces/IPluginSettingRepository.cs b/src/Artemis.Storage/Repositories/Interfaces/IPluginSettingRepository.cs index 6b522abd5..838ff60a6 100644 --- a/src/Artemis.Storage/Repositories/Interfaces/IPluginSettingRepository.cs +++ b/src/Artemis.Storage/Repositories/Interfaces/IPluginSettingRepository.cs @@ -9,10 +9,7 @@ namespace Artemis.Storage.Repositories.Interfaces { void Add(PluginSettingEntity pluginSettingEntity); List GetByPluginGuid(Guid pluginGuid); - Task> GetByPluginGuidAsync(Guid pluginGuid); PluginSettingEntity GetByNameAndPluginGuid(string name, Guid pluginGuid); - Task GetByNameAndPluginGuidAsync(string name, Guid pluginGuid); - void Save(); - Task SaveAsync(); + void Save(PluginSettingEntity pluginSettingEntity); } } \ No newline at end of file diff --git a/src/Artemis.Storage/Repositories/Interfaces/IProfileRepository.cs b/src/Artemis.Storage/Repositories/Interfaces/IProfileRepository.cs index f56215db2..b130a9642 100644 --- a/src/Artemis.Storage/Repositories/Interfaces/IProfileRepository.cs +++ b/src/Artemis.Storage/Repositories/Interfaces/IProfileRepository.cs @@ -1,17 +1,17 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Artemis.Storage.Entities; +using Artemis.Storage.Entities.Profile; namespace Artemis.Storage.Repositories.Interfaces { public interface IProfileRepository : IRepository { - IQueryable GetAll(); - Task> GetByPluginGuidAsync(Guid pluginGuid); - Task GetByGuidAsync(string guid); - void Save(); - Task SaveAsync(); + void Add(ProfileEntity profileEntity); + void Remove(ProfileEntity profileEntity); + List GetAll(); + ProfileEntity Get(Guid id); + List GetByPluginGuid(Guid pluginGuid); + void Save(ProfileEntity profileEntity); } } \ No newline at end of file diff --git a/src/Artemis.Storage/Repositories/Interfaces/ISettingRepository.cs b/src/Artemis.Storage/Repositories/Interfaces/ISettingRepository.cs deleted file mode 100644 index f3240c0eb..000000000 --- a/src/Artemis.Storage/Repositories/Interfaces/ISettingRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Artemis.Storage.Entities; - -namespace Artemis.Storage.Repositories.Interfaces -{ - public interface ISettingRepository : IRepository - { - void Add(SettingEntity settingEntity); - SettingEntity Get(string name); - Task GetAsync(string name); - List GetAll(); - Task> GetAllAsync(); - void Save(); - Task SaveAsync(); - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Repositories/Interfaces/ISurfaceRepository.cs b/src/Artemis.Storage/Repositories/Interfaces/ISurfaceRepository.cs index 220fdc2e4..e113cb17f 100644 --- a/src/Artemis.Storage/Repositories/Interfaces/ISurfaceRepository.cs +++ b/src/Artemis.Storage/Repositories/Interfaces/ISurfaceRepository.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using System.Threading.Tasks; using Artemis.Storage.Entities; +using Artemis.Storage.Entities.Surface; namespace Artemis.Storage.Repositories.Interfaces { @@ -8,12 +8,9 @@ namespace Artemis.Storage.Repositories.Interfaces { void Add(SurfaceEntity surfaceEntity); void Remove(SurfaceEntity surfaceEntity); - SurfaceEntity Get(string name); - Task GetAsync(string name); + SurfaceEntity GetByName(string name); List GetAll(); - Task> GetAllAsync(); - void Save(); - Task SaveAsync(); + void Save(SurfaceEntity surfaceEntity); } } \ No newline at end of file diff --git a/src/Artemis.Storage/Repositories/PluginSettingRepository.cs b/src/Artemis.Storage/Repositories/PluginSettingRepository.cs index d6663a003..3ea1564ff 100644 --- a/src/Artemis.Storage/Repositories/PluginSettingRepository.cs +++ b/src/Artemis.Storage/Repositories/PluginSettingRepository.cs @@ -1,56 +1,40 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Artemis.Storage.Entities; using Artemis.Storage.Repositories.Interfaces; -using Microsoft.EntityFrameworkCore; +using LiteDB; namespace Artemis.Storage.Repositories { public class PluginSettingRepository : IPluginSettingRepository { - private readonly StorageContext _dbContext; + private readonly LiteRepository _repository; - internal PluginSettingRepository() + internal PluginSettingRepository(LiteRepository repository) { - _dbContext = new StorageContext(); - _dbContext.Database.EnsureCreated(); + _repository = repository; + _repository.Database.GetCollection().EnsureIndex(s => s.Name); + _repository.Database.GetCollection().EnsureIndex(s => s.PluginGuid); } public void Add(PluginSettingEntity pluginSettingEntity) { - _dbContext.PluginSettings.Add(pluginSettingEntity); + _repository.Insert(pluginSettingEntity); } public List GetByPluginGuid(Guid pluginGuid) { - return _dbContext.PluginSettings.Where(p => p.PluginGuid == pluginGuid).ToList(); - } - - public async Task> GetByPluginGuidAsync(Guid pluginGuid) - { - return await _dbContext.PluginSettings.Where(p => p.PluginGuid == pluginGuid).ToListAsync(); + return _repository.Query().Where(p => p.PluginGuid == pluginGuid).ToList(); } public PluginSettingEntity GetByNameAndPluginGuid(string name, Guid pluginGuid) { - return _dbContext.PluginSettings.FirstOrDefault(p => p.Name == name && p.PluginGuid == pluginGuid); + return _repository.FirstOrDefault(p => p.Name == name && p.PluginGuid == pluginGuid); } - - public async Task GetByNameAndPluginGuidAsync(string name, Guid pluginGuid) + + public void Save(PluginSettingEntity pluginSettingEntity) { - return await _dbContext.PluginSettings.FirstOrDefaultAsync(p => p.Name == name && p.PluginGuid == pluginGuid); - } - - public void Save() - { - _dbContext.SaveChanges(); - } - - public async Task SaveAsync() - { - await _dbContext.SaveChangesAsync(); + _repository.Upsert(pluginSettingEntity); } } } \ No newline at end of file diff --git a/src/Artemis.Storage/Repositories/ProfileRepository.cs b/src/Artemis.Storage/Repositories/ProfileRepository.cs index 084cb236c..42149d4f9 100644 --- a/src/Artemis.Storage/Repositories/ProfileRepository.cs +++ b/src/Artemis.Storage/Repositories/ProfileRepository.cs @@ -1,51 +1,53 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Artemis.Storage.Entities; +using Artemis.Storage.Entities.Profile; using Artemis.Storage.Repositories.Interfaces; -using Microsoft.EntityFrameworkCore; +using LiteDB; namespace Artemis.Storage.Repositories { public class ProfileRepository : IProfileRepository { - private readonly StorageContext _dbContext; + private readonly LiteRepository _repository; - public ProfileRepository() + internal ProfileRepository(LiteRepository repository) { - _dbContext = new StorageContext(); - _dbContext.Database.EnsureCreated(); + _repository = repository; + _repository.Database.GetCollection().EnsureIndex(s => s.Name); } - public IQueryable GetAll() + public void Add(ProfileEntity profileEntity) { - return _dbContext.Profiles; + _repository.Insert(profileEntity); } - public async Task> GetByPluginGuidAsync(Guid pluginGuid) + public void Remove(ProfileEntity profileEntity) { - return await _dbContext.Profiles.Where(p => p.PluginGuid == pluginGuid).ToListAsync(); + _repository.Delete(s => s.Id == profileEntity.Id); } - public async Task GetActiveProfileByPluginGuidAsync(Guid pluginGuid) + public List GetAll() { - return await _dbContext.Profiles.FirstOrDefaultAsync(p => p.PluginGuid == pluginGuid && p.IsActive); + return _repository.Query().ToList(); } - public async Task GetByGuidAsync(string guid) + public ProfileEntity Get(Guid id) { - return await _dbContext.Profiles.FirstOrDefaultAsync(p => p.Guid == guid); + return _repository.FirstOrDefault(p => p.Id == id); } - public void Save() + public List GetByPluginGuid(Guid pluginGuid) { - _dbContext.SaveChanges(); + return _repository.Query() + .Include(p => p.Folders) + .Include(p => p.Layers) + .Where(s => s.PluginGuid == pluginGuid) + .ToList(); } - public async Task SaveAsync() + public void Save(ProfileEntity profileEntity) { - await _dbContext.SaveChangesAsync(); + _repository.Upsert(profileEntity); } } } \ No newline at end of file diff --git a/src/Artemis.Storage/Repositories/SettingRepository.cs b/src/Artemis.Storage/Repositories/SettingRepository.cs deleted file mode 100644 index ea05b1e37..000000000 --- a/src/Artemis.Storage/Repositories/SettingRepository.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Artemis.Storage.Entities; -using Artemis.Storage.Repositories.Interfaces; -using Microsoft.EntityFrameworkCore; - -namespace Artemis.Storage.Repositories -{ - public class SettingRepository : ISettingRepository - { - private readonly StorageContext _dbContext; - - internal SettingRepository() - { - _dbContext = new StorageContext(); - _dbContext.Database.EnsureCreated(); - } - - public void Add(SettingEntity settingEntity) - { - _dbContext.Settings.Add(settingEntity); - } - - public SettingEntity Get(string name) - { - return _dbContext.Settings.FirstOrDefault(p => p.Name == name); - } - - public async Task GetAsync(string name) - { - return await _dbContext.Settings.FirstOrDefaultAsync(p => p.Name == name); - } - - public List GetAll() - { - return _dbContext.Settings.ToList(); - } - - public async Task> GetAllAsync() - { - return await _dbContext.Settings.ToListAsync(); - } - - public void Save() - { - _dbContext.SaveChanges(); - } - - public async Task SaveAsync() - { - await _dbContext.SaveChangesAsync(); - } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Repositories/SurfaceRepository.cs b/src/Artemis.Storage/Repositories/SurfaceRepository.cs index 2aa8a3ebc..c8d474c1c 100644 --- a/src/Artemis.Storage/Repositories/SurfaceRepository.cs +++ b/src/Artemis.Storage/Repositories/SurfaceRepository.cs @@ -1,60 +1,43 @@ using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Artemis.Storage.Entities; +using Artemis.Storage.Entities.Surface; using Artemis.Storage.Repositories.Interfaces; -using Microsoft.EntityFrameworkCore; +using LiteDB; namespace Artemis.Storage.Repositories { public class SurfaceRepository : ISurfaceRepository { - private readonly StorageContext _dbContext; + private readonly LiteRepository _repository; - internal SurfaceRepository() + internal SurfaceRepository(LiteRepository repository) { - _dbContext = new StorageContext(); - _dbContext.Database.EnsureCreated(); + _repository = repository; + _repository.Database.GetCollection().EnsureIndex(s => s.Name); } public void Add(SurfaceEntity surfaceEntity) { - _dbContext.Surfaces.Add(surfaceEntity); + _repository.Insert(surfaceEntity); } public void Remove(SurfaceEntity surfaceEntity) { - _dbContext.Surfaces.Remove(surfaceEntity); + _repository.Delete(s => s.Id == surfaceEntity.Id); } - public SurfaceEntity Get(string name) + public SurfaceEntity GetByName(string name) { - return _dbContext.Surfaces.Include(s => s.DeviceEntities).FirstOrDefault(p => p.Name == name); - } - - public async Task GetAsync(string name) - { - return await _dbContext.Surfaces.Include(s => s.DeviceEntities).FirstOrDefaultAsync(p => p.Name == name); + return _repository.FirstOrDefault(s => s.Name == name); } public List GetAll() { - return _dbContext.Surfaces.Include(s => s.DeviceEntities).ToList(); + return _repository.Query().Include(s => s.DeviceEntities).ToList(); } - public async Task> GetAllAsync() + public void Save(SurfaceEntity surfaceEntity) { - return await _dbContext.Surfaces.Include(s => s.DeviceEntities).ToListAsync(); - } - - public void Save() - { - _dbContext.SaveChanges(); - } - - public async Task SaveAsync() - { - await _dbContext.SaveChangesAsync(); + _repository.Upsert(surfaceEntity); } } } \ No newline at end of file diff --git a/src/Artemis.Storage/StorageContext.cs b/src/Artemis.Storage/StorageContext.cs deleted file mode 100644 index 758a15ece..000000000 --- a/src/Artemis.Storage/StorageContext.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.IO; -using Artemis.Storage.Entities; -using Microsoft.EntityFrameworkCore; -using SQLitePCL; - -namespace Artemis.Storage -{ - public class StorageContext : DbContext - { - public DbSet Profiles { get; set; } - public DbSet Settings { get; set; } - public DbSet Surfaces { get; set; } - public DbSet PluginSettings { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - // ReSharper disable once RedundantAssignment - Used if not debugging - var dbLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Artemis\\Storage.db"); - #if DEBUG - dbLocation = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\Artemis.Storage\Storage.db")); - #endif - - optionsBuilder.UseSqlite("Data Source=" + dbLocation); - - // Requires Microsoft.Data.Sqlite in the startup project - Batteries.Init(); - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity().HasKey(s => s.Name); - modelBuilder.Entity().HasKey(s => new {s.Name, s.PluginGuid}); - base.OnModelCreating(modelBuilder); - } - } -} \ No newline at end of file diff --git a/src/Artemis.UI/App.config b/src/Artemis.UI/App.config index 26bb25a66..056019794 100644 --- a/src/Artemis.UI/App.config +++ b/src/Artemis.UI/App.config @@ -31,8 +31,7 @@ - + @@ -56,8 +55,7 @@ - + @@ -73,8 +71,7 @@ - + @@ -90,8 +87,7 @@ - + @@ -99,8 +95,7 @@ - + diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index ab4a6146f..3a82aa9b4 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -91,9 +91,6 @@ ..\packages\MaterialDesignThemes.2.6.0\lib\net45\MaterialDesignThemes.Wpf.dll - - ..\packages\Microsoft.Data.Sqlite.Core.2.2.4\lib\netstandard2.0\Microsoft.Data.Sqlite.dll - ..\packages\Ninject.3.3.4\lib\net45\Ninject.dll @@ -117,18 +114,6 @@ ..\packages\Serilog.2.8.0\lib\net46\Serilog.dll - - ..\packages\SQLitePCLRaw.bundle_green.1.1.12\lib\net45\SQLitePCLRaw.batteries_green.dll - - - ..\packages\SQLitePCLRaw.bundle_green.1.1.12\lib\net45\SQLitePCLRaw.batteries_v2.dll - - - ..\packages\SQLitePCLRaw.core.1.1.12\lib\net45\SQLitePCLRaw.core.dll - - - ..\packages\SQLitePCLRaw.provider.e_sqlite3.net45.1.1.12\lib\net45\SQLitePCLRaw.provider.e_sqlite3.dll - ..\packages\Stylet.1.3.0\lib\net45\Stylet.dll @@ -372,14 +357,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs index 709210a3b..bf4b67a1e 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs @@ -62,13 +62,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor protected override void OnActivate() { - Task.Run(LoadProfilesAsync); + Task.Run(() => LoadProfiles()); base.OnActivate(); } - private async Task LoadProfilesAsync() + private void LoadProfiles() { - var profiles = await _profileService.GetProfiles((ProfileModule) Module); + var profiles = _profileService.GetProfiles((ProfileModule) Module); Profiles.Clear(); Profiles.AddRange(profiles); diff --git a/src/Artemis.UI/packages.config b/src/Artemis.UI/packages.config index 9cc18eb98..643aa6fc2 100644 --- a/src/Artemis.UI/packages.config +++ b/src/Artemis.UI/packages.config @@ -1,5 +1,4 @@  - @@ -11,19 +10,11 @@ - - - - - - - -