Пример #1
0
        public void Remove(ShouldBeRemovedHandler shouldBeRemovedHandler)
        {
            var filteredSubdifferences = new DifferenceHashList();

            foreach (var subdifference in m_subdifferences)
            {
                if (shouldBeRemovedHandler(subdifference))
                {
                    // Do nothing
                }
                else if (subdifference is NodeDifference)
                {
                    var nodeSubdifference = subdifference as NodeDifference;
                    var nbSubdiffsBefore  = nodeSubdifference.Subdifferences.Count;
                    nodeSubdifference.Remove(shouldBeRemovedHandler);
                    if ((nodeSubdifference.Subdifferences.Count > 0) || (nbSubdiffsBefore == 0))
                    {
                        filteredSubdifferences.Add(subdifference);
                    }
                }
                else
                {
                    filteredSubdifferences.Add(subdifference);
                }
            }
            m_subdifferences = filteredSubdifferences;
        }
Пример #2
0
 public NodeDifference(
     ElementIdentifier identifier,
     OperationOnParent operationOnParent,
     IEnumerable <Difference> subdifferences)
     : base(identifier, operationOnParent)
 {
     m_subdifferences = new DifferenceHashList(subdifferences);
 }
Пример #3
0
        public NodeConflict(
            ElementIdentifier identifier,
            OperationOnParent operationOnParent,
            IEnumerable <Difference> acceptedSubdifferences,
            IEnumerable <Conflict> subconflicts)
            : base(identifier)
        {
            if (!Enum.IsDefined(operationOnParent.GetType(), operationOnParent))
            {
                throw new ArgumentOutOfRangeException("operationOnParent", operationOnParent, "Invalid value");
            }
            if (acceptedSubdifferences == null)
            {
                throw new ArgumentNullException("acceptedSubdifferences");
            }
            if (subconflicts == null)
            {
                throw new ArgumentNullException("subconflicts");
            }

            r_operationOnParent      = operationOnParent;
            r_acceptedSubdifferences = new DifferenceHashList(acceptedSubdifferences);
            r_subconflicts           = new List <Conflict>(subconflicts);
        }
Пример #4
0
        public override Conflict CompareTo(Difference destinationDifference)
        {
            if (destinationDifference == null)
            {
                throw new ArgumentNullException("destinationDifference");
            }
            if (!destinationDifference.Identifier.Equals(this.Identifier))
            {
                throw new MergeException("Cannot compare differences that does not share the same identifier.");
            }

            var source      = this;
            var destination = destinationDifference as NodeDifference;

            if (destination == null)
            {
                throw new MergeException(string.Format("Cannot compare a {0} to a {1}.", destinationDifference.GetType().Name, this.GetType().Name));
            }

            if (source.OperationOnParent != destination.OperationOnParent)
            {
                return(new OperationTypeConflict(
                           source,
                           destination));
            }
            else
            {
                var subconflicts           = new List <Conflict>();
                var acceptedSubdifferences = new DifferenceHashList();
                foreach (var destinationSubdifference in destination.Subdifferences)
                {
                    // Add all the destinationBranchDifferences to the acceptedSubdifferences (they might be removed from the list later).
                    acceptedSubdifferences.Add(destinationSubdifference);
                }
                foreach (var sourceSubdifference in source.Subdifferences)
                {
                    if (!acceptedSubdifferences.Contains(sourceSubdifference.Identifier))
                    {
                        // This is a new difference that is not present in the destination branch, add the difference to the acceptedSubdifferences.
                        acceptedSubdifferences.Add(sourceSubdifference);
                    }
                    else
                    {
                        // There is a difference in both branch for the same identifier, see if there is a conflict or not
                        var destinationSubdifference = acceptedSubdifferences[sourceSubdifference.Identifier];
                        var conflict = sourceSubdifference.CompareTo(destinationSubdifference);
                        if (conflict != null)
                        {
                            var nodeConflict = conflict as NodeConflict;
                            if ((nodeConflict != null) && (nodeConflict.Subconflicts.Count == 0))
                            {
                                acceptedSubdifferences.Remove(sourceSubdifference.Identifier);
                                acceptedSubdifferences.Add(
                                    new NodeDifference(
                                        nodeConflict.Identifier,
                                        nodeConflict.OperationOnParent,
                                        nodeConflict.AcceptedSubdifferences));
                            }
                            else
                            {
                                acceptedSubdifferences.Remove(sourceSubdifference.Identifier);
                                subconflicts.Add(conflict);
                            }
                        }
                    }
                }

                return(new NodeConflict(
                           source.Identifier,
                           source.OperationOnParent,
                           acceptedSubdifferences,
                           subconflicts));
            }
        }