mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Core - Replaced JSON.NET with System.Text.Json
This commit is contained in:
parent
e112ca9da8
commit
6d8572cce0
@ -42,7 +42,6 @@
|
|||||||
<PackageReference Include="Humanizer.Core" />
|
<PackageReference Include="Humanizer.Core" />
|
||||||
<PackageReference Include="JetBrains.Annotations" />
|
<PackageReference Include="JetBrains.Annotations" />
|
||||||
<PackageReference Include="McMaster.NETCore.Plugins" />
|
<PackageReference Include="McMaster.NETCore.Plugins" />
|
||||||
<PackageReference Include="Newtonsoft.Json" />
|
|
||||||
<PackageReference Include="RGB.NET.Core" />
|
<PackageReference Include="RGB.NET.Core" />
|
||||||
<PackageReference Include="RGB.NET.Layout" />
|
<PackageReference Include="RGB.NET.Layout" />
|
||||||
<PackageReference Include="RGB.NET.Presets" />
|
<PackageReference Include="RGB.NET.Presets" />
|
||||||
@ -50,6 +49,7 @@
|
|||||||
<PackageReference Include="Serilog.Sinks.Debug" />
|
<PackageReference Include="Serilog.Sinks.Debug" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" />
|
<PackageReference Include="Serilog.Sinks.File" />
|
||||||
<PackageReference Include="SkiaSharp" />
|
<PackageReference Include="SkiaSharp" />
|
||||||
|
<PackageReference Include="System.Text.Json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -4,10 +4,8 @@ using System.Collections.ObjectModel;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
using Artemis.Core.JsonConverters;
|
using Artemis.Core.JsonConverters;
|
||||||
using Artemis.Core.Services;
|
|
||||||
using Artemis.Core.SkiaSharp;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
@ -97,15 +95,9 @@ public static class Constants
|
|||||||
internal static readonly CorePluginFeature CorePluginFeature = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Core")};
|
internal static readonly CorePluginFeature CorePluginFeature = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Core")};
|
||||||
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Effect Placeholder")};
|
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Effect Placeholder")};
|
||||||
|
|
||||||
internal static JsonSerializerSettings JsonConvertSettings = new()
|
internal static JsonSerializerOptions JsonConvertSettings = new()
|
||||||
{
|
{
|
||||||
Converters = new List<JsonConverter> {new SKColorConverter(), new NumericJsonConverter(), new ForgivingIntConverter()}
|
Converters = {new SKColorConverter(), new NumericJsonConverter(), new ForgivingIntConverter()}
|
||||||
};
|
|
||||||
|
|
||||||
internal static JsonSerializerSettings JsonConvertTypedSettings = new()
|
|
||||||
{
|
|
||||||
TypeNameHandling = TypeNameHandling.All,
|
|
||||||
Converters = new List<JsonConverter> {new SKColorConverter(), new NumericJsonConverter(), new ForgivingIntConverter()}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,32 +1,34 @@
|
|||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Artemis.Core.JsonConverters;
|
namespace Artemis.Core.JsonConverters
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// An int converter that, if required, will round float values
|
|
||||||
/// </summary>
|
|
||||||
internal class ForgivingIntConverter : JsonConverter<int>
|
|
||||||
{
|
{
|
||||||
public override bool CanWrite => false;
|
/// <summary>
|
||||||
|
/// An int converter that, if required, will round float values
|
||||||
public override void WriteJson(JsonWriter writer, int value, JsonSerializer serializer)
|
/// </summary>
|
||||||
|
internal class ForgivingIntConverter : JsonConverter<int>
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
}
|
{
|
||||||
|
if (reader.TokenType == JsonTokenType.Null)
|
||||||
|
throw new JsonException("Cannot convert null value.");
|
||||||
|
|
||||||
public override int ReadJson(JsonReader reader, Type objectType, int existingValue, bool hasExistingValue, JsonSerializer serializer)
|
if (reader.TokenType == JsonTokenType.Number)
|
||||||
{
|
{
|
||||||
JValue? jsonValue = serializer.Deserialize<JValue>(reader);
|
if (reader.TryGetInt32(out int intValue))
|
||||||
if (jsonValue == null)
|
return intValue;
|
||||||
throw new JsonReaderException("Failed to deserialize forgiving int value");
|
|
||||||
|
|
||||||
if (jsonValue.Type == JTokenType.Float)
|
if (reader.TryGetDouble(out double doubleValue))
|
||||||
return (int) Math.Round(jsonValue.Value<double>());
|
return (int)Math.Round(doubleValue);
|
||||||
if (jsonValue.Type == JTokenType.Integer)
|
}
|
||||||
return jsonValue.Value<int>();
|
|
||||||
|
|
||||||
throw new JsonReaderException("Failed to deserialize forgiving int value");
|
throw new JsonException("Failed to deserialize forgiving int value");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,26 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Converters;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Artemis.Core.JsonConverters
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Version converter that is forgiving of missing parts of the version string,
|
|
||||||
/// setting them to zero instead of -1.
|
|
||||||
/// </summary>
|
|
||||||
internal class ForgivingVersionConverter : VersionConverter
|
|
||||||
{
|
|
||||||
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
|
||||||
{
|
|
||||||
object? obj = base.ReadJson(reader, objectType, existingValue, serializer);
|
|
||||||
if (obj is not Version v)
|
|
||||||
return obj;
|
|
||||||
|
|
||||||
int major = v.Major == -1 ? 0 : v.Major;
|
|
||||||
int minor = v.Minor == -1 ? 0 : v.Minor;
|
|
||||||
int build = v.Build == -1 ? 0 : v.Build;
|
|
||||||
int revision = v.Revision == -1 ? 0 : v.Revision;
|
|
||||||
return new Version(major, minor, build, revision);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,24 +1,26 @@
|
|||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Artemis.Core.JsonConverters;
|
namespace Artemis.Core.JsonConverters
|
||||||
|
|
||||||
internal class NumericJsonConverter : JsonConverter<Numeric>
|
|
||||||
{
|
{
|
||||||
#region Overrides of JsonConverter<Numeric>
|
internal class NumericJsonConverter : JsonConverter<Numeric>
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void WriteJson(JsonWriter writer, Numeric value, JsonSerializer serializer)
|
|
||||||
{
|
{
|
||||||
float floatValue = value;
|
public override void Write(Utf8JsonWriter writer, Numeric value, JsonSerializerOptions options)
|
||||||
writer.WriteValue(floatValue);
|
{
|
||||||
}
|
float floatValue = value;
|
||||||
|
writer.WriteNumberValue(floatValue);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
public override Numeric Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
public override Numeric ReadJson(JsonReader reader, Type objectType, Numeric existingValue, bool hasExistingValue, JsonSerializer serializer)
|
{
|
||||||
{
|
if (reader.TokenType != JsonTokenType.Number)
|
||||||
return new Numeric(reader.Value);
|
{
|
||||||
}
|
throw new JsonException($"Expected a number token, but got {reader.TokenType}.");
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
float floatValue = reader.GetSingle();
|
||||||
|
return new Numeric(floatValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,21 +1,26 @@
|
|||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace Artemis.Core.JsonConverters;
|
namespace Artemis.Core.JsonConverters
|
||||||
|
|
||||||
internal class SKColorConverter : JsonConverter<SKColor>
|
|
||||||
{
|
{
|
||||||
public override void WriteJson(JsonWriter writer, SKColor value, JsonSerializer serializer)
|
internal class SKColorConverter : JsonConverter<SKColor>
|
||||||
{
|
{
|
||||||
writer.WriteValue(value.ToString());
|
public override void Write(Utf8JsonWriter writer, SKColor value, JsonSerializerOptions options)
|
||||||
}
|
{
|
||||||
|
writer.WriteStringValue(value.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
public override SKColor ReadJson(JsonReader reader, Type objectType, SKColor existingValue, bool hasExistingValue, JsonSerializer serializer)
|
public override SKColor Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
if (reader.Value is string value && !string.IsNullOrWhiteSpace(value))
|
if (reader.TokenType != JsonTokenType.String)
|
||||||
return SKColor.Parse(value);
|
{
|
||||||
|
throw new JsonException($"Expected a string token, but got {reader.TokenType}.");
|
||||||
|
}
|
||||||
|
|
||||||
return SKColor.Empty;
|
string colorString = reader.GetString() ?? string.Empty;
|
||||||
|
return SKColor.TryParse(colorString, out SKColor color) ? color : SKColor.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,44 +1,31 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Artemis.Core.JsonConverters;
|
namespace Artemis.Core.JsonConverters
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public class StreamConverter : JsonConverter<Stream>
|
|
||||||
{
|
{
|
||||||
#region Overrides of JsonConverter<Stream>
|
internal class StreamConverter : JsonConverter<Stream>
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void WriteJson(JsonWriter writer, Stream? value, JsonSerializer serializer)
|
|
||||||
{
|
{
|
||||||
if (value == null)
|
public override void Write(Utf8JsonWriter writer, Stream value, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
writer.WriteNull();
|
using MemoryStream memoryStream = new();
|
||||||
return;
|
value.Position = 0;
|
||||||
|
value.CopyTo(memoryStream);
|
||||||
|
writer.WriteBase64StringValue(memoryStream.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
using MemoryStream memoryStream = new();
|
public override Stream Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
value.Position = 0;
|
{
|
||||||
value.CopyTo(memoryStream);
|
if (reader.TokenType != JsonTokenType.String)
|
||||||
writer.WriteValue(memoryStream.ToArray());
|
throw new JsonException($"Expected a string token, but got {reader.TokenType}.");
|
||||||
|
|
||||||
|
string base64 = reader.GetString() ?? string.Empty;
|
||||||
|
|
||||||
|
if (typeToConvert == typeof(MemoryStream))
|
||||||
|
return new MemoryStream(Convert.FromBase64String(base64));
|
||||||
|
|
||||||
|
throw new InvalidOperationException("StreamConverter only supports reading to MemoryStream");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Stream? ReadJson(JsonReader reader, Type objectType, Stream? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
|
||||||
{
|
|
||||||
if (reader.Value is not string base64)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (existingValue == null || !hasExistingValue || !existingValue.CanRead)
|
|
||||||
return new MemoryStream(Convert.FromBase64String(base64));
|
|
||||||
|
|
||||||
using MemoryStream memoryStream = new(Convert.FromBase64String(base64));
|
|
||||||
existingValue.Position = 0;
|
|
||||||
memoryStream.CopyTo(existingValue);
|
|
||||||
existingValue.Position = 0;
|
|
||||||
return existingValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ public sealed class Folder : RenderProfileElement
|
|||||||
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 = CoreJson.DeserializeObject<FolderEntity>(CoreJson.SerializeObject(FolderEntity, true), true)!;
|
FolderEntity entityCopy = CoreJson.DeserializeObject<FolderEntity>(CoreJson.SerializeObject(FolderEntity))!;
|
||||||
entityCopy.Id = Guid.NewGuid();
|
entityCopy.Id = Guid.NewGuid();
|
||||||
entityCopy.Name += " - Copy";
|
entityCopy.Name += " - Copy";
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ public class LayerProperty<T> : CorePropertyChanged, ILayerProperty
|
|||||||
// Reference types make a deep clone (ab)using JSON
|
// Reference types make a deep clone (ab)using JSON
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string json = CoreJson.SerializeObject(DefaultValue, true);
|
string json = CoreJson.SerializeObject(DefaultValue);
|
||||||
SetCurrentValue(CoreJson.DeserializeObject<T>(json)!);
|
SetCurrentValue(CoreJson.DeserializeObject<T>(json)!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Artemis.Core.JsonConverters;
|
using Artemis.Core.JsonConverters;
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ public class ProfileConfigurationExportModel : IDisposable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the storage entity of the profile
|
/// Gets or sets the storage entity of the profile
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonRequired]
|
||||||
public ProfileEntity ProfileEntity { get; set; } = null!;
|
public ProfileEntity ProfileEntity { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -4,8 +4,8 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core.Modules;
|
namespace Artemis.Core.Modules;
|
||||||
|
|
||||||
|
|||||||
@ -3,14 +3,12 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Storage.Entities.Plugins;
|
using Artemis.Storage.Entities.Plugins;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents basic info about a plugin feature and contains a reference to the instance of said feature
|
/// Represents basic info about a plugin feature and contains a reference to the instance of said feature
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonObject(MemberSerialization.OptIn)]
|
|
||||||
public class PluginFeatureInfo : CorePropertyChanged, IPrerequisitesSubject
|
public class PluginFeatureInfo : CorePropertyChanged, IPrerequisitesSubject
|
||||||
{
|
{
|
||||||
private string? _description;
|
private string? _description;
|
||||||
@ -64,7 +62,6 @@ public class PluginFeatureInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the feature
|
/// The name of the feature
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get => _name;
|
get => _name;
|
||||||
@ -74,7 +71,6 @@ public class PluginFeatureInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A short description of the feature
|
/// A short description of the feature
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public string? Description
|
public string? Description
|
||||||
{
|
{
|
||||||
get => _description;
|
get => _description;
|
||||||
@ -85,7 +81,6 @@ public class PluginFeatureInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// Marks the feature to always be enabled as long as the plugin is enabled and cannot be disabled.
|
/// Marks the feature to always be enabled as long as the plugin is enabled and cannot be disabled.
|
||||||
/// <para>Note: always <see langword="true" /> if this is the plugin's only feature</para>
|
/// <para>Note: always <see langword="true" /> if this is the plugin's only feature</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public bool AlwaysEnabled { get; internal set; }
|
public bool AlwaysEnabled { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,16 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Core.JsonConverters;
|
using System.Text.Json.Serialization;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents basic info about a plugin and contains a reference to the instance of said plugin
|
/// Represents basic info about a plugin and contains a reference to the instance of said plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonObject(MemberSerialization.OptIn)]
|
|
||||||
public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
||||||
{
|
{
|
||||||
private Version? _api;
|
private Version? _api;
|
||||||
@ -28,7 +25,7 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
private string _version = null!;
|
private string _version = null!;
|
||||||
private Uri? _website;
|
private Uri? _website;
|
||||||
private Uri? _helpPage;
|
private Uri? _helpPage;
|
||||||
private bool _hotReloadSupported;
|
private bool _hotReloadSupported = true;
|
||||||
private Uri? _license;
|
private Uri? _license;
|
||||||
private string? _licenseName;
|
private string? _licenseName;
|
||||||
|
|
||||||
@ -39,7 +36,7 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The plugins GUID
|
/// The plugins GUID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonRequired]
|
||||||
public Guid Guid
|
public Guid Guid
|
||||||
{
|
{
|
||||||
get => _guid;
|
get => _guid;
|
||||||
@ -49,7 +46,7 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the plugin
|
/// The name of the plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonRequired]
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get => _name;
|
get => _name;
|
||||||
@ -59,7 +56,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A short description of the plugin
|
/// A short description of the plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public string? Description
|
public string? Description
|
||||||
{
|
{
|
||||||
get => _description;
|
get => _description;
|
||||||
@ -69,7 +65,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the author of this plugin
|
/// Gets or sets the author of this plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public string? Author
|
public string? Author
|
||||||
{
|
{
|
||||||
get => _author;
|
get => _author;
|
||||||
@ -79,7 +74,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the website of this plugin or its author
|
/// Gets or sets the website of this plugin or its author
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public Uri? Website
|
public Uri? Website
|
||||||
{
|
{
|
||||||
get => _website;
|
get => _website;
|
||||||
@ -89,7 +83,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the repository of this plugin
|
/// Gets or sets the repository of this plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public Uri? Repository
|
public Uri? Repository
|
||||||
{
|
{
|
||||||
get => _repository;
|
get => _repository;
|
||||||
@ -99,7 +92,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the help page of this plugin
|
/// Gets or sets the help page of this plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public Uri? HelpPage
|
public Uri? HelpPage
|
||||||
{
|
{
|
||||||
get => _helpPage;
|
get => _helpPage;
|
||||||
@ -109,7 +101,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the help page of this plugin
|
/// Gets or sets the help page of this plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public Uri? License
|
public Uri? License
|
||||||
{
|
{
|
||||||
get => _license;
|
get => _license;
|
||||||
@ -119,7 +110,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the author of this plugin
|
/// Gets or sets the author of this plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public string? LicenseName
|
public string? LicenseName
|
||||||
{
|
{
|
||||||
get => _licenseName;
|
get => _licenseName;
|
||||||
@ -130,7 +120,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// The plugins display icon that's shown in the settings see <see href="https://materialdesignicons.com" /> for
|
/// The plugins display icon that's shown in the settings see <see href="https://materialdesignicons.com" /> for
|
||||||
/// available icons
|
/// available icons
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public string? Icon
|
public string? Icon
|
||||||
{
|
{
|
||||||
get => _icon;
|
get => _icon;
|
||||||
@ -140,7 +129,7 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The version of the plugin
|
/// The version of the plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonRequired]
|
||||||
public string Version
|
public string Version
|
||||||
{
|
{
|
||||||
get => _version;
|
get => _version;
|
||||||
@ -150,7 +139,7 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry DLL, should contain a class implementing Plugin
|
/// The main entry DLL, should contain a class implementing Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonRequired]
|
||||||
public string Main
|
public string Main
|
||||||
{
|
{
|
||||||
get => _main;
|
get => _main;
|
||||||
@ -161,8 +150,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// Gets or sets a boolean indicating whether this plugin should automatically enable all its features when it is first
|
/// Gets or sets a boolean indicating whether this plugin should automatically enable all its features when it is first
|
||||||
/// loaded
|
/// loaded
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DefaultValue(true)]
|
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
|
||||||
public bool AutoEnableFeatures
|
public bool AutoEnableFeatures
|
||||||
{
|
{
|
||||||
get => _autoEnableFeatures;
|
get => _autoEnableFeatures;
|
||||||
@ -172,7 +159,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a boolean indicating whether this plugin requires elevated admin privileges
|
/// Gets a boolean indicating whether this plugin requires elevated admin privileges
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public bool RequiresAdmin
|
public bool RequiresAdmin
|
||||||
{
|
{
|
||||||
get => _requiresAdmin;
|
get => _requiresAdmin;
|
||||||
@ -182,8 +168,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a boolean indicating whether hot reloading this plugin is supported
|
/// Gets or sets a boolean indicating whether hot reloading this plugin is supported
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DefaultValue(true)]
|
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
|
||||||
public bool HotReloadSupported
|
public bool HotReloadSupported
|
||||||
{
|
{
|
||||||
get => _hotReloadSupported;
|
get => _hotReloadSupported;
|
||||||
@ -193,7 +177,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets
|
/// Gets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
|
||||||
public PluginPlatform? Platforms
|
public PluginPlatform? Platforms
|
||||||
{
|
{
|
||||||
get => _platforms;
|
get => _platforms;
|
||||||
@ -203,8 +186,6 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the API version the plugin was built for
|
/// Gets the API version the plugin was built for
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
|
||||||
[JsonConverter(typeof(ForgivingVersionConverter))]
|
|
||||||
public Version? Api
|
public Version? Api
|
||||||
{
|
{
|
||||||
get => _api;
|
get => _api;
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
@ -8,7 +7,7 @@ namespace Artemis.Core;
|
|||||||
/// Specifies OS platforms a plugin may support.
|
/// Specifies OS platforms a plugin may support.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Flags]
|
[Flags]
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||||
public enum PluginPlatform
|
public enum PluginPlatform
|
||||||
{
|
{
|
||||||
/// <summary>The Windows platform.</summary>
|
/// <summary>The Windows platform.</summary>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
using Artemis.Storage.Entities.Plugins;
|
using Artemis.Storage.Entities.Plugins;
|
||||||
using Artemis.Storage.Repositories.Interfaces;
|
using Artemis.Storage.Repositories.Interfaces;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ public class PluginSetting<T> : CorePropertyChanged, IPluginSetting
|
|||||||
{
|
{
|
||||||
_value = CoreJson.DeserializeObject<T>(pluginSettingEntity.Value)!;
|
_value = CoreJson.DeserializeObject<T>(pluginSettingEntity.Value)!;
|
||||||
}
|
}
|
||||||
catch (JsonReaderException)
|
catch (JsonException)
|
||||||
{
|
{
|
||||||
_value = default!;
|
_value = default!;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,46 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core.Services.Core;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents build information related to the currently running Artemis build
|
|
||||||
/// </summary>
|
|
||||||
public class BuildInfo
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the unique ID of this build
|
|
||||||
/// </summary>
|
|
||||||
[JsonProperty]
|
|
||||||
public int BuildId { get; internal set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the build number. This contains the date and the build count for that day.
|
|
||||||
/// <para>Per example <c>20210108.4</c></para>
|
|
||||||
/// </summary>
|
|
||||||
[JsonProperty]
|
|
||||||
public double BuildNumber { get; internal set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the build number formatted as a string. This contains the date and the build count for that day.
|
|
||||||
/// <para>Per example <c>20210108.4</c></para>
|
|
||||||
/// </summary>
|
|
||||||
public string BuildNumberDisplay => BuildNumber.ToString(CultureInfo.InvariantCulture);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the branch of the triggering repo the build was created for.
|
|
||||||
/// </summary>
|
|
||||||
[JsonProperty]
|
|
||||||
public string SourceBranch { get; internal set; } = null!;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the commit ID used to create this build
|
|
||||||
/// </summary>
|
|
||||||
[JsonProperty]
|
|
||||||
public string SourceVersion { get; internal set; } = null!;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a boolean indicating whether the current build is a local build
|
|
||||||
/// </summary>
|
|
||||||
public bool IsLocalBuild { get; internal set; }
|
|
||||||
}
|
|
||||||
@ -5,7 +5,6 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using Artemis.Core.Modules;
|
using Artemis.Core.Modules;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace Artemis.Core.Services;
|
namespace Artemis.Core.Services;
|
||||||
|
|||||||
@ -4,7 +4,6 @@ using System.Linq;
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Artemis.Storage.Entities.Profile.Nodes;
|
using Artemis.Storage.Entities.Profile.Nodes;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace Artemis.Core.Services;
|
namespace Artemis.Core.Services;
|
||||||
@ -42,12 +41,12 @@ internal class NodeService : INodeService
|
|||||||
public string ExportScript(NodeScript nodeScript)
|
public string ExportScript(NodeScript nodeScript)
|
||||||
{
|
{
|
||||||
nodeScript.Save();
|
nodeScript.Save();
|
||||||
return JsonConvert.SerializeObject(nodeScript.Entity, IProfileService.ExportSettings);
|
return CoreJson.SerializeObject(nodeScript.Entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ImportScript(string json, NodeScript target)
|
public void ImportScript(string json, NodeScript target)
|
||||||
{
|
{
|
||||||
NodeScriptEntity? entity = JsonConvert.DeserializeObject<NodeScriptEntity>(json);
|
NodeScriptEntity? entity = CoreJson.DeserializeObject<NodeScriptEntity>(json);
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
throw new ArtemisCoreException("Failed to load node script");
|
throw new ArtemisCoreException("Failed to load node script");
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace Artemis.Core.Services;
|
namespace Artemis.Core.Services;
|
||||||
@ -12,11 +11,6 @@ namespace Artemis.Core.Services;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IProfileService : IArtemisService
|
public interface IProfileService : IArtemisService
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets the JSON serializer settings used to import/export profiles.
|
|
||||||
/// </summary>
|
|
||||||
public static JsonSerializerSettings ExportSettings { get; } = new() {TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a read only collection containing all the profile categories.
|
/// Gets a read only collection containing all the profile categories.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -5,13 +5,13 @@ using System.IO;
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core.Modules;
|
using Artemis.Core.Modules;
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using Artemis.Storage.Migrations;
|
using Artemis.Storage.Migrations;
|
||||||
using Artemis.Storage.Repositories.Interfaces;
|
using Artemis.Storage.Repositories.Interfaces;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
@ -410,8 +410,8 @@ internal class ProfileService : IProfileService
|
|||||||
if (profileEntity == null)
|
if (profileEntity == null)
|
||||||
throw new ArtemisCoreException("Could not locate profile entity");
|
throw new ArtemisCoreException("Could not locate profile entity");
|
||||||
|
|
||||||
string configurationJson = JsonConvert.SerializeObject(profileConfiguration.Entity, IProfileService.ExportSettings);
|
string configurationJson = CoreJson.SerializeObject(profileConfiguration.Entity);
|
||||||
string profileJson = JsonConvert.SerializeObject(profileEntity, IProfileService.ExportSettings);
|
string profileJson = CoreJson.SerializeObject(profileEntity);
|
||||||
|
|
||||||
MemoryStream archiveStream = new();
|
MemoryStream archiveStream = new();
|
||||||
|
|
||||||
@ -461,21 +461,21 @@ internal class ProfileService : IProfileService
|
|||||||
// Deserialize profile configuration to JObject
|
// Deserialize profile configuration to JObject
|
||||||
await using Stream configurationStream = configurationEntry.Open();
|
await using Stream configurationStream = configurationEntry.Open();
|
||||||
using StreamReader configurationReader = new(configurationStream);
|
using StreamReader configurationReader = new(configurationStream);
|
||||||
JObject? configurationJson = JsonConvert.DeserializeObject<JObject>(await configurationReader.ReadToEndAsync(), IProfileService.ExportSettings);
|
JsonObject? configurationJson = CoreJson.DeserializeObject<JsonObject>(await configurationReader.ReadToEndAsync());
|
||||||
// Deserialize profile to JObject
|
// Deserialize profile to JObject
|
||||||
await using Stream profileStream = profileEntry.Open();
|
await using Stream profileStream = profileEntry.Open();
|
||||||
using StreamReader profileReader = new(profileStream);
|
using StreamReader profileReader = new(profileStream);
|
||||||
JObject? profileJson = JsonConvert.DeserializeObject<JObject>(await profileReader.ReadToEndAsync(), IProfileService.ExportSettings);
|
JsonObject? profileJson = CoreJson.DeserializeObject<JsonObject>(await profileReader.ReadToEndAsync());
|
||||||
|
|
||||||
// Before deserializing, apply any pending migrations
|
// Before deserializing, apply any pending migrations
|
||||||
MigrateProfile(configurationJson, profileJson);
|
MigrateProfile(configurationJson, profileJson);
|
||||||
|
|
||||||
// Deserialize profile configuration to ProfileConfigurationEntity
|
// Deserialize profile configuration to ProfileConfigurationEntity
|
||||||
ProfileConfigurationEntity? configurationEntity = configurationJson?.ToObject<ProfileConfigurationEntity>(JsonSerializer.Create(IProfileService.ExportSettings));
|
ProfileConfigurationEntity? configurationEntity = configurationJson?.Deserialize<ProfileConfigurationEntity>(Constants.JsonConvertSettings);
|
||||||
if (configurationEntity == null)
|
if (configurationEntity == null)
|
||||||
throw new ArtemisCoreException("Could not import profile, failed to deserialize configuration.json");
|
throw new ArtemisCoreException("Could not import profile, failed to deserialize configuration.json");
|
||||||
// Deserialize profile to ProfileEntity
|
// Deserialize profile to ProfileEntity
|
||||||
ProfileEntity? profileEntity = profileJson?.ToObject<ProfileEntity>(JsonSerializer.Create(IProfileService.ExportSettings));
|
ProfileEntity? profileEntity = profileJson?.Deserialize<ProfileEntity>(Constants.JsonConvertSettings);
|
||||||
if (profileEntity == null)
|
if (profileEntity == null)
|
||||||
throw new ArtemisCoreException("Could not import profile, failed to deserialize profile.json");
|
throw new ArtemisCoreException("Could not import profile, failed to deserialize profile.json");
|
||||||
|
|
||||||
@ -559,7 +559,7 @@ internal class ProfileService : IProfileService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MigrateProfile(JObject? configurationJson, JObject? profileJson)
|
private void MigrateProfile(JsonObject? configurationJson, JsonObject? profileJson)
|
||||||
{
|
{
|
||||||
if (configurationJson == null || profileJson == null)
|
if (configurationJson == null || profileJson == null)
|
||||||
return;
|
return;
|
||||||
@ -568,7 +568,7 @@ internal class ProfileService : IProfileService
|
|||||||
|
|
||||||
foreach (IProfileMigration profileMigrator in _profileMigrators.OrderBy(m => m.Version))
|
foreach (IProfileMigration profileMigrator in _profileMigrators.OrderBy(m => m.Version))
|
||||||
{
|
{
|
||||||
if (profileMigrator.Version <= configurationJson["Version"]!.Value<int>())
|
if (profileMigrator.Version <= configurationJson["Version"]!.GetValue<int>())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
profileMigrator.Migrate(configurationJson, profileJson);
|
profileMigrator.Migrate(configurationJson, profileJson);
|
||||||
|
|||||||
@ -1,57 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Artemis.Core.Modules;
|
|
||||||
using EmbedIO;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core.Services;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a plugin web endpoint receiving an object of type <typeparamref name="T" /> and returning any
|
|
||||||
/// <see cref="object" /> or <see langword="null" />.
|
|
||||||
/// <para>Note: Both will be deserialized and serialized respectively using JSON.</para>
|
|
||||||
/// </summary>
|
|
||||||
public class DataModelJsonPluginEndPoint<T> : PluginEndPoint where T : DataModel, new()
|
|
||||||
{
|
|
||||||
private readonly Module<T> _module;
|
|
||||||
|
|
||||||
internal DataModelJsonPluginEndPoint(Module<T> module, string name, PluginsModule pluginsModule) : base(module, name, pluginsModule)
|
|
||||||
{
|
|
||||||
_module = module ?? throw new ArgumentNullException(nameof(module));
|
|
||||||
|
|
||||||
ThrowOnFail = true;
|
|
||||||
Accepts = MimeType.Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether or not the end point should throw an exception if deserializing the received JSON fails.
|
|
||||||
/// If set to <see langword="false" /> malformed JSON is silently ignored; if set to <see langword="true" /> malformed
|
|
||||||
/// JSON throws a <see cref="JsonException" />.
|
|
||||||
/// </summary>
|
|
||||||
public bool ThrowOnFail { get; set; }
|
|
||||||
|
|
||||||
#region Overrides of PluginEndPoint
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override async Task ProcessRequest(IHttpContext context)
|
|
||||||
{
|
|
||||||
if (context.Request.HttpVerb != HttpVerbs.Post && context.Request.HttpVerb != HttpVerbs.Put)
|
|
||||||
throw HttpException.MethodNotAllowed("This end point only accepts POST and PUT calls");
|
|
||||||
|
|
||||||
context.Response.ContentType = MimeType.Json;
|
|
||||||
|
|
||||||
using TextReader reader = context.OpenRequestText();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JsonConvert.PopulateObject(await reader.ReadToEndAsync(), _module.DataModel);
|
|
||||||
}
|
|
||||||
catch (JsonException)
|
|
||||||
{
|
|
||||||
if (ThrowOnFail)
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using EmbedIO;
|
using EmbedIO;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core.Services;
|
namespace Artemis.Core.Services;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public class JsonPluginEndPoint<T> : PluginEndPoint
|
|||||||
object? response = null;
|
object? response = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
T? deserialized = JsonConvert.DeserializeObject<T>(await reader.ReadToEndAsync());
|
T? deserialized = JsonSerializer.Deserialize<T>(await reader.ReadToEndAsync());
|
||||||
if (deserialized == null)
|
if (deserialized == null)
|
||||||
throw new JsonException("Deserialization returned null");
|
throw new JsonException("Deserialization returned null");
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ public class JsonPluginEndPoint<T> : PluginEndPoint
|
|||||||
}
|
}
|
||||||
|
|
||||||
await using TextWriter writer = context.OpenResponseText();
|
await using TextWriter writer = context.OpenResponseText();
|
||||||
await writer.WriteAsync(JsonConvert.SerializeObject(response));
|
await writer.WriteAsync(JsonSerializer.Serialize(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using EmbedIO;
|
using EmbedIO;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core.Services;
|
namespace Artemis.Core.Services;
|
||||||
|
|
||||||
|
|||||||
@ -44,15 +44,6 @@ public interface IWebServerService : IArtemisService
|
|||||||
/// <returns>The resulting end point</returns>
|
/// <returns>The resulting end point</returns>
|
||||||
JsonPluginEndPoint<T> AddResponsiveJsonEndPoint<T>(PluginFeature feature, string endPointName, Func<T, object?> requestHandler);
|
JsonPluginEndPoint<T> AddResponsiveJsonEndPoint<T>(PluginFeature feature, string endPointName, Func<T, object?> requestHandler);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a new endpoint that directly maps received JSON to the data model of the provided <paramref name="module" />.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The data model type of the module</typeparam>
|
|
||||||
/// <param name="module">The module whose datamodel to apply the received JSON to</param>
|
|
||||||
/// <param name="endPointName">The name of the end point, must be unique</param>
|
|
||||||
/// <returns>The resulting end point</returns>
|
|
||||||
DataModelJsonPluginEndPoint<T> AddDataModelJsonEndPoint<T>(Module<T> module, string endPointName) where T : DataModel, new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new endpoint for the given plugin feature receiving an a <see cref="string" />.
|
/// Adds a new endpoint for the given plugin feature receiving an a <see cref="string" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -3,12 +3,11 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core.Modules;
|
|
||||||
using EmbedIO;
|
using EmbedIO;
|
||||||
using EmbedIO.WebApi;
|
using EmbedIO.WebApi;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace Artemis.Core.Services;
|
namespace Artemis.Core.Services;
|
||||||
@ -22,6 +21,7 @@ internal class WebServerService : IWebServerService, IDisposable
|
|||||||
private readonly PluginSetting<bool> _webServerEnabledSetting;
|
private readonly PluginSetting<bool> _webServerEnabledSetting;
|
||||||
private readonly PluginSetting<int> _webServerPortSetting;
|
private readonly PluginSetting<int> _webServerPortSetting;
|
||||||
private readonly object _webserverLock = new();
|
private readonly object _webserverLock = new();
|
||||||
|
private readonly JsonSerializerOptions _jsonOptions = new() {WriteIndented = true};
|
||||||
private CancellationTokenSource? _cts;
|
private CancellationTokenSource? _cts;
|
||||||
|
|
||||||
public WebServerService(ILogger logger, ICoreService coreService, ISettingsService settingsService, IPluginManagementService pluginManagementService)
|
public WebServerService(ILogger logger, ICoreService coreService, ISettingsService settingsService, IPluginManagementService pluginManagementService)
|
||||||
@ -120,7 +120,7 @@ internal class WebServerService : IWebServerService, IDisposable
|
|||||||
Server = null;
|
Server = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebApiModule apiModule = new("/", JsonNetSerializer);
|
WebApiModule apiModule = new("/", SystemTextJsonSerializer);
|
||||||
PluginsModule.ServerUrl = $"http://localhost:{_webServerPortSetting.Value}/";
|
PluginsModule.ServerUrl = $"http://localhost:{_webServerPortSetting.Value}/";
|
||||||
WebServer server = new WebServer(o => o.WithUrlPrefix($"http://*:{_webServerPortSetting.Value}/").WithMode(HttpListenerMode.EmbedIO))
|
WebServer server = new WebServer(o => o.WithUrlPrefix($"http://*:{_webServerPortSetting.Value}/").WithMode(HttpListenerMode.EmbedIO))
|
||||||
.WithLocalSessionManager()
|
.WithLocalSessionManager()
|
||||||
@ -240,15 +240,6 @@ internal class WebServerService : IWebServerService, IDisposable
|
|||||||
return endPoint;
|
return endPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataModelJsonPluginEndPoint<T> AddDataModelJsonEndPoint<T>(Module<T> module, string endPointName) where T : DataModel, new()
|
|
||||||
{
|
|
||||||
if (module == null) throw new ArgumentNullException(nameof(module));
|
|
||||||
if (endPointName == null) throw new ArgumentNullException(nameof(endPointName));
|
|
||||||
DataModelJsonPluginEndPoint<T> endPoint = new(module, endPointName, PluginsModule);
|
|
||||||
PluginsModule.AddPluginEndPoint(endPoint);
|
|
||||||
return endPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RemovePluginEndPoint(PluginEndPoint endPoint)
|
public void RemovePluginEndPoint(PluginEndPoint endPoint)
|
||||||
{
|
{
|
||||||
PluginsModule.RemovePluginEndPoint(endPoint);
|
PluginsModule.RemovePluginEndPoint(endPoint);
|
||||||
@ -316,7 +307,7 @@ internal class WebServerService : IWebServerService, IDisposable
|
|||||||
context.Response.ContentType = MimeType.Json;
|
context.Response.ContentType = MimeType.Json;
|
||||||
await using TextWriter writer = context.OpenResponseText();
|
await using TextWriter writer = context.OpenResponseText();
|
||||||
|
|
||||||
string response = JsonConvert.SerializeObject(new Dictionary<string, object?>
|
string response = CoreJson.SerializeObject(new Dictionary<string, object?>
|
||||||
{
|
{
|
||||||
{"StatusCode", context.Response.StatusCode},
|
{"StatusCode", context.Response.StatusCode},
|
||||||
{"StackTrace", exception.StackTrace},
|
{"StackTrace", exception.StackTrace},
|
||||||
@ -331,17 +322,16 @@ internal class WebServerService : IWebServerService, IDisposable
|
|||||||
await writer.WriteAsync(response);
|
await writer.WriteAsync(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task JsonNetSerializer(IHttpContext context, object? data)
|
private async Task SystemTextJsonSerializer(IHttpContext context, object? data)
|
||||||
{
|
{
|
||||||
context.Response.ContentType = MimeType.Json;
|
context.Response.ContentType = MimeType.Json;
|
||||||
await using TextWriter writer = context.OpenResponseText();
|
await using TextWriter writer = context.OpenResponseText();
|
||||||
string json = JsonConvert.SerializeObject(data, new JsonSerializerSettings {PreserveReferencesHandling = PreserveReferencesHandling.Objects});
|
await writer.WriteAsync(JsonSerializer.Serialize(data, _jsonOptions));
|
||||||
await writer.WriteAsync(json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleHttpExceptionJson(IHttpContext context, IHttpException httpException)
|
private async Task HandleHttpExceptionJson(IHttpContext context, IHttpException httpException)
|
||||||
{
|
{
|
||||||
await context.SendStringAsync(JsonConvert.SerializeObject(httpException, Formatting.Indented), MimeType.Json, Encoding.UTF8);
|
await context.SendStringAsync(JsonSerializer.Serialize(httpException, _jsonOptions), MimeType.Json, Encoding.UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
@ -16,55 +15,28 @@ public static class CoreJson
|
|||||||
/// Serializes the specified object to a JSON string.
|
/// Serializes the specified object to a JSON string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The object to serialize.</param>
|
/// <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>
|
/// <returns>A JSON string representation of the object.</returns>
|
||||||
[DebuggerStepThrough]
|
[DebuggerStepThrough]
|
||||||
public static string SerializeObject(object? value, bool handleTypeNames = false)
|
public static string SerializeObject(object? value)
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(value, handleTypeNames ? Constants.JsonConvertTypedSettings : Constants.JsonConvertSettings);
|
return JsonSerializer.Serialize(value, Constants.JsonConvertSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Deserialize
|
#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>
|
/// <summary>
|
||||||
/// Deserializes the JSON to the specified .NET type.
|
/// Deserializes the JSON to the specified .NET type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type of the object to deserialize to.</typeparam>
|
/// <typeparam name="T">The type of the object to deserialize to.</typeparam>
|
||||||
/// <param name="value">The JSON to deserialize.</param>
|
/// <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>
|
/// <returns>The deserialized object from the JSON string.</returns>
|
||||||
[DebuggerStepThrough]
|
[DebuggerStepThrough]
|
||||||
[return: MaybeNull]
|
[return: MaybeNull]
|
||||||
public static T DeserializeObject<T>(string value, bool handleTypeNames = false)
|
public static T DeserializeObject<T>(string value)
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject<T>(value, handleTypeNames ? Constants.JsonConvertTypedSettings : Constants.JsonConvertSettings);
|
return JsonSerializer.Deserialize<T>(value, Constants.JsonConvertSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -41,7 +41,7 @@ public abstract class Node<TStorage> : Node
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string SerializeStorage()
|
public override string SerializeStorage()
|
||||||
{
|
{
|
||||||
return CoreJson.SerializeObject(Storage, true);
|
return CoreJson.SerializeObject(Storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
@ -10,7 +9,6 @@ public sealed class InputPin<T> : Pin
|
|||||||
{
|
{
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
[JsonConstructor]
|
|
||||||
internal InputPin(INode node, string name)
|
internal InputPin(INode node, string name)
|
||||||
: base(node, name)
|
: base(node, name)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.Core;
|
namespace Artemis.Core;
|
||||||
|
|
||||||
@ -10,7 +9,6 @@ public sealed class OutputPin<T> : Pin
|
|||||||
{
|
{
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
[JsonConstructor]
|
|
||||||
internal OutputPin(INode node, string name)
|
internal OutputPin(INode node, string name)
|
||||||
: base(node, name)
|
: base(node, name)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,6 +9,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="LiteDB" />
|
<PackageReference Include="LiteDB" />
|
||||||
<PackageReference Include="Serilog" />
|
<PackageReference Include="Serilog" />
|
||||||
<PackageReference Include="Newtonsoft.Json" />
|
<PackageReference Include="System.Text.Json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@ -1,9 +1,9 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace Artemis.Storage.Migrations;
|
namespace Artemis.Storage.Migrations;
|
||||||
|
|
||||||
public interface IProfileMigration
|
public interface IProfileMigration
|
||||||
{
|
{
|
||||||
int Version { get; }
|
int Version { get; }
|
||||||
void Migrate(JObject configurationJson, JObject profileJson);
|
void Migrate(JsonObject configurationJson, JsonObject profileJson);
|
||||||
}
|
}
|
||||||
@ -1,88 +1,95 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using Serilog.Core;
|
||||||
|
|
||||||
namespace Artemis.Storage.Migrations.Profile;
|
namespace Artemis.Storage.Migrations.Profile
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Migrates nodes to be provider-based.
|
|
||||||
/// This requires giving them a ProviderId and updating the their namespaces to match the namespace of the new plugin.
|
|
||||||
/// </summary>
|
|
||||||
internal class M0001NodeProviders : IProfileMigration
|
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <summary>
|
||||||
public int Version => 1;
|
/// Migrates nodes to be provider-based.
|
||||||
|
/// This requires giving them a ProviderId and updating the their namespaces to match the namespace of the new plugin.
|
||||||
/// <inheritdoc />
|
/// </summary>
|
||||||
public void Migrate(JObject configurationJson, JObject profileJson)
|
internal class M0001NodeProviders : IProfileMigration
|
||||||
{
|
{
|
||||||
JArray? folders = (JArray?) profileJson["Folders"]?["$values"];
|
/// <inheritdoc />
|
||||||
JArray? layers = (JArray?) profileJson["Layers"]?["$values"];
|
public int Version => 1;
|
||||||
|
|
||||||
if (folders != null)
|
/// <inheritdoc />
|
||||||
|
public void Migrate(JsonObject configurationJson, JsonObject profileJson)
|
||||||
{
|
{
|
||||||
foreach (JToken folder in folders)
|
JsonArray? folders = (JsonArray?) profileJson["Folders"]?["values"];
|
||||||
MigrateProfileElement(folder);
|
JsonArray? layers = (JsonArray?) profileJson["Layers"]?["values"];
|
||||||
|
|
||||||
|
if (folders != null)
|
||||||
|
{
|
||||||
|
foreach (JsonValue folder in folders)
|
||||||
|
MigrateProfileElement(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (layers != null)
|
||||||
|
{
|
||||||
|
foreach (JsonValue layer in layers)
|
||||||
|
{
|
||||||
|
MigrateProfileElement(layer);
|
||||||
|
MigratePropertyGroup(layer["GeneralPropertyGroup"]);
|
||||||
|
MigratePropertyGroup(layer["TransformPropertyGroup"]);
|
||||||
|
MigratePropertyGroup(layer["LayerBrush"]?["PropertyGroup"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layers != null)
|
private void MigrateProfileElement(JsonNode profileElement)
|
||||||
{
|
{
|
||||||
foreach (JToken layer in layers)
|
JsonArray? layerEffects = (JsonArray?) profileElement["LayerEffects"]?["values"];
|
||||||
|
if (layerEffects != null)
|
||||||
{
|
{
|
||||||
MigrateProfileElement(layer);
|
foreach (JsonValue layerEffect in layerEffects)
|
||||||
MigratePropertyGroup(layer["GeneralPropertyGroup"]);
|
MigratePropertyGroup(layerEffect["PropertyGroup"]);
|
||||||
MigratePropertyGroup(layer["TransformPropertyGroup"]);
|
}
|
||||||
MigratePropertyGroup(layer["LayerBrush"]?["PropertyGroup"]);
|
|
||||||
|
JsonNode? displayCondition = profileElement["DisplayCondition"];
|
||||||
|
if (displayCondition != null)
|
||||||
|
MigrateNodeScript(displayCondition["Script"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MigratePropertyGroup(JsonNode? propertyGroup)
|
||||||
|
{
|
||||||
|
if (propertyGroup == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
JsonArray? properties = (JsonArray?) propertyGroup["Properties"]?["values"];
|
||||||
|
JsonArray? propertyGroups = (JsonArray?) propertyGroup["PropertyGroups"]?["values"];
|
||||||
|
|
||||||
|
if (properties != null)
|
||||||
|
{
|
||||||
|
foreach (JsonValue property in properties)
|
||||||
|
MigrateNodeScript(property["DataBinding"]?["NodeScript"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propertyGroups != null)
|
||||||
|
{
|
||||||
|
foreach (JsonValue childPropertyGroup in propertyGroups)
|
||||||
|
MigratePropertyGroup(childPropertyGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MigrateNodeScript(JsonNode? nodeScript)
|
||||||
|
{
|
||||||
|
if (nodeScript == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
JsonArray? nodes = nodeScript["Nodes"]?.AsArray();
|
||||||
|
if (nodes == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (JsonNode? jsonNode in nodes)
|
||||||
|
{
|
||||||
|
if (jsonNode == null)
|
||||||
|
continue;
|
||||||
|
JsonObject nodeObject = jsonNode.AsObject();
|
||||||
|
nodeObject["Type"] = nodeObject["Type"]?.GetValue<string>().Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes");
|
||||||
|
nodeObject["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MigrateProfileElement(JToken profileElement)
|
|
||||||
{
|
|
||||||
JArray? layerEffects = (JArray?) profileElement["LayerEffects"]?["$values"];
|
|
||||||
if (layerEffects != null)
|
|
||||||
{
|
|
||||||
foreach (JToken layerEffect in layerEffects)
|
|
||||||
MigratePropertyGroup(layerEffect["PropertyGroup"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
JToken? displayCondition = profileElement["DisplayCondition"];
|
|
||||||
if (displayCondition != null)
|
|
||||||
MigrateNodeScript(displayCondition["Script"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MigratePropertyGroup(JToken? propertyGroup)
|
|
||||||
{
|
|
||||||
if (propertyGroup == null || !propertyGroup.HasValues)
|
|
||||||
return;
|
|
||||||
|
|
||||||
JArray? properties = (JArray?) propertyGroup["Properties"]?["$values"];
|
|
||||||
JArray? propertyGroups = (JArray?) propertyGroup["PropertyGroups"]?["$values"];
|
|
||||||
|
|
||||||
if (properties != null)
|
|
||||||
{
|
|
||||||
foreach (JToken property in properties)
|
|
||||||
MigrateNodeScript(property["DataBinding"]?["NodeScript"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyGroups != null)
|
|
||||||
{
|
|
||||||
foreach (JToken childPropertyGroup in propertyGroups)
|
|
||||||
MigratePropertyGroup(childPropertyGroup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MigrateNodeScript(JToken? nodeScript)
|
|
||||||
{
|
|
||||||
if (nodeScript == null || !nodeScript.HasValues)
|
|
||||||
return;
|
|
||||||
|
|
||||||
JArray? nodes = (JArray?) nodeScript["Nodes"]?["$values"];
|
|
||||||
if (nodes == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (JToken node in nodes)
|
|
||||||
{
|
|
||||||
node["Type"] = node["Type"]?.Value<string>()?.Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes");
|
|
||||||
node["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace Artemis.Storage.Migrations.Profile;
|
namespace Artemis.Storage.Migrations.Profile;
|
||||||
|
|
||||||
@ -12,24 +12,27 @@ internal class M0002NodeProvidersProfileConfig : IProfileMigration
|
|||||||
public int Version => 2;
|
public int Version => 2;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Migrate(JObject configurationJson, JObject profileJson)
|
public void Migrate(JsonObject configurationJson, JsonObject profileJson)
|
||||||
{
|
{
|
||||||
MigrateNodeScript(configurationJson["ActivationCondition"]);
|
MigrateNodeScript(configurationJson["ActivationCondition"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MigrateNodeScript(JToken? nodeScript)
|
private void MigrateNodeScript(JsonNode? nodeScript)
|
||||||
{
|
{
|
||||||
if (nodeScript == null || !nodeScript.HasValues)
|
if (nodeScript == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
JArray? nodes = (JArray?) nodeScript["Nodes"]?["$values"];
|
JsonArray? nodes = nodeScript["Nodes"]?.AsArray();
|
||||||
if (nodes == null)
|
if (nodes == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (JToken node in nodes)
|
foreach (JsonNode? jsonNode in nodes)
|
||||||
{
|
{
|
||||||
node["Type"] = node["Type"]?.Value<string>()?.Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes");
|
if (jsonNode == null)
|
||||||
node["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78";
|
continue;
|
||||||
|
JsonObject nodeObject = jsonNode.AsObject();
|
||||||
|
nodeObject["Type"] = nodeObject["Type"]?.GetValue<string>().Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes");
|
||||||
|
nodeObject["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,7 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Shared.DataModelVisualization;
|
using Artemis.UI.Shared.DataModelVisualization;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display;
|
namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display;
|
||||||
|
|
||||||
@ -11,16 +12,12 @@ namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal class DefaultDataModelDisplayViewModel : DataModelDisplayViewModel<object>
|
internal class DefaultDataModelDisplayViewModel : DataModelDisplayViewModel<object>
|
||||||
{
|
{
|
||||||
private readonly JsonSerializerSettings _serializerSettings;
|
private readonly JsonSerializerOptions _serializerSettings;
|
||||||
private string _display;
|
private string _display;
|
||||||
|
|
||||||
public DefaultDataModelDisplayViewModel()
|
public DefaultDataModelDisplayViewModel()
|
||||||
{
|
{
|
||||||
_serializerSettings = new JsonSerializerSettings
|
_serializerSettings = new JsonSerializerOptions() {ReferenceHandler = ReferenceHandler.IgnoreCycles};
|
||||||
{
|
|
||||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
|
||||||
PreserveReferencesHandling = PreserveReferencesHandling.None
|
|
||||||
};
|
|
||||||
_display = "null";
|
_display = "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +32,7 @@ internal class DefaultDataModelDisplayViewModel : DataModelDisplayViewModel<obje
|
|||||||
if (DisplayValue is Enum enumDisplayValue)
|
if (DisplayValue is Enum enumDisplayValue)
|
||||||
Display = EnumUtilities.HumanizeValue(enumDisplayValue);
|
Display = EnumUtilities.HumanizeValue(enumDisplayValue);
|
||||||
else if (DisplayValue is not string)
|
else if (DisplayValue is not string)
|
||||||
Display = JsonConvert.SerializeObject(DisplayValue, _serializerSettings);
|
Display = JsonSerializer.Serialize(DisplayValue, _serializerSettings);
|
||||||
else
|
else
|
||||||
Display = DisplayValue?.ToString() ?? "null";
|
Display = DisplayValue?.ToString() ?? "null";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,6 @@ public static class ClipboardExtensions
|
|||||||
public static async Task<T?> GetJsonAsync<T>(this IClipboard clipboard, string format)
|
public static async Task<T?> GetJsonAsync<T>(this IClipboard clipboard, string format)
|
||||||
{
|
{
|
||||||
byte[]? bytes = (byte[]?) await clipboard.GetDataAsync(format);
|
byte[]? bytes = (byte[]?) await clipboard.GetDataAsync(format);
|
||||||
return bytes == null ? default : CoreJson.DeserializeObject<T>(Encoding.Unicode.GetString(bytes), true);
|
return bytes == null ? default : CoreJson.DeserializeObject<T>(Encoding.Unicode.GetString(bytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ public class ResetLayerProperty<T> : IProfileEditorCommand
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
string json = CoreJson.SerializeObject(_layerProperty.DefaultValue, true);
|
string json = CoreJson.SerializeObject(_layerProperty.DefaultValue);
|
||||||
|
|
||||||
if (_keyframesEnabled)
|
if (_keyframesEnabled)
|
||||||
_layerProperty.KeyframesEnabled = false;
|
_layerProperty.KeyframesEnabled = false;
|
||||||
|
|||||||
@ -19,7 +19,7 @@ public static class ProfileElementExtensions
|
|||||||
public static async Task CopyToClipboard(this Folder folder)
|
public static async Task CopyToClipboard(this Folder folder)
|
||||||
{
|
{
|
||||||
DataObject dataObject = new();
|
DataObject dataObject = new();
|
||||||
string copy = CoreJson.SerializeObject(new FolderClipboardModel(folder), true);
|
string copy = CoreJson.SerializeObject(new FolderClipboardModel(folder));
|
||||||
dataObject.Set(ClipboardDataFormat, copy);
|
dataObject.Set(ClipboardDataFormat, copy);
|
||||||
await Shared.UI.Clipboard.SetDataObjectAsync(dataObject);
|
await Shared.UI.Clipboard.SetDataObjectAsync(dataObject);
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ public static class ProfileElementExtensions
|
|||||||
public static async Task CopyToClipboard(this Layer layer)
|
public static async Task CopyToClipboard(this Layer layer)
|
||||||
{
|
{
|
||||||
DataObject dataObject = new();
|
DataObject dataObject = new();
|
||||||
string copy = CoreJson.SerializeObject(layer.LayerEntity, true);
|
string copy = CoreJson.SerializeObject(layer.LayerEntity);
|
||||||
dataObject.Set(ClipboardDataFormat, copy);
|
dataObject.Set(ClipboardDataFormat, copy);
|
||||||
await Shared.UI.Clipboard.SetDataObjectAsync(dataObject);
|
await Shared.UI.Clipboard.SetDataObjectAsync(dataObject);
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ public static class ProfileElementExtensions
|
|||||||
if (bytes == null!)
|
if (bytes == null!)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
object? entity = CoreJson.DeserializeObject(Encoding.Unicode.GetString(bytes), true);
|
object? entity = CoreJson.DeserializeObject<IClipboardModel>(Encoding.Unicode.GetString(bytes));
|
||||||
switch (entity)
|
switch (entity)
|
||||||
{
|
{
|
||||||
case FolderClipboardModel folderClipboardModel:
|
case FolderClipboardModel folderClipboardModel:
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using Artemis.Storage.Entities.Profile.Abstract;
|
using Artemis.Storage.Entities.Profile.Abstract;
|
||||||
@ -7,7 +8,7 @@ using Artemis.UI.Exceptions;
|
|||||||
|
|
||||||
namespace Artemis.UI.Models;
|
namespace Artemis.UI.Models;
|
||||||
|
|
||||||
public class FolderClipboardModel
|
public class FolderClipboardModel: IClipboardModel
|
||||||
{
|
{
|
||||||
public FolderClipboardModel(Folder folder)
|
public FolderClipboardModel(Folder folder)
|
||||||
{
|
{
|
||||||
@ -20,7 +21,7 @@ public class FolderClipboardModel
|
|||||||
Layers.Add(allLayer.LayerEntity);
|
Layers.Add(allLayer.LayerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once UnusedMember.Global - For JSON.NET
|
[JsonConstructor]
|
||||||
public FolderClipboardModel()
|
public FolderClipboardModel()
|
||||||
{
|
{
|
||||||
FolderEntity = null;
|
FolderEntity = null;
|
||||||
|
|||||||
11
src/Artemis.UI/Models/IClipboardModel.cs
Normal file
11
src/Artemis.UI/Models/IClipboardModel.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Models;
|
||||||
|
|
||||||
|
[JsonDerivedType(typeof(LayerClipboardModel))]
|
||||||
|
[JsonDerivedType(typeof(FolderClipboardModel))]
|
||||||
|
[JsonDerivedType(typeof(KeyframeClipboardModel))]
|
||||||
|
[JsonDerivedType(typeof(NodesClipboardModel))]
|
||||||
|
public interface IClipboardModel
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -1,10 +1,10 @@
|
|||||||
using Artemis.Core;
|
using System.Text.Json.Serialization;
|
||||||
|
using Artemis.Core;
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.UI.Models;
|
namespace Artemis.UI.Models;
|
||||||
|
|
||||||
public class KeyframeClipboardModel
|
public class KeyframeClipboardModel: IClipboardModel
|
||||||
{
|
{
|
||||||
public const string ClipboardDataFormat = "Artemis.Keyframes";
|
public const string ClipboardDataFormat = "Artemis.Keyframes";
|
||||||
|
|
||||||
|
|||||||
13
src/Artemis.UI/Models/LayerClipboardModel.cs
Normal file
13
src/Artemis.UI/Models/LayerClipboardModel.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using Artemis.Core;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Models;
|
||||||
|
|
||||||
|
public class LayerClipboardModel : IClipboardModel
|
||||||
|
{
|
||||||
|
public LayerClipboardModel(Layer layer)
|
||||||
|
{
|
||||||
|
Layer = layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Layer Layer { get; set; }
|
||||||
|
}
|
||||||
@ -1,12 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.Storage.Entities.Profile.Nodes;
|
using Artemis.Storage.Entities.Profile.Nodes;
|
||||||
|
|
||||||
namespace Artemis.UI.Models;
|
namespace Artemis.UI.Models;
|
||||||
|
|
||||||
public class NodesClipboardModel
|
public class NodesClipboardModel: IClipboardModel
|
||||||
{
|
{
|
||||||
public NodesClipboardModel(NodeScript nodeScript, List<INode> nodes)
|
public NodesClipboardModel(NodeScript nodeScript, List<INode> nodes)
|
||||||
{
|
{
|
||||||
@ -18,6 +19,7 @@ public class NodesClipboardModel
|
|||||||
Connections = nodeScript.Entity.Connections.Where(e => nodes.Any(n => n.Id == e.SourceNode) && nodes.Any(n => n.Id == e.TargetNode)).ToList();
|
Connections = nodeScript.Entity.Connections.Where(e => nodes.Any(n => n.Id == e.SourceNode) && nodes.Any(n => n.Id == e.TargetNode)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonConstructor]
|
||||||
public NodesClipboardModel()
|
public NodesClipboardModel()
|
||||||
{
|
{
|
||||||
Nodes = new List<NodeEntity>();
|
Nodes = new List<NodeEntity>();
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Artemis.UI.Extensions;
|
using Artemis.UI.Extensions;
|
||||||
using Artemis.UI.Shared;
|
using Artemis.UI.Shared;
|
||||||
using Artemis.WebClient.Workshop.Services;
|
using Artemis.WebClient.Workshop.Services;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using PropertyChanged.SourceGenerator;
|
using PropertyChanged.SourceGenerator;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Debugger.Workshop;
|
namespace Artemis.UI.Screens.Debugger.Workshop;
|
||||||
|
|
||||||
public partial class WorkshopDebugViewModel : ActivatableViewModelBase
|
public partial class WorkshopDebugViewModel : ActivatableViewModelBase
|
||||||
{
|
{
|
||||||
|
|
||||||
[Notify] private string? _token;
|
[Notify] private string? _token;
|
||||||
[Notify] private bool _emailVerified;
|
[Notify] private bool _emailVerified;
|
||||||
[Notify] private string? _claims;
|
[Notify] private string? _claims;
|
||||||
@ -23,7 +22,7 @@ public partial class WorkshopDebugViewModel : ActivatableViewModelBase
|
|||||||
{
|
{
|
||||||
Token = await authenticationService.GetBearer();
|
Token = await authenticationService.GetBearer();
|
||||||
EmailVerified = authenticationService.GetIsEmailVerified();
|
EmailVerified = authenticationService.GetIsEmailVerified();
|
||||||
Claims = JsonConvert.SerializeObject(authenticationService.Claims, Formatting.Indented);
|
Claims = JsonSerializer.Serialize(authenticationService.Claims, new JsonSerializerOptions {WriteIndented = true});
|
||||||
WorkshopStatus = await workshopService.GetWorkshopStatus(CancellationToken.None);
|
WorkshopStatus = await workshopService.GetWorkshopStatus(CancellationToken.None);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,6 @@ using Artemis.UI.Shared;
|
|||||||
using Artemis.UI.Shared.Routing;
|
using Artemis.UI.Shared.Routing;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using PropertyChanged.SourceGenerator;
|
using PropertyChanged.SourceGenerator;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public class FolderTreeItemViewModel : TreeItemViewModel
|
|||||||
{
|
{
|
||||||
await ProfileEditorService.SaveProfileAsync();
|
await ProfileEditorService.SaveProfileAsync();
|
||||||
|
|
||||||
FolderEntity copy = CoreJson.DeserializeObject<FolderEntity>(CoreJson.SerializeObject(Folder.FolderEntity, true), true)!;
|
FolderEntity copy = CoreJson.DeserializeObject<FolderEntity>(CoreJson.SerializeObject(Folder.FolderEntity))!;
|
||||||
copy.Id = Guid.NewGuid();
|
copy.Id = Guid.NewGuid();
|
||||||
copy.Name = Folder.Parent.GetNewFolderName(copy.Name + " - copy");
|
copy.Name = Folder.Parent.GetNewFolderName(copy.Name + " - copy");
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,7 @@ public class LayerTreeItemViewModel : TreeItemViewModel
|
|||||||
{
|
{
|
||||||
await ProfileEditorService.SaveProfileAsync();
|
await ProfileEditorService.SaveProfileAsync();
|
||||||
|
|
||||||
LayerEntity copy = CoreJson.DeserializeObject<LayerEntity>(CoreJson.SerializeObject(Layer.LayerEntity, true), true)!;
|
LayerEntity copy = CoreJson.DeserializeObject<LayerEntity>(CoreJson.SerializeObject(Layer.LayerEntity))!;
|
||||||
copy.Id = Guid.NewGuid();
|
copy.Id = Guid.NewGuid();
|
||||||
copy.Name = Layer.Parent.GetNewFolderName(copy.Name + " - copy");
|
copy.Name = Layer.Parent.GetNewFolderName(copy.Name + " - copy");
|
||||||
|
|
||||||
|
|||||||
@ -135,7 +135,7 @@ public partial class TimelineKeyframeViewModel<T> : ActivatableViewModelBase, IT
|
|||||||
else
|
else
|
||||||
keyframes.AddRange(_profileEditorService.SelectedKeyframes.Select(k => new KeyframeClipboardModel(k)));
|
keyframes.AddRange(_profileEditorService.SelectedKeyframes.Select(k => new KeyframeClipboardModel(k)));
|
||||||
|
|
||||||
string copy = CoreJson.SerializeObject(keyframes, true);
|
string copy = CoreJson.SerializeObject(keyframes);
|
||||||
DataObject dataObject = new();
|
DataObject dataObject = new();
|
||||||
dataObject.Set(KeyframeClipboardModel.ClipboardDataFormat, copy);
|
dataObject.Set(KeyframeClipboardModel.ClipboardDataFormat, copy);
|
||||||
await Shared.UI.Clipboard.SetDataObjectAsync(dataObject);
|
await Shared.UI.Clipboard.SetDataObjectAsync(dataObject);
|
||||||
|
|||||||
@ -18,7 +18,6 @@ using Artemis.UI.Shared.Services;
|
|||||||
using Artemis.UI.Shared.Services.Builders;
|
using Artemis.UI.Shared.Services.Builders;
|
||||||
using DynamicData;
|
using DynamicData;
|
||||||
using DynamicData.Binding;
|
using DynamicData.Binding;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using PropertyChanged.SourceGenerator;
|
using PropertyChanged.SourceGenerator;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
@ -162,7 +161,7 @@ public partial class SidebarCategoryViewModel : ActivatableViewModelBase
|
|||||||
// Removing this at some point in the future
|
// Removing this at some point in the future
|
||||||
if (result[0].EndsWith("json"))
|
if (result[0].EndsWith("json"))
|
||||||
{
|
{
|
||||||
ProfileConfigurationExportModel? exportModel = JsonConvert.DeserializeObject<ProfileConfigurationExportModel>(await File.ReadAllTextAsync(result[0]), IProfileService.ExportSettings);
|
ProfileConfigurationExportModel? exportModel = CoreJson.DeserializeObject<ProfileConfigurationExportModel>(await File.ReadAllTextAsync(result[0]));
|
||||||
if (exportModel == null)
|
if (exportModel == null)
|
||||||
{
|
{
|
||||||
await _windowService.ShowConfirmContentDialog("Import profile", "Failed to import this profile, make sure it is a valid Artemis profile.", "Confirm", null);
|
await _windowService.ShowConfirmContentDialog("Import profile", "Failed to import this profile, make sure it is a valid Artemis profile.", "Confirm", null);
|
||||||
@ -235,8 +234,8 @@ public partial class SidebarCategoryViewModel : ActivatableViewModelBase
|
|||||||
{
|
{
|
||||||
MemoryStream archiveStream = new();
|
MemoryStream archiveStream = new();
|
||||||
|
|
||||||
string configurationJson = JsonConvert.SerializeObject(exportModel.ProfileConfigurationEntity, IProfileService.ExportSettings);
|
string configurationJson = CoreJson.SerializeObject(exportModel.ProfileConfigurationEntity);
|
||||||
string profileJson = JsonConvert.SerializeObject(exportModel.ProfileEntity, IProfileService.ExportSettings);
|
string profileJson = CoreJson.SerializeObject(exportModel.ProfileEntity);
|
||||||
|
|
||||||
// Create a ZIP archive
|
// Create a ZIP archive
|
||||||
using (ZipArchive archive = new(archiveStream, ZipArchiveMode.Create, true))
|
using (ZipArchive archive = new(archiveStream, ZipArchiveMode.Create, true))
|
||||||
|
|||||||
@ -277,7 +277,7 @@ public partial class NodeScriptViewModel : ActivatableViewModelBase
|
|||||||
{
|
{
|
||||||
List<INode> nodes = NodeViewModels.Where(vm => vm.IsSelected).Select(vm => vm.Node).Where(n => !n.IsDefaultNode && !n.IsExitNode).ToList();
|
List<INode> nodes = NodeViewModels.Where(vm => vm.IsSelected).Select(vm => vm.Node).Where(n => !n.IsDefaultNode && !n.IsExitNode).ToList();
|
||||||
DataObject dataObject = new();
|
DataObject dataObject = new();
|
||||||
string copy = CoreJson.SerializeObject(new NodesClipboardModel(NodeScript, nodes), true);
|
string copy = CoreJson.SerializeObject(new NodesClipboardModel(NodeScript, nodes));
|
||||||
dataObject.Set(CLIPBOARD_DATA_FORMAT, copy);
|
dataObject.Set(CLIPBOARD_DATA_FORMAT, copy);
|
||||||
await Shared.UI.Clipboard.SetDataObjectAsync(dataObject);
|
await Shared.UI.Clipboard.SetDataObjectAsync(dataObject);
|
||||||
}
|
}
|
||||||
@ -288,7 +288,7 @@ public partial class NodeScriptViewModel : ActivatableViewModelBase
|
|||||||
if (bytes == null!)
|
if (bytes == null!)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NodesClipboardModel? nodesClipboardModel = CoreJson.DeserializeObject<NodesClipboardModel>(Encoding.Unicode.GetString(bytes), true);
|
NodesClipboardModel? nodesClipboardModel = CoreJson.DeserializeObject<NodesClipboardModel>(Encoding.Unicode.GetString(bytes));
|
||||||
if (nodesClipboardModel == null)
|
if (nodesClipboardModel == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Shared.Utilities;
|
|
||||||
using Artemis.WebClient.Workshop.Entities;
|
using Artemis.WebClient.Workshop.Entities;
|
||||||
using Artemis.WebClient.Workshop.Exceptions;
|
using Artemis.WebClient.Workshop.Exceptions;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using RGB.NET.Layout;
|
using RGB.NET.Layout;
|
||||||
|
|
||||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||||
@ -70,7 +68,7 @@ public class LayoutEntryUploadHandler : IEntryUploadHandler
|
|||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
return EntryUploadResult.FromFailure($"{response.StatusCode} - {await response.Content.ReadAsStringAsync(cancellationToken)}");
|
return EntryUploadResult.FromFailure($"{response.StatusCode} - {await response.Content.ReadAsStringAsync(cancellationToken)}");
|
||||||
|
|
||||||
Release? release = JsonConvert.DeserializeObject<Release>(await response.Content.ReadAsStringAsync(cancellationToken));
|
Release? release = CoreJson.DeserializeObject<Release>(await response.Content.ReadAsStringAsync(cancellationToken));
|
||||||
return release != null ? EntryUploadResult.FromSuccess(release) : EntryUploadResult.FromFailure("Failed to deserialize response");
|
return release != null ? EntryUploadResult.FromSuccess(release) : EntryUploadResult.FromFailure("Failed to deserialize response");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
|
using Artemis.Core;
|
||||||
using Artemis.WebClient.Workshop.Entities;
|
using Artemis.WebClient.Workshop.Entities;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class PluginEntryUploadHandler : IEntryUploadHandler
|
|||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
return EntryUploadResult.FromFailure($"{response.StatusCode} - {await response.Content.ReadAsStringAsync(cancellationToken)}");
|
return EntryUploadResult.FromFailure($"{response.StatusCode} - {await response.Content.ReadAsStringAsync(cancellationToken)}");
|
||||||
|
|
||||||
Release? release = JsonConvert.DeserializeObject<Release>(await response.Content.ReadAsStringAsync(cancellationToken));
|
Release? release = CoreJson.DeserializeObject<Release>(await response.Content.ReadAsStringAsync(cancellationToken));
|
||||||
return release != null ? EntryUploadResult.FromSuccess(release) : EntryUploadResult.FromFailure("Failed to deserialize response");
|
return release != null ? EntryUploadResult.FromSuccess(release) : EntryUploadResult.FromFailure("Failed to deserialize response");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,8 +1,7 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
|
using Artemis.Core;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.Shared.Utilities;
|
|
||||||
using Artemis.WebClient.Workshop.Entities;
|
using Artemis.WebClient.Workshop.Entities;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ public class ProfileEntryUploadHandler : IEntryUploadHandler
|
|||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
return EntryUploadResult.FromFailure($"{response.StatusCode} - {await response.Content.ReadAsStringAsync(cancellationToken)}");
|
return EntryUploadResult.FromFailure($"{response.StatusCode} - {await response.Content.ReadAsStringAsync(cancellationToken)}");
|
||||||
|
|
||||||
Release? release = JsonConvert.DeserializeObject<Release>(await response.Content.ReadAsStringAsync(cancellationToken));
|
Release? release = CoreJson.DeserializeObject<Release>(await response.Content.ReadAsStringAsync(cancellationToken));
|
||||||
return release != null ? EntryUploadResult.FromSuccess(release) : EntryUploadResult.FromFailure("Failed to deserialize response");
|
return release != null ? EntryUploadResult.FromSuccess(release) : EntryUploadResult.FromFailure("Failed to deserialize response");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,7 +33,6 @@
|
|||||||
<PackageVersion Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
|
<PackageVersion Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
|
||||||
<PackageVersion Include="Microsoft.Win32" Version="2.0.1" />
|
<PackageVersion Include="Microsoft.Win32" Version="2.0.1" />
|
||||||
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="8.0.2" />
|
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="8.0.2" />
|
||||||
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
|
|
||||||
<PackageVersion Include="NoStringEvaluating" Version="2.5.2" />
|
<PackageVersion Include="NoStringEvaluating" Version="2.5.2" />
|
||||||
<PackageVersion Include="Octopus.Octodiff" Version="2.0.546" />
|
<PackageVersion Include="Octopus.Octodiff" Version="2.0.546" />
|
||||||
<PackageVersion Include="PropertyChanged.SourceGenerator" Version="1.1.0" />
|
<PackageVersion Include="PropertyChanged.SourceGenerator" Version="1.1.0" />
|
||||||
@ -52,6 +51,7 @@
|
|||||||
<PackageVersion Include="Splat.DryIoc" Version="14.8.12" />
|
<PackageVersion Include="Splat.DryIoc" Version="14.8.12" />
|
||||||
<PackageVersion Include="StrawberryShake.Server" Version="13.9.0" />
|
<PackageVersion Include="StrawberryShake.Server" Version="13.9.0" />
|
||||||
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
|
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
|
||||||
|
<PackageVersion Include="System.Text.Json" Version="8.0.2" />
|
||||||
<PackageVersion Include="TextMateSharp.Grammars" Version="1.0.56" />
|
<PackageVersion Include="TextMateSharp.Grammars" Version="1.0.56" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Loading…
x
Reference in New Issue
Block a user