comparison api/FileLoadFailure.cs @ 29:d7899f462d8c

Re #11 - Document methods * Document FileLoadFailure and rationalise constructors Also added parameter for holding the Exception that caused the failure
author IBBoard <dev@ibboard.co.uk>
date Sat, 14 Mar 2009 20:14:07 +0000
parents 306558904c2a
children 2f3cafb69799
comparison
equal deleted inserted replaced
28:e5ea6bfcde83 29:d7899f462d8c
7 using IBBoard.Lang; 7 using IBBoard.Lang;
8 using IBBoard.WarFoundry.API.Factories; 8 using IBBoard.WarFoundry.API.Factories;
9 9
10 namespace IBBoard.WarFoundry.API 10 namespace IBBoard.WarFoundry.API
11 { 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>
12 public class FileLoadFailure 15 public class FileLoadFailure
13 { 16 {
14 private FileInfo failedFile; 17 private FileInfo failedFile;
15 private IWarFoundryFactory loadingFactory; 18 private IWarFoundryFactory loadingFactory;
16 private string defaultMessage; 19 private string defaultMessage;
17 private string messageTranslationID; 20 private string messageTranslationID;
18 private string message; 21 private string message;
19 22 private Exception cause;
20 public FileLoadFailure(FileInfo file, string message) : this (file, message, "") 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, "")
21 { 37 {
22 } 38 }
23 39
24 public FileLoadFailure(FileInfo file, string message, string translationID) : this (file, null, message, "") 40 /// <summary>
25 { 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>.
26 } 42 /// </summary>
27 43 /// <param name="file">
28 public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message) : this (file, factory, message, "") 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)
29 { 56 {
30 } 57 }
31 58
32 public FileLoadFailure(FileInfo file,IWarFoundryFactory factory, string message, string translationID) 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)
33 { 78 {
34 failedFile = file; 79 failedFile = file;
35 loadingFactory = factory; 80 loadingFactory = factory;
36 defaultMessage = message; 81 defaultMessage = message;
37 messageTranslationID = translationID; 82 messageTranslationID = translationID;
83 cause = exception;
38 } 84 }
39 85
40 public FileInfo FailedFile 86 public FileInfo FailedFile
41 { 87 {
42 get 88 get
49 { 95 {
50 get 96 get
51 { 97 {
52 if (message == null) 98 if (message == null)
53 { 99 {
54 if (messageTranslationID == "") 100 string fileName = FailedFile.FullName;
101 string factoryType = (loadingFactory == null ? "" : loadingFactory.GetType().Name);
102 if (messageTranslationID == "" || messageTranslationID == null)
55 { 103 {
56 message = String.Format(defaultMessage, FailedFile, loadingFactory); 104 message = String.Format(defaultMessage, fileName, factoryType);
57 } 105 }
58 else 106 else
59 { 107 {
60 message = Translation.GetTranslation(messageTranslationID, defaultMessage, failedFile, loadingFactory); 108 message = Translation.GetTranslation(messageTranslationID, defaultMessage, fileName, factoryType);
61 } 109 }
62 } 110 }
63 111
64 return message; 112 return message;
65 } 113 }
66 } 114 }
115
116 public Exception Exception
117 {
118 get { return cause; }
119 }
67 } 120 }
68 } 121 }