public void view_OnValidateSchema(object sender, SchemaEventArgs e) { OnValidadeSchemaCalled = true; try { if (String.IsNullOrEmpty(e.DefinitionFilename)) { e.ShortErrorMessage = Resource.EmptyDefinitionFilename; e.LongErrorMessage = null; e.Result = false; } else if (!DefinitionsFileExists(e.DefinitionFilename)) { e.ShortErrorMessage = Resource.OVALDefinitionsFileNotFound; e.LongErrorMessage = null; e.Result = false; } else { var schemas = CreateXmlSchemaSet(); var settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas = schemas; settings.ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ReportValidationWarnings; settings.ValidationEventHandler += ValidationEventHandler; this.error = false; this.errorDescription = new StringBuilder(); using (var stream = GetStream(e.DefinitionFilename)) { var validationReader = XmlReader.Create(stream, settings); while (validationReader.Read()) { } if (this.error) { e.ShortErrorMessage = Resource.SchemaValidationFailure; e.LongErrorMessage = errorDescription.ToString(); e.Result = false; } else { validationReader.Close(); e.Result = true; } this.errorDescription = null; } } } catch (Exception ex) { view.ShowErrorMessage(Util.FormatExceptionMessage(ex)); } }
private void CheckDefinition(string filename, bool verbose = false) { this.Cursor = Cursors.WaitCursor; try { ExternalVariablesValues = null; ExternalVariables = null; DefinitionFilename = String.Empty; var args = new SchemaEventArgs() { DefinitionFilename = filename }; OnValidateSchema(this, args); if (args.Result) { string errors; if (CheckExternalVariables(filename, out errors)) { tbOvalDefs.Text = filename; DefinitionFilename = filename; lbDefName.Text = Path.GetFileName(filename); lbDefName.ForeColor = Color.Black; } else { if (verbose) { ShowErrorMessage(errors); } } } else { lbDefName.Text = args.ShortErrorMessage; lbDefName.ForeColor = Color.Red; if (args.LongErrorMessage != null) { ShowSchemaWindow(args); } } CreateSSHPortControl(); } finally { this.Cursor = Cursors.Default; } }
private void ShowSchemaWindow(SchemaEventArgs args) { var window = new SchemaWindow(args.LongErrorMessage); window.ShowDialog(); }