Started work on profiles

This commit is contained in:
Robert committed 2019-11-18 20:11:17 +01:00
1 parent 5921f8ab54
commit fd942dab25
28 files changed
+575 -375

No files matched your search

+3 -2
View File
@@ -192,8 +192,9 @@
<Compile Include="Events\PluginEventArgs.cs" />
<Compile Include="Services\PluginService.cs" />
<Compile Include="Services\SettingsService.cs" />
<Compile Include="Services\StorageService.cs" />
<Compile Include="Services\Storage\ISurfaceService.cs" />
<Compile Include="Services\Storage\Interfaces\IProfileService.cs" />
<Compile Include="Services\Storage\ProfileService.cs" />
<Compile Include="Services\Storage\Interfaces\ISurfaceService.cs" />
<Compile Include="Services\Storage\SurfaceService.cs" />
</ItemGroup>
<ItemGroup>
+13 -13
View File
@@ -11,9 +11,21 @@ namespace Artemis.Core.Models.Profile
{
public class Profile : IProfileElement
{
private Profile(PluginInfo pluginInfo)
internal Profile(PluginInfo pluginInfo, ProfileEntity profileEntity, IPluginService pluginService)
{
PluginInfo = pluginInfo;
Name = profileEntity.Name;
// Populate the profile starting at the root, the rest is populated recursively
Children = new List<IProfileElement> {Folder.FromFolderEntity(this, profileEntity.RootFolder, pluginService)};
}
internal Profile(PluginInfo pluginInfo, string name)
{
PluginInfo = pluginInfo;
Name = name;
Children = new List<IProfileElement>();
}
public PluginInfo PluginInfo { get; }
@@ -46,18 +58,6 @@ namespace Artemis.Core.Models.Profile
}
}
public static Profile FromProfileEntity(PluginInfo pluginInfo, ProfileEntity profileEntity, IPluginService pluginService)
{
var profile = new Profile(pluginInfo) {Name = profileEntity.Name};
lock (profile)
{
// Populate the profile starting at the root, the rest is populated recursively
profile.Children.Add(Folder.FromFolderEntity(profile, profileEntity.RootFolder, pluginService));
return profile;
}
}
public void Activate()
{
lock (this)
@@ -4,13 +4,12 @@ namespace Artemis.Core.Plugins.Abstract
{
public abstract class ModuleViewModel : Screen
{
protected ModuleViewModel(Module module, string name)
protected ModuleViewModel(Module module, string displayName)
{
Module = module;
Name = name;
DisplayName = displayName;
}
public string Name { get; }
public Module Module { get; }
}
}
@@ -46,6 +46,19 @@ namespace Artemis.Core.Plugins.Abstract
ActiveProfile = profile;
ActiveProfile.Activate();
}
OnActiveProfileChanged();
}
#region Events
public event EventHandler ActiveProfileChanged;
protected virtual void OnActiveProfileChanged()
{
ActiveProfileChanged?.Invoke(this, EventArgs.Empty);
}
#endregion
}
}
+1
View File
@@ -5,6 +5,7 @@ using Artemis.Core.Exceptions;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage;
using Artemis.Core.Services.Storage.Interfaces;
using RGB.NET.Core;
using Serilog;
using Color = System.Drawing.Color;
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Services.Interfaces;
namespace Artemis.Core.Services.Storage.Interfaces
{
public interface IProfileService : IArtemisService
{
Task<ICollection<Profile>> GetProfiles(ProfileModule module);
Task<Profile> GetActiveProfile(ProfileModule module);
}
}
@@ -4,7 +4,7 @@ using Artemis.Core.Events;
using Artemis.Core.Models.Surface;
using Artemis.Core.Services.Interfaces;
namespace Artemis.Core.Services.Storage
namespace Artemis.Core.Services.Storage.Interfaces
{
public interface ISurfaceService : IArtemisService
{
@@ -1,36 +1,46 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces;
using Artemis.Storage.Repositories;
namespace Artemis.Core.Services
namespace Artemis.Core.Services.Storage
{
/// <summary>
/// Provides access to profile storage
/// </summary>
public class StorageService : IStorageService
public class ProfileService : IProfileService
{
private readonly IPluginService _pluginService;
private readonly ProfileRepository _profileRepository;
internal StorageService(IPluginService pluginService)
internal ProfileService(IPluginService pluginService)
{
_pluginService = pluginService;
_profileRepository = new ProfileRepository();
}
public async Task<ICollection<Profile>> GetModuleProfiles(PluginInfo pluginInfo)
public async Task<ICollection<Profile>> GetProfiles(ProfileModule module)
{
var profileEntities = await _profileRepository.GetByPluginGuidAsync(pluginInfo.Guid);
var profileEntities = await _profileRepository.GetByPluginGuidAsync(module.PluginInfo.Guid);
var profiles = new List<Profile>();
foreach (var profileEntity in profileEntities)
profiles.Add(Profile.FromProfileEntity(pluginInfo, profileEntity, _pluginService));
profiles.Add(Profile.FromProfileEntity(module.PluginInfo, profileEntity, _pluginService));
return profiles;
}
public async Task<Profile> GetActiveProfile(ProfileModule module)
{
var profileEntity = await _profileRepository.GetActiveProfileByPluginGuidAsync(module.PluginInfo.Guid);
if (profileEntity == null)
return null;
return Profile.FromProfileEntity(module.PluginInfo, profileEntity, _pluginService);
}
public async Task SaveProfile(Profile profile)
{
// Find a matching profile entity to update
@@ -40,9 +50,4 @@ namespace Artemis.Core.Services
await _profileRepository.SaveAsync();
}
}
public interface IStorageService
{
Task<ICollection<Profile>> GetModuleProfiles(PluginInfo pluginInfo);
}
}
@@ -8,6 +8,7 @@ using Artemis.Core.Extensions;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces;
using Artemis.Storage.Repositories.Interfaces;
using RGB.NET.Core;
using Serilog;