public ValidationResult ValidateCore() { outputStream.WriteLine($"[Validator] Validating {XMLGenerator.ToRelativePath(filename)}"); XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema; readerSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation; readerSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; readerSettings.ValidationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes; readerSettings.ValidationEventHandler += new ValidationEventHandler(onValidation); readerSettings.ValidationType = ValidationType.Schema; readerSettings.Schemas.XmlResolver = new XmlUrlResolver(); XmlReader xmlReader = null; FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read); try { readerSettings.Schemas.Add("flowbased", xsdLocation); xmlReader = XmlReader.Create(fs, readerSettings); } catch (Exception e) { outputStream.WriteLine($"[Validator] Validation failed: {e.Message}"); if (xmlReader != null) { xmlReader.Close(); } fs.Close(); return(ValidationResult.Failed); } while (xmlReader.Read()) { ; } xmlReader.Close(); fs.Close(); if (validationWarnings == 0 && validationErrors == 0) { return(ValidationResult.OK); } if (validationErrors == 0) { return(ValidationResult.Warning); } return(ValidationResult.Error); }
static void Main(string[] args) { Application.EnableVisualStyles(); if (!Directory.Exists("output")) { Directory.CreateDirectory("output"); } StringWriter testOutput = new StringWriter(); XMLGenerator generator = new XMLGenerator(Console.Out, "output"); String outagesPath = PromptForFile("Select outages CSV"); String criticalBranchesPath = PromptForFile("Select critical branches CSV"); //Prompt user for data InputPrompt prompt; while (true) { Console.Write("Getting user input..."); prompt = new InputPrompt(); prompt.ShowDialog(); if (prompt.inputOK) { Console.WriteLine("OK"); break; } else { Console.WriteLine("Failed"); } } Settings s = new Settings(); s.constraintTimeInterval = prompt.constraintTimeInterval; s.senderIdentification = prompt.senderIdentification; s.receiverIdentification = prompt.receiverIdentification; s.outagesPerBranch = prompt.outagesPerBranch; generator.SetSettings(s); bool loaded = true; loaded = loaded && generator.LoadOutagesFromCSV(outagesPath); loaded = loaded && generator.LoadCriticalBranchesFromCSV(criticalBranchesPath); if (!loaded) { Console.ReadLine(); return; } generator.overwritePrompt = new XMLGenerator.OverwritePromptDelegate(OverwritePrompt); generator.validationResultPrompt = new XMLGenerator.ValidationResultPromptDelegate(ValidationResultPrompt); bool success = generator.Generate(); if (success) { Console.WriteLine("Press O to open location or any other key to close"); while (true) { ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.O) { string argument = Directory.GetCurrentDirectory(); Process.Start("explorer.exe", argument); } else { break; } } } }