예제 #1
0
        public IDifferenceObject Compare(InfoBase target, InfoBase source)
        {
            IDifferenceObject root = new DifferenceObject(null, target, DifferenceType.None);

            CompareLists <Namespace>(root, target.Namespaces.ToList(), source.Namespaces.ToList());
            return(root);
        }
예제 #2
0
        private void AddTableChildren(IDifferenceObject difference)
        {
            Table target = (Table)difference.Target;

            SetupTableParent(difference);
            foreach (Field child in target.Fields)
            {
                DifferenceObject diff = new DifferenceObject(difference, child, difference.Difference);
                SetupFieldParent(diff);
                difference.Children.Add(diff);
            }
        }
예제 #3
0
        private void AddPropertyChildren(IDifferenceObject difference)
        {
            Property target = (Property)difference.Target;

            SetupPropertyParent(difference);
            foreach (Relation child in target.Relations)
            {
                DifferenceObject diff = new DifferenceObject(difference, child, difference.Difference);
                SetupRelationParent(diff);
                difference.Children.Add(diff);
            }
        }
예제 #4
0
        private void AddNamespaceChildren(IDifferenceObject difference)
        {
            Namespace target = (Namespace)difference.Target;

            SetupNamespaceParent(difference);
            foreach (Namespace child in target.Namespaces)
            {
                DifferenceObject diff = new DifferenceObject(difference, child, difference.Difference);
                difference.Children.Add(diff);
                AddNamespaceChildren(diff);
            }
            foreach (Entity child in target.Entities)
            {
                DifferenceObject diff = new DifferenceObject(difference, child, difference.Difference);
                difference.Children.Add(diff);
                AddEntityChildren(diff);
            }
        }
예제 #5
0
        private void AddEntityChildren(IDifferenceObject difference)
        {
            Entity target = (Entity)difference.Target;

            SetupEntityParent(difference);
            foreach (Property child in target.Properties)
            {
                DifferenceObject diff = new DifferenceObject(difference, child, difference.Difference);
                difference.Children.Add(diff);
                AddPropertyChildren(diff);
            }
            foreach (Entity child in target.NestedEntities)
            {
                DifferenceObject diff = new DifferenceObject(difference, child, difference.Difference);
                difference.Children.Add(diff);
                AddEntityChildren(diff);
            }
            foreach (Table child in target.Tables)
            {
                DifferenceObject diff = new DifferenceObject(difference, child, difference.Difference);
                difference.Children.Add(diff);
                AddTableChildren(diff);
            }
        }
예제 #6
0
        private void CompareLists <T>(IDifferenceObject parent, List <T> target_list, List <T> source_list)
            where T : IPersistent, IComparable
        {
            int target_count = target_list.Count();
            int source_count = source_list.Count();
            int target_index = 0;
            int source_index = 0;
            int compareResult;

            if (target_count == 0 && source_count == 0)
            {
                return;
            }

            target_list.Sort();
            source_list.Sort();

            while (target_index < target_count)
            {
                if (source_index < source_count)
                {
                    compareResult = target_list[target_index].CompareTo(source_list[source_index]);
                    if (compareResult < 0)
                    {
                        DifferenceObject difference = new DifferenceObject(parent, target_list[target_index], DifferenceType.Delete);
                        parent.Children.Add(difference);
                        SetUpdateDifferenceType(parent);
                        AddChildren(difference);
                        target_index++;
                    }
                    else if (compareResult == 0)
                    {
                        DifferenceObject difference = new DifferenceObject(parent, target_list[target_index], DifferenceType.None);
                        CompareListItems(difference, target_list[target_index], source_list[source_index]);
                        if (difference.Difference == DifferenceType.Update)
                        {
                            parent.Children.Add(difference);
                        }
                        target_index++;
                        source_index++;
                    }
                    else
                    {
                        DifferenceObject difference = new DifferenceObject(parent, source_list[source_index], DifferenceType.Insert);
                        parent.Children.Add(difference);
                        SetUpdateDifferenceType(parent);
                        AddChildren(difference);
                        source_index++;
                    }
                }
                else
                {
                    DifferenceObject difference = new DifferenceObject(parent, target_list[target_index], DifferenceType.Delete);
                    parent.Children.Add(difference);
                    SetUpdateDifferenceType(parent);
                    AddChildren(difference);
                    target_index++;
                }
            }
            while (source_index < source_count)
            {
                DifferenceObject difference = new DifferenceObject(parent, source_list[source_index], DifferenceType.Insert);
                parent.Children.Add(difference);
                SetUpdateDifferenceType(parent);
                AddChildren(difference);
                source_index++;
            }
        }