Started work on profiles

This commit is contained in:
Robert committed 2019-11-18 17:33:20 +01:00
1 parent 36f3ec3071
commit bb56a45a7f
28 files changed
+575 -375

No files matched your search

@@ -0,0 +1,53 @@
using System.Collections.Generic;
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;
namespace Artemis.Core.Services.Storage
{
/// <summary>
/// Provides access to profile storage
/// </summary>
public class ProfileService : IProfileService
{
private readonly IPluginService _pluginService;
private readonly ProfileRepository _profileRepository;
internal ProfileService(IPluginService pluginService)
{
_pluginService = pluginService;
_profileRepository = new ProfileRepository();
}
public async Task<ICollection<Profile>> GetProfiles(ProfileModule module)
{
var profileEntities = await _profileRepository.GetByPluginGuidAsync(module.PluginInfo.Guid);
var profiles = new List<Profile>();
foreach (var profileEntity in profileEntities)
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
// If not found, create a new one
await _profileRepository.SaveAsync();
}
}
}