public List<string> Validate(ItemComparerContext context)
        {
            //set parameter to be passed to validation method
            Object[] args = new object[1];
            args[0] = context;

            Validator validator = null;
            if (HttpContext.Current.Cache[CacheName] != null)
            {
                validator = (Validator) HttpContext.Current.Cache[CacheName];
            }
            else
            {
                // load the assemly
                Assembly assembly = GetAssembly(this.AssemblyName);

                // Walk through each type in the assembly looking for our class
                Type type = assembly.GetType(this.Namespace);
                if (type == null || !type.IsClass) return new List<string>();

                //cast to validator class
                validator = (Validator)Activator.CreateInstance(type);
                HttpContext.Current.Cache[CacheName] = validator;
            }

            if (validator == null)
            {
                return new List<string>();
            }

            //validate
            return validator.Validate(context);
        }
        public override List<string> Validate(ItemComparerContext context)
        {
            //defaults
            List<string> outputs = new List<string>();

            //check ancestors to see if they exist in the target database
            foreach (Item ancestorItem in context.Item.Axes.GetAncestors())
            {
                Item targetAncestorItem = context.TargetDatabase.GetItem(ancestorItem.ID, context.Item.Language);
                if (targetAncestorItem == null)
                {
                    outputs.Add(string.Format("The ancestor ({0}) does not exist in the target database", ancestorItem.Name));
                }
                else
                {
                    //item exists in the target database, comparing fields
                    if (!ItemComparerUtil.Validate(ancestorItem, targetAncestorItem))
                    {
                        //there are differences between the two items
                        outputs.Add(string.Format("The ancestor ({0}) exists in the target database but the fields are different.",
                                                  ancestorItem.Name));
                    }
                }
            }

            return outputs;
        }
        public override List<string> Validate(ItemComparerContext context)
        {
            //do not run on templates
            if (context.Item.TemplateID.ToString() == "{AB86861A-6030-46C5-B394-E8F99E8B87DB}")
                return new List<string>();

            //defaults
            List<string> outputs = new List<string>();

            //check to see if the item exists in the target database which
            //was specified in the settings item
            Item publishedItem = context.TargetDatabase.GetItem(context.Item.ID, context.Item.Language);
            if (publishedItem == null) return outputs;

            //we are not on a template item, lets check the item's template to make
            //sure the template is published
            if (publishedItem.Template == null)
            {
                outputs.Add("The template is not published.");
                return outputs;
            }

            //need to reset the item in the context to represent the template item
            ItemComparerContext newContext = new ItemComparerContext();
            newContext.Item = context.Item.Template;
            newContext.ItemComparerSettingsItem = context.ItemComparerSettingsItem;
            newContext.TargetDatabase = context.TargetDatabase;

            //validating the items template
            TemplateValidator templateValidator = new TemplateValidator();
            outputs.AddRange(templateValidator.Validate(newContext));
            return outputs;
        }
        /// <summary>
        /// Uses the Published Item Comparer
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public string Execute(FieldGutterArgs args)
        {
            if (args.InnerItem == null)
            {
                return string.Format("<span title=\"The item could not be retrieved from Sitecore.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></span>");
            }

            if (args.InnerItem.Database != null && args.InnerItem.Database.Name.ToLower() == "core")
            {
                return string.Empty;
            }

            //verify settings item exists
            ItemComparerSettingsItem settingsItem = ItemComparerSettingsItem.GetSettingsItem();
            if (settingsItem == null)
            {
                Logger.Error("Published Item Comparer: The Settings Item Could not be retrieved.");
                return "<span title=\"The settings item could not be retrieved from Sitecore.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></span>";
            }

            //verify target database
            Database targetDatabase = ItemComparerUtil.GetTargetDatabase();
            if (targetDatabase == null)
            {
                Logger.Error("Published Item Comparer: The Target Database Could not be retrieved.");
                return "<span title=\"The target database could not be retrieved from Sitecore.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></span>";
            }

            try
            {
                ItemComparerContext context = new ItemComparerContext();
                context.Item = args.InnerItem;
                context.ItemComparerSettingsItem = settingsItem;
                context.TargetDatabase = targetDatabase;

                ItemValidator itemValidator = new ItemValidator();
                List<string> validations = itemValidator.Validate(context);
                if (validations != null && validations.Count > 0)
                {
                    return string.Format("<span title=\"The item did not pass validation.\"><a href=\"#\" style=\"border:0;padding:0;\" class=\"itemComparerGutterLink\" onclick=\"FieldSuite.Fields.OpenItemComparer('{0}','{1}')\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_red.png\"/></a></span>", args.InnerItem.ID, args.FieldId);
                }

                return "<span title=\"The item passed validation.\"><img class=\"fieldGutterItem\" src=\"/sitecore modules/shell/field suite/images/bullet_ball_green.png\"/></span>";
            }
            catch (Exception e)
            {
                Logger.Error("Field Gutter - Published Item Comparer: Error trying to validate");
                Logger.Error(e.InnerException);
                Logger.Error(e.Message);
            }

            return string.Empty;
        }
        public override List<string> Validate(ItemComparerContext context)
        {
            //do not run on templates
            if (context.Item.TemplateID.ToString() == "{AB86861A-6030-46C5-B394-E8F99E8B87DB}")
                return new List<string>();

            //defaults
            List<string> outputs = new List<string>();

            //check to see if the item exists in the target database which
            //was specified in the settings item
            Item publishedItem = context.TargetDatabase.GetItem(context.Item.ID, context.Item.Language);
            if (publishedItem == null)
            {
                outputs.Add("The item does not exist in the target database.");
                return outputs;
            }

            //Check if we have a version for the current language
            if(publishedItem.Versions.Count == 0)
            {
                outputs.Add("The item does not have a version in the selected language");
                return outputs;
            }

            //we are not on a template, compare only the current item
            //if the item is the same, pass validation
            if (!ItemComparerUtil.Validate(context.Item, publishedItem))
            {
                //there are differences between the two items
                outputs.Add("The item exists in the target database but the fields are different.");
            }

            //check to see if they live in different locations
            if (context.Item.Paths.FullPath != publishedItem.Paths.FullPath)
            {
                outputs.Add("The item's path is different than the path in the target database.");
            }

            return outputs;
        }
        public override List<string> Validate(ItemComparerContext context)
        {
            //only run on templates
            if (context.Item.TemplateID.ToString() != "{AB86861A-6030-46C5-B394-E8F99E8B87DB}")
            {
                return new List<string>();
            }

            SiteInfo shellSite = Factory.GetSiteInfoList().FirstOrDefault(x => x.Name == "shell");
            if (shellSite != null)
            {
                //templates are only run in the default language
                if (!context.Item.Language.Name.Equals(shellSite.Language, StringComparison.InvariantCultureIgnoreCase))
                {
                    context.Item = context.TargetDatabase.GetItem(context.Item.ID, Language.Parse(shellSite.Language));
                }
            }

            if (context.Item == null)
            {
                return new List<string>();
            }

            //defaults
            List<string> outputs = new List<string>();

            //check to see if the item exists in the target database which
            //was specified in the settings item
            Item publishedItem = context.TargetDatabase.GetItem(context.Item.ID);
            if (publishedItem == null) return outputs;

            if (!ItemComparerUtil.Validate(context.Item, publishedItem))
                outputs.Add(string.Format("The template item ({0}) exists in the target database but is different.",
                                          context.Item.Name));

            //check base templates
            TemplateItem currentTemplateItem = context.Item;

            //get list of base templates from current template item
            List<string> currentBaseTemplates = new List<string>();
            foreach (Item baseItem in currentTemplateItem.BaseTemplates)
                currentBaseTemplates.Add(baseItem.ID.ToString());

            //get list of base templates from published template item
            List<string> publishedBaseTemplates = new List<string>();
            foreach (Item baseItem in ((TemplateItem) publishedItem).BaseTemplates)
                publishedBaseTemplates.Add(baseItem.ID.ToString());

            //check to see if all base templates exist on the template in the target database
            foreach (string baseTemplateId in currentBaseTemplates)
            {
                if (!publishedBaseTemplates.Contains(baseTemplateId))
                {
                    Item baseTemplateItem = context.TargetDatabase.GetItem(baseTemplateId);
                    if (baseTemplateItem == null)
                    {
                        baseTemplateItem = Database.GetDatabase("master").GetItem(baseTemplateId);
                        outputs.Add(string.Format("The base template ({0}) does not exist in the target database.", baseTemplateItem.Name));
                    }
                    else
                        outputs.Add(string.Format("The base template ({0}) is not selected in the target template item.",
                                                  baseTemplateItem.Name));
                }
            }

            //check to see if all target base templates exist on the template in the current database
            foreach (string baseTemplateId in publishedBaseTemplates)
            {
                if (!publishedBaseTemplates.Contains(baseTemplateId))
                {
                    Item baseTemplateItem = context.TargetDatabase.GetItem(baseTemplateId);
                    outputs.Add(string.Format("The target base template ({0}) is not selected in the current template item.",
                                              baseTemplateItem.Name));
                }
            }

            foreach (Item descendant in context.Item.Axes.GetDescendants())
            {
                //check children of template, verify descendant exists in target database
                Item publishedDescendantItem = context.TargetDatabase.GetItem(descendant.ID);
                if (publishedDescendantItem == null)
                    outputs.Add(string.Format("The template descendant ({0}) does not exist in the target database.", descendant.Name));
                else
                {
                    //check name
                    if (descendant.Name != publishedDescendantItem.Name)
                        outputs.Add(string.Format("The template descendant's name ({0}) is different from the target item's name ({1}).",
                                                  descendant.Name, publishedDescendantItem.Name));

                    //if the item is the same, pass validation
                    if (!ItemComparerUtil.Validate(descendant, publishedDescendantItem))
                        outputs.Add(string.Format("The template descendant ({0}) is not published.", descendant.Name));
                }
            }

            return outputs;
        }
 public abstract List<string> Validate(ItemComparerContext context);
        public override List<string> Validate(ItemComparerContext context)
        {
            //defaults
            List<string> outputs = new List<string>();

            //check to see if the item exists in the target database which
            //was specified in the settings item
            Item publishedItem = context.TargetDatabase.GetItem(context.Item.ID);
            if (publishedItem == null) return outputs;

            //check presentation details for each device
            //if there is no device folder, bypass check
            Item devicesFolder = context.Item.Database.GetItem("/sitecore/layout/Devices");
            if (devicesFolder == null) return outputs;

            foreach (Item descendant in devicesFolder.Axes.GetDescendants())
            {
                //verify we have a device item
                if (descendant.TemplateID.ToString() != "{B6F7EEB4-E8D7-476F-8936-5ACE6A76F20B}") continue;

                //check against layout
                DeviceItem deviceItem = descendant;
                if (context.Item.Visualization.GetLayoutID(deviceItem) != publishedItem.Visualization.GetLayoutID(deviceItem))
                    outputs.Add(string.Format("The presentation layout for the {0} device does not match", deviceItem.InnerItem.Name));

                //get list of renderings in target db
                List<string> renderingsInTargetDb = new List<string>();
                foreach (RenderingReference renderingReference in publishedItem.Visualization.GetRenderings(deviceItem, false))
                {
                    if (renderingReference.RenderingItem == null || string.IsNullOrEmpty(renderingReference.RenderingID.ToString()))
                        continue;
                    renderingsInTargetDb.Add(renderingReference.RenderingID.ToString());
                }

                //verify rendering exist and are set for this device in the target db
                List<string> renderingsInAuthoringDb = new List<string>();
                foreach (RenderingReference renderingReference in context.Item.Visualization.GetRenderings(deviceItem, false))
                {
                    if (renderingReference.RenderingItem == null || string.IsNullOrEmpty(renderingReference.RenderingID.ToString()))
                        continue;

                    //add to list
                    renderingsInAuthoringDb.Add(renderingReference.RenderingID.ToString());

                    //check against target database
                    if (!renderingsInTargetDb.Contains(renderingReference.RenderingID.ToString()))
                        outputs.Add(
                            string.Format("The rendering ({0}) is not set or does not exist in the {1} device in the target database",
                                          renderingReference.RenderingItem.Name, deviceItem.InnerItem.Name));
                }

                //verify rendering exist and are set for this device in the authoring db - reverse validation
                foreach (RenderingReference renderingReference in publishedItem.Visualization.GetRenderings(deviceItem, false))
                {
                    if (renderingReference.RenderingItem == null || string.IsNullOrEmpty(renderingReference.RenderingID.ToString()))
                        continue;

                    //check against authoring database
                    if (!renderingsInAuthoringDb.Contains(renderingReference.RenderingID.ToString()))
                        outputs.Add(
                            string.Format("The rendering ({0}) is not set or does not exist in the {1} device in the authoring database",
                                          renderingReference.RenderingItem.Name, deviceItem.InnerItem.Name));
                }
            }

            return outputs;
        }