public RollingContextTest Update(string source, string fileName = DefaultFileName) { source = SourceHelper.CleanSource(source); if (!Validator.UpdateMarkdownFile(fileName, source)) { Validator.AddMarkdownFile(fileName, source); } return(this); }
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)); }
static void Main(string[] args) { Validator = new MarkdownContextValidator(); Validator.AddMarkdownFile("Test.md", ""); Server = new WebSocketServer(6300, true) { SslConfiguration = new ServerSslConfiguration( new X509Certificate2(@"C:\xampp\apache\conf\ssl.pfx\markdown-validator.ml.pfx")) }; Server.AddWebSocketService <MarkdownBehaviour>("/"); Server.Start(); while (true) { Thread.Sleep(10000); } }
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 static void Fuzz(int iterations, int stringSizeMin, int stringSizeMax, string alphabet, string fileAlphabet, int maxFileNameLength) { MarkdownContextValidator validator = new MarkdownContextValidator(); Random seedRandom = new Random(); #if RELEASE try { #endif int concurrent = 4; int localIterations = iterations / concurrent; Task[] tasks = new Task[concurrent]; for (int t = 0; t < concurrent; t++) { Random random = new Random(seedRandom.Next()); tasks[t] = Task.Run(() => { char[] stringChars = new string(' ', stringSizeMax).ToCharArray(); for (int i = 0; i < localIterations; i++) { if (i % 100 == 99) { validator.Validate(); } try { int fileNameLength = 1 + random.Next(maxFileNameLength); stringChars[random.Next(fileNameLength)] = fileAlphabet[random.Next(fileAlphabet.Length)]; string fileName = new string(stringChars, 0, fileNameLength); int stringLength = random.Next(stringSizeMin, stringSizeMax); stringChars[random.Next(stringLength)] = alphabet[random.Next(alphabet.Length)]; string randomString = new string(stringChars, 0, stringLength); if (i % 100 == 0) { if (!validator.UpdateMarkdownFile(fileName, randomString)) { validator.AddMarkdownFile(fileName, randomString); } } else { fileName = Guid.NewGuid() + fileName; validator.AddMarkdownFile(fileName, randomString); } } catch (ArgumentException ae) when(ae.Message.EndsWith("is not a child path of the root working directory of the context", StringComparison.Ordinal)) { } catch (PathTooLongException) { } } }); } Task.WaitAll(tasks); #if RELEASE } catch { Console.WriteLine("Failed"); Console.ReadLine(); } #endif }