Exemplo n.º 1
0
        private void ProcessXPath([NotNull] ValidationWriter output, [NotNull] ValidationAnalyzerOptions options)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(options, nameof(options));

            foreach (var database in options.Databases)
            {
                ItemList items;
                try
                {
                    items = database.SelectItemsUsingXPath(Code);
                }
                catch (Exception ex)
                {
                    Log.Error("Custom Validation", ex, GetType());
                    continue;
                }

                if (WhenExists)
                {
                    foreach (var item in items)
                    {
                        output.Write(Severity, Title, Problem, Solution, item);
                    }
                }
                else
                {
                    if (!items.Any())
                    {
                        output.Write(Severity, Title, Problem, Solution);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ProcessFileSystem([NotNull] ValidationWriter output, [NotNull] FileSystemNavigator webFileSystem)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(webFileSystem, nameof(webFileSystem));

            XPathNodeIterator nodes = null;

            try
            {
                nodes = webFileSystem.Select(Code);
            }
            catch (Exception ex)
            {
                Log.Error("Custom Validation", ex, GetType());
            }

            if (WhenExists)
            {
                if (nodes != null)
                {
                    foreach (XPathNavigator navigator in nodes)
                    {
                        output.Write(Severity, Title, Expand(Problem, navigator), Expand(Solution, navigator));
                    }
                }
            }
            else
            {
                if (nodes == null || nodes.Count == 0)
                {
                    output.Write(Severity, Title, Problem, Solution);
                }
            }
        }
Exemplo n.º 3
0
        private void ProcessWebConfig([NotNull] ValidationWriter output, [NotNull] XmlDocument webConfig)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(webConfig, nameof(webConfig));

            XmlNodeList nodes = null;

            try
            {
                nodes = webConfig.SelectNodes(Code);
            }
            catch (Exception ex)
            {
                Log.Error("Custom Validation", ex, GetType());
            }

            if (WhenExists)
            {
                if (nodes != null)
                {
                    foreach (XmlNode node in nodes)
                    {
                        output.Write(Severity, Title, Expand(Problem, node), Expand(Solution, node));
                    }
                }
            }
            else
            {
                if (nodes == null || nodes.Count == 0)
                {
                    output.Write(Severity, Title, Problem, Solution);
                }
            }
        }
Exemplo n.º 4
0
        private void ProcessItemValidation([NotNull] XmlTextWriter output, [NotNull] ValidationWriter writer, [NotNull] ValidationAnalyzerOptions options, [NotNull] IEnumerable <Language> languages, [NotNull] Item item, [NotNull] ValidationManager.ItemValidationDescriptor itemValidationDescriptor)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(writer, nameof(writer));
            Debug.ArgumentNotNull(options, nameof(options));
            Debug.ArgumentNotNull(languages, nameof(languages));
            Debug.ArgumentNotNull(item, nameof(item));
            Debug.ArgumentNotNull(itemValidationDescriptor, nameof(itemValidationDescriptor));

            if (options.InactiveValidations.Contains("[" + itemValidationDescriptor.Attribute.Name + "]"))
            {
                return;
            }

            if (!itemValidationDescriptor.Instance.CanCheck(options.ContextName, item))
            {
                return;
            }

            if (itemValidationDescriptor.Attribute.ExecutePerLanguage)
            {
                foreach (var language in languages)
                {
                    using (new LanguageSwitcher(language))
                    {
                        ProcessItem(output, writer, itemValidationDescriptor, item);
                    }
                }
            }
            else
            {
                ProcessItem(output, writer, itemValidationDescriptor, item);
            }
        }
Exemplo n.º 5
0
        private void ProcessItemValidations([NotNull] XmlTextWriter output, [NotNull] ValidationWriter writer, [NotNull] ValidationAnalyzerOptions options, [NotNull] IEnumerable <Language> languages, [NotNull] Item item)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(writer, nameof(writer));
            Debug.ArgumentNotNull(options, nameof(options));
            Debug.ArgumentNotNull(languages, nameof(languages));
            Debug.ArgumentNotNull(item, nameof(item));

            foreach (var itemValidationDescriptor in ValidationManager.ItemValidations)
            {
                ProcessItemValidation(output, writer, options, languages, item, itemValidationDescriptor);
            }
        }
