Implemented profile creation, deletion and activation

This commit is contained in:
Robert committed 2019-11-20 19:25:29 +01:00
1 parent 66f7dc94c8
commit 97907c97eb
17 files changed
+217 -49

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Models.Profile
{
public class Folder : ProfileElement
public sealed class Folder : ProfileElement
{
public Folder(Profile profile, Folder folder, string name)
{
+1 -1
View File
@@ -8,7 +8,7 @@ using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Models.Profile
{
public class Layer : ProfileElement
public sealed class Layer : ProfileElement
{
internal Layer(Profile profile, Folder folder, string name)
{
+3 -1
View File
@@ -10,7 +10,7 @@ using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Models.Profile
{
public class Profile : ProfileElement
public sealed class Profile : ProfileElement
{
internal Profile(PluginInfo pluginInfo, string name)
{
@@ -21,6 +21,8 @@ namespace Artemis.Core.Models.Profile
Name = name;
Children = new List<ProfileElement> {new Folder(this, null, "Root folder")};
ApplyToEntity();
}
internal Profile(PluginInfo pluginInfo, ProfileEntity profileEntity, IPluginService pluginService)
+1 -9
View File
@@ -71,8 +71,7 @@ namespace Artemis.Core.Models.Surface
internal void ApplyToEntity()
{
// Other properties are mapped computed
// Other properties are computed
DeviceEntity.DeviceHashCode = RgbDevice.GetDeviceHashCode();
}
@@ -102,13 +101,6 @@ namespace Artemis.Core.Models.Surface
RenderPath = path;
}
internal void Destroy()
{
DeviceEntity = null;
RgbDevice = null;
Surface = null;
}
public override string ToString()
{
return $"[{RgbDevice.DeviceInfo.DeviceType}] {RgbDevice.DeviceInfo.DeviceName} - {X}.{Y}.{ZIndex}";
@@ -61,15 +61,6 @@ namespace Artemis.Core.Models.Surface
}
}
internal void Destroy()
{
SurfaceEntity = null;
foreach (var deviceConfiguration in Devices)
deviceConfiguration.Destroy();
Devices.Clear();
}
public void UpdateScale(double value)
{
Scale = value;
@@ -38,13 +38,13 @@ namespace Artemis.Core.Plugins.Abstract
{
lock (this)
{
if (profile == null)
throw new ArgumentNullException(nameof(profile));
if (profile == ActiveProfile)
return;
ActiveProfile?.Deactivate();
ActiveProfile = profile;
ActiveProfile.Activate();
ActiveProfile?.Activate();
}
OnActiveProfileChanged();
@@ -7,7 +7,10 @@ namespace Artemis.Core.Services.Storage.Interfaces
{
public interface IProfileService : IArtemisService
{
Profile CreateProfile(ProfileModule module, string name);
List<Profile> GetProfiles(ProfileModule module);
Profile GetActiveProfile(ProfileModule module);
void UpdateProfile(Profile profile, bool includeChildren);
void DeleteProfile(Profile profile);
}
}
@@ -1,11 +1,9 @@
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
@@ -29,13 +27,22 @@ namespace Artemis.Core.Services.Storage
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));
{
// If the profile entity matches the module's currently active profile, use that instead
if (module.ActiveProfile != null && module.ActiveProfile.EntityId == profileEntity.Id)
profiles.Add(module.ActiveProfile);
else
profiles.Add(new Profile(module.PluginInfo, profileEntity, _pluginService));
}
return profiles;
}
public Profile GetActiveProfile(ProfileModule module)
{
if (module.ActiveProfile != null)
return module.ActiveProfile;
var profileEntity = _profileRepository.GetByPluginGuid(module.PluginInfo.Guid).FirstOrDefault(p => p.IsActive);
if (profileEntity == null)
return null;
@@ -46,20 +53,26 @@ namespace Artemis.Core.Services.Storage
public Profile CreateProfile(ProfileModule module, string name)
{
var profile = new Profile(module.PluginInfo, name);
_profileRepository.Add(profile.ProfileEntity);
return profile;
}
public void DeleteProfile(Profile profile)
{
_profileRepository.Remove(profile.ProfileEntity);
}
public void UpdateProfile(Profile profile, bool includeChildren)
{
profile.ApplyToEntity();
if (includeChildren)
{
foreach (var profileElement in profile.Children)
{
profileElement.ApplyToEntity();
}
}
_profileRepository.Save(profile.ProfileEntity);
}
}
}
@@ -123,8 +123,6 @@ namespace Artemis.Core.Services.Storage
lock (_surfaceConfigurations)
{
var entity = surface.SurfaceEntity;
surface.Destroy();
_surfaceConfigurations.Remove(surface);
_surfaceRepository.Remove(entity);
}