Mercurial > repos > IBBoard.WarFoundry.API
changeset 382:6da9db4a9c23
Re #241: Use built-in .Net methods
* Switch to built-in methods (list on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx)
* Tidy up code and fix export issue (trying to download DTD)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 13 Aug 2011 10:45:06 +0000 |
parents | 30db6669f5cd |
children | cbe69734f48f |
files | API/Exporters/WarFoundryHtmlExporter.cs API/Factories/Xml/WarFoundryXmlFactoryUtils.cs API/FileLoadFailure.cs API/Objects/WarFoundryObject.cs |
diffstat | 4 files changed, 13 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Exporters/WarFoundryHtmlExporter.cs Sun Aug 07 19:15:33 2011 +0000 +++ b/API/Exporters/WarFoundryHtmlExporter.cs Sat Aug 13 10:45:06 2011 +0000 @@ -42,7 +42,9 @@ { XmlDocument doc = new XmlDocument(); CustomXmlResolver resolver = new CustomXmlResolver(); - resolver.AddMapping("-//W3C//DTD XHTML 1.0 Strict//EN", new Uri("file://" + IBBoard.Constants.ExecutablePath + "/schemas/xhtml1-strict.dtd")); + Uri localUri = new Uri("file://" + IBBoard.Constants.ExecutablePath + "/schemas/xhtml1-strict.dtd"); + resolver.AddMapping("-//W3C//DTD XHTML 1.0 Strict//EN", localUri); + resolver.AddMapping("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", localUri); doc.XmlResolver = resolver; doc.AppendChild(doc.CreateDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", null)); XmlElement html = doc.CreateElement("html"); @@ -74,17 +76,8 @@ body.AppendChild(table); } } - - StreamWriter writer = new StreamWriter(path, false); - - try - { - writer.Write(doc.OuterXml); - } - finally - { - writer.Close(); - } + + File.WriteAllText(path, doc.OuterXml); } private bool IsTableOnlyHeader(XmlElement table)
--- a/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs Sun Aug 07 19:15:33 2011 +0000 +++ b/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs Sat Aug 13 10:45:06 2011 +0000 @@ -67,12 +67,12 @@ settings.ProhibitDtd = true; settings.ValidationEventHandler+= new ValidationEventHandler(ValidationEventMethod); XmlSchemaSet cache = new XmlSchemaSet(); - string path = IBBoard.Constants.ExecutablePath + "/schemas/"; - AddSchemaToCache(cache, NS_BASE + "core", path + "warfoundry-core.xsd"); - AddSchemaToCache(cache, NS_BASE + "cats", path + "warfoundry-cats.xsd"); - AddSchemaToCache(cache, NS_BASE + "race", path + "race.xsd"); - AddSchemaToCache(cache, NS_BASE + "system", path + "system.xsd"); - AddSchemaToCache(cache, NS_BASE + "army", path + "army.xsd"); + string path = Path.Combine(IBBoard.Constants.ExecutablePath, "schemas"); + AddSchemaToCache(cache, NS_BASE + "core", Path.Combine(path, "warfoundry-core.xsd")); + AddSchemaToCache(cache, NS_BASE + "cats", Path.Combine(path, "warfoundry-cats.xsd")); + AddSchemaToCache(cache, NS_BASE + "race", Path.Combine(path, "race.xsd")); + AddSchemaToCache(cache, NS_BASE + "system", Path.Combine(path, "system.xsd")); + AddSchemaToCache(cache, NS_BASE + "army", Path.Combine(path, "army.xsd")); settings.Schemas.Add(cache); settings.Schemas.CompilationSettings.EnableUpaCheck = false; }
--- a/API/FileLoadFailure.cs Sun Aug 07 19:15:33 2011 +0000 +++ b/API/FileLoadFailure.cs Sat Aug 13 10:45:06 2011 +0000 @@ -99,7 +99,7 @@ { string fileName = FailedFile.FullName; string factoryType = (loadingFactory == null ? "" : loadingFactory.GetType().Name); - if (messageTranslationID == "" || messageTranslationID == null) + if (String.IsNullOrEmpty(messageTranslationID)) { message = String.Format(defaultMessage, fileName, factoryType); }
--- a/API/Objects/WarFoundryObject.cs Sun Aug 07 19:15:33 2011 +0000 +++ b/API/Objects/WarFoundryObject.cs Sat Aug 13 10:45:06 2011 +0000 @@ -76,7 +76,7 @@ public bool HasDefaultName() { - return (name == null || name == ""); + return String.IsNullOrEmpty(name); } protected void OnNameChanged(string oldValue, string newValue)