comparison API/Factories/Xml/WarFoundryXmlFactory.cs @ 463:cbeee87dc2d3

Re #58: Remove LogNotifier from API * Remove LogNotifier from API - mostly unnecessary logging Also: * Formatting auto-corrected * LoadFile() "try...catch {silently dispose}" removed. Code shouldn't be throwing those errors and needs to be handled elsewhere if it does
author IBBoard <dev@ibboard.co.uk>
date Sat, 17 Mar 2012 20:02:32 +0000
parents 86725e88052e
children
comparison
equal deleted inserted replaced
462:159dc9be36c2 463:cbeee87dc2d3
1 // This file (WarFoundryXmlFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. 1 // This file (WarFoundryXmlFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
2 // 2 //
3 // 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. 3 // 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.
4
5 using System; 4 using System;
6 using System.IO; 5 using System.IO;
7 using System.Xml; 6 using System.Xml;
8 using System.Xml.Schema; 7 using System.Xml.Schema;
9 using System.Xml.XPath; 8 using System.Xml.XPath;
10 using System.Collections.Generic; 9 using System.Collections.Generic;
11 using System.Text; 10 using System.Text;
12 using IBBoard; 11 using IBBoard;
13 using IBBoard.IO; 12 using IBBoard.IO;
14 using IBBoard.Lang; 13 using IBBoard.Lang;
15 using IBBoard.Logging;
16 using IBBoard.Xml; 14 using IBBoard.Xml;
17 using IBBoard.WarFoundry.API.Objects; 15 using IBBoard.WarFoundry.API.Objects;
18 using ICSharpCode.SharpZipLib.Zip; 16 using ICSharpCode.SharpZipLib.Zip;
19 using System.Text.RegularExpressions; 17 using System.Text.RegularExpressions;
20 18
96 } 94 }
97 95
98 return entries; 96 return entries;
99 } 97 }
100 98
101 protected override Army CreateArmyFromStream (ZipFile file, Stream dataStream) 99 protected override Army CreateArmyFromStream(ZipFile file, Stream dataStream)
102 { 100 {
103 XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.ARMY_ELEMENT); 101 XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.ARMY_ELEMENT);
104 return armyFactory.CreateArmyFromElement(file, elem); 102 return armyFactory.CreateArmyFromElement(file, elem);
105 } 103 }
106 104
121 protected override ICollection<ZipEntry> GetGameSystemZipEntries(ZipFile file) 119 protected override ICollection<ZipEntry> GetGameSystemZipEntries(ZipFile file)
122 { 120 {
123 return FindEntries(file, "*.systemx"); 121 return FindEntries(file, "*.systemx");
124 } 122 }
125 123
126 protected override GameSystem CreateGameSystemFromStream (ZipFile file, Stream dataStream) 124 protected override GameSystem CreateGameSystemFromStream(ZipFile file, Stream dataStream)
127 { 125 {
128 XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.SYSTEM_ELEMENT); 126 XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.SYSTEM_ELEMENT);
129 LogNotifier.Debug(GetType(), "Create GameSystem");
130 return gameSystemFactory.CreateSystemFromElement(file, elem); 127 return gameSystemFactory.CreateSystemFromElement(file, elem);
131 } 128 }
132 129
133 protected override ICollection<ZipEntry> GetRaceZipEntries(ZipFile file) 130 protected override ICollection<ZipEntry> GetRaceZipEntries(ZipFile file)
134 { 131 {
135 return FindEntries(file, "*.racex"); 132 return FindEntries(file, "*.racex");
136 } 133 }
137 134
138 protected override Race CreateRaceFromStream (ZipFile file, Stream dataStream) 135 protected override Race CreateRaceFromStream(ZipFile file, Stream dataStream)
139 { 136 {
140 XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.RACE_ELEMENT); 137 XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.RACE_ELEMENT);
141 LogNotifier.Debug(GetType(), "Create Race");
142 return raceFactory.CreateRace(elem); 138 return raceFactory.CreateRace(elem);
143 } 139 }
144 140
145 protected override void CleanUpFileAsSupportedType(ZipFile typedFile) 141 protected override void CleanUpFileAsSupportedType(ZipFile typedFile)
146 { 142 {
147 typedFile.Close(); 143 typedFile.Close();
148 } 144 }
149 145
150 public override void CompleteLoading(IWarFoundryStagedLoadObject obj) 146 public override void CompleteLoading(IWarFoundryStagedLoadObject obj)
151 { 147 {
152 LogNotifier.DebugFormat(GetType(), "Complete loading of {0} with ID {1}", obj.GetType().Name, obj.ID);
153
154 if (obj is GameSystem) 148 if (obj is GameSystem)
155 { 149 {
156 CompleteLoadingGameSystem((GameSystem) obj); 150 CompleteLoadingGameSystem((GameSystem)obj);
157 } 151 }
158 else if (obj is Race) 152 else if (obj is Race)
159 { 153 {
160 CompleteLoadingRace((Race) obj); 154 CompleteLoadingRace((Race)obj);
161 } 155 }
162 } 156 }
163 157
164 private void CompleteLoadingRace(Race race) 158 private void CompleteLoadingRace(Race race)
165 { 159 {