Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison API/FileLoadFailure.cs @ 482:1ed2f3ab5e35
Re #419: Remove assumptions of a file-based install
* Swap API to using new "loadable object" and "loadable object source" wrappers to allow file-based or memory-based loading
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 07 Jul 2012 21:01:32 +0100 |
parents | 6da9db4a9c23 |
children |
comparison
equal
deleted
inserted
replaced
481:81f32062c9fa | 482:1ed2f3ab5e35 |
---|---|
4 | 4 |
5 using System; | 5 using System; |
6 using System.IO; | 6 using System.IO; |
7 using IBBoard.Lang; | 7 using IBBoard.Lang; |
8 using IBBoard.WarFoundry.API.Factories; | 8 using IBBoard.WarFoundry.API.Factories; |
9 using IBBoard.WarFoundry.API.Loading; | |
9 | 10 |
10 namespace IBBoard.WarFoundry.API | 11 namespace IBBoard.WarFoundry.API |
11 { | 12 { |
12 /// <summary> | 13 /// <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 /// 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 /// </summary> |
15 public class FileLoadFailure | 16 public class FileLoadFailure |
16 { | 17 { |
17 private FileInfo failedFile; | 18 private ILoadableObject failedFile; |
18 private IWarFoundryFactory loadingFactory; | 19 private IWarFoundryFactory loadingFactory; |
19 private string defaultMessage; | 20 private string defaultMessage; |
20 private string messageTranslationID; | 21 private string messageTranslationID; |
21 private string message; | 22 private string message; |
22 private Exception cause; | 23 private Exception cause; |
23 | 24 |
24 /// <summary> | 25 /// <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 /// 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 /// </summary> |
27 /// <param name="file"> | 28 /// <param name="file"> |
28 /// The <see cref="FileInfo"/> that failed to load | 29 /// The <see cref="ILoadableObject"/> that failed to load |
29 /// </param> | 30 /// </param> |
30 /// <param name="message"> | 31 /// <param name="message"> |
31 /// A message about the failure in English - used as a default fall-back message. | 32 /// A message about the failure in English - used as a default fall-back message. |
32 /// </param> | 33 /// </param> |
33 /// <param name="translationID"> | 34 /// <param name="translationID"> |
34 /// The ID of a translation for the message. | 35 /// The ID of a translation for the message. |
35 /// </param> | 36 /// </param> |
36 public FileLoadFailure(FileInfo file, string message, string translationID) : this (file, null, message, "") | 37 public FileLoadFailure(ILoadableObject file, string message, string translationID) : this (file, null, message, "") |
37 { | 38 { |
38 } | 39 } |
39 | 40 |
40 /// <summary> | 41 /// <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 /// 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 /// </summary> |
43 /// <param name="file"> | 44 /// <param name="file"> |
44 /// The <see cref="FileInfo"/> that failed to load | 45 /// The <see cref="ILoadableObject"/> that failed to load |
45 /// </param> | 46 /// </param> |
46 /// <param name="factory"> | 47 /// <param name="factory"> |
47 /// The <see cref="IWarFoundryFactory"/> that failed to load the file | 48 /// The <see cref="IWarFoundryFactory"/> that failed to load the file |
48 /// </param> | 49 /// </param> |
49 /// <param name="message"> | 50 /// <param name="message"> |
50 /// A message about the failure in English - used as a default fall-back message. | 51 /// A message about the failure in English - used as a default fall-back message. |
51 /// </param> | 52 /// </param> |
52 /// <param name="translationID"> | 53 /// <param name="translationID"> |
53 /// The ID of a translation for the message. | 54 /// The ID of a translation for the message. |
54 /// </param> | 55 /// </param> |
55 public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message, string translationID) : this(file, factory, message, translationID, null) | 56 public FileLoadFailure(ILoadableObject file, IWarFoundryFactory factory, string message, string translationID) : this(file, factory, message, translationID, null) |
56 { | 57 { |
57 } | 58 } |
58 | 59 |
59 /// <summary> | 60 /// <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 /// 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 /// </summary> |
62 /// <param name="file"> | 63 /// <param name="file"> |
63 /// The <see cref="FileInfo"/> that failed to load | 64 /// The <see cref="ILoadableObject"/> that failed to load |
64 /// </param> | 65 /// </param> |
65 /// <param name="factory"> | 66 /// <param name="factory"> |
66 /// The <see cref="IWarFoundryFactory"/> that failed to load the file | 67 /// The <see cref="IWarFoundryFactory"/> that failed to load the file |
67 /// </param> | 68 /// </param> |
68 /// <param name="message"> | 69 /// <param name="message"> |
72 /// The ID of a translation for the message. | 73 /// The ID of a translation for the message. |
73 /// </param> | 74 /// </param> |
74 /// <param name="exception"> | 75 /// <param name="exception"> |
75 /// The <see cref="Exception"/> that occurred to cause the load to fail | 76 /// The <see cref="Exception"/> that occurred to cause the load to fail |
76 /// </param> | 77 /// </param> |
77 public FileLoadFailure(FileInfo file, IWarFoundryFactory factory, string message, string translationID, Exception exception) | 78 public FileLoadFailure(ILoadableObject file, IWarFoundryFactory factory, string message, string translationID, Exception exception) |
78 { | 79 { |
79 failedFile = file; | 80 failedFile = file; |
80 loadingFactory = factory; | 81 loadingFactory = factory; |
81 defaultMessage = message; | 82 defaultMessage = message; |
82 messageTranslationID = translationID; | 83 messageTranslationID = translationID; |
83 cause = exception; | 84 cause = exception; |
84 } | 85 } |
85 | 86 |
86 public FileInfo FailedFile | 87 public ILoadableObject FailedFile |
87 { | 88 { |
88 get | 89 get |
89 { | 90 { |
90 return failedFile; | 91 return failedFile; |
91 } | 92 } |
95 { | 96 { |
96 get | 97 get |
97 { | 98 { |
98 if (message == null) | 99 if (message == null) |
99 { | 100 { |
100 string fileName = FailedFile.FullName; | 101 string fileName = FailedFile.Name; |
101 string factoryType = (loadingFactory == null ? "" : loadingFactory.GetType().Name); | 102 string factoryType = (loadingFactory == null ? "" : loadingFactory.GetType().Name); |
102 if (String.IsNullOrEmpty(messageTranslationID)) | 103 if (String.IsNullOrEmpty(messageTranslationID)) |
103 { | 104 { |
104 message = String.Format(defaultMessage, fileName, factoryType); | 105 message = String.Format(defaultMessage, fileName, factoryType); |
105 } | 106 } |
106 else | 107 else |
107 { | 108 { |
108 message = Translation.GetTranslation(messageTranslationID, defaultMessage, fileName, factoryType); | 109 message = Translation.GetTranslation(messageTranslationID, defaultMessage, fileName, factoryType); |
109 } | 110 } |
110 } | 111 } |
111 | 112 |
112 return message; | 113 return message; |