mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Core - Moved JSON calls into a helper
This commit is contained in:
parent
190d64b497
commit
a5e2dc81a4
@ -115,7 +115,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rightSideValue = JsonConvert.DeserializeObject(Entity.RightStaticValue, leftSideType, Constants.JsonConvertSettings);
|
rightSideValue = CoreJson.DeserializeObject(Entity.RightStaticValue, leftSideType);
|
||||||
}
|
}
|
||||||
// If deserialization fails, use the type's default
|
// If deserialization fails, use the type's default
|
||||||
catch (JsonSerializationException e)
|
catch (JsonSerializationException e)
|
||||||
@ -129,7 +129,7 @@ namespace Artemis.Core
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Hope for the best...
|
// Hope for the best...
|
||||||
UpdateRightSideStatic(JsonConvert.DeserializeObject(Entity.RightStaticValue, Constants.JsonConvertSettings));
|
UpdateRightSideStatic(CoreJson.DeserializeObject(Entity.RightStaticValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (JsonReaderException e)
|
catch (JsonReaderException e)
|
||||||
@ -349,7 +349,7 @@ namespace Artemis.Core
|
|||||||
RightPath?.Save();
|
RightPath?.Save();
|
||||||
Entity.RightPath = RightPath?.Entity;
|
Entity.RightPath = RightPath?.Entity;
|
||||||
|
|
||||||
Entity.RightStaticValue = JsonConvert.SerializeObject(RightStaticValue, Constants.JsonConvertSettings);
|
Entity.RightStaticValue = CoreJson.SerializeObject(RightStaticValue);
|
||||||
|
|
||||||
if (Operator?.Plugin != null)
|
if (Operator?.Plugin != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -74,7 +73,7 @@ namespace Artemis.Core
|
|||||||
Entity.Condition = Condition.Entity;
|
Entity.Condition = Condition.Entity;
|
||||||
Condition.Save();
|
Condition.Save();
|
||||||
|
|
||||||
Entity.Value = JsonConvert.SerializeObject(Value, Constants.JsonConvertSettings);
|
Entity.Value = CoreJson.SerializeObject(Value);
|
||||||
Entity.Order = Order;
|
Entity.Order = Order;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +87,7 @@ namespace Artemis.Core
|
|||||||
? new DataModelConditionGroup(null, Entity.Condition)
|
? new DataModelConditionGroup(null, Entity.Condition)
|
||||||
: new DataModelConditionGroup(null);
|
: new DataModelConditionGroup(null);
|
||||||
|
|
||||||
Value = (Entity.Value == null ? default : JsonConvert.DeserializeObject<TProperty>(Entity.Value, Constants.JsonConvertSettings))!;
|
Value = (Entity.Value == null ? default : CoreJson.DeserializeObject<TProperty>(Entity.Value))!;
|
||||||
Order = Entity.Order;
|
Order = Entity.Order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -112,30 +112,6 @@ namespace Artemis.Core
|
|||||||
ValidateParameter();
|
ValidateParameter();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ValidateParameter()
|
|
||||||
{
|
|
||||||
if (ModifierType == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ParameterType == ProfileRightSideType.Dynamic)
|
|
||||||
{
|
|
||||||
if (ParameterPath == null || !ParameterPath.IsValid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Type parameterType = ParameterPath.GetPropertyType()!;
|
|
||||||
if (!ModifierType.SupportsType(parameterType, ModifierTypePart.Parameter))
|
|
||||||
UpdateParameterDynamic(null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ParameterStaticValue == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!ModifierType.SupportsType(ParameterStaticValue.GetType(), ModifierTypePart.Parameter))
|
|
||||||
UpdateParameterStatic(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the parameter of the modifier and makes the modifier dynamic
|
/// Updates the parameter of the modifier and makes the modifier dynamic
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -181,6 +157,30 @@ namespace Artemis.Core
|
|||||||
ParameterStaticValue = null;
|
ParameterStaticValue = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ValidateParameter()
|
||||||
|
{
|
||||||
|
if (ModifierType == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ParameterType == ProfileRightSideType.Dynamic)
|
||||||
|
{
|
||||||
|
if (ParameterPath == null || !ParameterPath.IsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Type parameterType = ParameterPath.GetPropertyType()!;
|
||||||
|
if (!ModifierType.SupportsType(parameterType, ModifierTypePart.Parameter))
|
||||||
|
UpdateParameterDynamic(null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ParameterStaticValue == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!ModifierType.SupportsType(ParameterStaticValue.GetType(), ModifierTypePart.Parameter))
|
||||||
|
UpdateParameterStatic(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Initialize()
|
private void Initialize()
|
||||||
{
|
{
|
||||||
DataBindingModifierTypeStore.DataBindingModifierAdded += DataBindingModifierTypeStoreOnDataBindingModifierAdded;
|
DataBindingModifierTypeStore.DataBindingModifierAdded += DataBindingModifierTypeStoreOnDataBindingModifierAdded;
|
||||||
@ -208,9 +208,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
staticValue = parameterType != null
|
staticValue = parameterType != null
|
||||||
? JsonConvert.DeserializeObject(Entity.ParameterStaticValue, parameterType, Constants.JsonConvertSettings)
|
? CoreJson.DeserializeObject(Entity.ParameterStaticValue, parameterType)
|
||||||
: JsonConvert.DeserializeObject(Entity.ParameterStaticValue, Constants.JsonConvertSettings);
|
: CoreJson.DeserializeObject(Entity.ParameterStaticValue);
|
||||||
}
|
}
|
||||||
// If deserialization fails, use the type's default
|
// If deserialization fails, use the type's default
|
||||||
catch (JsonSerializationException e)
|
catch (JsonSerializationException e)
|
||||||
@ -252,7 +252,7 @@ namespace Artemis.Core
|
|||||||
ParameterPath?.Save();
|
ParameterPath?.Save();
|
||||||
Entity.ParameterPath = ParameterPath?.Entity;
|
Entity.ParameterPath = ParameterPath?.Entity;
|
||||||
|
|
||||||
Entity.ParameterStaticValue = JsonConvert.SerializeObject(ParameterStaticValue, Constants.JsonConvertSettings);
|
Entity.ParameterStaticValue = CoreJson.SerializeObject(ParameterStaticValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -122,9 +122,7 @@ namespace Artemis.Core
|
|||||||
if (Parent == null)
|
if (Parent == null)
|
||||||
throw new ArtemisCoreException("Cannot create a copy of a folder without a parent");
|
throw new ArtemisCoreException("Cannot create a copy of a folder without a parent");
|
||||||
|
|
||||||
FolderEntity entityCopy = JsonConvert.DeserializeObject<FolderEntity>(
|
FolderEntity entityCopy = CoreJson.DeserializeObject<FolderEntity>(CoreJson.SerializeObject(FolderEntity, true), true)!;
|
||||||
JsonConvert.SerializeObject(FolderEntity, Constants.JsonConvertTypedSettings), Constants.JsonConvertTypedSettings
|
|
||||||
)!;
|
|
||||||
entityCopy.Id = Guid.NewGuid();
|
entityCopy.Id = Guid.NewGuid();
|
||||||
entityCopy.Name += " - Copy";
|
entityCopy.Name += " - Copy";
|
||||||
|
|
||||||
|
|||||||
@ -123,9 +123,7 @@ namespace Artemis.Core
|
|||||||
if (Parent == null)
|
if (Parent == null)
|
||||||
throw new ArtemisCoreException("Cannot create a copy of a layer without a parent");
|
throw new ArtemisCoreException("Cannot create a copy of a layer without a parent");
|
||||||
|
|
||||||
LayerEntity entityCopy = JsonConvert.DeserializeObject<LayerEntity>(
|
LayerEntity entityCopy = CoreJson.DeserializeObject<LayerEntity>(CoreJson.SerializeObject(LayerEntity, true), true)!;
|
||||||
JsonConvert.SerializeObject(LayerEntity, Constants.JsonConvertTypedSettings), Constants.JsonConvertTypedSettings
|
|
||||||
)!;
|
|
||||||
entityCopy.Id = Guid.NewGuid();
|
entityCopy.Id = Guid.NewGuid();
|
||||||
entityCopy.Name += " - Copy";
|
entityCopy.Name += " - Copy";
|
||||||
|
|
||||||
|
|||||||
@ -208,9 +208,8 @@ namespace Artemis.Core
|
|||||||
if (_disposed)
|
if (_disposed)
|
||||||
throw new ObjectDisposedException("LayerProperty");
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(DefaultValue, Constants.JsonConvertTypedSettings);
|
string json = CoreJson.SerializeObject(DefaultValue, true);
|
||||||
|
SetCurrentValue(CoreJson.DeserializeObject<T>(json)!, time);
|
||||||
SetCurrentValue(JsonConvert.DeserializeObject<T>(json), time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReapplyUpdate()
|
private void ReapplyUpdate()
|
||||||
@ -512,7 +511,7 @@ namespace Artemis.Core
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Entity.Value != null)
|
if (Entity.Value != null)
|
||||||
BaseValue = JsonConvert.DeserializeObject<T>(Entity.Value, Constants.JsonConvertSettings)!;
|
BaseValue = CoreJson.DeserializeObject<T>(Entity.Value)!;
|
||||||
}
|
}
|
||||||
catch (JsonException)
|
catch (JsonException)
|
||||||
{
|
{
|
||||||
@ -528,7 +527,7 @@ namespace Artemis.Core
|
|||||||
_keyframes.AddRange(Entity.KeyframeEntities
|
_keyframes.AddRange(Entity.KeyframeEntities
|
||||||
.Where(k => k.Position <= ProfileElement.Timeline.Length)
|
.Where(k => k.Position <= ProfileElement.Timeline.Length)
|
||||||
.Select(k => new LayerPropertyKeyframe<T>(
|
.Select(k => new LayerPropertyKeyframe<T>(
|
||||||
JsonConvert.DeserializeObject<T>(k.Value, Constants.JsonConvertSettings)!, k.Position, (Easings.Functions) k.EasingFunction, this
|
CoreJson.DeserializeObject<T>(k.Value)!, k.Position, (Easings.Functions) k.EasingFunction, this
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -557,12 +556,12 @@ namespace Artemis.Core
|
|||||||
if (!_isInitialized)
|
if (!_isInitialized)
|
||||||
throw new ArtemisCoreException("Layer property is not yet initialized");
|
throw new ArtemisCoreException("Layer property is not yet initialized");
|
||||||
|
|
||||||
Entity.Value = JsonConvert.SerializeObject(BaseValue, Constants.JsonConvertSettings);
|
Entity.Value = CoreJson.SerializeObject(BaseValue);
|
||||||
Entity.KeyframesEnabled = KeyframesEnabled;
|
Entity.KeyframesEnabled = KeyframesEnabled;
|
||||||
Entity.KeyframeEntities.Clear();
|
Entity.KeyframeEntities.Clear();
|
||||||
Entity.KeyframeEntities.AddRange(Keyframes.Select(k => new KeyframeEntity
|
Entity.KeyframeEntities.AddRange(Keyframes.Select(k => new KeyframeEntity
|
||||||
{
|
{
|
||||||
Value = JsonConvert.SerializeObject(k.Value, Constants.JsonConvertSettings),
|
Value = CoreJson.SerializeObject(k.Value),
|
||||||
Position = k.Position,
|
Position = k.Position,
|
||||||
EasingFunction = (int) k.EasingFunction
|
EasingFunction = (int) k.EasingFunction
|
||||||
}));
|
}));
|
||||||
|
|||||||
@ -29,7 +29,7 @@ namespace Artemis.Core
|
|||||||
Name = pluginSettingEntity.Name;
|
Name = pluginSettingEntity.Name;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_value = JsonConvert.DeserializeObject<T>(pluginSettingEntity.Value, Constants.JsonConvertSettings);
|
_value = CoreJson.DeserializeObject<T>(pluginSettingEntity.Value)!;
|
||||||
}
|
}
|
||||||
catch (JsonReaderException)
|
catch (JsonReaderException)
|
||||||
{
|
{
|
||||||
@ -66,7 +66,7 @@ namespace Artemis.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether the setting has been changed
|
/// Determines whether the setting has been changed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool HasChanged => JsonConvert.SerializeObject(Value, Constants.JsonConvertSettings) != _pluginSettingEntity.Value;
|
public bool HasChanged => CoreJson.SerializeObject(Value) != _pluginSettingEntity.Value;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets whether changes must automatically be saved
|
/// Gets or sets whether changes must automatically be saved
|
||||||
@ -79,7 +79,7 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void RejectChanges()
|
public void RejectChanges()
|
||||||
{
|
{
|
||||||
Value = JsonConvert.DeserializeObject<T>(_pluginSettingEntity.Value, Constants.JsonConvertSettings);
|
Value = CoreJson.DeserializeObject<T>(_pluginSettingEntity.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -90,7 +90,7 @@ namespace Artemis.Core
|
|||||||
if (!HasChanged)
|
if (!HasChanged)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_pluginSettingEntity.Value = JsonConvert.SerializeObject(Value, Constants.JsonConvertSettings);
|
_pluginSettingEntity.Value = CoreJson.SerializeObject(Value);
|
||||||
_pluginRepository.SaveSetting(_pluginSettingEntity);
|
_pluginRepository.SaveSetting(_pluginSettingEntity);
|
||||||
OnSettingSaved();
|
OnSettingSaved();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
PluginGuid = Plugin.Guid,
|
PluginGuid = Plugin.Guid,
|
||||||
Value = JsonConvert.SerializeObject(defaultValue, Constants.JsonConvertSettings)
|
Value = CoreJson.SerializeObject(defaultValue)
|
||||||
};
|
};
|
||||||
_pluginRepository.AddSetting(settingEntity);
|
_pluginRepository.AddSetting(settingEntity);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,10 +5,8 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core.DataModelExpansions;
|
using Artemis.Core.DataModelExpansions;
|
||||||
using Artemis.Core.JsonConverters;
|
|
||||||
using Artemis.Core.Ninject;
|
using Artemis.Core.Ninject;
|
||||||
using Artemis.Storage;
|
using Artemis.Storage;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
@ -114,7 +112,11 @@ namespace Artemis.Core.Services
|
|||||||
IntroAnimation intro = new IntroAnimation(_logger, _profileService, _surfaceService);
|
IntroAnimation intro = new IntroAnimation(_logger, _profileService, _surfaceService);
|
||||||
|
|
||||||
// Draw a white overlay over the device
|
// Draw a white overlay over the device
|
||||||
void DrawOverlay(object? sender, FrameRenderingEventArgs args) => intro.Render(args.DeltaTime, args.Canvas);
|
void DrawOverlay(object? sender, FrameRenderingEventArgs args)
|
||||||
|
{
|
||||||
|
intro.Render(args.DeltaTime, args.Canvas);
|
||||||
|
}
|
||||||
|
|
||||||
FrameRendering += DrawOverlay;
|
FrameRendering += DrawOverlay;
|
||||||
|
|
||||||
// Stop rendering after the profile finishes (take 1 second extra in case of slow updates)
|
// Stop rendering after the profile finishes (take 1 second extra in case of slow updates)
|
||||||
@ -181,11 +183,9 @@ namespace Artemis.Core.Services
|
|||||||
using SKCanvas canvas = new SKCanvas(_rgbService.BitmapBrush.Bitmap);
|
using SKCanvas canvas = new SKCanvas(_rgbService.BitmapBrush.Bitmap);
|
||||||
canvas.Clear(new SKColor(0, 0, 0));
|
canvas.Clear(new SKColor(0, 0, 0));
|
||||||
if (!ModuleRenderingDisabled)
|
if (!ModuleRenderingDisabled)
|
||||||
{
|
|
||||||
// While non-activated modules may be updated above if they expand the main data model, they may never render
|
// While non-activated modules may be updated above if they expand the main data model, they may never render
|
||||||
foreach (Module module in modules.Where(m => m.IsActivated))
|
foreach (Module module in modules.Where(m => m.IsActivated))
|
||||||
module.InternalRender(args.DeltaTime, _surfaceService.ActiveSurface, canvas, _rgbService.BitmapBrush.Bitmap.Info);
|
module.InternalRender(args.DeltaTime, _surfaceService.ActiveSurface, canvas, _rgbService.BitmapBrush.Bitmap.Info);
|
||||||
}
|
|
||||||
|
|
||||||
OnFrameRendering(new FrameRenderingEventArgs(canvas, args.DeltaTime, _rgbService.Surface));
|
OnFrameRendering(new FrameRenderingEventArgs(canvas, args.DeltaTime, _rgbService.Surface));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,6 @@ using Artemis.Core.Ninject;
|
|||||||
using Artemis.Storage.Entities.Plugins;
|
using Artemis.Storage.Entities.Plugins;
|
||||||
using Artemis.Storage.Repositories.Interfaces;
|
using Artemis.Storage.Repositories.Interfaces;
|
||||||
using McMaster.NETCore.Plugins;
|
using McMaster.NETCore.Plugins;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using Ninject.Extensions.ChildKernel;
|
using Ninject.Extensions.ChildKernel;
|
||||||
using Ninject.Parameters;
|
using Ninject.Parameters;
|
||||||
@ -78,7 +77,7 @@ namespace Artemis.Core.Services
|
|||||||
throw new ArtemisPluginException("Couldn't find a plugin.json in " + zipFile.FullName);
|
throw new ArtemisPluginException("Couldn't find a plugin.json in " + zipFile.FullName);
|
||||||
|
|
||||||
using StreamReader reader = new StreamReader(metaDataFileEntry.Open());
|
using StreamReader reader = new StreamReader(metaDataFileEntry.Open());
|
||||||
PluginInfo builtInPluginInfo = JsonConvert.DeserializeObject<PluginInfo>(reader.ReadToEnd(), Constants.JsonConvertSettings)!;
|
PluginInfo builtInPluginInfo = CoreJson.DeserializeObject<PluginInfo>(reader.ReadToEnd())!;
|
||||||
|
|
||||||
// Find the matching plugin in the plugin folder
|
// Find the matching plugin in the plugin folder
|
||||||
DirectoryInfo? match = pluginDirectory.EnumerateDirectories().FirstOrDefault(d => d.Name == Path.GetFileNameWithoutExtension(zipFile.Name));
|
DirectoryInfo? match = pluginDirectory.EnumerateDirectories().FirstOrDefault(d => d.Name == Path.GetFileNameWithoutExtension(zipFile.Name));
|
||||||
@ -99,7 +98,7 @@ namespace Artemis.Core.Services
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Compare versions, copy if the same when debugging
|
// Compare versions, copy if the same when debugging
|
||||||
PluginInfo pluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile), Constants.JsonConvertSettings)!;
|
PluginInfo pluginInfo = CoreJson.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile))!;
|
||||||
|
|
||||||
if (builtInPluginInfo.Version > pluginInfo.Version)
|
if (builtInPluginInfo.Version > pluginInfo.Version)
|
||||||
{
|
{
|
||||||
@ -186,7 +185,6 @@ namespace Artemis.Core.Services
|
|||||||
// Load the plugin assemblies into the plugin context
|
// Load the plugin assemblies into the plugin context
|
||||||
DirectoryInfo pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
|
DirectoryInfo pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
|
||||||
foreach (DirectoryInfo subDirectory in pluginDirectory.EnumerateDirectories())
|
foreach (DirectoryInfo subDirectory in pluginDirectory.EnumerateDirectories())
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Plugin plugin = LoadPlugin(subDirectory);
|
Plugin plugin = LoadPlugin(subDirectory);
|
||||||
@ -197,7 +195,6 @@ namespace Artemis.Core.Services
|
|||||||
{
|
{
|
||||||
_logger.Warning(new ArtemisPluginException("Failed to load plugin", e), "Plugin exception");
|
_logger.Warning(new ArtemisPluginException("Failed to load plugin", e), "Plugin exception");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
LoadingPlugins = false;
|
LoadingPlugins = false;
|
||||||
}
|
}
|
||||||
@ -226,7 +223,7 @@ namespace Artemis.Core.Services
|
|||||||
_logger.Warning(new ArtemisPluginException("Couldn't find the plugins metadata file at " + metadataFile), "Plugin exception");
|
_logger.Warning(new ArtemisPluginException("Couldn't find the plugins metadata file at " + metadataFile), "Plugin exception");
|
||||||
|
|
||||||
// PluginInfo contains the ID which we need to move on
|
// PluginInfo contains the ID which we need to move on
|
||||||
PluginInfo pluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile), Constants.JsonConvertSettings)!;
|
PluginInfo pluginInfo = CoreJson.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile))!;
|
||||||
|
|
||||||
if (pluginInfo.Guid == Constants.CorePluginInfo.Guid)
|
if (pluginInfo.Guid == Constants.CorePluginInfo.Guid)
|
||||||
throw new ArtemisPluginException($"Plugin cannot use reserved GUID {pluginInfo.Guid}");
|
throw new ArtemisPluginException($"Plugin cannot use reserved GUID {pluginInfo.Guid}");
|
||||||
@ -300,7 +297,7 @@ namespace Artemis.Core.Services
|
|||||||
throw new ArtemisPluginException(
|
throw new ArtemisPluginException(
|
||||||
plugin,
|
plugin,
|
||||||
"Failed to initialize the plugin assembly",
|
"Failed to initialize the plugin assembly",
|
||||||
new AggregateException(e.LoaderExceptions.Where(le => le != null).Cast<Exception>().ToArray())
|
new AggregateException(e.LoaderExceptions.Where(le => le != null).ToArray())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +307,6 @@ namespace Artemis.Core.Services
|
|||||||
// Create instances of each feature and add them to the plugin
|
// Create instances of each feature and add them to the plugin
|
||||||
// Construction should be simple and not contain any logic so failure at this point means the entire plugin fails
|
// Construction should be simple and not contain any logic so failure at this point means the entire plugin fails
|
||||||
foreach (Type featureType in featureTypes)
|
foreach (Type featureType in featureTypes)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin.Kernel.Bind(featureType).ToSelf().InSingletonScope();
|
plugin.Kernel.Bind(featureType).ToSelf().InSingletonScope();
|
||||||
@ -328,11 +324,9 @@ namespace Artemis.Core.Services
|
|||||||
{
|
{
|
||||||
throw new ArtemisPluginException(plugin, "Failed to instantiate feature", e);
|
throw new ArtemisPluginException(plugin, "Failed to instantiate feature", e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Activate plugins after they are all loaded
|
// Activate plugins after they are all loaded
|
||||||
foreach (PluginFeature pluginFeature in plugin.Features.Where(i => i.Entity.IsEnabled))
|
foreach (PluginFeature pluginFeature in plugin.Features.Where(i => i.Entity.IsEnabled))
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
EnablePluginFeature(pluginFeature, false, !ignorePluginLock);
|
EnablePluginFeature(pluginFeature, false, !ignorePluginLock);
|
||||||
@ -341,7 +335,6 @@ namespace Artemis.Core.Services
|
|||||||
{
|
{
|
||||||
// ignored, logged in EnablePluginFeature
|
// ignored, logged in EnablePluginFeature
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (saveState)
|
if (saveState)
|
||||||
{
|
{
|
||||||
@ -483,10 +476,8 @@ namespace Artemis.Core.Services
|
|||||||
private void SavePlugin(Plugin plugin)
|
private void SavePlugin(Plugin plugin)
|
||||||
{
|
{
|
||||||
foreach (PluginFeature pluginFeature in plugin.Features)
|
foreach (PluginFeature pluginFeature in plugin.Features)
|
||||||
{
|
|
||||||
if (plugin.Entity.Features.All(i => i.Type != pluginFeature.GetType().FullName))
|
if (plugin.Entity.Features.All(i => i.Type != pluginFeature.GetType().FullName))
|
||||||
plugin.Entity.Features.Add(pluginFeature.Entity);
|
plugin.Entity.Features.Add(pluginFeature.Entity);
|
||||||
}
|
|
||||||
|
|
||||||
_pluginRepository.SavePlugin(plugin.Entity);
|
_pluginRepository.SavePlugin(plugin.Entity);
|
||||||
}
|
}
|
||||||
|
|||||||
69
src/Artemis.Core/Utilities/CoreJson.cs
Normal file
69
src/Artemis.Core/Utilities/CoreJson.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Artemis.Core
|
||||||
|
{
|
||||||
|
internal static class CoreJson
|
||||||
|
{
|
||||||
|
#region Serialize
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes the specified object to a JSON string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The object to serialize.</param>
|
||||||
|
/// <param name="handleTypeNames">If set to true sets TypeNameHandling to <see cref="TypeNameHandling.All" /></param>
|
||||||
|
/// <returns>A JSON string representation of the object.</returns>
|
||||||
|
[DebuggerStepThrough]
|
||||||
|
public static string SerializeObject(object? value, bool handleTypeNames = false)
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(value, handleTypeNames ? Constants.JsonConvertTypedSettings : Constants.JsonConvertSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Deserialize
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the JSON to a .NET object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The JSON to deserialize.</param>
|
||||||
|
/// <param name="handleTypeNames">If set to true sets TypeNameHandling to <see cref="TypeNameHandling.All" /></param>
|
||||||
|
/// <returns>The deserialized object from the JSON string.</returns>
|
||||||
|
[DebuggerStepThrough]
|
||||||
|
public static object? DeserializeObject(string value, bool handleTypeNames = false)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject(value, handleTypeNames ? Constants.JsonConvertTypedSettings : Constants.JsonConvertSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the JSON to the specified .NET type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The JSON to deserialize.</param>
|
||||||
|
/// <param name="type">The <see cref="Type" /> of object being deserialized.</param>
|
||||||
|
/// <param name="handleTypeNames">If set to true sets TypeNameHandling to <see cref="TypeNameHandling.All" /></param>
|
||||||
|
/// <returns>The deserialized object from the JSON string.</returns>
|
||||||
|
[DebuggerStepThrough]
|
||||||
|
public static object? DeserializeObject(string value, Type type, bool handleTypeNames = false)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject(value, type, handleTypeNames ? Constants.JsonConvertTypedSettings : Constants.JsonConvertSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the JSON to the specified .NET type.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the object to deserialize to.</typeparam>
|
||||||
|
/// <param name="value">The JSON to deserialize.</param>
|
||||||
|
/// <param name="handleTypeNames">If set to true sets TypeNameHandling to <see cref="TypeNameHandling.All" /></param>
|
||||||
|
/// <returns>The deserialized object from the JSON string.</returns>
|
||||||
|
[DebuggerStepThrough]
|
||||||
|
[return: MaybeNull]
|
||||||
|
public static T DeserializeObject<T>(string value, bool handleTypeNames = false)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(value, handleTypeNames ? Constants.JsonConvertTypedSettings : Constants.JsonConvertSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,7 +4,6 @@ using System.Linq;
|
|||||||
using Artemis.Core.Modules;
|
using Artemis.Core.Modules;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
// Load the intro profile from JSON into a ProfileEntity
|
// Load the intro profile from JSON into a ProfileEntity
|
||||||
string json = File.ReadAllText(Path.Combine(Constants.ApplicationFolder, "Resources", "intro-profile.json"));
|
string json = File.ReadAllText(Path.Combine(Constants.ApplicationFolder, "Resources", "intro-profile.json"));
|
||||||
ProfileEntity profileEntity = JsonConvert.DeserializeObject<ProfileEntity>(json, Constants.JsonConvertSettings)!;
|
ProfileEntity profileEntity = CoreJson.DeserializeObject<ProfileEntity>(json)!;
|
||||||
// Inject every LED on the surface into each layer
|
// Inject every LED on the surface into each layer
|
||||||
foreach (LayerEntity profileEntityLayer in profileEntity.Layers)
|
foreach (LayerEntity profileEntityLayer in profileEntity.Layers)
|
||||||
profileEntityLayer.Leds.AddRange(_surfaceService.ActiveSurface.Devices.SelectMany(d => d.Leds).Select(l => new LedEntity
|
profileEntityLayer.Leds.AddRange(_surfaceService.ActiveSurface.Devices.SelectMany(d => d.Leds).Select(l => new LedEntity
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user