mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Implemented profile creation, deletion and activation
This commit is contained in:
1 parent
2fb2e5444c
commit
57a2be778d
17 files changed
+217
-49
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user