Esempio n. 1
0
        protected virtual HttpWebRequest CreateRequest(string url)
        {
            var request = WebRequestFactory.Create(url);

            RateLimiter.Exec(() =>
            {
                request.UserAgent = string.Format("{0}/{1} +{2}", Publication.Product, Publication.Version, Publication.HomePage);
                if (this.Key != null && this.Secret != null)
                {
                    request.Headers[HttpRequestHeader.Authorization] = string.Format("Discogs key={0}, secret={1}", this.Key, this.Secret);
                }
            });
            return(request);
        }
Esempio n. 2
0
        public void Test001()
        {
            var stopwatch   = Stopwatch.StartNew();
            var interval    = 100;
            var count       = 0;
            var rateLimiter = new RateLimiter(interval);

            for (var a = 0; a < 10; a++)
            {
                var action = new Action(() =>
                {
                    count++;
                });
                rateLimiter.Exec(action);
            }
            stopwatch.Stop();
            Assert.AreEqual(10, count);
            Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 900);
        }
Esempio n. 3
0
 static Discogs()
 {
     RateLimiter = new RateLimiter(1000 / MAX_REQUESTS);
 }