Exemplo n.º 1
0
 public HitTracker(GridSquare gridSquare)
 {
     this.gridSquare      = gridSquare;
     hasTriedLeft         = false;
     hasTriedRight        = false;
     hasTriedUp           = false;
     hasTriedDown         = false;
     lastTryWasSuccessful = false;
     direction            = TrackingDirection.Neutral;
 }
Exemplo n.º 2
0
        /// <summary>
        ///  Adds a change when a value is missing
        /// </summary>
        /// <remarks>
        ///  Depending on the direction of the comapre this will add a delete (when value is mising from target)
        ///  or a create (when value is missing from source).
        /// </remarks>
        private uSyncChange AddMissingChange(string path, string name, string value, TrackingDirection direction)
        {
            switch (direction)
            {
            case TrackingDirection.TargetToSource:
                return(uSyncChange.Delete(path, name, value));

            case TrackingDirection.SourceToTarget:
                return(uSyncChange.Create(path, name, value));
            }

            return(null);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }