# HG changeset patch # User IBBoard # Date 1313232306 0 # Node ID 6da9db4a9c23adde2642025faea2f7c84f3ff535 # Parent 30db6669f5cdff981d85aabfeae7740f769f54e2 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) diff -r 30db6669f5cd -r 6da9db4a9c23 API/Exporters/WarFoundryHtmlExporter.cs --- 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) diff -r 30db6669f5cd -r 6da9db4a9c23 API/Factories/Xml/WarFoundryXmlFactoryUtils.cs --- 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; } diff -r 30db6669f5cd -r 6da9db4a9c23 API/FileLoadFailure.cs --- 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); } diff -r 30db6669f5cd -r 6da9db4a9c23 API/Objects/WarFoundryObject.cs --- 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)