static void Main(string[] args) { try { XmlDocument doc = null; string dtdFile = null; string rootElementName = null; string samplesFolder = null; int? iterations = null; string xmlns = null; var p = new OptionSet() { { "h|?|help", v => syntax() }, { "x|xmlns=", v => xmlns = v }, { "d|dtd=", v => dtdFile = v }, { "c|count=", v => iterations = int.Parse(v) }, { "r|root=", v => rootElementName = v }, { "s|samples=", v => samplesFolder = v }, }; p.Parse(args); if (dtdFile == null || rootElementName == null) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FormMain()); return; } DisplayTitle(); Console.WriteLine(" * Using DTD '" + dtdFile + "'."); Console.WriteLine(" * Root element '" + rootElementName + "'."); TextReader reader = new StreamReader(dtdFile); Parser parser = new ParserDtd(); parser.parse(reader); if (samplesFolder != null) { Console.Write(" * Loading Samples from '" + samplesFolder + "'..."); Defaults defaults = new Defaults(parser.elements, true); defaults.ProcessFolder(samplesFolder); Console.WriteLine("done."); } Generator generator = new Generator(parser.elements[rootElementName], parser.elements); Console.Write(" * Generating XML files..."); for (int i = 0; true; i++) { if (iterations != null && i >= iterations) { break; } if (i % 100 == 0) { Console.Write("."); } doc = generator.GenerateXmlDocument(); if (xmlns != null) { doc.DocumentElement.Attributes.Append(CreateXmlAttribute(doc, "xmlns", xmlns)); } if (File.Exists("fuzzed-" + i.ToString() + ".svg")) { File.Delete("fuzzed-" + i.ToString() + ".svg"); } using (FileStream sout = File.OpenWrite("fuzzed-" + i.ToString() + ".svg")) { using (StreamWriter tout = new StreamWriter(sout)) { tout.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); tout.WriteLine(doc.OuterXml); } } } Console.WriteLine("done.\n"); } catch (SyntaxException) { } }
private void buttonGenerate_Click(object sender, EventArgs e) { Generate dialog = new Generate(); dialog.Show(); XmlDocument doc = null; string dtdFile = textBoxDtd.Text; string rootElementName = string.IsNullOrEmpty(textBoxRootElement.Text) ? null : textBoxRootElement.Text; string samplesFolder = string.IsNullOrEmpty(textBoxSamples.Text) ? null : textBoxSamples.Text; int iterations = int.Parse(textBoxCount.Text); string xmlns = string.IsNullOrEmpty(textBoxRootNamespace.Text) ? null : textBoxRootNamespace.Text; Console.WriteLine(" * Using DTD '" + dtdFile + "'."); Console.WriteLine(" * Root element '" + rootElementName + "'."); TextReader reader = new StreamReader(dtdFile); Parser parser = new ParserDtd(); parser.parse(reader); if (samplesFolder != null) { Console.Write(" * Loading Samples from '" + samplesFolder + "'..."); Defaults defaults = new Defaults(parser.elements, true); defaults.ProcessFolder(samplesFolder); Console.WriteLine("done."); } Generator generator = new Generator(parser.elements[rootElementName], parser.elements); Console.Write(" * Generating XML files..."); dialog.progressBarGenerate.Maximum = (int)iterations; for (int i = 0; true; i++) { if (iterations != null && i >= iterations) { break; } dialog.progressBarGenerate.Value = i; if (i % 100 == 0) { Console.Write("."); } doc = generator.GenerateXmlDocument(); if (xmlns != null) { doc.DocumentElement.Attributes.Append(CreateXmlAttribute(doc, "xmlns", xmlns)); } if (File.Exists("fuzzed-" + i.ToString() + ".svg")) { File.Delete("fuzzed-" + i.ToString() + ".svg"); } using (FileStream sout = File.OpenWrite("fuzzed-" + i.ToString() + ".svg")) { using (StreamWriter tout = new StreamWriter(sout)) { tout.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); tout.WriteLine(doc.OuterXml); } } } Console.WriteLine("done.\n"); dialog.Hide(); }