Mercurial > repos > IBDev-IBBoard.WarFoundry.API
changeset 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 | 159dc9be36c2 |
children | 59e1fb8a476a |
files | API/AbstractWarFoundryLoader.cs API/Factories/AbstractNativeWarFoundryFactory.cs API/Factories/AbstractNonNativeFileExtensionWarFoundryFactory.cs API/Factories/Xml/WarFoundryXmlFactory.cs API/Objects/Category.cs API/Objects/UnitType.cs API/WarFoundryCore.cs |
diffstat | 7 files changed, 46 insertions(+), 97 deletions(-) [+] |
line wrap: on
line diff
--- a/API/AbstractWarFoundryLoader.cs Tue Mar 06 20:31:31 2012 +0000 +++ b/API/AbstractWarFoundryLoader.cs Sat Mar 17 20:02:32 2012 +0000 @@ -1,13 +1,11 @@ // This file (AbstractWarFoundryLoader.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; using System.Collections.Generic; using System.IO; using IBBoard.Collections; using IBBoard.IO; -using IBBoard.Logging; using IBBoard.WarFoundry.API.Factories; using IBBoard.WarFoundry.API.Objects; @@ -26,7 +24,6 @@ public delegate void FileLoadingCompleteDelegate(List<FileLoadFailure> failures); public event MethodInvoker FileLoadingStarted; - public event FileLoadingCompleteDelegate FileLoadingFinished; protected AbstractWarFoundryLoader() @@ -180,10 +177,6 @@ List<FileLoadFailure> directoryFails = FillLoadableFilesForDirectory(loadableRaces, loadableGameSystems, directory); fails.AddRange(directoryFails); } - else - { - LogNotifier.WarnFormat(GetType(), "Load for {0} failed because directory didn't exist", directory.FullName); - } } return fails; @@ -192,7 +185,6 @@ private List<FileLoadFailure> FillLoadableFilesForDirectory(Dictionary<FileInfo, IWarFoundryFactory> loadableRaces, Dictionary<FileInfo, IWarFoundryFactory> loadableGameSystems, DirectoryInfo directory) { List<FileLoadFailure> fails = new List<FileLoadFailure>(); - LogNotifier.Debug(GetType(), "Load from " + directory.FullName); foreach (FileInfo file in directory.GetFiles()) { @@ -214,7 +206,6 @@ { FileLoadFailure failure = new FileLoadFailure(file, "File not handled as a Race or Game System definition: {0}", "FileNotHandled"); fails.Add(failure); - LogNotifier.Info(GetType(), failure.Message); } } } @@ -309,7 +300,6 @@ if (failure != null) { fails.Add(failure); - LogNotifier.Warn(GetType(), failure.Message, failure.Exception); } } @@ -341,7 +331,6 @@ if (failure != null) { fails.Add(failure); - LogNotifier.Warn(GetType(), failure.Message, failure.Exception); } } @@ -350,9 +339,8 @@ private bool LoadObject(FileInfo file, IWarFoundryFactory factory) { - LogNotifier.DebugFormat(GetType(), "Loading {0} using {1}", file.FullName, factory.GetType().Name); - factory.RaceLoaded+= StoreRace; - factory.GameSystemLoaded+= StoreGameSystem; + factory.RaceLoaded += StoreRace; + factory.GameSystemLoaded += StoreGameSystem; ICollection<IWarFoundryObject> objects = factory.CreateObjectsFromFile(file); return objects.Count > 0; } @@ -369,21 +357,12 @@ /// </returns> public ICollection<IWarFoundryObject> LoadFile(FileInfo file) { - ICollection<IWarFoundryObject> objs = null; IWarFoundryFactory loadFactory = null; - - try - { - objs = LoadFileWithNonNativeFactories(file, out loadFactory); + ICollection<IWarFoundryObject> objs = LoadFileWithNonNativeFactories(file, out loadFactory); - if (objs == null) - { - objs = LoadFileWithNativeFactories(file, out loadFactory); - } - } - catch (InvalidFileException ex) + if (objs == null) { - LogNotifier.Error(GetType(), file.FullName + " failed to load", ex); + objs = LoadFileWithNativeFactories(file, out loadFactory); } if (objs != null) @@ -405,12 +384,9 @@ if (nonNativeFactories.Count > 0) { - LogNotifier.Debug(GetType(), "Attempting to load " + file.FullName + " as a non-native file"); - foreach (INonNativeWarFoundryFactory factory in nonNativeFactories) { bool canLoad = factory.CanHandleFileFormat(file); - LogNotifier.Debug(GetType(), "Load using " + factory.GetType().FullName + "? " + (canLoad ? "yes" : "no")); if (canLoad) { @@ -435,8 +411,6 @@ if (factories.Count > 0) { - LogNotifier.Debug(GetType(), "Attempting to load " + file.FullName + " as native file"); - foreach (INativeWarFoundryFactory factory in factories) { if (factory.CanHandleFileFormat(file))
--- a/API/Factories/AbstractNativeWarFoundryFactory.cs Tue Mar 06 20:31:31 2012 +0000 +++ b/API/Factories/AbstractNativeWarFoundryFactory.cs Sat Mar 17 20:02:32 2012 +0000 @@ -1,7 +1,6 @@ // This file (AbstractNativeWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 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; using System.IO; using System.Xml; @@ -11,7 +10,6 @@ using IBBoard; using IBBoard.IO; using IBBoard.Lang; -using IBBoard.Logging; using IBBoard.Xml; using IBBoard.WarFoundry.API.Objects; using ICSharpCode.SharpZipLib.Zip; @@ -52,7 +50,7 @@ return zip; } - protected override bool CheckCanHandleFileFormat (ZipFile file) + protected override bool CheckCanHandleFileFormat(ZipFile file) { return CheckCanHandleFileAsGameSystem(file) || CheckCanHandleFileAsRace(file) || CheckCanHandleFileAsArmy(file); } @@ -78,7 +76,7 @@ protected abstract bool CheckCanFindArmyFileContent(ZipFile file); - protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile (ZipFile file) + protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile(ZipFile file) { ICollection<IWarFoundryObject> objects = new List<IWarFoundryObject>(); @@ -94,9 +92,9 @@ { try { - CreateSystemObjectsFromZip (file, objects); - CreateRaceObjectsFromZip (file, objects); - CreateArmyObjectsFromZip (file, objects); + CreateSystemObjectsFromZip(file, objects); + CreateRaceObjectsFromZip(file, objects); + CreateArmyObjectsFromZip(file, objects); } finally { @@ -104,7 +102,7 @@ } } - private void CreateSystemObjectsFromZip (ZipFile file, ICollection<IWarFoundryObject> objects) + private void CreateSystemObjectsFromZip(ZipFile file, ICollection<IWarFoundryObject> objects) { if (CheckCanFindSystemFileContent(file)) { @@ -116,11 +114,11 @@ } } - void CreateRaceObjectsFromZip (ZipFile file, ICollection<IWarFoundryObject> objects) + void CreateRaceObjectsFromZip(ZipFile file, ICollection<IWarFoundryObject> objects) { if (CheckCanFindRaceFileContent(file)) { - foreach(Race race in CreateRacesFromFile(file)) + foreach (Race race in CreateRacesFromFile(file)) { OnRaceLoaded(race); objects.Add(race); @@ -128,7 +126,7 @@ } } - void CreateArmyObjectsFromZip (ZipFile file, ICollection<IWarFoundryObject> objects) + void CreateArmyObjectsFromZip(ZipFile file, ICollection<IWarFoundryObject> objects) { if (CheckCanFindArmyFileContent(file)) { @@ -169,6 +167,7 @@ } protected abstract ICollection<ZipEntry> GetArmyZipEntries(ZipFile file); + protected abstract Army CreateArmyFromStream(ZipFile file, Stream dataStream); protected ICollection<Race> CreateRacesFromFile(ZipFile file) @@ -193,6 +192,7 @@ } protected abstract ICollection<ZipEntry> GetRaceZipEntries(ZipFile file); + protected abstract Race CreateRaceFromStream(ZipFile file, Stream dataStream); protected ICollection<GameSystem> CreateGameSystemsFromFile(ZipFile file) @@ -217,9 +217,10 @@ } protected abstract ICollection<ZipEntry> GetGameSystemZipEntries(ZipFile file); + protected abstract GameSystem CreateGameSystemFromStream(ZipFile file, Stream dataStream); - public override bool Equals (object o) + public override bool Equals(object o) { if (o == this) { @@ -233,7 +234,7 @@ return true; } - public override int GetHashCode () + public override int GetHashCode() { return GetType().FullName.GetHashCode(); }
--- a/API/Factories/AbstractNonNativeFileExtensionWarFoundryFactory.cs Tue Mar 06 20:31:31 2012 +0000 +++ b/API/Factories/AbstractNonNativeFileExtensionWarFoundryFactory.cs Sat Mar 17 20:02:32 2012 +0000 @@ -1,11 +1,9 @@ // This file (AbstractNonNativeFileExtensionWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 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; using System.Collections.Generic; using System.IO; -using IBBoard.Logging; using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.API.Factories @@ -13,64 +11,64 @@ public abstract class AbstractNonNativeFileExtensionWarFoundryFactory : AbstractNonNativeWarFoundryFactory<FileInfo> { protected abstract string ArmyFileExtension { get; } + protected abstract string RaceFileExtension { get; } + protected abstract string GameSystemFileExtension { get; } - protected override bool CheckCanHandleFileFormat (FileInfo file) + protected override bool CheckCanHandleFileFormat(FileInfo file) { return CheckCanHandleFileAsArmy(file) || CheckCanHandleFileAsRace(file) || CheckCanHandleFileAsGameSystem(file); } protected override bool CheckCanHandleFileAsArmy(FileInfo file) { - return ArmyFileExtension!=null && file.Name.ToLower().EndsWith(ArmyFileExtension); + return ArmyFileExtension != null && file.Name.ToLower().EndsWith(ArmyFileExtension); } protected override bool CheckCanHandleFileAsRace(FileInfo file) { - return RaceFileExtension!=null && file.Name.ToLower().EndsWith(RaceFileExtension); + return RaceFileExtension != null && file.Name.ToLower().EndsWith(RaceFileExtension); } protected override bool CheckCanHandleFileAsGameSystem(FileInfo file) { - return GameSystemFileExtension!=null && file.Name.ToLower().EndsWith(GameSystemFileExtension); + return GameSystemFileExtension != null && file.Name.ToLower().EndsWith(GameSystemFileExtension); } - protected override FileInfo GetFileAsSupportedType (FileInfo file) + protected override FileInfo GetFileAsSupportedType(FileInfo file) { return file; - } + } protected abstract Army CreateArmyFromFile(FileInfo file); + protected abstract Race CreateRaceFromFile(FileInfo file); + protected abstract GameSystem CreateGameSystemFromFile(FileInfo file); - protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile (FileInfo file) + protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FileInfo file) { IWarFoundryObject obj = null; if (CheckCanHandleFileAsGameSystem(file)) { - GameSystem gameSystem = CreateGameSystemFromFile (file); + GameSystem gameSystem = CreateGameSystemFromFile(file); OnGameSystemLoaded(gameSystem); obj = gameSystem; } else if (CheckCanHandleFileAsRace(file)) { - Race race = CreateRaceFromFile (file); + Race race = CreateRaceFromFile(file); OnRaceLoaded(race); obj = race; } - else if (CheckCanHandleFileAsArmy(file)) + else //Must have been an army file { - Army army = CreateArmyFromFile (file); + Army army = CreateArmyFromFile(file); OnArmyLoaded(army); obj = army; } - else - { - LogNotifier.Warn(GetType(), "Failed trying to create from "+file.FullName+" - not a Race, Army or GameSystem"); - } ICollection<IWarFoundryObject> objects = new List<IWarFoundryObject>();
--- a/API/Factories/Xml/WarFoundryXmlFactory.cs Tue Mar 06 20:31:31 2012 +0000 +++ b/API/Factories/Xml/WarFoundryXmlFactory.cs Sat Mar 17 20:02:32 2012 +0000 @@ -1,7 +1,6 @@ // This file (WarFoundryXmlFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 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; using System.IO; using System.Xml; @@ -12,7 +11,6 @@ using IBBoard; using IBBoard.IO; using IBBoard.Lang; -using IBBoard.Logging; using IBBoard.Xml; using IBBoard.WarFoundry.API.Objects; using ICSharpCode.SharpZipLib.Zip; @@ -98,7 +96,7 @@ return entries; } - protected override Army CreateArmyFromStream (ZipFile file, Stream dataStream) + protected override Army CreateArmyFromStream(ZipFile file, Stream dataStream) { XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.ARMY_ELEMENT); return armyFactory.CreateArmyFromElement(file, elem); @@ -123,10 +121,9 @@ return FindEntries(file, "*.systemx"); } - protected override GameSystem CreateGameSystemFromStream (ZipFile file, Stream dataStream) + protected override GameSystem CreateGameSystemFromStream(ZipFile file, Stream dataStream) { XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.SYSTEM_ELEMENT); - LogNotifier.Debug(GetType(), "Create GameSystem"); return gameSystemFactory.CreateSystemFromElement(file, elem); } @@ -135,10 +132,9 @@ return FindEntries(file, "*.racex"); } - protected override Race CreateRaceFromStream (ZipFile file, Stream dataStream) + protected override Race CreateRaceFromStream(ZipFile file, Stream dataStream) { XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.RACE_ELEMENT); - LogNotifier.Debug(GetType(), "Create Race"); return raceFactory.CreateRace(elem); } @@ -148,16 +144,14 @@ } public override void CompleteLoading(IWarFoundryStagedLoadObject obj) - { - LogNotifier.DebugFormat(GetType(), "Complete loading of {0} with ID {1}", obj.GetType().Name, obj.ID); - + { if (obj is GameSystem) { - CompleteLoadingGameSystem((GameSystem) obj); + CompleteLoadingGameSystem((GameSystem)obj); } else if (obj is Race) { - CompleteLoadingRace((Race) obj); + CompleteLoadingRace((Race)obj); } }
--- a/API/Objects/Category.cs Tue Mar 06 20:31:31 2012 +0000 +++ b/API/Objects/Category.cs Sat Mar 17 20:02:32 2012 +0000 @@ -1,10 +1,8 @@ // This file (Category.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 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; using System.Xml; -using IBBoard.Logging; namespace IBBoard.WarFoundry.API.Objects { @@ -17,7 +15,6 @@ private int maxPts = WarFoundryCore.INFINITY; private int minPc = 0; private int maxPc = 100; - public Category(string id, string name) : base(id, name) { @@ -59,10 +56,9 @@ /// </summary> private void CheckMinimumPoints() { - if (MinimumPoints > MaximumPoints && MaximumPoints!=WarFoundryCore.INFINITY) + if (MinimumPoints > MaximumPoints && MaximumPoints != WarFoundryCore.INFINITY) { MinimumPoints = MaximumPoints; - LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum points limit greater than its maximum points limit.", Name, ID); } } @@ -112,7 +108,6 @@ if (MinimumPercentage > MaximumPercentage) { MinimumPercentage = MaximumPercentage; - LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID); } } }
--- a/API/Objects/UnitType.cs Tue Mar 06 20:31:31 2012 +0000 +++ b/API/Objects/UnitType.cs Sat Mar 17 20:02:32 2012 +0000 @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Xml; using IBBoard.Limits; -using IBBoard.Logging; using IBBoard.WarFoundry.API.Objects.Requirement; namespace IBBoard.WarFoundry.API.Objects @@ -191,7 +190,6 @@ if (MinNumber > MaxNumber && MaxNumber != WarFoundryCore.INFINITY) { MinNumber = MaxNumber; - LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum number greater than their maximum number.", Name, ID); } } @@ -203,7 +201,6 @@ if (MinSize > MaxSize && MaxSize != WarFoundryCore.INFINITY) { MinSize = MaxSize; - LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum size greater than their maximum size.", Name, ID); } }
--- a/API/WarFoundryCore.cs Tue Mar 06 20:31:31 2012 +0000 +++ b/API/WarFoundryCore.cs Sat Mar 17 20:02:32 2012 +0000 @@ -1,9 +1,7 @@ // This file (WarFoundryCore.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 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; -using IBBoard.Logging; using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.API @@ -16,6 +14,7 @@ } public static readonly int INFINITY = -1; + public static event GameSystemChangedDelegate GameSystemChanged; public static event ArmyChangedDelegate ArmyChanged; @@ -27,21 +26,12 @@ get { return system; } set { - if (system==null || !system.Equals(value)) + if (system == null || !system.Equals(value)) { GameSystem oldSystem = system; system = value; - - if (system==null) - { - LogNotifier.Debug(typeof(WarFoundryCore), "Game system set to null"); - } - else - { - LogNotifier.DebugFormat(typeof(WarFoundryCore), "Game system set to {0} with ID {1}", system.Name, system.ID); - } - if (GameSystemChanged!=null) + if (GameSystemChanged != null) { GameSystemChanged(oldSystem, system); } @@ -57,7 +47,7 @@ get { return currentArmy; } set { - if (currentArmy==null || !currentArmy.Equals(value)) + if (currentArmy == null || !currentArmy.Equals(value)) { Army oldArmy = currentArmy; @@ -71,7 +61,7 @@ currentArmy = null; } - if (ArmyChanged!=null) + if (ArmyChanged != null) { ArmyChanged(oldArmy, currentArmy); }