Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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());
                }
            }
        }