From b78cdb4a9d1624474a19810101191c44313926e7 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 8 Oct 2023 20:47:12 +0300 Subject: [PATCH 01/25] Convert Newtonsoft converters to STJ converters --- .../Notify/NotifyEntryConverter.cs | 80 +++++++++++-------- .../Converters/LocalizedStringConverter.cs | 25 ++---- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Notify/NotifyEntryConverter.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Notify/NotifyEntryConverter.cs index b63ac09ff1b..1dff03fc296 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Notify/NotifyEntryConverter.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Notify/NotifyEntryConverter.cs @@ -2,13 +2,13 @@ using System.IO; using System.Text; using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Json.Serialization; using Microsoft.AspNetCore.Html; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace OrchardCore.DisplayManagement.Notify { - public class NotifyEntryConverter : JsonConverter + public class NotifyEntryConverter : JsonConverter { private readonly HtmlEncoder _htmlEncoder; @@ -17,52 +17,62 @@ public NotifyEntryConverter(HtmlEncoder htmlEncoder) _htmlEncoder = htmlEncoder; } - public override bool CanConvert(Type objectType) - { - return typeof(NotifyEntry).IsAssignableFrom(objectType); - } + public override bool CanConvert(Type typeToConvert) => typeof(NotifyEntry).IsAssignableFrom(typeToConvert); - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override NotifyEntry Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - var jo = JObject.Load(reader); - - NotifyType type; - - var notifyEntry = new NotifyEntry + if (reader.TokenType != JsonTokenType.StartObject) { - Message = new HtmlString(jo.Value("Message")), - }; + throw new JsonException(); + } - if (Enum.TryParse(jo.Value("Type"), out type)) + var notifyEntry = new NotifyEntry(); + while (reader.Read()) { - notifyEntry.Type = type; - } + if (reader.TokenType == JsonTokenType.EndObject) + { + return notifyEntry; + } - return notifyEntry; - } + if (reader.TokenType != JsonTokenType.PropertyName) + { + throw new JsonException(); + } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - var notifyEntry = value as NotifyEntry; - if (notifyEntry == null) - { - return; + var propertyName = reader.GetString(); + reader.Read(); + + switch(propertyName) + { + case nameof(notifyEntry.Type): + if (Enum.TryParse(reader.GetString(), out NotifyType type)) + { + notifyEntry.Type = type; + } + break; + case nameof(notifyEntry.Message): + notifyEntry.Message = new HtmlString(reader.GetString()); + break; + } + + return notifyEntry; } - var o = new JObject(); + throw new JsonException(); + } + public override void Write(Utf8JsonWriter writer, NotifyEntry value, JsonSerializerOptions options) + { // Serialize the message as it's an IHtmlContent - var stringBuilder = new StringBuilder(); - using (var stringWriter = new StringWriter(stringBuilder)) + using (var stringWriter = new StringWriter(new StringBuilder())) { - notifyEntry.Message.WriteTo(stringWriter, _htmlEncoder); + value.Message.WriteTo(stringWriter, _htmlEncoder); } - // Write all well-known properties - o.Add(new JProperty(nameof(NotifyEntry.Type), notifyEntry.Type.ToString())); - o.Add(new JProperty(nameof(NotifyEntry.Message), notifyEntry.GetMessageAsString(_htmlEncoder))); - - o.WriteTo(writer); + writer.WriteStartObject(nameof(NotifyEntry)); + writer.WriteString(nameof(NotifyEntry.Type), value.Type.ToString()); + writer.WriteString(nameof(NotifyEntry.Message), value.GetMessageAsString(_htmlEncoder)); + writer.WriteEndObject(); } } } diff --git a/src/OrchardCore/OrchardCore.Workflows.Abstractions/Converters/LocalizedStringConverter.cs b/src/OrchardCore/OrchardCore.Workflows.Abstractions/Converters/LocalizedStringConverter.cs index 97b0df2db1d..2ecb805f9c4 100644 --- a/src/OrchardCore/OrchardCore.Workflows.Abstractions/Converters/LocalizedStringConverter.cs +++ b/src/OrchardCore/OrchardCore.Workflows.Abstractions/Converters/LocalizedStringConverter.cs @@ -1,6 +1,7 @@ using System; +using System.Text.Json; +using System.Text.Json.Serialization; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; namespace OrchardCore.Workflows.Abstractions.Converters { @@ -8,24 +9,14 @@ namespace OrchardCore.Workflows.Abstractions.Converters /// /// Serializes the to a simple string using the translated text. /// - public class LocalizedStringConverter : JsonConverter + public class LocalizedStringConverter : JsonConverter { - public override bool CanConvert(Type objectType) - { - return objectType == typeof(LocalizedString); - } + public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(LocalizedString); - public override bool CanRead => false; + public override LocalizedString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => throw new NotImplementedException(); - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - var localizedString = (LocalizedString)value; - writer.WriteValue(localizedString.Value); - } + public override void Write(Utf8JsonWriter writer, LocalizedString value, JsonSerializerOptions options) + => writer.WriteStringValue(value.Value); } } From b2ce4be902c3b61885a2aea895f1ed229dcd55bb Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 8 Oct 2023 21:08:43 +0300 Subject: [PATCH 02/25] Fix the build --- .../Notify/NotifyFilter.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Notify/NotifyFilter.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Notify/NotifyFilter.cs index dc748bfe607..97d396f9f0a 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Notify/NotifyFilter.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Notify/NotifyFilter.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Net; using System.Text.Encodings.Web; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Http; @@ -9,7 +10,6 @@ using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using OrchardCore.DisplayManagement.Layout; namespace OrchardCore.DisplayManagement.Notify @@ -168,13 +168,14 @@ private static void DeleteCookies(ResultExecutingContext filterContext) private string SerializeNotifyEntry(NotifyEntry[] notifyEntries) { - var settings = new JsonSerializerSettings(); - settings.Converters.Add(new NotifyEntryConverter(_htmlEncoder)); + var serializerOptions = new JsonSerializerOptions(); + serializerOptions.Converters.Add(new NotifyEntryConverter(_htmlEncoder)); try { + var protector = _dataProtectionProvider.CreateProtector(nameof(NotifyFilter)); - var signed = protector.Protect(JsonConvert.SerializeObject(notifyEntries, settings)); + var signed = protector.Protect(JsonSerializer.Serialize(notifyEntries, serializerOptions)); return WebUtility.UrlEncode(signed); } catch @@ -185,14 +186,14 @@ private string SerializeNotifyEntry(NotifyEntry[] notifyEntries) private void DeserializeNotifyEntries(string value, out NotifyEntry[] messageEntries) { - var settings = new JsonSerializerSettings(); - settings.Converters.Add(new NotifyEntryConverter(_htmlEncoder)); + var serializerOptions = new JsonSerializerOptions(); + serializerOptions.Converters.Add(new NotifyEntryConverter(_htmlEncoder)); try { var protector = _dataProtectionProvider.CreateProtector(nameof(NotifyFilter)); var decoded = protector.Unprotect(WebUtility.UrlDecode(value)); - messageEntries = JsonConvert.DeserializeObject(decoded, settings); + messageEntries = JsonSerializer.Deserialize(decoded, serializerOptions); } catch { From cf8b11e8b2f4941dd963fd19dca149bce542081d Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 8 Oct 2023 21:27:12 +0300 Subject: [PATCH 03/25] ContentItemConverter --- .../ContentItemConverter.cs | 133 +++++++++++------- 1 file changed, 80 insertions(+), 53 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentItemConverter.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentItemConverter.cs index 95fa3547560..50fb8924321 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentItemConverter.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentItemConverter.cs @@ -1,100 +1,72 @@ using System; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; using Newtonsoft.Json.Linq; namespace OrchardCore.ContentManagement { - public class ContentItemConverter : JsonConverter + public class ContentItemConverter : JsonConverter { - private readonly JsonLoadSettings _jsonLoadSettings = new() - { - LineInfoHandling = LineInfoHandling.Ignore, // Defaults to loading which allocates quite a lot. - }; - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - var contentItem = (ContentItem)value; - var o = new JObject - { - // Write all well-known properties. - new JProperty(nameof(ContentItem.ContentItemId), contentItem.ContentItemId), - new JProperty(nameof(ContentItem.ContentItemVersionId), contentItem.ContentItemVersionId), - new JProperty(nameof(ContentItem.ContentType), contentItem.ContentType), - new JProperty(nameof(ContentItem.DisplayText), contentItem.DisplayText), - new JProperty(nameof(ContentItem.Latest), contentItem.Latest), - new JProperty(nameof(ContentItem.Published), contentItem.Published), - new JProperty(nameof(ContentItem.ModifiedUtc), contentItem.ModifiedUtc), - new JProperty(nameof(ContentItem.PublishedUtc), contentItem.PublishedUtc), - new JProperty(nameof(ContentItem.CreatedUtc), contentItem.CreatedUtc), - new JProperty(nameof(ContentItem.Owner), contentItem.Owner), - new JProperty(nameof(ContentItem.Author), contentItem.Author), - }; - - // Write all custom content properties. - o.Merge(contentItem.Data); + public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(ContentItem); - o.WriteTo(writer); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override ContentItem Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { var contentItem = new ContentItem(); var skip = false; - while (skip || reader.Read()) { skip = false; - - if (reader.TokenType == JsonToken.EndObject) + if (reader.TokenType == JsonTokenType.EndObject) { break; } - if (reader.TokenType != JsonToken.PropertyName) + if (reader.TokenType != JsonTokenType.PropertyName) { - continue; + break; } - var propertyName = (string)reader.Value; + var propertyName = reader.GetString(); + reader.Read(); switch (propertyName) { case nameof(ContentItem.ContentItemId): - contentItem.ContentItemId = reader.ReadAsString(); + contentItem.ContentItemId = reader.GetString(); break; case nameof(ContentItem.ContentItemVersionId): - contentItem.ContentItemVersionId = reader.ReadAsString(); + contentItem.ContentItemVersionId = reader.GetString(); break; case nameof(ContentItem.ContentType): - contentItem.ContentType = reader.ReadAsString(); + contentItem.ContentType = reader.GetString(); break; case nameof(ContentItem.DisplayText): - contentItem.DisplayText = reader.ReadAsString(); + contentItem.DisplayText = reader.GetString(); break; case nameof(ContentItem.Latest): - contentItem.Latest = reader.ReadAsBoolean() ?? false; + contentItem.Latest = reader.GetBoolean(); break; case nameof(ContentItem.Published): - contentItem.Published = reader.ReadAsBoolean() ?? false; + contentItem.Published = reader.GetBoolean(); break; case nameof(ContentItem.PublishedUtc): - contentItem.PublishedUtc = reader.ReadAsDateTime(); + contentItem.PublishedUtc = reader.GetDateTime(); break; case nameof(ContentItem.ModifiedUtc): - contentItem.ModifiedUtc = reader.ReadAsDateTime(); + contentItem.ModifiedUtc = reader.GetDateTime(); break; case nameof(ContentItem.CreatedUtc): - contentItem.CreatedUtc = reader.ReadAsDateTime(); + contentItem.CreatedUtc = reader.GetDateTime(); break; case nameof(ContentItem.Author): - contentItem.Author = reader.ReadAsString(); + contentItem.Author = reader.GetString(); break; case nameof(ContentItem.Owner): - contentItem.Owner = reader.ReadAsString(); + contentItem.Owner = reader.GetString(); break; default: - var customProperty = JProperty.Load(reader, _jsonLoadSettings); - contentItem.Data.Add(customProperty); + // var customProperty = JProperty.Load(reader, _jsonLoadSettings); + // contentItem.Data.Add(customProperty); // Skip reading a token as JProperty.Load already did the next one. skip = true; @@ -105,9 +77,64 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist return contentItem; } - public override bool CanConvert(Type objectType) + public override void Write(Utf8JsonWriter writer, ContentItem value, JsonSerializerOptions options) { - return objectType == typeof(ContentItem); + writer.WriteStartObject(nameof(ContentItem)); + writer.WriteString(nameof(ContentItem.ContentItemId), value.ContentItemId); + writer.WriteString(nameof(ContentItem.ContentItemVersionId), value.ContentItemVersionId); + writer.WriteString(nameof(ContentItem.ContentType), value.ContentType); + writer.WriteString(nameof(ContentItem.DisplayText), value.DisplayText); + writer.WriteBoolean(nameof(ContentItem.Latest), value.Latest); + writer.WriteBoolean(nameof(ContentItem.Published), value.Published); + writer.WriteString(nameof(ContentItem.ModifiedUtc), value.ModifiedUtc.ToString()); + writer.WriteString(nameof(ContentItem.PublishedUtc), value.PublishedUtc.ToString()); + writer.WriteString(nameof(ContentItem.CreatedUtc), value.CreatedUtc.ToString()); + writer.WriteString(nameof(ContentItem.Owner), value.Owner); + writer.WriteString(nameof(ContentItem.Author), value.Author); + + WriteJObject(writer, value.Data); + + writer.WriteEndObject(); + } + + private static void WriteJObject(Utf8JsonWriter writer, JObject data) + { + foreach (var item in data) + { + if (item.Value != null) + { + switch (item.Value.Type) + { + case JTokenType.Boolean: + writer.WriteBoolean(item.Key, item.Value.Value()); + break; + case JTokenType.Integer: + writer.WriteNumber(item.Key, item.Value.Value()); + break; + case JTokenType.Null: + writer.WriteNull(item.Key); + break; + case JTokenType.Array: + case JTokenType.Object: + case JTokenType.Bytes: + case JTokenType.None: + case JTokenType.Constructor: + case JTokenType.Property: + case JTokenType.Comment: + case JTokenType.Undefined: + case JTokenType.Raw: + break; + case JTokenType.Float: + case JTokenType.Guid: + case JTokenType.Uri: + case JTokenType.TimeSpan: + case JTokenType.String: + case JTokenType.Date: + writer.WriteString(item.Key, item.Value.Value()); + break; + } + } + } } } } From d862aacf1e017d65ddbaeabcf4028c6a38b1291a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Sun, 15 Oct 2023 11:27:09 +0200 Subject: [PATCH 04/25] Replace JObject properties. --- .../Deployment/AdminMenuDeploymentSource.cs | 6 +++--- .../ViewModels/EditTypeViewModel.cs | 6 +++--- .../Recipes/DeploymentPlansRecipeStep.cs | 4 ++-- .../Recipes/LuceneIndexStep.cs | 4 ++-- .../Metadata/Models/ContentDefinition.cs | 4 ++-- .../Records/ContentPartDefinitionRecord.cs | 13 ++++--------- .../ContentPartFieldDefinitionRecord.cs | 4 ++-- .../Records/ContentTypeDefinitionRecord.cs | 4 ++-- .../ContentTypePartDefinitionRecord.cs | 4 ++-- .../DeploymentPlanResult.cs | 11 ++++++----- .../Shapes/ShapeSerializer.cs | 19 +++++++++---------- .../Documents/DocumentEntity.cs | 4 ++-- .../Entities/Entity.cs | 4 ++-- .../Models/DatabaseShellConfigurations.cs | 4 ++-- .../Models/DatabaseShellsSettings.cs | 4 ++-- .../Utilities/StringExtensions.cs | 4 ++-- .../YesSql/Models/OpenIdApplication.cs | 4 ++-- .../YesSql/Models/OpenIdAuthorization.cs | 4 ++-- .../YesSql/Models/OpenIdScope.cs | 4 ++-- .../YesSql/Models/OpenIdToken.cs | 4 ++-- .../Models/ConfigurationContext.cs | 6 +++--- .../Models/RecipeExecutionContext.cs | 4 ++-- .../UpdateRecipeExecutionStepContext.cs | 6 +++--- .../Models/Workflow.cs | 4 ++-- 24 files changed, 65 insertions(+), 70 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs index c90a7107ccc..7a9a2a580ac 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs @@ -1,6 +1,6 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.AdminMenu.Services; using OrchardCore.Deployment; @@ -24,7 +24,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var data = new JArray(); + var data = new JsonArray(); result.Steps.Add(new JObject( new JProperty("name", "AdminMenu"), new JProperty("data", data) @@ -36,7 +36,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var adminMenu in (await _adminMenuService.GetAdminMenuListAsync()).AdminMenu) { var objectData = JObject.FromObject(adminMenu, serializer); - data.Add(objectData); + data.Add(adminMenu); } return; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditTypeViewModel.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditTypeViewModel.cs index 60ef0bac230..717089f6666 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditTypeViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditTypeViewModel.cs @@ -1,5 +1,5 @@ +using System.Text.Json.Nodes; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement.Metadata.Models; namespace OrchardCore.ContentTypes.ViewModels @@ -8,7 +8,7 @@ public class EditTypeViewModel { public EditTypeViewModel() { - Settings = new JObject(); + Settings = new JsonObject(); } public EditTypeViewModel(ContentTypeDefinition contentTypeDefinition) @@ -25,7 +25,7 @@ public EditTypeViewModel(ContentTypeDefinition contentTypeDefinition) public string[] OrderedPartNames { get; set; } [BindNever] - public JObject Settings { get; set; } + public JsonObject Settings { get; set; } [BindNever] public ContentTypeDefinition TypeDefinition { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs b/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs index e2cd3eec9a9..22af8f5010b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -90,7 +90,7 @@ private class DeploymentStepModel { public string Type { get; set; } - public JObject Step { get; set; } + public JsonObject Step { get; set; } } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs index dc2dec2d0fb..83580dc3ec0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Search.Lucene.Model; @@ -52,6 +52,6 @@ public async Task ExecuteAsync(RecipeExecutionContext context) public class ContentStepModel { - public JObject Data { get; set; } + public JsonObject Data { get; set; } } } diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Models/ContentDefinition.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Models/ContentDefinition.cs index 49a190f6842..e9cef61dbfd 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Models/ContentDefinition.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Models/ContentDefinition.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Newtonsoft.Json; +using System.Text.Json.Nodes; using Newtonsoft.Json.Linq; namespace OrchardCore.ContentManagement.Metadata.Models @@ -14,7 +14,7 @@ public abstract class ContentDefinition /// /// Do not access this property directly. Migrate to use GetSettings and PopulateSettings. /// - public JObject Settings { get; protected set; } + public JsonObject Settings { get; protected set; } public T GetSettings() where T : new() { diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartDefinitionRecord.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartDefinitionRecord.cs index c6d792a8be9..5f433c80654 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartDefinitionRecord.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartDefinitionRecord.cs @@ -1,24 +1,19 @@ using System.Collections.Generic; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.ContentManagement.Metadata.Records { public class ContentPartDefinitionRecord { - public ContentPartDefinitionRecord() - { - ContentPartFieldDefinitionRecords = new List(); - Settings = new JObject(); - } - public string Name { get; set; } /// /// Gets or sets the settings of a part, like description, or any property that a module would attach /// to a part. /// - public JObject Settings { get; set; } + public JsonObject Settings { get; set; } = new(); - public IList ContentPartFieldDefinitionRecords { get; set; } + public IList ContentPartFieldDefinitionRecords { get; set; } = + new List(); } } diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartFieldDefinitionRecord.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartFieldDefinitionRecord.cs index 97d84a35f58..24cda685430 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartFieldDefinitionRecord.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentPartFieldDefinitionRecord.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.ContentManagement.Metadata.Records { @@ -20,6 +20,6 @@ public class ContentPartFieldDefinitionRecord /// /// Gets or sets the settings of the field for this part. /// - public JObject Settings { get; set; } + public JsonObject Settings { get; set; } } } diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypeDefinitionRecord.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypeDefinitionRecord.cs index d4988ce7e03..579a1b1daea 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypeDefinitionRecord.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypeDefinitionRecord.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.ContentManagement.Metadata.Records { @@ -12,7 +12,7 @@ public ContentTypeDefinitionRecord() public string Name { get; set; } public string DisplayName { get; set; } - public JObject Settings { get; set; } + public JsonObject Settings { get; set; } public IList ContentTypePartDefinitionRecords { get; set; } } diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypePartDefinitionRecord.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypePartDefinitionRecord.cs index a7f50cd8385..7c2c344b919 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypePartDefinitionRecord.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Records/ContentTypePartDefinitionRecord.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.ContentManagement.Metadata.Records { @@ -20,6 +20,6 @@ public class ContentTypePartDefinitionRecord /// /// Gets or sets the settings of the part for this type. /// - public JObject Settings { get; set; } + public JsonObject Settings { get; set; } } } diff --git a/src/OrchardCore/OrchardCore.Deployment.Abstractions/DeploymentPlanResult.cs b/src/OrchardCore/OrchardCore.Deployment.Abstractions/DeploymentPlanResult.cs index 160ad88e3df..e334e4c5bc3 100644 --- a/src/OrchardCore/OrchardCore.Deployment.Abstractions/DeploymentPlanResult.cs +++ b/src/OrchardCore/OrchardCore.Deployment.Abstractions/DeploymentPlanResult.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -17,7 +18,7 @@ public DeploymentPlanResult(IFileBuilder fileBuilder, RecipeDescriptor recipeDes { FileBuilder = fileBuilder; - Recipe = new JObject + Recipe = new JsonObject { ["name"] = recipeDescriptor.Name ?? "", ["displayName"] = recipeDescriptor.DisplayName ?? "", @@ -26,13 +27,13 @@ public DeploymentPlanResult(IFileBuilder fileBuilder, RecipeDescriptor recipeDes ["website"] = recipeDescriptor.WebSite ?? "", ["version"] = recipeDescriptor.Version ?? "", ["issetuprecipe"] = recipeDescriptor.IsSetupRecipe, - ["categories"] = new JArray(recipeDescriptor.Categories ?? Array.Empty()), - ["tags"] = new JArray(recipeDescriptor.Tags ?? Array.Empty()), + ["categories"] = new JsonArray(recipeDescriptor.Categories ?? Array.Empty()), + ["tags"] = new JsonArray(recipeDescriptor.Tags ?? Array.Empty()), }; } - public JObject Recipe { get; } - public IList Steps { get; } = new List(); + public JsonObject Recipe { get; } + public IList Steps { get; } = new List(); public IFileBuilder FileBuilder { get; } public async Task FinalizeAsync() { diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/ShapeSerializer.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/ShapeSerializer.cs index 981e8a8cd7e..4c02ccb21dd 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/ShapeSerializer.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/ShapeSerializer.cs @@ -1,7 +1,6 @@ -using System; using System.Collections.Generic; using System.Linq; -using Newtonsoft.Json; +using System.Text.Json.Nodes; using Newtonsoft.Json.Linq; namespace OrchardCore.DisplayManagement.Shapes @@ -28,14 +27,14 @@ public ShapeSerializer(IShape shape) _shape = shape; } - public JObject Serialize() + public JsonObject Serialize() { if (_shape == null) { - return new JObject(); + return new JsonObject(); } - var jObject = new JObject(); + var jObject = new JsonObject(); // Provides a convenient identifier in console. var displayText = _shape.Metadata.Name; @@ -51,23 +50,23 @@ public JObject Serialize() jObject.Add("Shape", displayText); - var metadata = JObject.FromObject(_shape.Metadata, _shapeJsonSerializer); + var metadata = JsonObject.FromObject(_shape.Metadata, _shapeJsonSerializer); jObject.Add(nameof(ShapeMetadata), metadata); if (_shape.Classes != null && _shape.Classes.Any()) { - jObject.Add(nameof(_shape.Classes), JArray.FromObject(_shape.Classes, _shapeJsonSerializer)); + jObject.Add(nameof(_shape.Classes), JsonArray.FromObject(_shape.Classes, _shapeJsonSerializer)); } if (_shape.Attributes != null && _shape.Attributes.Any()) { - jObject.Add(nameof(_shape.Attributes), JObject.FromObject(_shape.Attributes, _shapeJsonSerializer)); + jObject.Add(nameof(_shape.Attributes), JsonObject.FromObject(_shape.Attributes, _shapeJsonSerializer)); } if (_shape.Properties != null && _shape.Properties.Any()) { - jObject.Add(nameof(_shape.Properties), JObject.FromObject(_shape.Properties, _shapeJsonSerializer)); + jObject.Add(nameof(_shape.Properties), JsonObject.FromObject(_shape.Properties, _shapeJsonSerializer)); FindShapesInProperties(_shape); } @@ -85,7 +84,7 @@ public JObject Serialize() jItems.Add(jItem); } } - jObject.Add(nameof(actualShape.Items), jItems); + JsonObject.Add(nameof(actualShape.Items), jItems); } return jObject; diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Documents/DocumentEntity.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Documents/DocumentEntity.cs index ba25b5add3b..8de5f05e8a7 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Documents/DocumentEntity.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Documents/DocumentEntity.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; using OrchardCore.Data.Documents; namespace OrchardCore.Documents @@ -8,6 +8,6 @@ namespace OrchardCore.Documents /// public class DocumentEntity : Document, IDocumentEntity { - public JObject Properties { get; set; } = new JObject(); + public JsonObject Properties { get; set; } = new JsonObject(); } } diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Entities/Entity.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Entities/Entity.cs index 2cbb9d34f75..7e86e47c66e 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Entities/Entity.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Entities/Entity.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.Entities { public class Entity : IEntity { - public JObject Properties { get; set; } = new JObject(); + public JsonObject Properties { get; set; } = new JsonObject(); } } diff --git a/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Models/DatabaseShellConfigurations.cs b/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Models/DatabaseShellConfigurations.cs index 59232ac87f9..8d95b2354dc 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Models/DatabaseShellConfigurations.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Models/DatabaseShellConfigurations.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.Shells.Database.Models { public class DatabaseShellConfigurations { - public JObject ShellConfigurations { get; set; } + public JsonObject ShellConfigurations { get; set; } } } diff --git a/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Models/DatabaseShellsSettings.cs b/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Models/DatabaseShellsSettings.cs index 0cc073dde3e..a9d16682d8f 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Models/DatabaseShellsSettings.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Models/DatabaseShellsSettings.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.Shells.Database.Models { public class DatabaseShellsSettings { - public JObject ShellsSettings { get; set; } + public JsonObject ShellsSettings { get; set; } } } diff --git a/src/OrchardCore/OrchardCore.Mvc.Core/Utilities/StringExtensions.cs b/src/OrchardCore/OrchardCore.Mvc.Core/Utilities/StringExtensions.cs index 5727ca24278..a4ebb78d34d 100644 --- a/src/OrchardCore/OrchardCore.Mvc.Core/Utilities/StringExtensions.cs +++ b/src/OrchardCore/OrchardCore.Mvc.Core/Utilities/StringExtensions.cs @@ -4,10 +4,10 @@ using System.Globalization; using System.Net; using System.Text; +using System.Text.Json.Nodes; using System.Text.RegularExpressions; using Cysharp.Text; using Microsoft.Extensions.Localization; -using Newtonsoft.Json.Linq; namespace OrchardCore.Mvc.Utilities { @@ -511,7 +511,7 @@ public static bool IsJson(this string json) { try { - JToken.Parse(json); + JsonNode.Parse(json); return true; } catch diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdApplication.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdApplication.cs index 9f5962d9e66..e18f41c340a 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdApplication.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdApplication.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; using System.Globalization; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.OpenId.YesSql.Models { @@ -64,7 +64,7 @@ public class OpenIdApplication /// /// Gets or sets the additional properties associated with the current application. /// - public JObject Properties { get; set; } + public JsonObject Properties { get; set; } /// /// Gets or sets the callback URLs associated with the current application. diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdAuthorization.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdAuthorization.cs index 8f79929c381..58cef37ce44 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdAuthorization.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdAuthorization.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Immutable; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.OpenId.YesSql.Models { @@ -35,7 +35,7 @@ public class OpenIdAuthorization /// /// Gets or sets the additional properties associated with the current authorization. /// - public JObject Properties { get; set; } + public JsonObject Properties { get; set; } /// /// Gets or sets the scopes associated with the current authorization. diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdScope.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdScope.cs index 0a988051e2b..b86a286bc48 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdScope.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdScope.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; using System.Globalization; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.OpenId.YesSql.Models { @@ -51,7 +51,7 @@ public class OpenIdScope /// /// Gets or sets the additional properties associated with the current scope. /// - public JObject Properties { get; set; } + public JsonObject Properties { get; set; } /// /// Gets or sets the resources associated with the current scope. diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdToken.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdToken.cs index 18342a8148a..bd68b2fc5e3 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdToken.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Models/OpenIdToken.cs @@ -1,5 +1,5 @@ using System; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.OpenId.YesSql.Models { @@ -53,7 +53,7 @@ public class OpenIdToken /// /// Gets or sets the additional properties associated with the current token. /// - public JObject Properties { get; set; } + public JsonObject Properties { get; set; } /// /// Gets or sets the redemption date of the current token. diff --git a/src/OrchardCore/OrchardCore.Recipes.Abstractions/Models/ConfigurationContext.cs b/src/OrchardCore/OrchardCore.Recipes.Abstractions/Models/ConfigurationContext.cs index 1b464da593d..31e21823124 100644 --- a/src/OrchardCore/OrchardCore.Recipes.Abstractions/Models/ConfigurationContext.cs +++ b/src/OrchardCore/OrchardCore.Recipes.Abstractions/Models/ConfigurationContext.cs @@ -1,14 +1,14 @@ -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.Recipes.Models { public class ConfigurationContext { - protected ConfigurationContext(JObject configurationElement) + protected ConfigurationContext(JsonObject configurationElement) { ConfigurationElement = configurationElement; } - public JObject ConfigurationElement { get; set; } + public JsonObject ConfigurationElement { get; set; } } } diff --git a/src/OrchardCore/OrchardCore.Recipes.Abstractions/Models/RecipeExecutionContext.cs b/src/OrchardCore/OrchardCore.Recipes.Abstractions/Models/RecipeExecutionContext.cs index a6b5e5dc7a9..0efdd1b715e 100644 --- a/src/OrchardCore/OrchardCore.Recipes.Abstractions/Models/RecipeExecutionContext.cs +++ b/src/OrchardCore/OrchardCore.Recipes.Abstractions/Models/RecipeExecutionContext.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.Recipes.Models { @@ -8,7 +8,7 @@ public class RecipeExecutionContext public string ExecutionId { get; set; } public object Environment { get; set; } public string Name { get; set; } - public JObject Step { get; set; } + public JsonObject Step { get; set; } public RecipeDescriptor RecipeDescriptor { get; set; } public IEnumerable InnerRecipes { get; set; } } diff --git a/src/OrchardCore/OrchardCore.Recipes.Abstractions/Services/UpdateRecipeExecutionStepContext.cs b/src/OrchardCore/OrchardCore.Recipes.Abstractions/Services/UpdateRecipeExecutionStepContext.cs index bd313b9e273..d86a122be09 100644 --- a/src/OrchardCore/OrchardCore.Recipes.Abstractions/Services/UpdateRecipeExecutionStepContext.cs +++ b/src/OrchardCore/OrchardCore.Recipes.Abstractions/Services/UpdateRecipeExecutionStepContext.cs @@ -1,10 +1,10 @@ -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.Recipes.Services { public class UpdateRecipeExecutionStepContext { - public JObject RecipeDocument { get; set; } - public JObject Step { get; set; } + public JsonObject RecipeDocument { get; set; } + public JsonObject Step { get; set; } } } diff --git a/src/OrchardCore/OrchardCore.Workflows.Abstractions/Models/Workflow.cs b/src/OrchardCore/OrchardCore.Workflows.Abstractions/Models/Workflow.cs index ee8fa2b0cf6..415000435ad 100644 --- a/src/OrchardCore/OrchardCore.Workflows.Abstractions/Models/Workflow.cs +++ b/src/OrchardCore/OrchardCore.Workflows.Abstractions/Models/Workflow.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.Workflows.Models { @@ -26,7 +26,7 @@ public class Workflow /// /// Serialized state of the workflow. /// - public JObject State { get; set; } = new JObject(); + public JsonObject State { get; set; } = new JsonObject(); public WorkflowStatus Status { get; set; } public string FaultMessage { get; set; } From 25d4e6c78cfd7d5e00f6393ee289dd5e600f7fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Sun, 15 Oct 2023 11:30:43 +0200 Subject: [PATCH 05/25] Replace JArray properties. --- .../OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs | 4 ++-- .../OrchardCore.Contents/Recipes/ContentStep.cs | 4 ++-- .../OrchardCore.Layers/Recipes/LayerStep.cs | 4 ++-- .../OrchardCore.Queries/Recipes/QueryStep.cs | 3 ++- .../OrchardCore.Sitemaps/Recipes/SitemapsStep.cs | 4 ++-- .../OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs | 4 ++-- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs index efc4c7c01f9..835abdef015 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs @@ -1,5 +1,5 @@ using System; -using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -51,6 +51,6 @@ public async Task ExecuteAsync(RecipeExecutionContext context) public class AdminMenuStepModel { - public JArray Data { get; set; } + public JsonArray Data { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs index c1c100ee6bd..f59787d0cd6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs @@ -1,7 +1,7 @@ using System; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Environment.Shell.Scope; using OrchardCore.Recipes.Models; @@ -45,6 +45,6 @@ public Task ExecuteAsync(RecipeExecutionContext context) public class ContentStepModel { - public JArray Data { get; set; } + public JsonArray Data { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs index fd9988378c4..6ce2c84d3d2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.Layers.Models; using OrchardCore.Layers.Services; using OrchardCore.Recipes.Models; @@ -149,6 +149,6 @@ public class RuleStepModel { public string Name { get; set; } public string ConditionId { get; set; } - public JArray Conditions { get; set; } + public JsonArray Conditions { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs index 5c031807502..e5fd99bcba4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Newtonsoft.Json.Linq; @@ -57,6 +58,6 @@ public async Task ExecuteAsync(RecipeExecutionContext context) public class QueryStepModel { - public JArray Queries { get; set; } + public JsonArray Queries { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs index 86774f544fa..18002033cde 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs @@ -1,5 +1,5 @@ using System; -using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -45,7 +45,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) public class SitemapStepModel { - public JArray Data { get; set; } + public JsonArray Data { get; set; } } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs index 1ceb3241044..6fcccacb873 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs @@ -1,5 +1,5 @@ using System; -using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Newtonsoft.Json.Linq; using OrchardCore.Recipes.Models; @@ -49,6 +49,6 @@ public async Task ExecuteAsync(RecipeExecutionContext context) public class WorkflowStepModel { - public JArray Data { get; set; } + public JsonArray Data { get; set; } } } From d450344888fa249878b537941fbbfac273c48537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Sun, 15 Oct 2023 11:47:19 +0200 Subject: [PATCH 06/25] Store ContentElement.Data and IEntity.Properties as JsonObject. --- .../ContentPartFieldDefinitionExtensions.cs | 19 +++++++-------- .../ContentElement.cs | 24 +++++++++++++------ .../Entities/IEntity.cs | 4 ++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs index 143688b62ba..5360843cc07 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; -using Newtonsoft.Json.Linq; +using System.Text.Json; +using System.Text.Json.Nodes; namespace OrchardCore.ContentManagement.Metadata.Models; @@ -11,16 +12,12 @@ public static class ContentPartFieldDefinitionExtensions public static TField GetContentField( this ContentPartFieldDefinition fieldDefinition, ContentItem contentItem) - where TField : ContentField - { - if (((JObject)contentItem.Content)[fieldDefinition.PartDefinition.Name] is not JObject jPart || - jPart[fieldDefinition.Name] is not JObject jField) - { - return null; - } - - return jField.ToObject(); - } + where TField : ContentField => + contentItem.TryGetPropertyValue(fieldDefinition.PartDefinition.Name, out var jPart) && + (jPart as JsonObject)?.TryGetPropertyValue(fieldDefinition.Name, out var jField) == true && + jField is JsonObject + ? jField.Deserialize() + : null; /// /// Returns each field from that exists in in a diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentElement.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentElement.cs index 7b86a835e33..f20e9ac559a 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentElement.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentElement.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; namespace OrchardCore.ContentManagement { @@ -12,23 +12,24 @@ public class ContentElement : IContent { private Dictionary _elements; - protected ContentElement() : this(new JObject()) + protected ContentElement() : this(new JsonObject()) { } - protected ContentElement(JObject data) + protected ContentElement(JsonObject data) { Data = data; } [JsonIgnore] - protected internal Dictionary Elements => _elements ??= new Dictionary(); + protected internal Dictionary Elements => + _elements ??= new Dictionary(); [JsonIgnore] - public dynamic Content { get { return Data; } } + public dynamic Content => Data; [JsonIgnore] - internal JObject Data { get; set; } + internal JsonObject Data { get; set; } [JsonIgnore] public ContentItem ContentItem { get; set; } @@ -41,5 +42,14 @@ public bool Has(string name) { return Data.ContainsKey(name); } + + /// + /// Tries to access a property in the by name. + /// + /// The name of the property to look for. + /// The property value node. + /// + public bool TryGetPropertyValue(string propertyName, out JsonNode jsonNode) => + Data.TryGetPropertyValue(propertyName, out jsonNode); } } diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Entities/IEntity.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Entities/IEntity.cs index 6b81afc55cc..a2c3f7074bd 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Entities/IEntity.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Entities/IEntity.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.Entities { public interface IEntity { - JObject Properties { get; } + JsonObject Properties { get; } } } From e7783473cdfd00803d1383c6b4d62f097937fb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Sun, 15 Oct 2023 12:52:31 +0200 Subject: [PATCH 07/25] Convert and simplify template steps. --- .../Recipes/PlacementStep.cs | 14 ++--------- .../Recipes/ShortcodeTemplateStep.cs | 14 ++--------- .../Recipes/AdminTemplateStep.cs | 14 ++--------- .../Recipes/TemplateStep.cs | 12 ++-------- .../Models/RecipeExecutionContext.cs | 23 +++++++++++++++++++ 5 files changed, 31 insertions(+), 46 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs b/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs index ee63bbadc66..66694e7efc3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs @@ -1,6 +1,4 @@ -using System; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.DisplayManagement.Descriptors.ShapePlacementStrategy; using OrchardCore.Placements.Services; using OrchardCore.Recipes.Models; @@ -22,18 +20,10 @@ public PlacementStep(PlacementsManager placementsManager) public async Task ExecuteAsync(RecipeExecutionContext context) { - if (!string.Equals(context.Name, "Placements", StringComparison.OrdinalIgnoreCase)) + if (context.TryGetStepPropertyIfNameMatches("Placements", out var templates)) { - return; - } - - if (context.Step.Property("Placements").Value is JObject templates) - { - foreach (var property in templates.Properties()) + foreach (var (name, value) in templates) { - var name = property.Name; - var value = property.Value.ToObject(); - await _placementsManager.UpdateShapePlacementsAsync(name, value); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs index 1491770126a..674aca2e094 100644 --- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs @@ -1,6 +1,4 @@ -using System; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Shortcodes.Models; @@ -22,18 +20,10 @@ public ShortcodeTemplateStep(ShortcodeTemplatesManager templatesManager) public async Task ExecuteAsync(RecipeExecutionContext context) { - if (!string.Equals(context.Name, "ShortcodeTemplates", StringComparison.OrdinalIgnoreCase)) + if (context.TryGetStepPropertyIfNameMatches("ShortcodeTemplates", out var templates)) { - return; - } - - if (context.Step.Property("ShortcodeTemplates").Value is JObject templates) - { - foreach (var property in templates.Properties()) + foreach (var (name, value) in templates) { - var name = property.Name; - var value = property.Value.ToObject(); - await _templatesManager.UpdateShortcodeTemplateAsync(name, value); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs index 492969f3119..50ca58ab090 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs @@ -1,6 +1,4 @@ -using System; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Templates.Models; @@ -22,18 +20,10 @@ public AdminTemplateStep(AdminTemplatesManager templatesManager) public async Task ExecuteAsync(RecipeExecutionContext context) { - if (!string.Equals(context.Name, "AdminTemplates", StringComparison.OrdinalIgnoreCase)) + if (context.TryGetStepPropertyIfNameMatches