1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Thanks Visual Studio 👍

This commit is contained in:
Robert Beekman 2019-04-16 17:04:57 +02:00
parent 99d15ad6ac
commit 40c3222ae9
2 changed files with 2 additions and 61 deletions

View File

@ -116,7 +116,8 @@
<Compile Include="Plugins\Abstract\Module.cs" />
<Compile Include="Plugins\Abstract\Plugin.cs" />
<Compile Include="Plugins\Models\PluginInfo.cs" />
<Compile Include="Plugins\Models\PluginSettings.cs" />
<Compile Include="Plugins\Models\PluginSetting.cs" />
<Compile Include="Plugins\Models\PluginSettingsContainer.cs" />
<Compile Include="ProfileElements\Folder.cs" />
<Compile Include="ProfileElements\Interfaces\IProfileElement.cs" />
<Compile Include="ProfileElements\Layer.cs" />

View File

@ -2,7 +2,6 @@
using System.Threading.Tasks;
using Artemis.Storage.Entities;
using Artemis.Storage.Repositories;
using Newtonsoft.Json;
namespace Artemis.Core.Plugins.Models
{
@ -28,63 +27,4 @@ namespace Artemis.Core.Plugins.Models
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();
}
}
}