mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Fixed build
Added PluginSetting, settings service needs some more thought
This commit is contained in:
1 parent
bfc320c0ac
commit
99d15ad6ac
6 files changed
+171
-30
No files matched your search
@@ -0,0 +1,66 @@
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Storage.Entities;
|
||||
using Artemis.Storage.Repositories;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
public class PluginSetting<T>
|
||||
{
|
||||
private readonly PluginInfo _pluginInfo;
|
||||
private readonly SettingEntity _settingEntity;
|
||||
private readonly SettingRepository _settingRepository;
|
||||
|
||||
internal PluginSetting(PluginInfo pluginInfo, SettingRepository settingRepository, SettingEntity settingEntity)
|
||||
{
|
||||
_pluginInfo = pluginInfo;
|
||||
_settingRepository = settingRepository;
|
||||
_settingEntity = settingEntity;
|
||||
|
||||
Name = settingEntity.Name;
|
||||
Value = JsonConvert.DeserializeObject<T>(settingEntity.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of the setting, unique to this plugin
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The value of the setting
|
||||
/// </summary>
|
||||
public T Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the setting has been changed
|
||||
/// </summary>
|
||||
public bool HasChanged => JsonConvert.SerializeObject(Value) != _settingEntity.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Resets the setting to the last saved value
|
||||
/// </summary>
|
||||
public void RejectChanges()
|
||||
{
|
||||
Value = JsonConvert.DeserializeObject<T>(_settingEntity.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the setting
|
||||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
_settingEntity.Value = JsonConvert.SerializeObject(Value);
|
||||
_settingRepository.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the setting asynchronously
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task SaveAsync()
|
||||
{
|
||||
_settingEntity.Value = JsonConvert.SerializeObject(Value);
|
||||
await _settingRepository.SaveAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using Artemis.Storage.Repositories;
|
||||
|
||||
namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
public class PluginSettings
|
||||
{
|
||||
private readonly PluginInfo _pluginInfo;
|
||||
private readonly SettingRepository _settingRepository;
|
||||
|
||||
internal PluginSettings(PluginInfo pluginInfo, SettingRepository settingRepository)
|
||||
{
|
||||
_pluginInfo = pluginInfo;
|
||||
_settingRepository = settingRepository;
|
||||
}
|
||||
|
||||
public bool HasSettingChanged(string settingName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool HasAnySettingChanged()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Storage.Entities;
|
||||
using Artemis.Storage.Repositories;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
public class PluginSettingsContainer
|
||||
{
|
||||
private readonly PluginInfo _pluginInfo;
|
||||
private readonly SettingRepository _settingRepository;
|
||||
private Task<List<SettingEntity>> _settings;
|
||||
|
||||
internal PluginSettingsContainer(PluginInfo pluginInfo, SettingRepository settingRepository)
|
||||
{
|
||||
_pluginInfo = pluginInfo;
|
||||
_settingRepository = settingRepository;
|
||||
}
|
||||
|
||||
public bool HasSettingChanged(string settingName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool HasAnySettingChanged()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class PluginSetting<T>
|
||||
{
|
||||
private readonly PluginInfo _pluginInfo;
|
||||
private readonly SettingEntity _settingEntity;
|
||||
private readonly SettingRepository _settingRepository;
|
||||
|
||||
internal PluginSetting(PluginInfo pluginInfo, SettingRepository settingRepository, SettingEntity settingEntity)
|
||||
{
|
||||
_pluginInfo = pluginInfo;
|
||||
_settingRepository = settingRepository;
|
||||
_settingEntity = settingEntity;
|
||||
|
||||
Name = settingEntity.Name;
|
||||
Value = JsonConvert.DeserializeObject<T>(settingEntity.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of the setting, unique to this plugin
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The value of the setting
|
||||
/// </summary>
|
||||
public T Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the setting has been changed
|
||||
/// </summary>
|
||||
public bool HasChanged => JsonConvert.SerializeObject(Value) != _settingEntity.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Resets the setting to the last saved value
|
||||
/// </summary>
|
||||
public void RejectChanges()
|
||||
{
|
||||
Value = JsonConvert.DeserializeObject<T>(_settingEntity.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the setting
|
||||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
_settingEntity.Value = JsonConvert.SerializeObject(Value);
|
||||
_settingRepository.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the setting asynchronously
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task SaveAsync()
|
||||
{
|
||||
_settingEntity.Value = JsonConvert.SerializeObject(Value);
|
||||
await _settingRepository.SaveAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user