Exemplo n.º 1
0
        public virtual IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            var releases = new List <ReleaseInfo>();

            if (!PreProcess(indexerResponse))
            {
                return(releases);
            }

            using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings {
                DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true
            }))
            {
                var document = XDocument.Load(xmlTextReader);
                var items    = GetItems(document);

                foreach (var item in items)
                {
                    try
                    {
                        var reportInfo = ProcessItem(item);

                        releases.AddIfNotNull(reportInfo);
                    }
                    catch (Exception itemEx)
                    {
                        itemEx.Data.Add("Item", item.Title());
                        _logger.ErrorException("An error occurred while processing feed item from " + indexerResponse.Request.Url, itemEx);
                    }
                }
            }

            return(releases);
        }
Exemplo n.º 2
0
        public virtual IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            _indexerResponse = indexerResponse;

            var releases = new List <ReleaseInfo>();

            if (!PreProcess(indexerResponse))
            {
                return(releases);
            }

            var document = LoadXmlDocument(indexerResponse);
            var items    = GetItems(document);

            foreach (var item in items)
            {
                try
                {
                    var reportInfo = ProcessItem(item);

                    releases.AddIfNotNull(reportInfo);
                }
                catch (Exception itemEx)
                {
                    itemEx.Data.Add("Item", item.Title());
                    _logger.Error(itemEx, "An error occurred while processing feed item from {0}", indexerResponse.Request.Url);
                }
            }

            return(releases);
        }
Exemplo n.º 3
0
        protected virtual XDocument LoadXmlDocument(IndexerResponse indexerResponse)
        {
            try
            {
                var content = indexerResponse.Content;
                content = ReplaceEntities.Replace(content, ReplaceEntity);

                using (var xmlTextReader = XmlReader.Create(new StringReader(content), new XmlReaderSettings {
                    DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true
                }))
                {
                    return(XDocument.Load(xmlTextReader));
                }
            }
            catch (XmlException ex)
            {
                var contentSample = indexerResponse.Content.Substring(0, Math.Min(indexerResponse.Content.Length, 512));
                _logger.Debug("Truncated response content (originally {0} characters): {1}", indexerResponse.Content.Length, contentSample);

                ex.Data.Add("ContentLength", indexerResponse.Content.Length);
                ex.Data.Add("ContentSample", contentSample);

                throw;
            }
        }
Exemplo n.º 4
0
        public virtual IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            _indexerResponse = indexerResponse;

            var releases = new List<ReleaseInfo>();

            if (!PreProcess(indexerResponse))
            {
                return releases;
            }

            var document = LoadXmlDocument(indexerResponse);
            var items = GetItems(document);

            foreach (var item in items)
            {
                try
                {
                    var reportInfo = ProcessItem(item);

                    releases.AddIfNotNull(reportInfo);
                }
                catch (Exception itemEx)
                {
                    itemEx.Data.Add("Item", item.Title());
                    _logger.ErrorException("An error occurred while processing feed item from " + indexerResponse.Request.Url, itemEx);
                }
            }

            return releases;
        }
Exemplo n.º 5
0
        public IEnumerable <XElement> GetItems(IndexerResponse indexerResponse)
        {
            var document = LoadXmlDocument(indexerResponse);
            var items    = GetItems(document);

            return(items);
        }
Exemplo n.º 6
0
        public IEnumerable<XElement> GetItems(IndexerResponse indexerResponse)
        {
            var document = LoadXmlDocument(indexerResponse);
            var items = GetItems(document);

            return items;
        }
Exemplo n.º 7
0
        protected virtual IList <ReleaseInfo> FetchPage(IndexerRequest request, IParseIndexerResponse parser)
        {
            _logger.Debug("Downloading Feed " + request.Url);

            var response = new IndexerResponse(request, _httpClient.Execute(request.HttpRequest));

            return(parser.ParseResponse(response).ToList());
        }
