Exemple #1
0
        private void DevourCallback(DownloaderObj obj)
        {
            if (obj.DataStr != null)
            {
                if (_validator != null)
                {
                    if (_validator.Validate(obj.DataStr))
                    {
                        HandleSuccessDownload(obj);
                    }
                    else
                    {
                        HandleBadDownload(obj);
                    }
                }
                else
                {
                    HandleSuccessDownload(obj);
                }
            }
            else
            {
                HandleBadDownload(obj);
            }

            MoveObjComplete();
        }
        public async Task <PageResponse <AuthorProxy> > GetAuthorPageAsync(PageRequest pageRequest)
        {
            var pageError = _pageValidator.Validate(pageRequest);

            if (pageError != null)
            {
                ThrowHttp.BadRequest(pageError);
            }

            var page = await _repository.GetPageAsync(pageRequest);

            var total = await _repository.GetCountAsync();

            return(new PageResponse <AuthorProxy>(page.Select(MapToProxy).ToArray(), total));
        }
Exemple #3
0
        private bool TryCheckDownloadSpeed(RatedProxy proxy, Uri uri, IPageValidator validator, ref double siteRate, ref double downloadSpeed)
        {
            Stopwatch timer = new Stopwatch();

            for (int i = 0; i < 3; i++)
            {
                DownloaderObj obj = new DownloaderObj(uri, null, true, proxy, CookieOptions.Empty, 1);
                timer.Restart();
                Downloader.DownloadSync(obj);
                timer.Stop();
                string data = obj.DataStr;
                if (data != null)
                {
                    if (validator.Validate(data))
                    {
                        siteRate = (1 - i / 3d);
                        int leng = Encoding.UTF8.GetBytes(data).Length;
                        downloadSpeed = Encoding.UTF8.GetBytes(data).Length / (double)timer.ElapsedMilliseconds; //KB-sec
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #4
0
 private bool TryCheckDownloadSpeed(RatedProxy proxy, Uri uri, IPageValidator validator, ref double siteRate, ref double downloadSpeed)
 {
     Stopwatch timer = new Stopwatch();
     for (int i = 0; i < 3; i++)
     {
         DownloaderObj obj = new DownloaderObj(uri, null, true, proxy, CookieOptions.Empty, 1);
         timer.Restart();
         Downloader.DownloadSync(obj);
         timer.Stop();
         string data = obj.DataStr;
         if (data != null)
         {
             if (validator.Validate(data))
             {
                 siteRate = (1 - i / 3d);
                 int leng = Encoding.UTF8.GetBytes(data).Length;
                 downloadSpeed = Encoding.UTF8.GetBytes(data).Length / (double)timer.ElapsedMilliseconds; //KB-sec
                 return true;
             }
         }
     }
     return false;
 }