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 diff
     1.1 --- a/API/Exporters/WarFoundryHtmlExporter.cs	Sun Aug 07 19:15:33 2011 +0000
     1.2 +++ b/API/Exporters/WarFoundryHtmlExporter.cs	Sat Aug 13 10:45:06 2011 +0000
     1.3 @@ -42,7 +42,9 @@
     1.4  		{
     1.5  			XmlDocument doc = new XmlDocument();
     1.6  			CustomXmlResolver resolver = new CustomXmlResolver();
     1.7 -			resolver.AddMapping("-//W3C//DTD XHTML 1.0 Strict//EN", new Uri("file://" + IBBoard.Constants.ExecutablePath + "/schemas/xhtml1-strict.dtd"));
     1.8 +			Uri localUri = new Uri("file://" + IBBoard.Constants.ExecutablePath + "/schemas/xhtml1-strict.dtd");
     1.9 +			resolver.AddMapping("-//W3C//DTD XHTML 1.0 Strict//EN", localUri);
    1.10 +			resolver.AddMapping("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", localUri);
    1.11  			doc.XmlResolver = resolver;
    1.12  			doc.AppendChild(doc.CreateDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", null));
    1.13  			XmlElement html = doc.CreateElement("html");
    1.14 @@ -74,17 +76,8 @@
    1.15  					body.AppendChild(table);
    1.16  				}
    1.17  			}
    1.18 -			
    1.19 -			StreamWriter writer = new StreamWriter(path, false);
    1.20 -			
    1.21 -			try
    1.22 -			{
    1.23 -				writer.Write(doc.OuterXml);
    1.24 -			}
    1.25 -			finally
    1.26 -			{
    1.27 -				writer.Close();
    1.28 -			}
    1.29 +
    1.30 +			File.WriteAllText(path, doc.OuterXml);
    1.31  		}
    1.32  
    1.33  		private bool IsTableOnlyHeader(XmlElement table)
     2.1 --- a/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs	Sun Aug 07 19:15:33 2011 +0000
     2.2 +++ b/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs	Sat Aug 13 10:45:06 2011 +0000
     2.3 @@ -67,12 +67,12 @@
     2.4  				settings.ProhibitDtd = true;
     2.5  				settings.ValidationEventHandler+= new ValidationEventHandler(ValidationEventMethod);
     2.6  				XmlSchemaSet cache = new XmlSchemaSet();
     2.7 -				string path =  IBBoard.Constants.ExecutablePath + "/schemas/";
     2.8 -				AddSchemaToCache(cache, NS_BASE + "core", path + "warfoundry-core.xsd");
     2.9 -				AddSchemaToCache(cache, NS_BASE + "cats", path + "warfoundry-cats.xsd");
    2.10 -				AddSchemaToCache(cache, NS_BASE + "race", path + "race.xsd");
    2.11 -				AddSchemaToCache(cache, NS_BASE + "system", path + "system.xsd");
    2.12 -				AddSchemaToCache(cache, NS_BASE + "army", path + "army.xsd");
    2.13 +				string path =  Path.Combine(IBBoard.Constants.ExecutablePath, "schemas");
    2.14 +				AddSchemaToCache(cache, NS_BASE + "core", Path.Combine(path, "warfoundry-core.xsd"));
    2.15 +				AddSchemaToCache(cache, NS_BASE + "cats", Path.Combine(path, "warfoundry-cats.xsd"));
    2.16 +				AddSchemaToCache(cache, NS_BASE + "race", Path.Combine(path, "race.xsd"));
    2.17 +				AddSchemaToCache(cache, NS_BASE + "system", Path.Combine(path, "system.xsd"));
    2.18 +				AddSchemaToCache(cache, NS_BASE + "army", Path.Combine(path, "army.xsd"));
    2.19  				settings.Schemas.Add(cache);
    2.20  				settings.Schemas.CompilationSettings.EnableUpaCheck = false;
    2.21  			}
     3.1 --- a/API/FileLoadFailure.cs	Sun Aug 07 19:15:33 2011 +0000
     3.2 +++ b/API/FileLoadFailure.cs	Sat Aug 13 10:45:06 2011 +0000
     3.3 @@ -99,7 +99,7 @@
     3.4  				{
     3.5  					string fileName = FailedFile.FullName;
     3.6  					string factoryType = (loadingFactory == null ? "" : loadingFactory.GetType().Name);
     3.7 -					if (messageTranslationID == "" || messageTranslationID == null)
     3.8 +					if (String.IsNullOrEmpty(messageTranslationID))
     3.9  					{
    3.10  						message = String.Format(defaultMessage, fileName, factoryType);
    3.11  				 	}
     4.1 --- a/API/Objects/WarFoundryObject.cs	Sun Aug 07 19:15:33 2011 +0000
     4.2 +++ b/API/Objects/WarFoundryObject.cs	Sat Aug 13 10:45:06 2011 +0000
     4.3 @@ -76,7 +76,7 @@
     4.4  
     4.5  		public bool HasDefaultName()
     4.6  		{
     4.7 -			return (name == null || name == "");
     4.8 +			return String.IsNullOrEmpty(name);
     4.9  		}
    4.10  
    4.11  		protected void OnNameChanged(string oldValue, string newValue)