Exemplo n.º 6
0
        private void ProcessLayoutRendering([NotNull] XmlTextWriter output, [NotNull] ValidationWriter writer, [NotNull] ValidationAnalyzerOptions options, [NotNull] Item item, [NotNull] XElement renderingElement)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(writer, nameof(writer));
            Debug.ArgumentNotNull(options, nameof(options));
            Debug.ArgumentNotNull(item, nameof(item));
            Debug.ArgumentNotNull(renderingElement, nameof(renderingElement));

            var renderingItemId = renderingElement.GetAttributeValue("id");

            if (string.IsNullOrEmpty(renderingItemId))
            {
                return;
            }

            var renderingItem = item.Database.GetItem(renderingItemId);

            if (renderingItem == null)
            {
                return;
            }

            foreach (var renderingValidationDescriptor in ValidationManager.RenderingValidations)
            {
                if (options.InactiveValidations.Contains("[" + renderingValidationDescriptor.Attribute.Name + "]"))
                {
                    continue;
                }

                if (!renderingValidationDescriptor.Instance.CanCheck(options.ContextName, item, renderingElement, renderingItem))
                {
                    continue;
                }

                try
                {
                    writer.Clear();

                    renderingValidationDescriptor.Instance.Check(writer, item, renderingElement, renderingItem);

                    writer.Write(output, renderingValidationDescriptor.Attribute.Category, renderingValidationDescriptor.Attribute.Name);
                }
                catch (Exception ex)
                {
                    Log.Error("Validations", ex, GetType());
                }
            }
        }
Exemplo n.º 7
0
        private void ProcessItems([NotNull] XmlTextWriter output, [NotNull] ValidationAnalyzerOptions options)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(options, nameof(options));

            var writer = new ValidationWriter();

            foreach (var database in options.Databases)
            {
                var languages = options.DatabasesAndLanguages.Where(d => d.Database == database).Select(d => d.Language).ToList();

                var item = options.RootItem ?? database.GetRootItem();

                ProcessItem(output, writer, options, languages, item);
            }
        }
Exemplo n.º 8
0
        private void ProcessItem([NotNull] XmlTextWriter output, [NotNull] ValidationWriter writer, [NotNull] ValidationManager.ItemValidationDescriptor descriptor, [NotNull] Item item)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(writer, nameof(writer));
            Debug.ArgumentNotNull(descriptor, nameof(descriptor));
            Debug.ArgumentNotNull(item, nameof(item));

            try
            {
                writer.Clear();

                descriptor.Instance.Check(writer, item);

                writer.Write(output, descriptor.Attribute.Category, descriptor.Attribute.Name);
            }
            catch (Exception ex)
            {
                Log.Error("Validations", ex, GetType());
            }
        }
Exemplo n.º 9
0
        private void ProcessCustomValidations([NotNull] XmlTextWriter output, [NotNull] ValidationWriter writer, [NotNull] XElement element, [NotNull] ValidationAnalyzerOptions options, [NotNull] XmlDocument webConfig, [NotNull] XmlDocument expandedWebConfig, [NotNull] FileSystemNavigator webFileSystem, [NotNull] FileSystemNavigator dataFileSystem)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(writer, nameof(writer));
            Debug.ArgumentNotNull(element, nameof(element));
            Debug.ArgumentNotNull(options, nameof(options));
            Debug.ArgumentNotNull(webConfig, nameof(webConfig));
            Debug.ArgumentNotNull(expandedWebConfig, nameof(expandedWebConfig));
            Debug.ArgumentNotNull(webFileSystem, nameof(webFileSystem));
            Debug.ArgumentNotNull(dataFileSystem, nameof(dataFileSystem));

            var customValidation = new CustomValidation();

            customValidation.Load(element);

            writer.Clear();

            customValidation.Process(writer, options, webConfig, expandedWebConfig, webFileSystem, dataFileSystem);

            writer.Write(output, customValidation.Category, customValidation.Title);
        }
Exemplo n.º 10
0
        private void ProcessItem([NotNull] XmlTextWriter output, [NotNull] ValidationWriter writer, [NotNull] ValidationAnalyzerOptions options, [NotNull] IEnumerable <Language> languages, [NotNull] Item item)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(writer, nameof(writer));
            Debug.ArgumentNotNull(options, nameof(options));
            Debug.ArgumentNotNull(languages, nameof(languages));
            Debug.ArgumentNotNull(item, nameof(item));

            ProcessItemValidations(output, writer, options, languages, item);
            ProcessLayout(output, writer, options, item);

            if (!options.Deep)
            {
                return;
            }

            foreach (Item child in item.Children)
            {
                ProcessItem(output, writer, options, languages, child);
            }
        }
Exemplo n.º 11
0
        public override void Check(ValidationWriter output, Item item)
        {
            var layout = GetFieldValuePipeline.Run().WithParameters(item.Fields[FieldIDs.LayoutField]).Value ?? string.Empty;

            if (string.IsNullOrEmpty(layout))
            {
                return;
            }

            var devices = item.Database.GetItem(ItemIDs.DevicesRoot);

            foreach (Item deviceItem in devices.Children)
            {
                var device = new DeviceItem(deviceItem);

                if (item.Visualization.GetLayoutID(device) == Page)
                {
                    CheckDevice(output, item, device);
                }
            }
        }
Exemplo n.º 12
0
        private void ProcessValidations([NotNull] XmlTextWriter output, [NotNull] ValidationAnalyzerOptions options)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(options, nameof(options));

            var writer = new ValidationWriter();

            foreach (var definition in ValidationManager.Validations.OrderBy(v => v.Attribute.Category).ThenBy(v => v.Type.Name))
            {
                if (options.InactiveValidations.Contains("[" + definition.Attribute.Name + "]"))
                {
                    continue;
                }

                var instance = definition.GetInstance();
                if (instance == null)
                {
                    continue;
                }

                if (!instance.CanCheck(options.ContextName))
                {
                    continue;
                }

                try
                {
                    writer.Clear();

                    instance.Check(writer);

                    writer.Write(output, definition.Attribute.Category, definition.Attribute.Name);
                }
                catch (Exception ex)
                {
                    Log.Error("Validations", ex, GetType());
                }
            }
        }
