mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Removed seperate plugins project since you're always referencing both..
Added more loading logic
This commit is contained in:
1 parent
b80e1ea528
commit
9a2ea0c2b3
57 files changed
+959
-650
No files matched your search
@@ -2,8 +2,8 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Plugins.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Plugins.Interfaces;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
{
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Plugins.Interfaces;
|
||||
using Artemis.Plugins.Models;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.ProfileElements;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
{
|
||||
@@ -55,5 +56,12 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// Occurs when loading all plugins has finished
|
||||
/// </summary>
|
||||
event EventHandler FinishedLoadedPlugins;
|
||||
|
||||
/// <summary>
|
||||
/// If found, returns an instance of the layer type matching the given GUID
|
||||
/// </summary>
|
||||
/// <param name="layerTypeGuid">The GUID of the layer type to find</param>
|
||||
/// <returns>An instance of the layer type</returns>
|
||||
ILayerType GetLayerTypeByGuid(Guid layerTypeGuid);
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Plugins.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Plugins.Exceptions;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.ProfileElements;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Plugins.Interfaces;
|
||||
using Artemis.Plugins.Models;
|
||||
using Ninject;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
@@ -64,6 +67,22 @@ namespace Artemis.Core.Services
|
||||
return await Task.Run(() => pluginInfo.GetModuleViewModel(_kernel));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ILayerType GetLayerTypeByGuid(Guid layerTypeGuid)
|
||||
{
|
||||
var pluginInfo = _plugins.FirstOrDefault(p => p.Guid == layerTypeGuid);
|
||||
if (pluginInfo == null)
|
||||
return null;
|
||||
|
||||
// Layer types are instantiated per layer so lets compile and return a new instance
|
||||
if (!(pluginInfo.Plugin is ILayerType))
|
||||
{
|
||||
throw new ArtemisPluginException(pluginInfo, "Plugin is expected to implement ILayerType");
|
||||
}
|
||||
|
||||
return (ILayerType) pluginInfo.Plugin;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Empty the list of plugins
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.ProfileElements;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
public class StorageService : IStorageService
|
||||
{
|
||||
private readonly StorageContext _dbContext;
|
||||
private readonly IPluginService _pluginService;
|
||||
|
||||
public StorageService(StorageContext dbContext, IPluginService pluginService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_pluginService = pluginService;
|
||||
}
|
||||
|
||||
public async Task<ICollection<Profile>> GetModuleProfiles(PluginInfo pluginInfo)
|
||||
{
|
||||
var profileEntities = await _dbContext.Profiles.Where(p => p.PluginGuid == pluginInfo.Guid).ToListAsync();
|
||||
var profiles = new List<Profile>();
|
||||
foreach (var profileEntity in profileEntities)
|
||||
profiles.Add(Profile.FromProfileEntity(pluginInfo, profileEntity, _pluginService));
|
||||
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public async Task SaveProfile(Profile profile)
|
||||
{
|
||||
// Find a matching profile entity to update
|
||||
|
||||
// If not found, create a new one
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public interface IStorageService
|
||||
{
|
||||
Task<ICollection<Profile>> GetModuleProfiles(PluginInfo pluginInfo);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user