Skip to content

Commit

Permalink
Tidy: GuidUdi lookups.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Dec 19, 2019
1 parent 0b20064 commit 951606f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 26 deletions.
14 changes: 4 additions & 10 deletions uSync8.ContentEdition/Mapping/Mappers/MultiUrlMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

using Newtonsoft.Json;
Expand Down Expand Up @@ -26,17 +27,10 @@ public override IEnumerable<uSyncDependency> GetDependencies(object value, strin
{
var links = JsonConvert.DeserializeObject<IEnumerable<LinkDto>>(value.ToString());

var dependencies = new List<uSyncDependency>();
if (links == null || !links.Any()) return Enumerable.Empty<uSyncDependency>();

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
Expand Down
2 changes: 1 addition & 1 deletion uSync8.ContentEdition/Mapping/Mappers/RTEMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override IEnumerable<uSyncDependency> 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));
Expand Down
1 change: 0 additions & 1 deletion uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ protected IEnumerable<uSyncDependency> GetPropertyDependencies(
}

return dependencies;

}


Expand Down
22 changes: 8 additions & 14 deletions uSync8.ContentEdition/Mapping/SyncValueMapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,26 @@ public virtual string GetImportValue(string value, string editorAlias)

protected IEnumerable<uSyncDependency> CreateDependencies(IEnumerable<string> udiStrings, DependencyFlags flags)
{
if (udiStrings == null || !udiStrings.Any()) return Enumerable.Empty<uSyncDependency>();

var dependencies = new List<uSyncDependency>();
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);
}

return null;
}

protected uSyncDependency CreateDependency(Udi udi, DependencyFlags flags)
protected uSyncDependency CreateDependency(GuidUdi udi, DependencyFlags flags)
{
var entity = GetElement(udi);

Expand All @@ -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;
}

Expand Down

0 comments on commit 951606f

Please sign in to comment.