annotate api/Factories/AbstractWarFoundryFactory.cs @ 148:8e636443aa8e

Re #176: Bug when saving recently edited army * Try to make sure that we clear up our open streams
author IBBoard <dev@ibboard.co.uk>
date Sat, 26 Sep 2009 10:14:04 +0000
parents fcbc3beea498
children 1d13820b3d96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 28
diff changeset
1 // This file (AbstractWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 28
diff changeset
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.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.IO;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Collections.Generic;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.WarFoundry.API.Objects;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 namespace IBBoard.WarFoundry.API.Factories
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 public abstract class AbstractWarFoundryFactory<FILE_TYPE> : IWarFoundryFactory
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
13 {
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
14 public virtual void CompleteLoading(IWarFoundryStagedLoadObject obj)
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
15 {
120
fcbc3beea498 * Change default factory behaviour to pretend it has loaded files without changing anything
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
16 //Pretend we've fully loaded, as this will probably be standard for non-native factories and some native factories
fcbc3beea498 * Change default factory behaviour to pretend it has loaded files without changing anything
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
17 obj.SetAsFullyLoaded();
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
18 }
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
19
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 public bool CanHandleFileFormat (FileInfo file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
22 FILE_TYPE typedFile = GetFileAsSupportedType(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
23 return typedFile != null && CheckCanHandleFileFormat(typedFile);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
24 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
25
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
26 public bool CanHandleFileAsRace(FileInfo file)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
27 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
28 FILE_TYPE typedFile = GetFileAsSupportedType(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
29 return typedFile != null && CheckCanHandleFileAsRace(typedFile);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
30 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
31
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
32 public bool CanHandleFileAsGameSystem(FileInfo file)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
33 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
34 FILE_TYPE typedFile = GetFileAsSupportedType(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
35 return typedFile != null && CheckCanHandleFileAsGameSystem(typedFile);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
36 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
37
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
38 public bool CanHandleFileAsArmy(FileInfo file)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
39 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
40 FILE_TYPE typedFile = GetFileAsSupportedType(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
41 return typedFile != null && CheckCanHandleFileAsArmy(typedFile);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 /// Converts the <see cref="FileInfo"/> object in to the appropriate type for this class so that it can perform its checks. If no conversion is required (the test can be performed on a <see cref="FileInfo"/> object) the object should be returned with no modification.
28
e5ea6bfcde83 Re #44 - Fix tests
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
46 /// If the file is not of supported type the <code>null</code> should be returned.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 /// <param name="file">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 /// A <see cref="FileInfo"/> to get the supported source object from.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 /// An object of type <see cref="FILE_TYPE"/> that has been converted from the input <see cref="FileInfo"/> object, or <code>null</code> if the conversion cannot be made.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 protected abstract FILE_TYPE GetFileAsSupportedType(FileInfo file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 /// Checks whether the factory thinks it can load data from the file in its paramaterised type.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 /// <param name="file">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 /// An object of the converted <see cref="FILE_TYPE"/> to check support for
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 /// <code>true</code> if the factory thinks it can support the file, else <code>false</code>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 protected abstract bool CheckCanHandleFileFormat(FILE_TYPE file);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
66
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
67 /// <summary>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
68 /// Checks whether the factory thinks it can load data from the file in its paramaterised type as a Race object.
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
69 /// </summary>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
70 /// <param name="file">
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
71 /// An object of the converted <see cref="FILE_TYPE"/> to check support for
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
72 /// </param>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
73 /// <returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
74 /// <code>true</code> if the factory thinks it can support the file as a Race, else <code>false</code>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
75 /// </returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
76 protected abstract bool CheckCanHandleFileAsRace(FILE_TYPE file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
77
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
78 /// <summary>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
79 /// Checks whether the factory thinks it can load data from the file in its paramaterised type as a GameSystem object.
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
80 /// </summary>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
81 /// <param name="file">
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
82 /// An object of the converted <see cref="FILE_TYPE"/> to check support for
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
83 /// </param>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
84 /// <returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
85 /// <code>true</code> if the factory thinks it can support the file as a GameSystem, else <code>false</code>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
86 /// </returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
87 protected abstract bool CheckCanHandleFileAsGameSystem(FILE_TYPE file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
88
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
89 /// <summary>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
90 /// Checks whether the factory thinks it can load data from the file in its paramaterised type as an Army object.
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
91 /// </summary>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
92 /// <param name="file">
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
93 /// An object of the converted <see cref="FILE_TYPE"/> to check support for
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
94 /// </param>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
95 /// <returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
96 /// <code>true</code> if the factory thinks it can support the file as a Army, else <code>false</code>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
97 /// </returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
98 protected abstract bool CheckCanHandleFileAsArmy(FILE_TYPE file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
99
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 public ICollection<IWarFoundryObject> CreateObjectsFromFile(FileInfo file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 return DoCreateObjectsFromFile(GetFileAsSupportedType(file));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 /// Reads the data from the supplied converted <see cref="FILE_TYPE"/> object and returns it as a collection of loadable objects.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 /// <param name="file">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 /// An object of the converted <see cref="FILE_TYPE"/> for the file to load data from
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 /// A <see cref="ICollection`1"/> of <see cref="IWarFoundryObject"/>s that were loaded from the file object
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 protected abstract ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FILE_TYPE file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 }