예제 #1
0
        static int ProcessContext(Config config, int errorThreshold, bool warningIsError)
        {
            var validator = new MarkdownContextValidator(config);

            int markdownFiles = 0;

            Stack <string> directories = new Stack <string>();

            directories.Push(config.RootWorkingDirectory);
            while (directories.Count > 0)
            {
                string directory = directories.Pop();
                foreach (var dir in Directory.GetDirectories(directory))
                {
                    directories.Push(dir);
                    validator.AddEntity(dir);
                }
                foreach (var file in Directory.GetFiles(directory))
                {
                    if (IsMarkdownFile(file))
                    {
                        markdownFiles++;
                        validator.AddMarkdownFile(file, ReadTextFile(file));
                    }
                    else
                    {
                        validator.AddEntity(file);
                    }
                }
            }

            Console.WriteLine("Validating {0} markdown files", markdownFiles);

            return(Validate(validator, errorThreshold, warningIsError));
        }
 private void TryAdd(string path)
 {
     try
     {
         _validator.AddEntity(path);
     }
     catch (ArgumentException ae)
     {
         OnOutOfContext(path, ae);
     }
 }
        private void Init()
        {
            _validator = new MarkdownContextValidator(new Config(string.Empty));

            List <string>  files       = new List <string>();
            Stack <string> directories = new Stack <string>();

            directories.Push(Environment.CurrentDirectory);
            while (directories.Count > 0)
            {
                string directory = directories.Pop();
                foreach (var dir in Directory.GetDirectories(directory))
                {
                    directories.Push(dir);
                    _validator.AddEntity(dir);
                }
                foreach (var file in Directory.GetFiles(directory))
                {
                    if (IsMarkdownFile(file))
                    {
                        files.Add(file);
                    }
                    else
                    {
                        _validator.AddEntity(file);
                    }
                }
            }

            Parallel.ForEach(files, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 2
            },
                             file =>
            {
                string source = File.ReadAllText(file);
                _validator.AddMarkdownFile(file, source);
            });
        }
 public RollingContextTest AddEntity(string path, bool assertReturn = true)
 {
     Xunit.Assert.Equal(assertReturn, Validator.AddEntity(path));
     return(this);
 }