Exemplo n.º 8
0
        protected virtual Boolean PreProcess(IndexerResponse indexerResponse)
        {
            if (indexerResponse.HttpResponse.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new IndexerException("Indexer API call resulted in an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
            }

            return(true);
        }
Exemplo n.º 9
0
        protected override bool PreProcess(IndexerResponse indexerResponse)
        {
            var document = LoadXmlDocument(indexerResponse);
            var items    = GetItems(document).ToList();

            if (items.Count == 1 && GetTitle(items.First()).Equals("No items exist - Try again later"))
            {
                throw new IndexerException(indexerResponse, "No results were found");
            }

            return(base.PreProcess(indexerResponse));
        }
Exemplo n.º 10
0
        protected override bool PreProcess(IndexerResponse indexerResponse)
        {
            var document = LoadXmlDocument(indexerResponse);
            var items = GetItems(document).ToList();

            if (items.Count == 1 && GetTitle(items.First()).Equals("No items exist - Try again later"))
            {
                throw new IndexerException(indexerResponse, "No results were found");
            }

            return base.PreProcess(indexerResponse);
        }
Exemplo n.º 11
0
        protected virtual IList <ReleaseInfo> FetchPage(IndexerRequest request, IParseIndexerResponse parser)
        {
            var url = request.Url;

            _logger.Debug("Downloading Feed " + request.Url);
            var response = new IndexerResponse(request, _httpClient.Execute(request.HttpRequest));

            if (response.HttpResponse.Headers.ContentType != null && response.HttpResponse.Headers.ContentType.Contains("text/html") &&
                request.HttpRequest.Headers.Accept != null && !request.HttpRequest.Headers.Accept.Contains("text/html"))
            {
                throw new WebException("Indexer responded with html content. Site is likely blocked or unavailable.");
            }

            return(parser.ParseResponse(response).ToList());
        }
Exemplo n.º 12
0
        protected virtual bool PreProcess(IndexerResponse indexerResponse)
        {
            if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new IndexerException(indexerResponse, "Indexer API call resulted in an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
            }

            if (indexerResponse.HttpResponse.Headers.ContentType != null && indexerResponse.HttpResponse.Headers.ContentType.Contains("text/html") &&
                indexerResponse.HttpRequest.Headers.Accept != null && !indexerResponse.HttpRequest.Headers.Accept.Contains("text/html"))
            {
                throw new IndexerException(indexerResponse, "Indexer responded with html content. Site is likely blocked or unavailable.");
            }

            return(true);
        }
Exemplo n.º 13
0
        protected override bool PreProcess(IndexerResponse indexerResponse)
        {
            using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true }))
            {
                var document = XDocument.Load(xmlTextReader);
                var items = GetItems(document).ToList();

                if (items.Count == 1 && GetTitle(items.First()).Equals("No items exist - Try again later"))
                {
                    throw new IndexerException(indexerResponse, "No results were found");
                }
            }

            return base.PreProcess(indexerResponse);
        }
Exemplo n.º 14
0
        protected override bool PreProcess(IndexerResponse indexerResponse)
        {
            using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings {
                DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true
            }))
            {
                var document = XDocument.Load(xmlTextReader);
                var items    = GetItems(document).ToList();

                if (items.Count == 1 && GetTitle(items.First()).Equals("No items exist - Try again later"))
                {
                    throw new IndexerException(indexerResponse, "No results were found");
                }
            }

            return(base.PreProcess(indexerResponse));
        }
Exemplo n.º 15
0
        protected virtual XDocument LoadXmlDocument(IndexerResponse indexerResponse)
        {
            try
            {
                using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true }))
                {
                    return XDocument.Load(xmlTextReader);
                }
            }
            catch (XmlException ex)
            {
                var contentSample = indexerResponse.Content.Substring(0, Math.Min(indexerResponse.Content.Length, 512));
                _logger.Debug("Truncated response content (originally {0} characters): {1}", indexerResponse.Content.Length, contentSample);

                ex.Data.Add("ContentLength", indexerResponse.Content.Length);
                ex.Data.Add("ContentSample", contentSample);

                throw;
            }
        }
Exemplo n.º 16
0
 protected virtual bool PostProcess(IndexerResponse indexerResponse, List <XElement> elements, List <ReleaseInfo> releases)
 {
     return(true);
 }
Exemplo n.º 17
0
        protected virtual Boolean PreProcess(IndexerResponse indexerResponse)
        {
            if (indexerResponse.HttpResponse.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new IndexerException(indexerResponse, "Indexer API call resulted in an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
            }

            if (indexerResponse.HttpResponse.Headers.ContentType != null && indexerResponse.HttpResponse.Headers.ContentType.Contains("text/html") &&
                indexerResponse.HttpRequest.Headers.Accept != null && !indexerResponse.HttpRequest.Headers.Accept.Contains("text/html"))
            {
                throw new IndexerException(indexerResponse, "Indexer responded with html content. Site is likely blocked or unavailable.");
            }

            return true;
        }