Exemple #1
0
        private uSyncChange TrackSingleItem(TrackingItem item, XElement target, XElement source, TrackingDirection direction)
        {
            var sourceNode = source.XPathSelectElement(item.Path);
            var targetNode = target.XPathSelectElement(item.Path);

            if (sourceNode != null)
            {
                if (targetNode == null)
                {
                    // value is missing, this is a delete or create depending on compare direction
                    return(AddMissingChange(item.Path, item.Name, sourceNode.ValueOrDefault(string.Empty), direction));
                }

                // only track updates when tracking target to source.
                else if (direction == TrackingDirection.TargetToSource)
                {
                    if (item.HasAttributes())
                    {
                        return(Compare(targetNode.Attribute(item.AttributeKey).ValueOrDefault(string.Empty),
                                       sourceNode.Attribute(item.AttributeKey).ValueOrDefault(string.Empty),
                                       item.Path, item.Name, item.MaskValue));
                    }
                    else
                    {
                        return(Compare(targetNode.ValueOrDefault(string.Empty),
                                       sourceNode.ValueOrDefault(string.Empty),
                                       item.Path, item.Name, item.MaskValue));
                    }
                }
            }

            return(null);
        }
Exemple #2
0
        private IEnumerable <uSyncChange> TrackMultipleKeyedItems(TrackingItem trackingItem, XElement target, XElement source, TrackingDirection direction)
        {
            var changes = new List <uSyncChange>();

            var sourceItems = source.XPathSelectElements(trackingItem.Path);

            foreach (var sourceNode in sourceItems)
            {
                // make the selection path for this item.
                var itemPath = trackingItem.Path.Replace("*", sourceNode.Parent.Name.LocalName) + MakeSelectionPath(sourceNode, trackingItem.Keys);

                var itemName = trackingItem.Name.Replace("*", sourceNode.Parent.Name.LocalName) +
                               MakeSelectionName(sourceNode, String.IsNullOrWhiteSpace(trackingItem.ValueKey) ? trackingItem.Keys : trackingItem.ValueKey);

                var targetNode = target.XPathSelectElement(itemPath);

                if (targetNode == null)
                {
                    var value = sourceNode.ValueOrDefault(string.Empty);
                    if (!string.IsNullOrEmpty(trackingItem.ValueKey))
                    {
                        value = GetKeyValue(sourceNode, trackingItem.ValueKey);
                    }

                    // missing, we add either a delete or create - depending on tracking direction
                    changes.AddNotNull(AddMissingChange(trackingItem.Path, itemName, value, direction));
                }

                // only track updates when tracking target to source.
                else if (direction == TrackingDirection.TargetToSource)
                {
                    // check the node to see if its an update.
                    changes.AddRange(CompareNode(targetNode, sourceNode, trackingItem.Path, itemName, trackingItem.MaskValue));
                }
            }

            return(changes);
        }