Core - Removed JsonConvert.DefaultSettings assignement

This could break libraries used by plugins, this closes #501
This commit is contained in:
Robert committed 2020-11-26 19:15:52 +01:00
1 parent 81bb278abe
commit 190d64b497
12 files changed
+56 -44

No files matched your search

@@ -115,7 +115,7 @@ namespace Artemis.Core
try
{
rightSideValue = JsonConvert.DeserializeObject(Entity.RightStaticValue, leftSideType);
rightSideValue = JsonConvert.DeserializeObject(Entity.RightStaticValue, leftSideType, Constants.JsonConvertSettings);
}
// If deserialization fails, use the type's default
catch (JsonSerializationException e)
@@ -129,7 +129,7 @@ namespace Artemis.Core
else
{
// Hope for the best...
UpdateRightSideStatic(JsonConvert.DeserializeObject(Entity.RightStaticValue));
UpdateRightSideStatic(JsonConvert.DeserializeObject(Entity.RightStaticValue, Constants.JsonConvertSettings));
}
}
catch (JsonReaderException e)
@@ -349,7 +349,7 @@ namespace Artemis.Core
RightPath?.Save();
Entity.RightPath = RightPath?.Entity;
Entity.RightStaticValue = JsonConvert.SerializeObject(RightStaticValue);
Entity.RightStaticValue = JsonConvert.SerializeObject(RightStaticValue, Constants.JsonConvertSettings);
if (Operator?.Plugin != null)
{
@@ -74,7 +74,7 @@ namespace Artemis.Core
Entity.Condition = Condition.Entity;
Condition.Save();
Entity.Value = JsonConvert.SerializeObject(Value);
Entity.Value = JsonConvert.SerializeObject(Value, Constants.JsonConvertSettings);
Entity.Order = Order;
}
@@ -88,7 +88,7 @@ namespace Artemis.Core
? new DataModelConditionGroup(null, Entity.Condition)
: new DataModelConditionGroup(null);
Value = (Entity.Value == null ? default : JsonConvert.DeserializeObject<TProperty>(Entity.Value))!;
Value = (Entity.Value == null ? default : JsonConvert.DeserializeObject<TProperty>(Entity.Value, Constants.JsonConvertSettings))!;
Order = Entity.Order;
}
@@ -209,8 +209,8 @@ namespace Artemis.Core
try
{
staticValue = parameterType != null
? JsonConvert.DeserializeObject(Entity.ParameterStaticValue, parameterType)
: JsonConvert.DeserializeObject(Entity.ParameterStaticValue);
? JsonConvert.DeserializeObject(Entity.ParameterStaticValue, parameterType, Constants.JsonConvertSettings)
: JsonConvert.DeserializeObject(Entity.ParameterStaticValue, Constants.JsonConvertSettings);
}
// If deserialization fails, use the type's default
catch (JsonSerializationException e)
@@ -252,7 +252,7 @@ namespace Artemis.Core
ParameterPath?.Save();
Entity.ParameterPath = ParameterPath?.Entity;
Entity.ParameterStaticValue = JsonConvert.SerializeObject(ParameterStaticValue);
Entity.ParameterStaticValue = JsonConvert.SerializeObject(ParameterStaticValue, Constants.JsonConvertSettings);
}
/// <inheritdoc />
+5 -4
View File
@@ -29,7 +29,7 @@ namespace Artemis.Core
Profile = Parent.Profile;
Name = name;
Enabled = true;
Parent.AddChild(this);
}
@@ -43,7 +43,7 @@ namespace Artemis.Core
Name = folderEntity.Name;
Enabled = folderEntity.Enabled;
Order = folderEntity.Order;
Load();
}
@@ -122,8 +122,9 @@ namespace Artemis.Core
if (Parent == null)
throw new ArtemisCoreException("Cannot create a copy of a folder without a parent");
JsonSerializerSettings settings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
FolderEntity entityCopy = JsonConvert.DeserializeObject<FolderEntity>(JsonConvert.SerializeObject(FolderEntity, settings), settings)!;
FolderEntity entityCopy = JsonConvert.DeserializeObject<FolderEntity>(
JsonConvert.SerializeObject(FolderEntity, Constants.JsonConvertTypedSettings), Constants.JsonConvertTypedSettings
)!;
entityCopy.Id = Guid.NewGuid();
entityCopy.Name += " - Copy";
+7 -6
View File
@@ -39,9 +39,9 @@ namespace Artemis.Core
Enabled = true;
_general = new LayerGeneralProperties();
_transform = new LayerTransformProperties();
_leds = new List<ArtemisLed>();
Initialize();
Parent.AddChild(this);
}
@@ -55,7 +55,7 @@ namespace Artemis.Core
Parent = parent;
_general = new LayerGeneralProperties();
_transform = new LayerTransformProperties();
_leds = new List<ArtemisLed>();
Load();
@@ -123,8 +123,9 @@ namespace Artemis.Core
if (Parent == null)
throw new ArtemisCoreException("Cannot create a copy of a layer without a parent");
JsonSerializerSettings settings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
LayerEntity entityCopy = JsonConvert.DeserializeObject<LayerEntity>(JsonConvert.SerializeObject(LayerEntity, settings), settings)!;
LayerEntity entityCopy = JsonConvert.DeserializeObject<LayerEntity>(
JsonConvert.SerializeObject(LayerEntity, Constants.JsonConvertTypedSettings), Constants.JsonConvertTypedSettings
)!;
entityCopy.Id = Guid.NewGuid();
entityCopy.Name += " - Copy";
@@ -640,7 +641,7 @@ namespace Artemis.Core
if (current == null)
return;
LayerBrushDescriptor? descriptor = current.LayerBrushProviderId != null && current.BrushType != null
LayerBrushDescriptor? descriptor = current.LayerBrushProviderId != null && current.BrushType != null
? LayerBrushStore.Get(current.LayerBrushProviderId, current.BrushType)?.LayerBrushDescriptor
: null;
descriptor?.CreateInstance(this);
@@ -208,7 +208,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("LayerProperty");
string json = JsonConvert.SerializeObject(DefaultValue, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All });
string json = JsonConvert.SerializeObject(DefaultValue, Constants.JsonConvertTypedSettings);
SetCurrentValue(JsonConvert.DeserializeObject<T>(json), time);
}
@@ -512,7 +512,7 @@ namespace Artemis.Core
try
{
if (Entity.Value != null)
BaseValue = JsonConvert.DeserializeObject<T>(Entity.Value);
BaseValue = JsonConvert.DeserializeObject<T>(Entity.Value, Constants.JsonConvertSettings)!;
}
catch (JsonException)
{
@@ -525,9 +525,11 @@ namespace Artemis.Core
_keyframes.Clear();
try
{
_keyframes.AddRange(
Entity.KeyframeEntities.Where(k => k.Position <= ProfileElement.Timeline.Length)
.Select(k => new LayerPropertyKeyframe<T>(JsonConvert.DeserializeObject<T>(k.Value), k.Position, (Easings.Functions) k.EasingFunction, this))
_keyframes.AddRange(Entity.KeyframeEntities
.Where(k => k.Position <= ProfileElement.Timeline.Length)
.Select(k => new LayerPropertyKeyframe<T>(
JsonConvert.DeserializeObject<T>(k.Value, Constants.JsonConvertSettings)!, k.Position, (Easings.Functions) k.EasingFunction, this
))
);
}
catch (JsonException)
@@ -555,12 +557,12 @@ namespace Artemis.Core
if (!_isInitialized)
throw new ArtemisCoreException("Layer property is not yet initialized");
Entity.Value = JsonConvert.SerializeObject(BaseValue);
Entity.Value = JsonConvert.SerializeObject(BaseValue, Constants.JsonConvertSettings);
Entity.KeyframesEnabled = KeyframesEnabled;
Entity.KeyframeEntities.Clear();
Entity.KeyframeEntities.AddRange(Keyframes.Select(k => new KeyframeEntity
{
Value = JsonConvert.SerializeObject(k.Value),
Value = JsonConvert.SerializeObject(k.Value, Constants.JsonConvertSettings),
Position = k.Position,
EasingFunction = (int) k.EasingFunction
}));