Пример #1
0
        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
        public ComparisonItem AddStaticNode(string name)
        {
            var newNode = new ComparisonItem();

            newNode.Left.Presentation  = name;
            newNode.Right.Presentation = name;
            this.Items.Add(newNode);

            return(newNode);
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        private void SetNodeFilter(TreeViewItem node, bool Hide)
        {
            if (node == null)
            {
                return;
            }

            ComparisonItem nodeItem = node.Header as ComparisonItem;

            if (nodeItem != null)
            {
                if (Hide && nodeItem.Status == ComparisonStatus.Match)
                {
                    node.Visibility = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    node.Visibility = System.Windows.Visibility.Visible;
                }

                IterateFiltering(node, Hide);
            }
        }
Пример #5
0
        private ComparisonItem CompareProperties(IMDPropertyProvider Left, IMDPropertyProvider Right, ComparisonItem parentNode)
        {
            var PropStub = parentNode.AddStaticNode("Свойства");

            bool HasDifference = false;

            foreach (PropDef propDef in Left.Properties.Values)
            {
                if (m_CurrentMode == MatchingMode.ByName && propDef.Key == "ID")
                {
                    continue;
                }

                object  RightVal      = null;
                PropDef RightProperty = null;

                if (Right != null)
                {
                    RightVal      = Right.GetValue(propDef.Key);
                    RightProperty = Right.Properties[propDef.Key];
                }

                bool childDifference = !propDef.CompareTo(RightVal);
                HasDifference = HasDifference || childDifference;

                var newNode = new ComparisonItem(propDef, RightProperty, propDef.Name);
                newNode.IsDiffer = childDifference;

                PropStub.Items.Add(newNode);
            }

            parentNode.IsDiffer = HasDifference;
            PropStub.IsDiffer   = HasDifference;

            return(PropStub);
        }
Пример #6
0
        private void GatherUICommands(ComparisonItem cmpItem, List <UICommand> RClickCommands, bool IsLeftSourced)
        {
            if (cmpItem == null || cmpItem.NodeType == ResultNodeType.ObjectsCollection)
            {
                return;
            }

            if (cmpItem.NodeType == ResultNodeType.FakeNode)
            {
                GatherUICommands(cmpItem.Parent, RClickCommands, IsLeftSourced);
                return;
            }

            // gathering treeitem commands
            object srcObject = (IsLeftSourced) ? cmpItem.Left.Object : cmpItem.Right.Object;

            if (cmpItem.NodeType == ResultNodeType.PropertyDef)
            {
                if (srcObject != null)
                {
                    var PropDef = (PropDef)srcObject;
                    AddProviderCommands(PropDef as ICommandProvider, RClickCommands);

                    if (cmpItem.Status == ComparisonStatus.Modified || cmpItem.Status == ComparisonStatus.Match)
                    {
                        if (PropDef.Value is V8ModuleProcessor)
                        {
                            var cmd = new UICommand("Показать различия в модулях", cmpItem, new Action(
                                                        () =>
                            {
                                V8ModuleProcessor LeftVal  = ((PropDef)cmpItem.Left.Object).Value as V8ModuleProcessor;
                                V8ModuleProcessor RightVal = ((PropDef)cmpItem.Right.Object).Value as V8ModuleProcessor;
                                var viewer = LeftVal.GetDifferenceViewer(RightVal);
                                if (viewer != null)
                                {
                                    viewer.ShowDifference(LeftName, RightName);
                                }
                            }));

                            RClickCommands.Add(cmd);
                        }
                        else if (PropDef.Value is TemplateDocument)
                        {
                            var cmd = new UICommand("Показать различия в макетах", cmpItem, new Action(
                                                        () =>
                            {
                                TemplateDocument LeftVal  = ((PropDef)cmpItem.Left.Object).Value as TemplateDocument;
                                TemplateDocument RightVal = ((PropDef)cmpItem.Right.Object).Value as TemplateDocument;
                                var viewer = LeftVal.GetDifferenceViewer(RightVal);
                                if (viewer != null)
                                {
                                    viewer.ShowDifference(LeftName, RightName);
                                }
                            }));

                            RClickCommands.Add(cmd);
                        }
                        else if (PropDef.Value is MDUserDialogBase)
                        {
                            var cmd = new UICommand("Показать различия в диалогах", cmpItem, new Action(
                                                        () =>
                            {
                                MDUserDialogBase LeftVal  = ((PropDef)cmpItem.Left.Object).Value as MDUserDialogBase;
                                MDUserDialogBase RightVal = ((PropDef)cmpItem.Right.Object).Value as MDUserDialogBase;
                                var viewer = new Comparison.ExternalTextDiffViewer(LeftVal.ToString(), RightVal.ToString());
                                if (viewer != null)
                                {
                                    viewer.ShowDifference(LeftName, RightName);
                                }
                            }));

                            RClickCommands.Add(cmd);
                        }
                    }
                    GatherUICommands(cmpItem.Parent, RClickCommands, IsLeftSourced);
                }
            }
            else if (cmpItem.NodeType == ResultNodeType.Object)
            {
                var Provider = srcObject as ICommandProvider;
                AddProviderCommands(Provider, RClickCommands);
            }

            if (srcObject != null && srcObject is IMDPropertyProvider)
            {
                var cmd = new UICommand("Отчет по свойствам", srcObject, () =>
                {
                    PropertiesReport repGenerator;
                    string windowTitle;

                    if (cmpItem.Left.Object != null && cmpItem.Right.Object != null)
                    {
                        repGenerator = new PropertiesReportCompare(cmpItem.Left.Object as IMDPropertyProvider, cmpItem.Right.Object as IMDPropertyProvider);
                        windowTitle  = String.Format("Отчет по свойствам: {0}/{1}", cmpItem.Left.Object.ToString(), cmpItem.Right.Object.ToString());
                    }
                    else
                    {
                        repGenerator = new PropertiesReportSingle((IMDPropertyProvider)srcObject);
                        windowTitle  = srcObject.ToString();
                    }

                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        FlowDocViewer fdViewer = new FlowDocViewer();
                        fdViewer.Title         = windowTitle;
                        fdViewer.Document      = repGenerator.GenerateReport();
                        fdViewer.Show();
                    }));
                });

                RClickCommands.Add(cmd);
            }
        }
Пример #7
0
        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;
                    }
                }
            }
        }
Пример #8
0
        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;
            }
        }