Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using System.Configuration;
11 : using System.Runtime.Serialization;
12 :
13 : namespace Cqrs.Exceptions
14 : {
15 : /// <summary>
16 : /// An app setting is missing from <see cref="ConfigurationManager.AppSettings"/>.
17 : /// </summary>
18 : [Serializable]
19 : public class MissingApplicationSettingException : Exception
20 1 : {
21 : /// <summary>
22 : /// Instantiate a new instance of <see cref="MissingApplicationSettingException"/>.
23 : /// </summary>
24 : /// <param name="appSettingKey">The key of the app setting that is missing.</param>
25 1 : public MissingApplicationSettingException(string appSettingKey)
26 : : this(appSettingKey, false)
27 : {
28 : }
29 :
30 : /// <summary>
31 : /// Instantiate a new instance of <see cref="MissingApplicationSettingException"/> with a specified error message.
32 : /// </summary>
33 : /// <param name="appSettingKey">The key of the app setting that is missing.</param>
34 : /// <param name="message">The message that describes the error.</param>
35 1 : public MissingApplicationSettingException(string appSettingKey, string message)
36 : : base(message)
37 : {
38 : AppSettingKey = appSettingKey;
39 : }
40 :
41 : /// <summary>
42 : /// Instantiate a new instance of <see cref="MissingApplicationSettingException"/> with a specified error message and and a reference to the inner <paramref name="exception"/> that is the cause of this <see cref="Exception"/>
43 : /// </summary>
44 : /// <param name="appSettingKey">The key of the app setting that is missing.</param>
45 : /// <param name="message">The message that describes the error.</param>
46 : /// <param name="exception">The <see cref="Exception"/> that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner <see cref="Exception"/> is specified.</param>
47 1 : public MissingApplicationSettingException(string appSettingKey, string message, Exception exception)
48 : : base(message, exception)
49 : {
50 : AppSettingKey = appSettingKey;
51 : }
52 :
53 : /// <summary>
54 : /// Instantiate a new instance of <see cref="MissingApplicationSettingException"/>.
55 : /// </summary>
56 : /// <param name="appSettingKey">The key of the app setting that is missing.</param>
57 : /// <param name="settingLocatesConnectionString">If true, this missing app setting points to a connection string.</param>
58 1 : protected MissingApplicationSettingException(string appSettingKey, bool settingLocatesConnectionString)
59 : : base(string.Format(settingLocatesConnectionString ? "No app setting with the key '{0}' was found in the configuration file with the name of a connection string to look for." : "No app setting with the key '{0}' was found in the configuration file.", appSettingKey))
60 : {
61 : AppSettingKey = appSettingKey;
62 : }
63 :
64 : /// <summary>
65 : /// Instantiate a new instance of <see cref="MissingApplicationSettingException"/> and a reference to the inner <paramref name="exception"/> that is the cause of this <see cref="Exception"/>.
66 : /// </summary>
67 : /// <param name="appSettingKey">The key of the app setting that is missing.</param>
68 : /// <param name="exception">The <see cref="Exception"/> that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner <see cref="Exception"/> is specified.</param>
69 1 : public MissingApplicationSettingException(string appSettingKey, Exception exception)
70 : : this(appSettingKey, false, exception)
71 : {
72 : }
73 :
74 : /// <summary>
75 : /// Instantiate a new instance of <see cref="MissingApplicationSettingException"/> and a reference to the inner <paramref name="exception"/> that is the cause of this <see cref="Exception"/>.
76 : /// </summary>
77 : /// <param name="appSettingKey">The key of the app setting that is missing.</param>
78 : /// <param name="settingLocatesConnectionString">If true, this missing app setting points to a connection string.</param>
79 : /// <param name="exception">The <see cref="Exception"/> that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner <see cref="Exception"/> is specified.</param>
80 1 : protected MissingApplicationSettingException(string appSettingKey, bool settingLocatesConnectionString, Exception exception)
81 : : base(string.Format(settingLocatesConnectionString ? "No app setting with the key '{0}' was found in the configuration file with the name of a connection string to look for." : "No app setting with the key '{0}' was found in the configuration file.", appSettingKey), exception)
82 : {
83 : AppSettingKey = appSettingKey;
84 : }
85 :
86 : /// <summary>
87 : /// The key of the app setting that is missing.
88 : /// </summary>
89 : [DataMember]
90 : public string AppSettingKey { get; set; }
91 : }
92 : }
|