Moved from EF and SQLite to LiteDB

This commit is contained in:
Robert committed 2019-11-20 19:19:13 +01:00
1 parent d4dd371a50
commit 66f7dc94c8
57 files changed
+379 -1279

No files matched your search

+1 -1
View File
@@ -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;