diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs index c4a441b3e82..ff4e3777a17 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OrchardCore.Deployment; using OrchardCore.Entities; @@ -10,7 +11,12 @@ namespace OrchardCore.Layers.Deployment { public class AllLayersDeploymentSource : IDeploymentSource - { + { + private readonly static JsonSerializer JsonSerializer = new JsonSerializer() + { + TypeNameHandling = TypeNameHandling.Auto + }; + private readonly ILayerService _layerService; private readonly ISiteService _siteService; @@ -33,7 +39,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JObject( new JProperty("name", "Layers"), - new JProperty("Layers", layers.Layers.Select(JObject.FromObject)) + new JProperty("Layers", layers.Layers.Select(layer => JObject.FromObject(layer, JsonSerializer))) )); var siteSettings = await _siteService.GetSiteSettingsAsync(); diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs index a74b94f4d50..53a5cd5f39e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OrchardCore.Layers.Models; using OrchardCore.Layers.Services; @@ -16,6 +17,11 @@ namespace OrchardCore.Layers.Recipes /// public class LayerStep : IRecipeStepHandler { + private readonly static JsonSerializer JsonSerializer = new JsonSerializer() + { + TypeNameHandling = TypeNameHandling.Auto + }; + private readonly ILayerService _layerService; private readonly IRuleMigrator _ruleMigrator; private readonly IConditionIdGenerator _conditionIdGenerator; @@ -40,7 +46,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(); var allLayers = await _layerService.LoadLayersAsync(); @@ -83,18 +89,18 @@ public async Task ExecuteAsync(RecipeExecutionContext context) // The conditions list is cleared, because we cannot logically merge conditions. layer.LayerRule.Conditions.Clear(); - foreach (var condition in layerStep.LayerRule.Conditions) + foreach (var jCondition in layerStep.LayerRule.Conditions) { - if (factories.TryGetValue(condition.Name, out var factory)) + var name = jCondition["Name"].ToString(); + if (factories.TryGetValue(name, out var factory)) { - var jCondition = JObject.FromObject(condition); - var factoryCondition = (Condition)jCondition.ToObject(factory.Create().GetType()); + var factoryCondition = (Condition)jCondition.ToObject(factory.Create().GetType(), JsonSerializer); layer.LayerRule.Conditions.Add(factoryCondition); } else { - unknownTypes.Add(condition.Name); + unknownTypes.Add(name); } } } @@ -126,8 +132,25 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } + public class LayersStepModel + { + public LayerStepModel[] Layers { get; set; } + } + public class LayerStepModel { - public Layer[] Layers { get; set; } + public string Name { get; set; } + + public string Rule { get; set; } + public string Description { get; set; } + + public RuleStepModel LayerRule { get; set; } + } + + public class RuleStepModel + { + public string Name { get; set; } + public string ConditionId { get; set; } + public JArray Conditions { get; set; } } } diff --git a/src/OrchardCore.Themes/TheAgencyTheme/Recipes/agency.recipe.json b/src/OrchardCore.Themes/TheAgencyTheme/Recipes/agency.recipe.json index 7f56d6e73ff..3375e089faa 100644 --- a/src/OrchardCore.Themes/TheAgencyTheme/Recipes/agency.recipe.json +++ b/src/OrchardCore.Themes/TheAgencyTheme/Recipes/agency.recipe.json @@ -856,6 +856,7 @@ "ConditionId": "[js: uuid()]", "Conditions": [ { + "$type": "OrchardCore.Rules.Models.BooleanCondition, OrchardCore.Rules", "Name": "BooleanCondition", "Value": true, "ConditionId": "[js: uuid()]" @@ -870,6 +871,7 @@ "ConditionId": "[js: uuid()]", "Conditions": [ { + "$type": "OrchardCore.Rules.Models.HomepageCondition, OrchardCore.Rules", "Name": "HomepageCondition", "Value": true, "ConditionId": "[js: uuid()]" diff --git a/src/OrchardCore.Themes/TheBlogTheme/Recipes/blog.recipe.json b/src/OrchardCore.Themes/TheBlogTheme/Recipes/blog.recipe.json index aea98c2fa7c..295f5100098 100644 --- a/src/OrchardCore.Themes/TheBlogTheme/Recipes/blog.recipe.json +++ b/src/OrchardCore.Themes/TheBlogTheme/Recipes/blog.recipe.json @@ -1175,6 +1175,7 @@ "ConditionId":"[js: uuid()]", "Conditions": [ { + "$type": "OrchardCore.Rules.Models.BooleanCondition, OrchardCore.Rules", "Name": "BooleanCondition", "Value": true, "ConditionId": "[js: uuid()]" @@ -1189,6 +1190,7 @@ "ConditionId": "[js: uuid()]", "Conditions": [ { + "$type": "OrchardCore.Rules.Models.HomepageCondition, OrchardCore.Rules", "Name": "HomepageCondition", "Value": true, "ConditionId": "[js: uuid()]"