From 951606f6e6908bdb8bea43c48c8aa2246724b8fe Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Thu, 19 Dec 2019 11:53:15 +0000 Subject: [PATCH] Tidy: GuidUdi lookups. --- .../Mapping/Mappers/MultiUrlMapper.cs | 14 ++++-------- .../Mapping/Mappers/RTEMapper.cs | 2 +- .../Mapping/SyncNestedValueMapperBase.cs | 1 - .../Mapping/SyncValueMapperBase.cs | 22 +++++++------------ 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/uSync8.ContentEdition/Mapping/Mappers/MultiUrlMapper.cs b/uSync8.ContentEdition/Mapping/Mappers/MultiUrlMapper.cs index 4d0b4eaa..d6206b25 100644 --- a/uSync8.ContentEdition/Mapping/Mappers/MultiUrlMapper.cs +++ b/uSync8.ContentEdition/Mapping/Mappers/MultiUrlMapper.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Runtime.Serialization; using Newtonsoft.Json; @@ -26,17 +27,10 @@ public override IEnumerable GetDependencies(object value, strin { var links = JsonConvert.DeserializeObject>(value.ToString()); - var dependencies = new List(); + if (links == null || !links.Any()) return Enumerable.Empty(); - foreach (var link in links) - { - if (link.Udi != null) - { - dependencies.Add(CreateDependency(link.Udi, flags)); - } - } - - return dependencies; + return links.Where(x => x.Udi != null) + .Select(link => CreateDependency(link.Udi, flags)); } // taken from umbraco source - this is how it's stored diff --git a/uSync8.ContentEdition/Mapping/Mappers/RTEMapper.cs b/uSync8.ContentEdition/Mapping/Mappers/RTEMapper.cs index a7222e33..c43e3c4a 100644 --- a/uSync8.ContentEdition/Mapping/Mappers/RTEMapper.cs +++ b/uSync8.ContentEdition/Mapping/Mappers/RTEMapper.cs @@ -50,7 +50,7 @@ public override IEnumerable GetDependencies(object value, strin foreach (Match m in UdiRegEx.Matches(stringValue)) { - if (Udi.TryParse(m.Value, out Udi udi)) + if (GuidUdi.TryParse(m.Value, out GuidUdi udi)) { if (!dependencies.Any(x => x.Udi == udi)) dependencies.Add(CreateDependency(udi, flags)); diff --git a/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs b/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs index 9e2abc2a..ccc91aad 100644 --- a/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs +++ b/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs @@ -77,7 +77,6 @@ protected IEnumerable GetPropertyDependencies( } return dependencies; - } diff --git a/uSync8.ContentEdition/Mapping/SyncValueMapperBase.cs b/uSync8.ContentEdition/Mapping/SyncValueMapperBase.cs index 90e4533c..ccc7fba8 100644 --- a/uSync8.ContentEdition/Mapping/SyncValueMapperBase.cs +++ b/uSync8.ContentEdition/Mapping/SyncValueMapperBase.cs @@ -39,23 +39,18 @@ public virtual string GetImportValue(string value, string editorAlias) protected IEnumerable CreateDependencies(IEnumerable udiStrings, DependencyFlags flags) { - if (udiStrings == null || !udiStrings.Any()) return Enumerable.Empty(); - - var dependencies = new List(); + if (udiStrings == null || !udiStrings.Any()) yield break; foreach (var udiString in udiStrings) { var dependency = CreateDependency(udiString, flags); - if (dependency != null) - dependencies.Add(dependency); + if (dependency != null) yield return dependency; } - - return dependencies; } protected uSyncDependency CreateDependency(string udiString, DependencyFlags flags) { - if (Udi.TryParse(udiString, out Udi udi)) + if (GuidUdi.TryParse(udiString, out GuidUdi udi)) { return CreateDependency(udi, flags); } @@ -63,7 +58,7 @@ protected uSyncDependency CreateDependency(string udiString, DependencyFlags fla return null; } - protected uSyncDependency CreateDependency(Udi udi, DependencyFlags flags) + protected uSyncDependency CreateDependency(GuidUdi udi, DependencyFlags flags) { var entity = GetElement(udi); @@ -77,12 +72,11 @@ protected uSyncDependency CreateDependency(Udi udi, DependencyFlags flags) }; } - private IEntitySlim GetElement(Udi udi) + private IEntitySlim GetElement(GuidUdi udi) { - if (udi is GuidUdi guidUdi) - { - return entityService.Get(guidUdi.Guid); - } + if (udi != null) + return entityService.Get(udi.Guid); + return null; }