~ubuntu-branches/debian/squeeze/f-spot/squeeze

« back to all changes in this revision

Viewing changes to extensions/Exporters/FlickrExport/FlickrNet/FlickrConfigurationSettings.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane, Mirco Bauer, Iain Lane
  • Date: 2009-02-07 20:23:32 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090207202332-oc93rfjo1st0571s
Tags: 0.5.0.3-2
[ Mirco Bauer]
* Upload to unstable.
* debian/control:
  + Lowered GNOME# build-deps to 2.0 ABI as that transition didn't happen
    yet in unstable.

[ Iain Lane ]
* debian/patches/svn-r4545_locales-import.dpatch: Patch backported from SVN
  trunk revision 4545 - initialize the translation catalog earlier (LP: #293305)
  (Closes: #514457). Thanks to Florian Heinle for finding the patch and to
  Chris Coulson for preparing the update.
* debian/control: Build-depend on libmono-dev (>= 1.2.4) to match configure
  checks.
* debian/rules: Pass CSC=/usr/bin/csc to configure for gio-sharp to fix FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if !WindowsCE
 
2
using System;
 
3
using System.Collections.Specialized ;
 
4
using System.Xml;
 
5
 
 
6
namespace FlickrNet
 
7
{
 
8
        /// <summary>
 
9
        /// Configuration settings for the Flickr.Net API Library.
 
10
        /// </summary>
 
11
        /// <remarks>
 
12
        /// <p>First, register the configuration section in the configSections section:</p>
 
13
        /// <p><code>&lt;configSections&gt;
 
14
        /// &lt;section name="flickrNet" type="FlickrNet.FlickrConfigurationManager,FlickrNet"/&gt;
 
15
        /// &lt;/configSections&gt;</code>
 
16
        /// </p>
 
17
        /// <p>
 
18
        /// Next, include the following config section:
 
19
        /// </p>
 
20
        /// <p><code>
 
21
        ///     &lt;flickrNet
 
22
        /// apiKey="1234567890abc"      // optional
 
23
        /// secret="2134123"            // optional
 
24
        /// token="234234"                      // optional
 
25
        /// cacheSize="1234"            // optional, in bytes (defaults to 50 * 1024 * 1024 = 50MB)
 
26
        /// cacheTimeout="[d.]HH:mm:ss" // optional, defaults to 1 day (1.00:00:00) - day component is optional
 
27
        /// // e.g. 10 minutes = 00:10:00 or 1 hour = 01:00:00 or 2 days, 12 hours = 2.12:00:00
 
28
        /// &gt;
 
29
        /// &lt;proxy           // proxy element is optional, but if included the attributes below are mandatory as mentioned
 
30
        /// ipaddress="127.0.0.1"       // mandatory
 
31
        /// port="8000"                         // mandatory
 
32
        /// username="username"         // optional, but must have password if included
 
33
        /// password="password"         // optional, see username
 
34
        /// domain="domain"                     // optional, used for Microsoft authenticated proxy servers
 
35
        /// /&gt;
 
36
        /// &lt;/flickrNet&gt;
 
37
        /// </code></p>
 
38
        /// </remarks>
 
39
        internal class FlickrConfigurationSettings
 
40
        {
 
41
                #region Private Variables
 
42
                private string _apiKey;
 
43
                private string _apiSecret;
 
44
                private string _apiToken;
 
45
                private int _cacheSize;
 
46
                private TimeSpan _cacheTimeout = TimeSpan.MinValue;
 
47
                private string _proxyAddress;
 
48
                private int _proxyPort;
 
49
                private bool _proxyDefined;
 
50
                private string _proxyUsername;
 
51
                private string _proxyPassword;
 
52
                private string _proxyDomain;
 
53
                private string _cacheLocation;
 
54
                private bool _cacheDisabled;
 
55
                private SupportedService _service;
 
56
                #endregion
 
57
 
 
58
                #region FlickrConfigurationSettings Constructor
 
59
                /// <summary>
 
60
                /// Loads FlickrConfigurationSettings with the settings in the config file.
 
61
                /// </summary>
 
62
                /// <param name="configNode">XmlNode containing the configuration settings.</param>
 
63
                public FlickrConfigurationSettings(XmlNode configNode)
 
64
                {
 
65
                        if( configNode == null ) throw new ArgumentNullException("configNode");
 
66
 
 
67
                        foreach(XmlAttribute attribute in configNode.Attributes)
 
68
                        {
 
69
                                switch(attribute.Name)
 
70
                                {
 
71
                                        case "apiKey":
 
72
                                                _apiKey = attribute.Value;
 
73
                                                break;
 
74
                                        case "secret":
 
75
                                                _apiSecret = attribute.Value;
 
76
                                                break;
 
77
                                        case "token":
 
78
                                                _apiToken = attribute.Value;
 
79
                                                break;
 
80
                                        case "cacheDisabled":
 
81
                                                try
 
82
                                                {
 
83
                                                        _cacheDisabled = bool.Parse(attribute.Value);
 
84
                                                        break;
 
85
                                                }
 
86
                                                catch(FormatException ex)
 
87
                                                {
 
88
                                                        throw new System.Configuration.ConfigurationException("cacheDisbled should be \"true\" or \"false\"", ex, configNode);
 
89
                                                }
 
90
                                        case "cacheSize":
 
91
                                                try
 
92
                                                {
 
93
                                                        _cacheSize = int.Parse(attribute.Value);
 
94
                                                        break;
 
95
                                                }
 
96
                                                catch(FormatException ex)
 
97
                                                {
 
98
                                                        throw new System.Configuration.ConfigurationException("cacheSize should be integer value", ex, configNode);
 
99
                                                }
 
100
                                        case "cacheTimeout":
 
101
                                                try
 
102
                                                {
 
103
                                                        _cacheTimeout = TimeSpan.Parse(attribute.Value);
 
104
                                                        break;
 
105
                                                }
 
106
                                                catch(FormatException ex)
 
107
                                                {
 
108
                                                        throw new System.Configuration.ConfigurationException("cacheTimeout should be TimeSpan value ([d:]HH:mm:ss)", ex, configNode);
 
109
                                                }
 
110
                                        case "cacheLocation":
 
111
                                                _cacheLocation = attribute.Value;
 
112
                                                break;
 
113
 
 
114
                                        case "service":
 
115
                                                try
 
116
                                                {
 
117
                                                        _service = (SupportedService)Enum.Parse(typeof(SupportedService), attribute.Value, true);
 
118
                                                        break;
 
119
                                                }
 
120
                                                catch(ArgumentException ex)
 
121
                                                {
 
122
                                                        throw new System.Configuration.ConfigurationException("service must be one of the supported services (See SupportedServices enum)", ex, configNode);
 
123
                                                }
 
124
 
 
125
                                        default:
 
126
                                                throw new System.Configuration.ConfigurationException(String.Format("Unknown attribute '{0}' in flickrNet node", attribute.Name), configNode);
 
127
                                }
 
128
                        }
 
129
 
 
130
                        foreach(XmlNode node in configNode.ChildNodes)
 
131
                        {
 
132
                                switch(node.Name)
 
133
                                {
 
134
                                        case "proxy":
 
135
                                                ProcessProxyNode(node, configNode);
 
136
                                                break;
 
137
                                        default:
 
138
                                                throw new System.Configuration.ConfigurationException(String.Format("Unknown node '{0}' in flickrNet node", node.Name), configNode);
 
139
                                }
 
140
                        }
 
141
                }
 
142
                #endregion
 
143
 
 
144
                #region ProcessProxyNode - Constructor Helper Method
 
145
                private void ProcessProxyNode(XmlNode proxy, XmlNode configNode)
 
146
                {
 
147
                        if( proxy.ChildNodes.Count > 0 )
 
148
                                throw new System.Configuration.ConfigurationException("proxy element does not support child elements");
 
149
 
 
150
                        _proxyDefined = true;
 
151
                        foreach(XmlAttribute attribute in proxy.Attributes)
 
152
                        {
 
153
 
 
154
                                switch(attribute.Name)
 
155
                                {
 
156
                                        case "ipaddress":
 
157
                                                _proxyAddress = attribute.Value;
 
158
                                                break;
 
159
                                        case "port":
 
160
                                                try
 
161
                                                {
 
162
                                                        _proxyPort = int.Parse(attribute.Value);
 
163
                                                }
 
164
                                                catch(FormatException ex)
 
165
                                                {
 
166
                                                        throw new System.Configuration.ConfigurationException("proxy port should be integer value", ex, configNode);
 
167
                                                }
 
168
                                                break;
 
169
                                        case "username":
 
170
                                                _proxyUsername = attribute.Value;
 
171
                                                break;
 
172
                                        case "password":
 
173
                                                _proxyPassword = attribute.Value;
 
174
                                                break;
 
175
                                        case "domain":
 
176
                                                _proxyDomain = attribute.Value;
 
177
                                                break;
 
178
                                        default:
 
179
                                                throw new System.Configuration.ConfigurationException(String.Format("Unknown attribute '{0}' in flickrNet/proxy node", attribute.Name), configNode);
 
180
                                }
 
181
                        }
 
182
 
 
183
                        if( _proxyAddress == null )
 
184
                                throw new System.Configuration.ConfigurationException("proxy ipaddress is mandatory if you specify the proxy element");
 
185
                        if( _proxyPort == 0 )
 
186
                                throw new System.Configuration.ConfigurationException("proxy port is mandatory if you specify the proxy element");
 
187
                        if( _proxyUsername != null && _proxyPassword == null )
 
188
                                throw new System.Configuration.ConfigurationException("proxy password must be specified if proxy username is specified");
 
189
                        if( _proxyUsername == null && _proxyPassword != null )
 
190
                                throw new System.Configuration.ConfigurationException("proxy username must be specified if proxy password is specified");
 
191
                        if( _proxyDomain != null && _proxyUsername == null )
 
192
                                throw new System.Configuration.ConfigurationException("proxy username/password must be specified if proxy domain is specified");
 
193
                }
 
194
                #endregion
 
195
 
 
196
                #region Public Properties
 
197
                /// <summary>
 
198
                /// API key. Null if not present. Optional.
 
199
                /// </summary>
 
200
                public string ApiKey
 
201
                {
 
202
                        get { return _apiKey; }
 
203
                }
 
204
 
 
205
                /// <summary>
 
206
                /// Shared Secret. Null if not present. Optional.
 
207
                /// </summary>
 
208
                public string SharedSecret
 
209
                {
 
210
                        get { return _apiSecret; }
 
211
                }
 
212
 
 
213
                /// <summary>
 
214
                /// API token. Null if not present. Optional.
 
215
                /// </summary>
 
216
                public string ApiToken
 
217
                {
 
218
                        get { return _apiToken; }
 
219
                }
 
220
 
 
221
                /// <summary>
 
222
                /// Cache size in bytes. 0 if not present. Optional.
 
223
                /// </summary>
 
224
                public bool CacheDisabled
 
225
                {
 
226
                        get { return _cacheDisabled; }
 
227
                }
 
228
 
 
229
                /// <summary>
 
230
                /// Cache size in bytes. 0 if not present. Optional.
 
231
                /// </summary>
 
232
                public int CacheSize
 
233
                {
 
234
                        get { return _cacheSize; }
 
235
                }
 
236
 
 
237
                /// <summary>
 
238
                /// Cache timeout. Equals TimeSpan.MinValue is not present. Optional.
 
239
                /// </summary>
 
240
                public TimeSpan CacheTimeout
 
241
                {
 
242
                        get { return _cacheTimeout; }
 
243
                }
 
244
 
 
245
                public string CacheLocation
 
246
                {
 
247
                        get { return _cacheLocation; }
 
248
                }
 
249
 
 
250
                public SupportedService Service
 
251
                {
 
252
                        get { return _service; }
 
253
                }
 
254
 
 
255
                /// <summary>
 
256
                /// If the proxy is defined in the configuration section.
 
257
                /// </summary>
 
258
                public bool IsProxyDefined
 
259
                {
 
260
                        get { return _proxyDefined; }
 
261
                }
 
262
 
 
263
                /// <summary>
 
264
                /// If <see cref="IsProxyDefined"/> is true then this is mandatory.
 
265
                /// </summary>
 
266
                public string ProxyIPAddress
 
267
                {
 
268
                        get { return _proxyAddress; }
 
269
                }
 
270
 
 
271
                /// <summary>
 
272
                /// If <see cref="IsProxyDefined"/> is true then this is mandatory.
 
273
                /// </summary>
 
274
                public int ProxyPort
 
275
                {
 
276
                        get { return _proxyPort; }
 
277
                }
 
278
 
 
279
                /// <summary>
 
280
                /// The username for the proxy. Optional.
 
281
                /// </summary>
 
282
                public string ProxyUsername
 
283
                {
 
284
                        get { return _proxyUsername; }
 
285
                }
 
286
 
 
287
                /// <summary>
 
288
                /// The password for the proxy. Optional.
 
289
                /// </summary>
 
290
                public string ProxyPassword
 
291
                {
 
292
                        get { return _proxyPassword; }
 
293
                }
 
294
 
 
295
                /// <summary>
 
296
                /// The domain for the proxy. Optional.
 
297
                /// </summary>
 
298
                public string ProxyDomain
 
299
                {
 
300
                        get { return _proxyDomain; }
 
301
                }
 
302
                #endregion
 
303
 
 
304
        }
 
305
}
 
306
#endif
 
 
b'\\ No newline at end of file'