Exemplo n.º 13
0
        private void ProcessLayout([NotNull] XmlTextWriter output, [NotNull] ValidationWriter writer, [NotNull] ValidationAnalyzerOptions options, [NotNull] Item item)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(writer, nameof(writer));
            Debug.ArgumentNotNull(options, nameof(options));
            Debug.ArgumentNotNull(item, nameof(item));

            var layout = GetFieldValuePipeline.Run().WithParameters(item.Fields[FieldIDs.LayoutField]).Value ?? string.Empty;

            if (string.IsNullOrEmpty(layout))
            {
                return;
            }

            XDocument doc;

            try
            {
                doc = XDocument.Parse(layout);
            }
            catch
            {
                return;
            }

            var root = doc.Root;

            if (root == null)
            {
                return;
            }

            foreach (var renderingElement in root.Elements().Elements())
            {
                ProcessLayoutRendering(output, writer, options, item, renderingElement);
            }
        }
Exemplo n.º 14
0
        public void Process([NotNull] ValidationWriter output, [NotNull] ValidationAnalyzerOptions options, [NotNull] XmlDocument webConfig, [NotNull] XmlDocument expandedWebConfig, [NotNull] FileSystemNavigator webFileSystem, [NotNull] FileSystemNavigator dataFileSystem)
        {
            Assert.ArgumentNotNull(output, nameof(output));
            Assert.ArgumentNotNull(options, nameof(options));
            Assert.ArgumentNotNull(webConfig, nameof(webConfig));
            Assert.ArgumentNotNull(expandedWebConfig, nameof(expandedWebConfig));
            Assert.ArgumentNotNull(webFileSystem, nameof(webFileSystem));
            Assert.ArgumentNotNull(dataFileSystem, nameof(dataFileSystem));

            switch (Type)
            {
            case CustomValidationType.Query:
                ProcessQuery(output, options);
                break;

            case CustomValidationType.XPath:
                ProcessXPath(output, options);
                break;

            case CustomValidationType.WebConfig:
                ProcessWebConfig(output, webConfig);
                break;

            case CustomValidationType.ExpandedWebConfig:
                ProcessExpandedWebConfig(output, expandedWebConfig);
                break;

            case CustomValidationType.WebFileSystem:
                ProcessFileSystem(output, webFileSystem);
                break;

            case CustomValidationType.DataFileSystem:
                ProcessFileSystem(output, dataFileSystem);
                break;
            }
        }
Exemplo n.º 15
0
 public abstract void Check(ValidationWriter output, Item item, XElement renderingElement, Item renderingItem);
Exemplo n.º 16
0
        private void ProcessCustomValidations([NotNull] XmlTextWriter output, [NotNull] ValidationAnalyzerOptions options)
        {
            Debug.ArgumentNotNull(output, nameof(output));
            Debug.ArgumentNotNull(options, nameof(options));

            if (string.IsNullOrEmpty(options.CustomValidations))
            {
                return;
            }

            XDocument doc;

            try
            {
                doc = XDocument.Parse(options.CustomValidations);
            }
            catch (Exception ex)
            {
                Log.Error("Could not parse validations: " + ex.Message, GetType());
                return;
            }

            var root = doc.Root;

            if (root == null)
            {
                return;
            }

            var webConfig = new XmlDocument();

            webConfig.Load(FileUtil.MapPath("/web.config"));
            var expandedWebConfig = Factory.GetConfiguration();

            var webFolder = FileUtil.MapPath("/");

            if (webFolder.EndsWith("\\"))
            {
                webFolder = webFolder.Left(webFolder.Length - 1);
            }

            var webFileSystem = new FileSystemNavigator(webFolder);

            webFileSystem.MoveToFirstChild();

            var dataFolder = FileUtil.MapPath(Settings.DataFolder);

            if (dataFolder.EndsWith("\\"))
            {
                dataFolder = dataFolder.Left(dataFolder.Length - 1);
            }

            var dataFileSystem = new FileSystemNavigator(dataFolder);

            dataFileSystem.MoveToFirstChild();

            var writer = new ValidationWriter();

            foreach (var element in root.Elements())
            {
                webFileSystem.MoveToRoot();
                dataFileSystem.MoveToRoot();
                ProcessCustomValidations(output, writer, element, options, webConfig, expandedWebConfig, webFileSystem, dataFileSystem);
            }
        }
Exemplo n.º 17
0
 protected abstract void CheckDevice(ValidationWriter output, Item item, DeviceItem device);
Exemplo n.º 18
0
 public abstract void Check(ValidationWriter output, Item item);