Skip to content

Commit

Permalink
Improve the tracker - so things that are matched on key then alias, d…
Browse files Browse the repository at this point in the history
…on't show up as delete/create
  • Loading branch information
Kevin Jump committed Oct 8, 2020
1 parent 6480a2d commit 1a0a3d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion uSync8.Core/Tracking/Impliment/ContentTypeBaseTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override TrackedItem TrackChanges()
{
new TrackedItem("Property", "/GenericProperty")
{
Repeating = new RepeatingInfo("Key", "/GenericProperty", "Name"),
Repeating = new RepeatingInfo("Key", "Alias", "/GenericProperty", "Name"),
Children = new List<TrackedItem>()
{
new TrackedItem("Key", "/Key", true),
Expand Down
38 changes: 35 additions & 3 deletions uSync8.Core/Tracking/SyncBaseTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ private IEnumerable<uSyncChange> CalculateRepeatingChanges(TrackedItem change, X
// now we need to make the XPath for the children this will be [key = ''] or [@key ='']
// depending if its an attribute or element key
currentNodePath += MakeKeyPath(change.Repeating.Key, currentKey, change.Repeating.KeyIsAttribute);

// now see if we can find that node in the target elements we have loaded
targetNode = GetTarget(targetItems, change.Repeating.Key, currentKey, change.Repeating.KeyIsAttribute);

if (targetNode == null && !string.IsNullOrWhiteSpace(change.Repeating.Key2))
{
// we couldn't find it, but we have a second key to look up, so lets do that.
currentKey = GetKeyValue(currentNode, change.Repeating.Key2, change.Repeating.Key2IsAttribute);
if (currentKey == string.Empty) continue;
currentNodePath = path + MakeKeyPath(change.Repeating.Key2, currentKey, change.Repeating.Key2IsAttribute);

targetNode = GetTarget(targetItems, change.Repeating.Key2, currentKey, change.Repeating.Key2IsAttribute);
}

// make the name
if (!string.IsNullOrWhiteSpace(change.Repeating.Name))
{
var itemName = GetKeyValue(currentNode, change.Repeating.Name, change.Repeating.NameIsAttribute);
Expand All @@ -250,9 +265,6 @@ private IEnumerable<uSyncChange> CalculateRepeatingChanges(TrackedItem change, X
currentNodeName += $": {itemName}";
}
}

// now see if we can find that node in the target elements we have loaded
targetNode = GetTarget(targetItems, change.Repeating.Key, currentKey, change.Repeating.KeyIsAttribute);
}

if (targetNode == null)
Expand Down Expand Up @@ -309,6 +321,12 @@ private IEnumerable<uSyncChange> CalculateRepeatingChanges(TrackedItem change, X

targetNodePath += MakeKeyPath(change.Repeating.Key, targetKey, change.Repeating.KeyIsAttribute);
var currentNode = GetTarget(currentItems, change.Repeating.Key, targetKey, change.Repeating.KeyIsAttribute);
if (currentNode == null && !string.IsNullOrWhiteSpace(change.Repeating.Key2))
{
var targetKey2 = GetKeyValue(targetItem, change.Repeating.Key2, change.Repeating.Key2IsAttribute);
currentNode = GetTarget(currentItems, change.Repeating.Key2, targetKey2, change.Repeating.Key2IsAttribute);
}

if (currentNode == null)
{
missing.Add(targetItem);
Expand Down Expand Up @@ -565,12 +583,24 @@ public RepeatingInfo(string key, string value, string name)
Name = name;
}

public RepeatingInfo(string key, string key2, string value, string name)
: this(key, value, name)
{
Key2 = key2;
}

/// <summary>
/// Element used to match items in a collection of nodes
/// (e.g Key)
/// </summary>
public string Key { get; set; }

/// <summary>
/// secondary element used to match items (e.g if key fails, we check alias)
/// </summary>
public string Key2 { get; set; }


/// <summary>
/// The repeating element name
/// (e.g GenericProperty)
Expand All @@ -588,6 +618,8 @@ public RepeatingInfo(string key, string value, string name)
/// </summary>
public bool KeyIsAttribute { get; set; }

public bool Key2IsAttribute { get; set; }

public bool NameIsAttribute { get; set; }

/// <summary>
Expand Down

0 comments on commit 1a0a3d1

Please sign in to comment.