Пример #1
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);
                }
            }
        }
 public FileSystemNavigator(FileSystemNavigator navigator)
 {
     State     = new NavigatorState(navigator.State);
     nametable = (NameTable)navigator.NameTable;
 }
Пример #3
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;
            }
        }
Пример #4
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);
            }
        }
Пример #5
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);
        }