Skip to content

Commit

Permalink
Merge pull request #94 from SimonAntony/TypeConvertor-fix
Browse files Browse the repository at this point in the history
Test fix for TypeConvertor issues on Cloud with v13
  • Loading branch information
AaronSadlerUK authored Nov 14, 2024
2 parents 1d381bd + 24858fc commit eb7da84
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 51 deletions.
3 changes: 3 additions & 0 deletions src/UmbNav.Core/UmbNav.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
<PackageReference Include="Umbraco.Cms.Web.Website" version="[13.0.0, 14)" />
<PackageReference Include="Umbraco.Cms.Web.BackOffice" version="[13.0.0, 14)" />
<PackageReference Include="Umbraco.Deploy.Core">
<Version>13.2.2</Version>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
106 changes: 56 additions & 50 deletions src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,80 +14,86 @@ namespace UmbNav.Core.ValueConnectors
/// <seealso cref="IValueConnector" />
public class UmbNavValueConnector : IValueConnector
{
public IEnumerable<string> PropertyEditorAliases => new[] { "UmbNav" };

#if NET8_0_OR_GREATER
public string ToArtifact(object value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)
{
if (AppSettingsManager.GetDisableUmbracoCloudSync())
return null;
public async Task<string?> ToArtifactAsync(object? value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)

Check warning on line 20 in src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 20 in src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
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<object?> FromArtifactAsync(string? value, IPropertyType propertyType, object? currentValue, IContextCache contextCache)

Check warning on line 35 in src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
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<ArtifactDependency> 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<ArtifactDependency> dependencies)
public string? ToArtifact(object? value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies)

Check warning on line 69 in src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 69 in src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
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)

Check warning on line 81 in src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 81 in src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 81 in src/UmbNav.Core/ValueConnectors/UmbNavValueConnector.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
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<string> PropertyEditorAliases => new[] { UmbNavConstants.PropertyEditorAlias };


private static JArray ParseLinks(JArray links, ICollection<ArtifactDependency> dependencies)
private JArray ParseLinks(JArray jsonArray)
{
foreach (var link in links)
{
if (!AppSettingsManager.GetDisableUmbracoCloudDependencySync())
{
var validUdi = UdiParser.TryParse(link.Value<string>("udi"), out var guidUdi);
if (validUdi)
{
dependencies.Add(new ArtifactDependency(guidUdi, false, ArtifactDependencyMode.Exist));
}
}

var children = link.Value<JArray>("children");
if (children != null)
{
link["children"] = ParseLinks(children, dependencies);
}
}

return links;
// Placeholder ParseLinks method implementation
return jsonArray;
}
}
}
}
9 changes: 9 additions & 0 deletions src/UmbNav.Core/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion src/UmbNav.Web/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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, )"
}
}
}
Expand Down

0 comments on commit eb7da84

Please sign in to comment.