# HG changeset patch # User IBBoard # Date 1235227155 0 # Node ID 57451981545c3272299c64674f26cb7f7a2254d4 # Parent 3c228f093a71cbadb7200c2556b823d48fce922c Re #10 and re #11 - Refactor code and document code * Split LoadFile method out in to smaller methods * Document possible exception from IWarFoundryFactory object loading method * Catch exception in WarFoundryLoader file loading diff -r 3c228f093a71 -r 57451981545c api/Factories/IWarFoundryFactory.cs --- a/api/Factories/IWarFoundryFactory.cs Sat Feb 21 14:23:53 2009 +0000 +++ b/api/Factories/IWarFoundryFactory.cs Sat Feb 21 14:39:15 2009 +0000 @@ -65,6 +65,7 @@ /// /// Reads the data from the supplied file and returns it as a collection of loadable objects. + /// May throw a if the file is supported by the Factory but the content is invalid. /// /// /// A for the file to load data from diff -r 3c228f093a71 -r 57451981545c api/WarFoundryLoader.cs --- a/api/WarFoundryLoader.cs Sat Feb 21 14:23:53 2009 +0000 +++ b/api/WarFoundryLoader.cs Sat Feb 21 14:39:15 2009 +0000 @@ -345,9 +345,41 @@ /// public ICollection LoadFile(FileInfo file) { - ICollection objs = null; + ICollection objs = null; IWarFoundryFactory loadFactory = null; + try + { + objs = LoadFileWithNonNativeFactories(file, out loadFactory); + + if (objs == null) + { + objs = LoadFileWithNativeFactories(file, out loadFactory); + } + } + catch (InvalidFileException ex) + { + LogNotifier.Error(GetType(), file.FullName+" failed to load: "+ex.Message); + } + + if (objs!=null) + { + AddLoadedObjects(objs, loadFactory); + } + else + { + LogNotifier.Debug(GetType(), "Could not load "+file.FullName); + objs = new List(); + } + + return objs; + } + + private ICollection LoadFileWithNonNativeFactories(FileInfo file, out IWarFoundryFactory loadFactory) + { + ICollection objs = null; + loadFactory = null; + if (nonNativeFactories.Count > 0) { LogNotifier.Debug(GetType(), "Attempting to load "+file.FullName+" as a non-native file"); @@ -370,10 +402,18 @@ } } - if (objs == null) + return objs; + } + + private ICollection LoadFileWithNativeFactories(FileInfo file, out IWarFoundryFactory loadFactory) + { + ICollection objs = null; + loadFactory = null; + + if (factories.Count > 0) { LogNotifier.Debug(GetType(), "Attempting to load "+file.FullName+" as native file"); - + foreach (INativeWarFoundryFactory factory in factories) { if (factory.CanHandleFileFormat(file)) @@ -388,17 +428,7 @@ } } } - - if (objs!=null) - { - AddLoadedObjects(objs, loadFactory); - } - else - { - LogNotifier.Debug(GetType(), "Loading of "+file.FullName+" failed"); - objs = new List(); - } - + return objs; }