Mercurial > repos > IBBoard.WarFoundry.API
changeset 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 | e5ea6bfcde83 |
children | 92cf25b0493b |
files | api/FileLoadFailure.cs |
diffstat | 1 files changed, 64 insertions(+), 11 deletions(-) [+] |
line diff
1.1 --- a/api/FileLoadFailure.cs Sat Mar 14 19:18:43 2009 +0000 1.2 +++ b/api/FileLoadFailure.cs Sat Mar 14 20:14:07 2009 +0000 1.3 @@ -9,6 +9,9 @@ 1.4 1.5 namespace IBBoard.WarFoundry.API 1.6 { 1.7 + /// <summary> 1.8 + /// 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 1.9 + /// </summary> 1.10 public class FileLoadFailure 1.11 { 1.12 private FileInfo failedFile; 1.13 @@ -16,25 +19,68 @@ 1.14 private string defaultMessage; 1.15 private string messageTranslationID; 1.16 private string message; 1.17 - 1.18 - public FileLoadFailure(FileInfo file, string message) : this (file, message, "") 1.19 + private Exception cause; 1.20 + 1.21 + /// <summary> 1.22 + /// 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>. 1.23 + /// </summary> 1.24 + /// <param name="file"> 1.25 + /// The <see cref="FileInfo"/> that failed to load 1.26 + /// </param> 1.27 + /// <param name="message"> 1.28 + /// A message about the failure in English - used as a default fall-back message. 1.29 + /// </param> 1.30 + /// <param name="translationID"> 1.31 + /// The ID of a translation for the message. 1.32 + /// </param> 1.33 + public FileLoadFailure(FileInfo file, string message, string translationID) : this (file, null, message, "") 1.34 { 1.35 } 1.36 1.37 - public FileLoadFailure(FileInfo file, string message, string translationID) : this (file, null, message, "") 1.38 - { 1.39 - } 1.40 - 1.41 - public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message) : this (file, factory, message, "") 1.42 + /// <summary> 1.43 + /// 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>. 1.44 + /// </summary> 1.45 + /// <param name="file"> 1.46 + /// The <see cref="FileInfo"/> that failed to load 1.47 + /// </param> 1.48 + /// <param name="factory"> 1.49 + /// The <see cref="IWarFoundryFactory"/> that failed to load the file 1.50 + /// </param> 1.51 + /// <param name="message"> 1.52 + /// A message about the failure in English - used as a default fall-back message. 1.53 + /// </param> 1.54 + /// <param name="translationID"> 1.55 + /// The ID of a translation for the message. 1.56 + /// </param> 1.57 + public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message, string translationID) : this(file, factory, message, translationID, null) 1.58 { 1.59 } 1.60 1.61 - public FileLoadFailure(FileInfo file,IWarFoundryFactory factory, string message, string translationID) 1.62 + /// <summary> 1.63 + /// 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>. 1.64 + /// </summary> 1.65 + /// <param name="file"> 1.66 + /// The <see cref="FileInfo"/> that failed to load 1.67 + /// </param> 1.68 + /// <param name="factory"> 1.69 + /// The <see cref="IWarFoundryFactory"/> that failed to load the file 1.70 + /// </param> 1.71 + /// <param name="message"> 1.72 + /// A message about the failure in English - used as a default fall-back message. 1.73 + /// </param> 1.74 + /// <param name="translationID"> 1.75 + /// The ID of a translation for the message. 1.76 + /// </param> 1.77 + /// <param name="exception"> 1.78 + /// The <see cref="Exception"/> that occurred to cause the load to fail 1.79 + /// </param> 1.80 + public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message, string translationID, Exception exception) 1.81 { 1.82 failedFile = file; 1.83 loadingFactory = factory; 1.84 defaultMessage = message; 1.85 messageTranslationID = translationID; 1.86 + cause = exception; 1.87 } 1.88 1.89 public FileInfo FailedFile 1.90 @@ -51,18 +97,25 @@ 1.91 { 1.92 if (message == null) 1.93 { 1.94 - if (messageTranslationID == "") 1.95 + string fileName = FailedFile.FullName; 1.96 + string factoryType = (loadingFactory == null ? "" : loadingFactory.GetType().Name); 1.97 + if (messageTranslationID == "" || messageTranslationID == null) 1.98 { 1.99 - message = String.Format(defaultMessage, FailedFile, loadingFactory); 1.100 + message = String.Format(defaultMessage, fileName, factoryType); 1.101 } 1.102 else 1.103 { 1.104 - message = Translation.GetTranslation(messageTranslationID, defaultMessage, failedFile, loadingFactory); 1.105 + message = Translation.GetTranslation(messageTranslationID, defaultMessage, fileName, factoryType); 1.106 } 1.107 } 1.108 1.109 return message; 1.110 } 1.111 } 1.112 + 1.113 + public Exception Exception 1.114 + { 1.115 + get { return cause; } 1.116 + } 1.117 } 1.118 }