From 7433a1a31dc79a4fe5613b0177fd10dd30338ebd Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Thu, 1 Oct 2020 09:25:33 +0100 Subject: [PATCH] Fixes #162 better handling when a string "looks" like JSON --- .../SyncHandlers/SyncHandlerRoot.cs | 6 +++ .../Mapping/Mappers/GridMapper.cs | 10 +---- .../Mapping/SyncNestedValueMapperBase.cs | 10 +---- uSync8.Core/Extensions/JsonExtensions.cs | 39 +++++++++++++++++++ uSync8.Core/uSync8.Core.csproj | 1 + 5 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 uSync8.Core/Extensions/JsonExtensions.cs diff --git a/uSync8.BackOffice/SyncHandlers/SyncHandlerRoot.cs b/uSync8.BackOffice/SyncHandlers/SyncHandlerRoot.cs index c0ab7298..e88a0545 100644 --- a/uSync8.BackOffice/SyncHandlers/SyncHandlerRoot.cs +++ b/uSync8.BackOffice/SyncHandlers/SyncHandlerRoot.cs @@ -802,10 +802,14 @@ public virtual IEnumerable ReportFolder(string folder, HandlerSetti { List actions = new List(); + var files = GetImportFiles(folder); int count = 0; int total = files.Count(); + + logger.Debug(handlerType, "ReportFolder: {folder} ({count} files)", folder, total); + foreach (string file in files) { count++; @@ -906,6 +910,8 @@ protected IEnumerable ReportItem(string file, HandlerSettings confi { try { + logger.Debug(handlerType, "Report Item {file}", file); + var node = syncFileService.LoadXElement(file); if (ShouldImport(node, config)) { diff --git a/uSync8.ContentEdition/Mapping/Mappers/GridMapper.cs b/uSync8.ContentEdition/Mapping/Mappers/GridMapper.cs index 5450c5cc..a6032b20 100644 --- a/uSync8.ContentEdition/Mapping/Mappers/GridMapper.cs +++ b/uSync8.ContentEdition/Mapping/Mappers/GridMapper.cs @@ -8,6 +8,7 @@ using Umbraco.Core; using Umbraco.Core.Services; +using uSync8.Core; using uSync8.Core.Dependency; namespace uSync8.ContentEdition.Mapping.Mappers @@ -94,14 +95,7 @@ private string ProcessGridValues(string gridContent, Func + /// get a JToken value of a string. + /// + /// + /// if the string is valid JSON then you will get a parsed + /// version of the json. + /// + /// if it isn't then you just get the string value (which will cast + /// automatically to JToken when you need it). + /// + public static JToken GetJsonTokenValue(this string value) + { + if (value.DetectIsJson()) + { + try + { + return JToken.Parse(value); + } + catch + { + // error parsing, so it's not actually json + // it just might look like it a bit. + return value; + } + } + + return value; + } + } +} diff --git a/uSync8.Core/uSync8.Core.csproj b/uSync8.Core/uSync8.Core.csproj index b829c1f8..1d608d5c 100644 --- a/uSync8.Core/uSync8.Core.csproj +++ b/uSync8.Core/uSync8.Core.csproj @@ -79,6 +79,7 @@ +