Configuration settings for the Flickr.Net API Library.

First, register the configuration section in the configSections section:

<configSections> <section name="flickrNet" type="FlickrNet.FlickrConfigurationManager,FlickrNet"/> </configSections>

Next, include the following config section:

<flickrNet apiKey="1234567890abc" // optional secret="2134123" // optional token="234234" // optional cacheSize="1234" // optional, in bytes (defaults to 50 * 1024 * 1024 = 50MB) cacheTimeout="[d.]HH:mm:ss" // optional, defaults to 1 day (1.00:00:00) - day component is optional // e.g. 10 minutes = 00:10:00 or 1 hour = 01:00:00 or 2 days, 12 hours = 2.12:00:00 > <proxy // proxy element is optional, but if included the attributes below are mandatory as mentioned ipaddress="127.0.0.1" // mandatory port="8000" // mandatory username="username" // optional, but must have password if included password="password" // optional, see username domain="domain" // optional, used for Microsoft authenticated proxy servers /> </flickrNet>

        public void FlickrConfigurationSettingsConstructorTest()
        {
            const string xml = "<flickrNet apiKey=\"apikey\" secret=\"secret\" token=\"thetoken\" " +
                               "cacheDisabled=\"true\" cacheSize=\"1024\" cacheTimeout=\"01:00:00\" " +
                               "cacheLocation=\"testlocation\" service=\"flickr\">"
                               + "<proxy ipaddress=\"localhost\" port=\"8800\" username=\"testusername\" " +
                               "password=\"testpassword\" domain=\"testdomain\"/>"
                               + "</flickrNet>";
            var doc = new XmlDocument();
            doc.LoadXml(xml);

            var configNode = doc.SelectSingleNode("flickrNet");
            var target = new FlickrConfigurationSettings(configNode);

            Assert.AreEqual("apikey", target.ApiKey);
            Assert.AreEqual("secret", target.SharedSecret);
            Assert.AreEqual("thetoken", target.ApiToken);
            Assert.IsTrue(target.CacheDisabled);
            Assert.AreEqual(1024, target.CacheSize);
            Assert.AreEqual(new TimeSpan(1, 0, 0), target.CacheTimeout);
            Assert.AreEqual("testlocation", target.CacheLocation);

            Assert.IsTrue(target.IsProxyDefined, "IsProxyDefined should be true");
            Assert.AreEqual("localhost", target.ProxyIPAddress);
            Assert.AreEqual(8800, target.ProxyPort);
            Assert.AreEqual("testusername", target.ProxyUsername);
            Assert.AreEqual("testpassword", target.ProxyPassword);
            Assert.AreEqual("testdomain", target.ProxyDomain);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor loads configuration settings from app.config or web.config file if they exist.
        /// </summary>
        public Flickr()
        {
#if !(MONOTOUCH || WindowsCE || SILVERLIGHT)
            FlickrConfigurationSettings settings = FlickrConfigurationManager.Settings;
            if (settings == null)
            {
                return;
            }

            if (settings.CacheSize != 0)
            {
                CacheSizeLimit = settings.CacheSize;
            }
            if (settings.CacheTimeout != TimeSpan.MinValue)
            {
                CacheTimeout = settings.CacheTimeout;
            }
            ApiKey    = settings.ApiKey;
            AuthToken = settings.ApiToken;
            ApiSecret = settings.SharedSecret;

            if (settings.IsProxyDefined)
            {
                Proxy         = new WebProxy();
                Proxy.Address = new Uri("http://" + settings.ProxyIPAddress + ":" + settings.ProxyPort);
                if (settings.ProxyUsername != null && settings.ProxyUsername.Length > 0)
                {
                    NetworkCredential creds = new NetworkCredential();
                    creds.UserName    = settings.ProxyUsername;
                    creds.Password    = settings.ProxyPassword;
                    creds.Domain      = settings.ProxyDomain;
                    Proxy.Credentials = creds;
                }
            }
#endif
            InstanceCacheDisabled = CacheDisabled;
            CurrentService        = DefaultService;
        }