diff --git a/uSync8.Core/Tracking/Impliment/ContentTypeBaseTracker.cs b/uSync8.Core/Tracking/Impliment/ContentTypeBaseTracker.cs index 91a54540..05001ba1 100644 --- a/uSync8.Core/Tracking/Impliment/ContentTypeBaseTracker.cs +++ b/uSync8.Core/Tracking/Impliment/ContentTypeBaseTracker.cs @@ -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() { new TrackedItem("Key", "/Key", true), diff --git a/uSync8.Core/Tracking/SyncBaseTracker.cs b/uSync8.Core/Tracking/SyncBaseTracker.cs index 53df1933..0b94de77 100644 --- a/uSync8.Core/Tracking/SyncBaseTracker.cs +++ b/uSync8.Core/Tracking/SyncBaseTracker.cs @@ -242,6 +242,21 @@ private IEnumerable 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); @@ -250,9 +265,6 @@ private IEnumerable 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) @@ -309,6 +321,12 @@ private IEnumerable 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); @@ -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; + } + /// /// Element used to match items in a collection of nodes /// (e.g Key) /// public string Key { get; set; } + /// + /// secondary element used to match items (e.g if key fails, we check alias) + /// + public string Key2 { get; set; } + + /// /// The repeating element name /// (e.g GenericProperty) @@ -588,6 +618,8 @@ public RepeatingInfo(string key, string value, string name) /// public bool KeyIsAttribute { get; set; } + public bool Key2IsAttribute { get; set; } + public bool NameIsAttribute { get; set; } ///