public void AddNode(SimpleTreeNode node)
 {
     // Determine level
     node.Parent = this;
     this.Nodes.Add(node);
 }
        private bool RunCompare(SimpleTreeNode parentnode, Item item, Database compareDB, CompareStatus missingDirection)
        {
            var dirty = false;

            try
            {
                var info = new ItemComparisonInfo(item);
                if (_differences.ContainsKey(info.ItemKey))
                    info = _differences[info.ItemKey];

                CompareEngine.RunCompare(compareDB, item, info, missingDirection, _ignoreMissingVersions, _ignoreMissingLanguages);

                // Create the tree node
                var nodeIsNew = false;
                //var node = parentnode.ChildNodes.Cast<TreeNode>().SingleOrDefault(x => x.Value == item.Paths.Path);
                var node = parentnode.Nodes.SingleOrDefault(x => x.Value == info.ItemKey);
                if (node == null)
                {
                    node = CreateNode(info);
                    nodeIsNew = true;
                }

                if (info.Status != CompareStatus.Matched)
                {
                    dirty = true;
                    if (!_differences.ContainsKey(info.ItemKey))
                        _differences.Add(info.ItemKey, info);
                }

                if (Sitecore.Data.Managers.TemplateManager.IsTemplate(item))
                {
                    var t = (TemplateItem)item;
                    if (t.StandardValues != null)
                        dirty = RunCompare(node, t.StandardValues, compareDB, missingDirection) | dirty;
                }
                else
                {
                    foreach (var child in item.GetChildren().InnerChildren)
                    {
                        dirty = RunCompare(node, child, compareDB, missingDirection) | dirty;
                    }
                }

                if (dirty && nodeIsNew)
                    parentnode.AddNode(node);

            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("RunCompare failed. [parentnode:{0}][item:{1}][compareDB:{2}]", new object[]{
                    parentnode == null? "NULL!" : parentnode.Value,
                    item == null ? "NULL!" : item.Paths.Path,
                    compareDB == null ? "NULL!" : compareDB.Name
                }), ex);
            }

            return dirty;
        }
        public SimpleTreeNode BuildCompareTree(string path)
        {
            var root = new SimpleTreeNode();

            // Find items in local that don't exist in external
            var localRoot = _localDB.GetItem(path);

            if (localRoot == null)
                throw new Exception("Path does not exist in local DB: " + path);

            RunCompare(root, localRoot, _compareDB, CompareStatus.MissingRight);

            var compareRoot = _compareDB.GetItem(path);
            if (compareRoot != null)
                RunCompare(root, compareRoot, _localDB, CompareStatus.MissingLeft);

            return root;
        }
        private static SimpleTreeNode CreateNode(ItemComparisonInfo info)
        {
            var imageUrl = _IMG_MATCHED;
            var cssClass = string.Empty;
            var statusName = Enum.GetName(typeof(CompareStatus), info.Status);
            switch (info.Status)
            {
                case CompareStatus.Different:
                    imageUrl = _IMG_DIFFERENT;
                    cssClass = "comparison-node-different";
                    break;
                case CompareStatus.MissingLeft:
                    imageUrl = _IMG_MISSING_LEFT;
                    cssClass = "comparison-node-missing-left";
                    break;
                case CompareStatus.MissingRight:
                    imageUrl = _IMG_MISSING_RIGHT;
                    cssClass = "comparison-node-missing-right";
                    break;
            }

            var node = new SimpleTreeNode()
            {
                CssClass = cssClass,
                Text = Path.GetFileName(info.ItemPath),
                Value = info.ItemKey,
                ImageUrl = imageUrl
            };

            node.Data.Add("type", statusName);

            return node;
        }