Beispiel #1
0
        private void HandleRequest(UrlRepeaterQuery query)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            IHttpRequest  request  = _provider.GetRequest(query.Url);
            IHttpResponse response = request.GetResponse();

            query.Status = response.StatusCode;
            watch.Stop();
            query.Duration = watch.Elapsed;
        }
Beispiel #2
0
        public IEnumerable <UrlRepeaterQuery> Run(Uri url, int nbTimes, TimeSpan delay)
        {
            DateTime start     = DateTime.Now;
            DateTime nextQuery = start;

            for (int i = 0; i < nbTimes; i++)
            {
                UrlRepeaterQuery query = new UrlRepeaterQuery(url);
                HandleRequest(query);
                yield return(query);

                if (i < nbTimes - 1)
                {
                    DateTime now = DateTime.Now;
                    while (now > nextQuery)
                    {
                        nextQuery = nextQuery + delay;
                    }

                    Thread.Sleep(nextQuery - now);
                }
            }
        }