44
44
45
45
namespace RabbitMQ . Client
46
46
{
47
- ///<summary>Concrete, predefined IProtocol instances ready for use
48
- ///with ConnectionFactory.</summary>
49
- ///<remarks>
50
- ///<para>
51
- /// Applications will in the common case use the FromEnvironment()
52
- /// method to search a fallback-chain of configuration sources for
53
- /// the IProtocol instance to use. However, in some cases, the
54
- /// default fallback-chain is not appropriate; in these cases,
55
- /// other methods such as FromConfiguration(string) or
56
- /// SafeLookup(string) may suffice.
57
- ///</para>
58
- ///</remarks>
47
+ ///<summary>Provides access to the supported IProtocol implementations</summary>
59
48
public class Protocols
60
49
{
61
50
// Hide the constructor - no instances of Protocols needed.
62
51
// We'd make this class static, but for MS's .NET 1.1 compilers
63
52
private Protocols ( ) { }
64
53
65
- ///<summary>The default App.config appSettings key used by
66
- ///FromConfiguration and FromEnvironment. At the time of
67
- ///writing, "AMQP_PROTOCOL".</summary>
68
- public readonly static string DefaultAppSettingsKey = "AMQP_PROTOCOL" ;
69
-
70
- ///<summary>The environment variable read by
71
- ///FromEnvironmentVariable() and FromEnvironment(). At the
72
- ///time of writing, "AMQP_PROTOCOL".</summary>
73
- public readonly static string EnvironmentVariable = "AMQP_PROTOCOL" ;
74
-
75
54
///<summary>Protocol version 0-9-1 as modified by VMWare.</summary>
76
55
public static IProtocol AMQP_0_9_1
77
56
{
@@ -84,126 +63,5 @@ public static IProtocol DefaultProtocol
84
63
{
85
64
get { return AMQP_0_9_1 ; }
86
65
}
87
-
88
- ///<summary>Low-level method for retrieving a protocol version
89
- ///by name (of one of the static properties on this
90
- ///class)</summary>
91
- ///<remarks>
92
- ///<para>
93
- /// Returns null if no suitable property could be found.
94
- ///</para>
95
- ///<para>
96
- /// In many cases, FromEnvironment() will be a more
97
- /// appropriate method for applications to call; this method
98
- /// is provided for cases where the caller wishes to know the
99
- /// answer to the question "does a suitable IProtocol property
100
- /// with this name exist, and if so, what is its value?"
101
- ///</para>
102
- ///</remarks>
103
- public static IProtocol Lookup ( string name )
104
- {
105
- PropertyInfo pi = typeof ( Protocols ) . GetProperty ( name ,
106
- BindingFlags . Public |
107
- BindingFlags . Static ) ;
108
- if ( pi == null )
109
- {
110
- return null ;
111
- }
112
- return pi . GetValue ( null , new object [ 0 ] ) as IProtocol ;
113
- }
114
-
115
- ///<summary>Retrieve a protocol version by name (of one of the
116
- ///static properties on this class)</summary>
117
- ///<remarks>
118
- ///<para>
119
- /// If the argument is null, Protocols.DefaultProtocol is
120
- /// used. If the protocol variant named is not found,
121
- /// ConfigurationErrorsException is thrown.
122
- ///</para>
123
- ///<para>
124
- /// In many cases, FromEnvironment() will be a more
125
- /// appropriate method for applications to call; this method
126
- /// is provided for cases where the caller wishes to know the
127
- /// answer to the question "does a suitable IProtocol property
128
- /// with this name exist, and if so, what is its value?", with
129
- /// the additional guarantee that if a suitable property does
130
- /// not exist, a ConfigurationErrorsException will be thrown.
131
- ///</para>
132
- ///</remarks>
133
- ///<exception cref="System.Configuration.ConfigurationErrorsException"/>
134
- public static IProtocol SafeLookup ( string name )
135
- {
136
- if ( name != null )
137
- {
138
- IProtocol p = Lookup ( name ) ;
139
- if ( p != null )
140
- {
141
- return p ;
142
- }
143
- else
144
- {
145
- throw new ConfigurationErrorsException ( "Unsupported protocol variant name: " + name ) ;
146
- }
147
- }
148
- return DefaultProtocol ;
149
- }
150
-
151
- private static string ReadEnvironmentVariable ( )
152
- {
153
- return Environment . GetEnvironmentVariable ( EnvironmentVariable ) ;
154
- }
155
-
156
- ///<summary>Uses the process environment variable
157
- ///<code>EnvironmentVariable</code> to retrieve an IProtocol
158
- ///instance.</summary>
159
- ///<remarks>
160
- ///If the environment variable is unset,
161
- ///Protocols.DefaultProtocol is used. If the protocol variant
162
- ///named is not found, ConfigurationErrorsException is thrown.
163
- ///</remarks>
164
- ///<exception cref="System.Configuration.ConfigurationErrorsException"/>
165
- public static IProtocol FromEnvironmentVariable ( )
166
- {
167
- return SafeLookup ( ReadEnvironmentVariable ( ) ) ;
168
- }
169
-
170
- ///<summary>Uses App.config's appSettings section to retrieve
171
- ///an IProtocol instance.</summary>
172
- ///<remarks>
173
- ///If the appSettings key is missing,
174
- ///Protocols.DefaultProtocol is used. If the protocol variant
175
- ///named is not found, ConfigurationErrorsException is thrown.
176
- ///</remarks>
177
- ///<exception cref="System.Configuration.ConfigurationErrorsException"/>
178
- public static IProtocol FromConfiguration ( string appSettingsKey )
179
- {
180
- string name = ConfigurationManager . AppSettings [ appSettingsKey ] ;
181
- return SafeLookup ( name ) ;
182
- }
183
-
184
- ///<summary>Returns FromConfiguration(DefaultAppSettingsKey).</summary>
185
- public static IProtocol FromConfiguration ( )
186
- {
187
- return FromConfiguration ( DefaultAppSettingsKey ) ;
188
- }
189
-
190
- ///<summary>Tries FromConfiguration() first, followed by
191
- ///FromEnvironmentVariable() if no setting was found in the
192
- ///App.config.</summary>
193
- ///<exception cref="System.Configuration.ConfigurationErrorsException"/>
194
- public static IProtocol FromEnvironment ( string appSettingsKey )
195
- {
196
- string name = ConfigurationManager . AppSettings [ appSettingsKey ] ;
197
- if ( name == null ) {
198
- name = ReadEnvironmentVariable ( ) ;
199
- }
200
- return SafeLookup ( name ) ;
201
- }
202
-
203
- ///<summary>Returns FromEnvironment(DefaultAppSettingsKey).</summary>
204
- public static IProtocol FromEnvironment ( )
205
- {
206
- return FromEnvironment ( DefaultAppSettingsKey ) ;
207
- }
208
66
}
209
67
}
0 commit comments