Exemplo n.º 1
0
        public List <RssDocumentSingle> AddNewContentToDocuments
            (List <RssDocumentSingle> documentsWithNewContentAvailable)
        {
            List <RssDocumentSingle> documentsWithNewContent = new List <RssDocumentSingle>();

            foreach (var document in documentsWithNewContentAvailable)
            {
                var subContent = XElement.Load(document.Link).Descendants("item").ToList();

                foreach (var item in subContent)
                {
                    var checkDate = item.Descendants("pubDate").FirstOrDefault()?.Value;
                    if (document.LastFetched < Convert.ToDateTime(checkDate))
                    {
                        var rssDocumentContent = new RssDocumentItem()
                        {
                            Guid              = item.Descendants("guid").FirstOrDefault()?.Value,
                            Title             = item.Descendants("title").FirstOrDefault()?.Value,
                            Description       = item.Descendants("description").FirstOrDefault()?.Value,
                            Image             = item.Descendants("enclosure").Attributes("url").FirstOrDefault()?.Value,
                            Links             = item.Descendants("link").FirstOrDefault()?.Value,
                            DateOfPublication = item.Descendants("pubDate").FirstOrDefault()?.Value,
                            Category          = item.Descendants("category").FirstOrDefault()?.Value,
                        };
                        document.RssDocumentContent.Add(rssDocumentContent);
                    }
                }
                documentsWithNewContent.Add(document);
            }
            return(documentsWithNewContent);
        }
Exemplo n.º 2
0
        public void FillSingleDocumentWithSubContent(RssDocumentSingle mainContent)
        {
            List <RssDocumentItem> subContentOfSingleRssDocument = new List <RssDocumentItem>();

            var itemsInsideMainRssDocument = XElement.Load(mainContent.Link)
                                             .Descendants("item").ToList();

            foreach (var item in itemsInsideMainRssDocument)
            {
                var rssDocumentContent = new RssDocumentItem()
                {
                    Guid              = item.Descendants("guid").FirstOrDefault()?.Value,
                    Title             = item.Descendants("title").FirstOrDefault()?.Value,
                    Description       = item.Descendants("description").FirstOrDefault()?.Value,
                    Image             = item.Descendants("enclosure").Attributes("url").FirstOrDefault()?.Value,
                    Links             = item.Descendants("link").FirstOrDefault()?.Value,
                    DateOfPublication = item.Descendants("pubDate").FirstOrDefault()?.Value,
                    Category          = item.Descendants("category").FirstOrDefault()?.Value,
                };
                subContentOfSingleRssDocument.Add(rssDocumentContent);
            }

            mainContent.RssDocumentContent = subContentOfSingleRssDocument;
        }