annotate api/FileLoadFailure.cs @ 44:db951aad24b9

Re #50 - Complete loading of WarFoundry XML * Fix loading of armour type by fixing typo in Race schema * Revert to an exception if there is a parse error on the armour type (since the schema should validate it)
author IBBoard <dev@ibboard.co.uk>
date Sun, 22 Mar 2009 17:10:49 +0000
parents d7899f462d8c
children 2f3cafb69799
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (FileLoadFailure.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
15
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.IO;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Lang;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.WarFoundry.API.Factories;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 namespace IBBoard.WarFoundry.API
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 {
29
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
12 /// <summary>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
13 /// A container class that holds information about file load failures. Core information covers the file that failed and a message. Additional information includes the factory loading the file and the excetion that was thrown. Messages are passed through <code>String.Format</code> and supplied with the failed file path and the failing factory
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
14 /// </summary>
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 public class FileLoadFailure
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 private FileInfo failedFile;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 private IWarFoundryFactory loadingFactory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 private string defaultMessage;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 private string messageTranslationID;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 private string message;
29
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
22 private Exception cause;
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
23
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
24 /// <summary>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
25 /// Constructor for a failed file load where no factory was found. Translatable messages can be providied through a <code>translationID</code> or skipped by passing <code>null</code>.
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
26 /// </summary>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
27 /// <param name="file">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
28 /// The <see cref="FileInfo"/> that failed to load
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
29 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
30 /// <param name="message">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
31 /// A message about the failure in English - used as a default fall-back message.
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
32 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
33 /// <param name="translationID">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
34 /// The ID of a translation for the message.
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
35 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
36 public FileLoadFailure(FileInfo file, string message, string translationID) : this (file, null, message, "")
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39
29
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
40 /// <summary>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
41 /// Constructor for a failed file load where a factory was identified as supporting the file but failed to load it. Translatable messages can be providied through a <code>translationID</code> or skipped by passing <code>null</code>.
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
42 /// </summary>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
43 /// <param name="file">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
44 /// The <see cref="FileInfo"/> that failed to load
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
45 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
46 /// <param name="factory">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
47 /// The <see cref="IWarFoundryFactory"/> that failed to load the file
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
48 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
49 /// <param name="message">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
50 /// A message about the failure in English - used as a default fall-back message.
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
51 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
52 /// <param name="translationID">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
53 /// The ID of a translation for the message.
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
54 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
55 public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message, string translationID) : this(file, factory, message, translationID, null)
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58
29
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
59 /// <summary>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
60 /// Constructor for a failed file load where a factory was identified as supporting the file but an exception occurred while loading it. Translatable messages can be providied through a <code>translationID</code> or skipped by passing <code>null</code>.
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
61 /// </summary>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
62 /// <param name="file">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
63 /// The <see cref="FileInfo"/> that failed to load
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
64 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
65 /// <param name="factory">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
66 /// The <see cref="IWarFoundryFactory"/> that failed to load the file
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
67 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
68 /// <param name="message">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
69 /// A message about the failure in English - used as a default fall-back message.
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
70 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
71 /// <param name="translationID">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
72 /// The ID of a translation for the message.
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
73 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
74 /// <param name="exception">
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
75 /// The <see cref="Exception"/> that occurred to cause the load to fail
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
76 /// </param>
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
77 public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message, string translationID, Exception exception)
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 failedFile = file;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 loadingFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 defaultMessage = message;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 messageTranslationID = translationID;
29
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
83 cause = exception;
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 public FileInfo FailedFile
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 get
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 return failedFile;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 public string Message
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 get
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 if (message == null)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 {
29
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
100 string fileName = FailedFile.FullName;
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
101 string factoryType = (loadingFactory == null ? "" : loadingFactory.GetType().Name);
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
102 if (messageTranslationID == "" || messageTranslationID == null)
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 {
29
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
104 message = String.Format(defaultMessage, fileName, factoryType);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 else
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 {
29
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
108 message = Translation.GetTranslation(messageTranslationID, defaultMessage, fileName, factoryType);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 return message;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 }
29
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
115
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
116 public Exception Exception
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
117 {
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
118 get { return cause; }
d7899f462d8c Re #11 - Document methods
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
119 }
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121 }