Exemplo n.º 1
0
        private string GetFolderColor(DirEntry dirEntry, CompareStatus blueStatus, CompareStatus redStatus, CompareStatus grayStatus)
        {
            var colors = new List<string>();

            if (dirEntry.CompareStatuses.Contains(blueStatus))
            {
                colors.Add("Blue");
            }

            if (dirEntry.CompareStatuses.Contains(redStatus))
            {
                colors.Add("Red");
            }

            if (dirEntry.CompareStatuses.Contains(CompareStatus.NotEqual) ||
                dirEntry.CompareStatuses.Contains(grayStatus) ||
                dirEntry.CompareStatuses.Contains(CompareStatus.Unknown))
            {
                colors.Add("Gray");
            }

            if (colors.Count >= 2)
            {
                return colors[0] + colors[1];
            }
            else if (colors.Count == 1)
            {
                return colors[0];
            }
            else
            {
                return "Black";
            }
        }
Exemplo n.º 2
0
        private string GetFileColor(FileEntry fileEntry, CompareStatus blueStatus, CompareStatus redStatus, CompareStatus grayStatus)
        {
            if (fileEntry.CompareStatuses.Contains(blueStatus))
            {
                return "Blue";
            }

            if (fileEntry.CompareStatuses.Contains(redStatus))
            {
                return "Red";
            }

            if (fileEntry.CompareStatuses.Contains(CompareStatus.NotEqual) ||
                fileEntry.CompareStatuses.Contains(grayStatus) ||
                fileEntry.CompareStatuses.Contains(CompareStatus.Unknown))
            {
                return "Gray";
            }

            return "Black";
        }
Exemplo n.º 3
0
        /// <summary>
        /// Compares two items or templates
        /// </summary>
        /// <param name="compareDB">The compare database</param>
        /// <param name="item">The local item being compared against</param>
        /// <param name="info">Comparison results are stored in this object</param>
        /// <param name="missingDirection">Enum that indicates the appropriate missing flag ('left' or 'right')</param>
        public static void RunCompare(Database compareDB, Item item, ItemComparisonInfo info, CompareStatus missingDirection, bool ignoreMissingVersions, bool ignoreMissingLanguages)
        {
            // See if item exists on other server
            var compare = compareDB.GetItem(item.Paths.Path);
            if (compare == null)
            {
                info.Messages.Add(string.Format("Item does not exist on database '{0}': {1}", compareDB.Name, item.Paths.Path));
                info.Status = missingDirection;

                compare = compareDB.GetItem(item.ID);
                if (compare != null)
                {
                    if (!info.FieldComparisons.ContainsKey("@Path"))
                    {
                        //info.Messages.Add(string.Format("ID matches different item path!!: {0}", compare.Paths.Path));
                        info.ItemPath += "*";
                        info.Messages.Add("Item moved and/or renamed.");
                        var infoF = new FieldComparisonInfo() { Name = "@Path" };
                        infoF.AddDifference("Path different", item.Paths.Path, compare.Paths.Path);
                        info.FieldComparisons.Add("@Path", infoF);
                        info.Status = CompareStatus.Different;
                    }
                }
            }
            else
            {
                // Languages
                foreach (var lang in item.Languages)
                {
                    if (!compare.Languages.Any(x => x.Name == lang.Name))
                    {
                        if (!ignoreMissingLanguages)
                        {
                            info.Messages.Add(string.Format("Language version missing on database '{0}': {1}", compareDB.Name, lang.Name));
                            info.Status = CompareStatus.Different;
                        }
                    }
                    else
                    {
                        foreach (var versionItem in item.Versions.GetVersions(true).Where(x => x.Language.Name == lang.Name))
                        {
                            var compareVersionItem = compare.Versions.GetVersions(true).SingleOrDefault(x => x.Language.Name == lang.Name
                                                                             && x.Version.Number == versionItem.Version.Number);
                            if (compareVersionItem == null)
                            {
                                if (!ignoreMissingVersions)
                                {
                                    info.Messages.Add(string.Format("Version '{0}' missing on database '{1}'", versionItem.Version.Number, compareDB.Name));
                                    info.Status = CompareStatus.Different;
                                }
                            }
                            else
                            {
                                if (Sitecore.Data.Managers.TemplateManager.IsTemplate(item))
                                    CompareTwoTemplates(compareDB, info, (TemplateItem)versionItem, (TemplateItem)compareVersionItem);
                                else
                                    CompareTwoItems(compareDB, info, versionItem, compareVersionItem);
                            }
                        }

                    }
                }
            }
        }
Exemplo n.º 4
0
        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;
        }