comparison API/FileLoadFailure.cs @ 337:3c4a6403a88c

* Fix capitalisation so that new files are in the namespace no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sun, 03 Apr 2011 18:50:32 +0000
parents
children 6da9db4a9c23
comparison
equal deleted inserted replaced
336:3631c1493c7f 337:3c4a6403a88c
1 // This file (FileLoadFailure.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
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.
4
5 using System;
6 using System.IO;
7 using IBBoard.Lang;
8 using IBBoard.WarFoundry.API.Factories;
9
10 namespace IBBoard.WarFoundry.API
11 {
12 /// <summary>
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
14 /// </summary>
15 public class FileLoadFailure
16 {
17 private FileInfo failedFile;
18 private IWarFoundryFactory loadingFactory;
19 private string defaultMessage;
20 private string messageTranslationID;
21 private string message;
22 private Exception cause;
23
24 /// <summary>
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>.
26 /// </summary>
27 /// <param name="file">
28 /// The <see cref="FileInfo"/> that failed to load
29 /// </param>
30 /// <param name="message">
31 /// A message about the failure in English - used as a default fall-back message.
32 /// </param>
33 /// <param name="translationID">
34 /// The ID of a translation for the message.
35 /// </param>
36 public FileLoadFailure(FileInfo file, string message, string translationID) : this (file, null, message, "")
37 {
38 }
39
40 /// <summary>
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>.
42 /// </summary>
43 /// <param name="file">
44 /// The <see cref="FileInfo"/> that failed to load
45 /// </param>
46 /// <param name="factory">
47 /// The <see cref="IWarFoundryFactory"/> that failed to load the file
48 /// </param>
49 /// <param name="message">
50 /// A message about the failure in English - used as a default fall-back message.
51 /// </param>
52 /// <param name="translationID">
53 /// The ID of a translation for the message.
54 /// </param>
55 public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message, string translationID) : this(file, factory, message, translationID, null)
56 {
57 }
58
59 /// <summary>
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>.
61 /// </summary>
62 /// <param name="file">
63 /// The <see cref="FileInfo"/> that failed to load
64 /// </param>
65 /// <param name="factory">
66 /// The <see cref="IWarFoundryFactory"/> that failed to load the file
67 /// </param>
68 /// <param name="message">
69 /// A message about the failure in English - used as a default fall-back message.
70 /// </param>
71 /// <param name="translationID">
72 /// The ID of a translation for the message.
73 /// </param>
74 /// <param name="exception">
75 /// The <see cref="Exception"/> that occurred to cause the load to fail
76 /// </param>
77 public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message, string translationID, Exception exception)
78 {
79 failedFile = file;
80 loadingFactory = factory;
81 defaultMessage = message;
82 messageTranslationID = translationID;
83 cause = exception;
84 }
85
86 public FileInfo FailedFile
87 {
88 get
89 {
90 return failedFile;
91 }
92 }
93
94 public string Message
95 {
96 get
97 {
98 if (message == null)
99 {
100 string fileName = FailedFile.FullName;
101 string factoryType = (loadingFactory == null ? "" : loadingFactory.GetType().Name);
102 if (messageTranslationID == "" || messageTranslationID == null)
103 {
104 message = String.Format(defaultMessage, fileName, factoryType);
105 }
106 else
107 {
108 message = Translation.GetTranslation(messageTranslationID, defaultMessage, fileName, factoryType);
109 }
110 }
111
112 return message;
113 }
114 }
115
116 public Exception Exception
117 {
118 get { return cause; }
119 }
120 }
121 }