private void TraverseRightObject(IMDTreeItem Right, ComparisonItem ParentNode)
        {
            if (Right.HasChildren())
            {
                foreach (var item in Right.ChildItems)
                {
                    AddAndFillNewNode(null, item, ParentNode);
                }
            }

            if (Right is IMDPropertyProvider)
            {
                var PropStub = ParentNode.AddStaticNode("Свойства");
                var PropProv = Right as IMDPropertyProvider;

                foreach (PropDef propDef in PropProv.Properties.Values)
                {
                    var propNode = new ComparisonItem(null, propDef.Value, propDef.Name);
                    propNode.IsDiffer = true;

                    PropStub.Items.Add(propNode);
                }

                PropStub.IsDiffer = true;
            }
        }
示例#2
0
        private void mnuCompareTo_Click(object sender, RoutedEventArgs e)
        {
            var dlg = Utils.UIHelper.GetOpenFileDialog();

            if ((bool)dlg.ShowDialog(this))
            {
                V8MetadataContainer Container = new V8MetadataContainer(dlg.FileName);
                IMDTreeItem         proc      = Container.RaiseObject() as IMDTreeItem;
                if (proc == null)
                {
                    MessageBox.Show("Отображение данного объекта не поддерживается", "V8 Reader", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    Container.Dispose();
                    return;
                }

                Comparison.ComparisonPerformer Performer
                    = new Comparison.ComparisonPerformer((IMDTreeItem)m_Object, (IMDTreeItem)proc);

                var diffWnd = new Comparison.CompareTreeWnd();
                diffWnd.PrintResult(Performer);
                diffWnd.Owner   = this;
                diffWnd.Closed += (s, evArg) =>
                {
                    Container.Dispose();
                };

                diffWnd.Show();
            }
        }
        public void Dispose()
        {
            LocalDispose(_LeftFile);
            LocalDispose(_RightFile);

            _LeftObject  = null;
            _RightObject = null;
        }
 private void FillSide(ComparisonSide SideObject, IMDTreeItem Value)
 {
     SideObject.Object = Value;
     if (Value == null)
     {
         SideObject.Presentation = "<отсутствует>";
     }
     else
     {
         SideObject.Presentation = Value.Text;
     }
 }
        private void InstantiateObject(V8MetadataContainer cnt, ref IMDTreeItem obj)
        {
            if (obj == null)
            {
                var tmpObj = cnt.RaiseObject();

                if (tmpObj is IMDTreeItem)
                {
                    obj = (IMDTreeItem)tmpObj;
                }
                else
                {
                    throw new InvalidOperationException(String.Format("Comparison of '{0}' isn't supported", obj.GetType().ToString()));
                }
            }
        }
        private ComparisonItem AddAndFillNewNode(IMDTreeItem Left, IMDTreeItem Right, ComparisonItem ParentNode)
        {
            ComparisonItem newNode = new ComparisonItem();

            FillComparisonNode(Left, Right, newNode);

            if (!(newNode.Left == null && newNode.Right == null))
            {
                ParentNode.Items.Add(newNode);
                return(newNode);
            }
            else
            {
                return(null);
            }
        }
 private int?CompareObjects(IMDTreeItem left, IMDTreeItem right)
 {
     if (left.GetType() == right.GetType())
     {
         if (m_CurrentMode == MatchingMode.ByID)
         {
             return(String.CompareOrdinal(left.Key, right.Key));
         }
         else
         {
             return(String.CompareOrdinal(left.Text, right.Text));
         }
     }
     else
     {
         return(null);
     }
 }
        private void FillComparisonNode(IMDTreeItem Left, IMDTreeItem Right, ComparisonItem node)
        {
            if ((Left != null && Right != null) && Left.GetType() != Right.GetType())
            {
                throw new InvalidOperationException("Compared components must be of the same type");
            }

            FillSide(node.Left, Left);
            FillSide(node.Right, Right);

            if (Left == null)
            {
                TraverseRightObject(Right, node);
                return;
            }

            if (Left is IMDPropertyProvider)
            {
                CompareProperties((IMDPropertyProvider)Left, (IMDPropertyProvider)Right, node);
            }

            if (Left is IComparableItem)
            {
                // Разница определяется самим объектом
                node.IsDiffer = !((IComparableItem)Left).CompareTo(Right);
            }
            else if (Left is MDObjectsCollection <MDObjectBase> || Left is StaticTreeNode)
            {
                MapAndCompareCollections(Left, Right, node);
            }
            else if (Left.HasChildren())
            {
                // это статичные свойства метаданных
                // порядок свойств будет соблюдаться в обоих объектах
                var LeftWalker = Left.ChildItems.GetEnumerator();

                IEnumerator <IMDTreeItem> RightWalker = null;
                if (Right != null)
                {
                    RightWalker = Right.ChildItems.GetEnumerator();
                }

                while (LeftWalker.MoveNext())
                {
                    var newNode = new ComparisonItem();

                    if (Right != null)
                    {
                        RightWalker.MoveNext();
                        FillComparisonNode(LeftWalker.Current, RightWalker.Current, newNode);
                    }
                    else
                    {
                        FillComparisonNode(LeftWalker.Current, null, newNode);
                    }

                    if (!(newNode.Left == null && newNode.Right == null))
                    {
                        node.Items.Add(newNode);
                        node.IsDiffer = node.IsDiffer || newNode.IsDiffer;
                    }
                }
            }
        }
 public ComparisonPerformer(IMDTreeItem Left, IMDTreeItem Right)
 {
     m_Left  = Left;
     m_Right = Right;
 }
        private void MapAndCompareCollections(IMDTreeItem Left, IMDTreeItem Right, ComparisonItem node)
        {
            IEnumerable <IMDTreeItem> LeftItems;
            IEnumerable <IMDTreeItem> RightItems;

            if (m_CurrentMode == MatchingMode.ByID)
            {
                LeftItems  = from item in Left.ChildItems orderby item.Key, item.Text select item;
                RightItems = from item in Right.ChildItems orderby item.Key, item.Text select item;
            }
            else
            {
                LeftItems  = from item in Left.ChildItems orderby item.Text, item.Text select item;
                RightItems = from item in Right.ChildItems orderby item.Text, item.Text select item;
            }

            var LeftList  = LeftItems.ToArray <IMDTreeItem>();
            var RightList = RightItems.ToArray <IMDTreeItem>();

            int leftIdx    = 0;
            int rightIdx   = 0;
            int leftCount  = LeftList.Length - 1;
            int rightCount = RightList.Length - 1;

            bool Modified = false;

            while (true)
            {
                if (leftIdx > leftCount)
                {
                    rightIdx++;
                    if (rightIdx > rightCount)
                    {
                        break;
                    }

                    var Item = RightList[rightIdx];
                    AddAndFillNewNode(null, Item, node);
                    Modified = true;
                    continue;
                }

                if (rightIdx > rightCount)
                {
                    leftIdx++;
                    if (leftIdx > leftCount)
                    {
                        break;
                    }

                    var Item = LeftList[leftIdx];
                    AddAndFillNewNode(Item, null, node);
                    Modified = true;
                    continue;
                }

                var LeftItem  = LeftList[leftIdx];
                var RightItem = RightList[rightIdx];

                int?comparisonResult = CompareObjects(LeftItem, RightItem);

                if (comparisonResult == 0)
                {
                    var addedNode = AddAndFillNewNode(LeftItem, RightItem, node);
                    if (addedNode != null)
                    {
                        Modified = Modified || addedNode.IsDiffer;
                    }

                    leftIdx++;
                    rightIdx++;
                }
                else if (comparisonResult < 0)
                {
                    AddAndFillNewNode(LeftItem, null, node);
                    Modified = true;
                    leftIdx++;
                }
                else if (comparisonResult > 0)
                {
                    AddAndFillNewNode(null, RightItem, node);
                    Modified = true;
                    rightIdx++;
                }
                else
                {
                    AddAndFillNewNode(LeftItem, null, node);
                    AddAndFillNewNode(null, RightItem, node);

                    leftIdx++;
                    rightIdx++;

                    Modified = true;
                }
            }

            if (Modified)
            {
                node.IsDiffer = true;
            }
        }