Exemplo n.º 1
0
        private DownloaderResult MakeRequest(Uri uri)
        {
            var             result = new DownloaderResult(uri);
            HttpWebRequest  request;
            HttpWebResponse response = null;

            try
            {
                request  = BuildRequestObject(uri);
                response = (HttpWebResponse)request.GetResponse();
                ProcessResponseObject(response);
            }
            catch (WebException e)
            {
                result.SetException(e);

                if (e.Response != null)
                {
                    response = (HttpWebResponse)e.Response;
                }

                Log.Debug()
                .Message("Error occurred requesting url [{0}]", uri.AbsoluteUri)
                .Exception(e)
                .Write();
            }
            catch (Exception e)
            {
                result.SetException(e);

                Log.Debug()
                .Message("Error occurred requesting url [{0}]", uri.AbsoluteUri)
                .Exception(e)
                .Write();
            }
            finally
            {
                try
                {
                    result.SetResponseParams(response);
                    result.SetResponseData(_contentExtractor.GetContent(response));

                    response?.Close();
                }
                catch (Exception e)
                {
                    result.SetException(e);

                    Log.Info()
                    .Message("Error occurred finalizing requesting url [{0}]", uri.AbsoluteUri)
                    .Exception(e)
                    .Write();
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public DownloaderResult AddToDownloadQueue(string uri)
        {
            var result = new DownloaderResult(uri);

            if (_linkDataStorage.TryGetLinkContent(uri, out var content))
            {
                result.SetResponseData(content);
                return(result);
            }

            _queue.Add(result);
            return(result);
        }