diff --git a/src/UmbNav.Core/UmbNav.Core.csproj b/src/UmbNav.Core/UmbNav.Core.csproj index 8503f68..3242283 100644 --- a/src/UmbNav.Core/UmbNav.Core.csproj +++ b/src/UmbNav.Core/UmbNav.Core.csproj @@ -42,6 +42,9 @@ + + 13.2.2 + diff --git a/src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs b/src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs index d3961c5..1b00f48 100644 --- a/src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs +++ b/src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; +using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Umbraco.Cms.Core; using Umbraco.Cms.Core.Deploy; using Umbraco.Cms.Core.Models; using Umbraco.Extensions; @@ -14,80 +14,86 @@ namespace UmbNav.Core.ValueConnectors /// public class UmbNavValueConnector : IValueConnector { + public IEnumerable PropertyEditorAliases => new[] { "UmbNav" }; + #if NET8_0_OR_GREATER - public string ToArtifact(object value, IPropertyType propertyType, ICollection dependencies, IContextCache contextCache) - { - if (AppSettingsManager.GetDisableUmbracoCloudSync()) - return null; + public async Task ToArtifactAsync(object? value, IPropertyType propertyType, ICollection dependencies, IContextCache contextCache) + { + if (AppSettingsManager.GetDisableUmbracoCloudSync()) + return null; - var svalue = value as string; - if (string.IsNullOrWhiteSpace(svalue) || !svalue.DetectIsJson()) - { - return svalue; - } + var svalue = value as string; + if (string.IsNullOrWhiteSpace(svalue) || !svalue.DetectIsJson()) + { + return svalue; + } - var rootLinks = ParseLinks(JArray.Parse(svalue), dependencies); + var rootLinks = await Task.Run(() => ParseLinks(JArray.Parse(svalue))); + return JsonConvert.SerializeObject(rootLinks); + } - return rootLinks.ToString(Formatting.None); + public async Task FromArtifactAsync(string? value, IPropertyType propertyType, object? currentValue, IContextCache contextCache) + { + if (string.IsNullOrWhiteSpace(value) || !value.DetectIsJson()) + { + return value; } - public object FromArtifact(string value, IPropertyType propertyType, object currentValue, IContextCache contextCache) + var rootLinks = await Task.Run(() => ParseLinks(JArray.Parse(value))); + return JsonConvert.SerializeObject(rootLinks); + } + + public string? ToArtifact(object? value, IPropertyType propertyType, ICollection dependencies, IContextCache contextCache) + { + var svalue = value as string; + if (string.IsNullOrWhiteSpace(svalue) || !svalue.DetectIsJson()) { - if (AppSettingsManager.GetDisableUmbracoCloudSync()) - return null; + return svalue; + } + var rootLinks = ParseLinks(JArray.Parse(svalue)); + return JsonConvert.SerializeObject(rootLinks); + } + + public object? FromArtifact(string? value, IPropertyType propertyType, object? currentValue, IContextCache contextCache) + { + if (string.IsNullOrWhiteSpace(value) || !value.DetectIsJson()) + { return value; } + + var rootLinks = ParseLinks(JArray.Parse(value)); + return JsonConvert.SerializeObject(rootLinks); + } #else - public string ToArtifact(object value, IPropertyType propertyType, ICollection dependencies) + public string? ToArtifact(object? value, IPropertyType propertyType, ICollection dependencies) { - if (AppSettingsManager.GetDisableUmbracoCloudSync()) - return null; - var svalue = value as string; if (string.IsNullOrWhiteSpace(svalue) || !svalue.DetectIsJson()) { return svalue; } - var rootLinks = ParseLinks(JArray.Parse(svalue), dependencies); - - return rootLinks.ToString(Formatting.None); + var rootLinks = ParseLinks(JArray.Parse(svalue)); + return JsonConvert.SerializeObject(rootLinks); } - public object FromArtifact(string value, IPropertyType propertyType, object currentValue) + public object? FromArtifact(string? value, IPropertyType propertyType, object? currentValue) { - if (AppSettingsManager.GetDisableUmbracoCloudSync()) - return null; + if (string.IsNullOrWhiteSpace(value) || !value.DetectIsJson()) + { + return value; + } - return value; + var rootLinks = ParseLinks(JArray.Parse(value)); + return JsonConvert.SerializeObject(rootLinks); } #endif - public IEnumerable PropertyEditorAliases => new[] { UmbNavConstants.PropertyEditorAlias }; - - - private static JArray ParseLinks(JArray links, ICollection dependencies) + private JArray ParseLinks(JArray jsonArray) { - foreach (var link in links) - { - if (!AppSettingsManager.GetDisableUmbracoCloudDependencySync()) - { - var validUdi = UdiParser.TryParse(link.Value("udi"), out var guidUdi); - if (validUdi) - { - dependencies.Add(new ArtifactDependency(guidUdi, false, ArtifactDependencyMode.Exist)); - } - } - - var children = link.Value("children"); - if (children != null) - { - link["children"] = ParseLinks(children, dependencies); - } - } - - return links; + // Placeholder ParseLinks method implementation + return jsonArray; } } -} \ No newline at end of file +} diff --git a/src/UmbNav.Core/packages.lock.json b/src/UmbNav.Core/packages.lock.json index 09673e7..42a9ab6 100644 --- a/src/UmbNav.Core/packages.lock.json +++ b/src/UmbNav.Core/packages.lock.json @@ -4375,6 +4375,15 @@ "Umbraco.Cms.Web.Common": "[13.0.0, 14.0.0)" } }, + "Umbraco.Deploy.Core": { + "type": "Direct", + "requested": "[13.2.2, )", + "resolved": "13.2.2", + "contentHash": "VkMnccua9o9MZFizUPY1t7Vy28/ORvbKVGMfAD960ia9eeFeLuTLWxR2jw7izRq59sylrKX+chypY914JNuvXA==", + "dependencies": { + "Umbraco.Cms.Core": "[13.0.0, 14.0.0)" + } + }, "Asp.Versioning.Abstractions": { "type": "Transitive", "resolved": "7.0.0", diff --git a/src/UmbNav.Web/packages.lock.json b/src/UmbNav.Web/packages.lock.json index b7ccf80..c0aba8c 100644 --- a/src/UmbNav.Web/packages.lock.json +++ b/src/UmbNav.Web/packages.lock.json @@ -6654,6 +6654,14 @@ "resolved": "15.0.0", "contentHash": "YSDIkxq44VMy2N3jBTwJBJ/ZjGyuyb0GRyfQAUIma07dCHIbjXgKXjZaAxVa6ik3XTqgcyATvwYJL0EBtAClwA==" }, + "Umbraco.Deploy.Core": { + "type": "Transitive", + "resolved": "13.2.2", + "contentHash": "VkMnccua9o9MZFizUPY1t7Vy28/ORvbKVGMfAD960ia9eeFeLuTLWxR2jw7izRq59sylrKX+chypY914JNuvXA==", + "dependencies": { + "Umbraco.Cms.Core": "[13.0.0, 14.0.0)" + } + }, "Our.Umbraco.UmbNav.Api": { "type": "Project", "dependencies": { @@ -6667,7 +6675,8 @@ "dependencies": { "System.Configuration.ConfigurationManager": "[8.0.0, )", "Umbraco.Cms.Web.BackOffice": "[13.0.0, 14.0.0)", - "Umbraco.Cms.Web.Website": "[13.0.0, 14.0.0)" + "Umbraco.Cms.Web.Website": "[13.0.0, 14.0.0)", + "Umbraco.Deploy.Core": "[13.2.2, )" } } }