# HG changeset patch # User IBBoard # Date 1250965100 0 # Node ID 863518044d38d8e36db8dbd767499a596c7724fe # Parent b5ae022ce7b80e3a9de34d260c170245fbc3c21d Re #54: Add Army support to WarFoundryFactory * Stop "custom equipment" node being mandatory * Remove unused "ratio" definition * Change "integer or ratio" definition to "integer or percentage" * Use "integer or percentage" definition in army XSD * Add exception to say that required objects were missing (Game System and Race) * Throw exceptions on creating army if game system or race is missing Re #53: Add saving of Army to XML file * Add namespace attributes to XML root node diff -r b5ae022ce7b8 -r 863518044d38 IBBoard.WarFoundry.API.csproj --- a/IBBoard.WarFoundry.API.csproj Sat Aug 22 15:34:25 2009 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sat Aug 22 18:18:20 2009 +0000 @@ -133,6 +133,7 @@ + diff -r b5ae022ce7b8 -r 863518044d38 api/Factories/RequiredDataMissingException.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api/Factories/RequiredDataMissingException.cs Sat Aug 22 18:18:20 2009 +0000 @@ -0,0 +1,19 @@ +// This file (RequiredDataMissingException.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. + +using System; + +namespace IBBoard.WarFoundry.API +{ + /// + /// An exception that is thrown when a file cannot be loaded because one of the data files that it depends on has + /// not been loaded. Normally occurs when loading an army file without having the correct game system or race. + /// + public class RequiredDataMissingException : Exception + { + public RequiredDataMissingException(String file, String missingAttribute, String requiredValue) : base(String.Format("Could not find object with ID {2} for {1} of {0}", file, missingAttribute, requiredValue)) + { + } + } +} diff -r b5ae022ce7b8 -r 863518044d38 api/Factories/Xml/WarFoundryXmlArmyFactory.cs --- a/api/Factories/Xml/WarFoundryXmlArmyFactory.cs Sat Aug 22 15:34:25 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlArmyFactory.cs Sat Aug 22 18:18:20 2009 +0000 @@ -20,8 +20,20 @@ string name = elem.GetAttribute("name"); string systemID = elem.GetAttribute("gameSystem"); GameSystem system = WarFoundryLoader.GetDefault().GetGameSystem(systemID); + + if (system == null) + { + throw new RequiredDataMissingException(file.Name, "gameSystem", systemID); + } + string raceID = elem.GetAttribute("race"); Race race = WarFoundryLoader.GetDefault().GetRace(system, raceID); + + if (race == null) + { + throw new RequiredDataMissingException(file.Name, "race", raceID); + } + int points = XmlTools.GetIntValueFromAttribute(elem, "maxPoints"); Army army = new Army(race, name, points, file); //TODO: Complete loading of army diff -r b5ae022ce7b8 -r 863518044d38 api/Factories/Xml/WarFoundryXmlSaver.cs --- a/api/Factories/Xml/WarFoundryXmlSaver.cs Sat Aug 22 15:34:25 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlSaver.cs Sat Aug 22 18:18:20 2009 +0000 @@ -71,6 +71,8 @@ schema.Namespaces.Add("xmlns:core", "http://ibboard.co.uk/warfoundry/core"); doc.Schemas.Add(schema); XmlElement root = doc.CreateElement("army"); + root.SetAttribute("xmlns", "http://ibboard.co.uk/warfoundry/army"); + root.SetAttribute("xmlns:core", "http://ibboard.co.uk/warfoundry/core"); doc.AppendChild(root); root.SetAttribute("id", XmlTools.GetAsciiXmlIdForString(toSave.ID)); root.SetAttribute("name", toSave.Name); diff -r b5ae022ce7b8 -r 863518044d38 api/WarFoundryLoader.cs --- a/api/WarFoundryLoader.cs Sat Aug 22 15:34:25 2009 +0000 +++ b/api/WarFoundryLoader.cs Sat Aug 22 18:18:20 2009 +0000 @@ -814,18 +814,21 @@ public Army LoadArmy(FileInfo file) { - IWarFoundryFactory factory = GetArmyLoadingFactoryForFile(file); - ICollection objs = factory.CreateObjectsFromFile(file); - + IWarFoundryFactory factory = GetArmyLoadingFactoryForFile(file); Army loadedArmy = null; - if (objs.Count == 1) + if (factory != null) { - foreach (IWarFoundryObject obj in objs) + ICollection objs = factory.CreateObjectsFromFile(file); + + if (objs.Count == 1) { - if (obj is Army) + foreach (IWarFoundryObject obj in objs) { - loadedArmy = (Army) obj; + if (obj is Army) + { + loadedArmy = (Army) obj; + } } } } diff -r b5ae022ce7b8 -r 863518044d38 dtds/army.xsd --- a/dtds/army.xsd Sat Aug 22 15:34:25 2009 +0000 +++ b/dtds/army.xsd Sat Aug 22 18:18:20 2009 +0000 @@ -15,7 +15,7 @@ - + @@ -45,7 +45,7 @@ - + diff -r b5ae022ce7b8 -r 863518044d38 dtds/warfoundry-core.xsd --- a/dtds/warfoundry-core.xsd Sat Aug 22 15:34:25 2009 +0000 +++ b/dtds/warfoundry-core.xsd Sat Aug 22 18:18:20 2009 +0000 @@ -30,13 +30,7 @@ - - - - - - - - + + \ No newline at end of file