# HG changeset patch # User IBBoard # Date 1237668746 0 # Node ID 422ddd5fedd11c3b8156b7ec3d174ffb1b551c93 # Parent 3664eee50390836bdb12ded5e380ffe4c1e223c6 Re #48 - Require schemas to validate * Restructure schema caching so that it warns instead of exceptioning - allows a missing schema to not kill an unrelated file load * Fix exception handling for GameSystems while working out where exceptions were being caught Current situation: Missing Race/System schema stops file loading but missing cat/core schema doesn't diff -r 3664eee50390 -r 422ddd5fedd1 api/Factories/Xml/WarFoundryXmlFactory.cs --- a/api/Factories/Xml/WarFoundryXmlFactory.cs Sat Mar 21 17:04:33 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs Sat Mar 21 20:52:26 2009 +0000 @@ -308,36 +308,44 @@ { if (settings == null) { - try - { - settings = new XmlReaderSettings(); - settings.ValidationType = ValidationType.Schema; - settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings; - settings.ValidationEventHandler+= new ValidationEventHandler(ValidationEventMethod); - XmlSchemaSet cache = new XmlSchemaSet(); - cache.Add("http://ibboard.co.uk/warfoundry/core", IBBoard.Constants.ExecutablePath + "/dtds/warfoundry-core.xsd"); - cache.Add("http://ibboard.co.uk/warfoundry/cats", IBBoard.Constants.ExecutablePath + "/dtds/warfoundry-cats.xsd"); - cache.Add("http://ibboard.co.uk/warfoundry/race", IBBoard.Constants.ExecutablePath + "/dtds/race.xsd"); - cache.Add("http://ibboard.co.uk/warfoundry/system", IBBoard.Constants.ExecutablePath + "/dtds/system.xsd"); - settings.Schemas.Add(cache); - } - catch (DirectoryNotFoundException ex) - { - throw new InvalidDataException("Problem validating schema for WarFoundry data: " + ex.Message, ex); - } - catch (XmlSchemaException ex) - { - throw new InvalidDataException("Problem validating schema for WarFoundry data: " + ex.Message, ex); - } - catch (XmlException ex) - { - throw new InvalidDataException("Problem reading data for schema: " + ex.Message, ex); - } + settings = new XmlReaderSettings(); + settings.ValidationType = ValidationType.Schema; + settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings; + settings.ProhibitDtd = true; + settings.ValidationEventHandler+= new ValidationEventHandler(ValidationEventMethod); + XmlSchemaSet cache = new XmlSchemaSet(); + string path = IBBoard.Constants.ExecutablePath + "/dtds/"; + string nsBase = "http://ibboard.co.uk/warfoundry/"; + AddSchemaToCache(cache, nsBase + "core", path + "warfoundry-core.xsd"); + AddSchemaToCache(cache, nsBase + "cats", path + "warfoundry-cats.xsd"); + AddSchemaToCache(cache, nsBase + "race", path + "race.xsd"); + AddSchemaToCache(cache, nsBase + "system", path + "system.xsd"); + settings.Schemas.Add(cache); } return settings; } + private void AddSchemaToCache(XmlSchemaSet cache, string xmlNamespace, string schemaLocation) + { + try + { + cache.Add(xmlNamespace, schemaLocation); + } + catch (IOException ex) + { + LogNotifier.Warn(GetType(), "Problem reading schema: " + ex.Message, ex); + } + catch (XmlSchemaException ex) + { + LogNotifier.Warn(GetType(), "Problem validating schema for WarFoundry data: " + ex.Message, ex); + } + catch (XmlException ex) + { + LogNotifier.Warn(GetType(), "Problem reading data for schema: " + ex.Message, ex); + } + } + private void ValidationEventMethod(object sender, ValidationEventArgs e) { throw new InvalidDataException("Problem validating against schema for WarFoundry data: " + e.Exception.Message, e.Exception); diff -r 3664eee50390 -r 422ddd5fedd1 api/WarFoundryLoader.cs --- a/api/WarFoundryLoader.cs Sat Mar 21 17:04:33 2009 +0000 +++ b/api/WarFoundryLoader.cs Sat Mar 21 20:52:26 2009 +0000 @@ -285,7 +285,7 @@ if (!loaded) { - failure = new FileLoadFailure(file, "FileLoadFailed", "Failed to load {0} as Race using {1}"); + failure = new FileLoadFailure(file, "FileLoadFailed", "Failed to load {0} as GameSystem using {1}"); } } catch (Exception ex) @@ -296,7 +296,7 @@ if (failure!=null) { fails.Add(failure); - LogNotifier.Warn(GetType(), failure.Message); + LogNotifier.Warn(GetType(), failure.Message, failure.Exception); } }