DotNetGroup.Services.Rss.RssService.GetFeeds C# (CSharp) Method

GetFeeds() public method

public GetFeeds ( string url, System.DateTime fromDate ) : IEnumerable
url string
fromDate System.DateTime
return IEnumerable
        public IEnumerable<Item> GetFeeds(string url, DateTime fromDate)
        {
            try
            {
                using (var reader = XmlReader.Create(url))
                {
                    return SyndicationFeed.Load(reader).Items.Select(i => new Item
                    {
                        Url = i.Id,
                        Published = GetPublishDate(i),
                        AuthorName = i.Authors[0].Name,
                        AuthorUri = i.Authors[0].Uri,
                        Title = i.Title.Text,
                        Content = ((TextSyndicationContent)i.Content).Text,
                        Tags = i.Categories.Select(c => c.Name).ToArray(),
                        ItemType = ItemType.Rss
                    }).TakeWhile(i => i.Published > fromDate).ToList();
                }
            }
            catch
            {
                return new List<Item>();
            }
        }

Usage Example

Example #1
0
        public void Given_Last_Feed_Date_GetFeeds_Can_Successfully_Retrieve_Latest_Values_From_Rss()
        {
            var url = ConfigurationManager.AppSettings["rss.sergejus"];
            var rssService = new RssService();

            var feeds = rssService.GetFeeds(url, this.date).ToList();
            if (feeds.Count() > 1)
            {
                var fromDate = feeds.Last().Published;
                var latestFeeds = rssService.GetFeeds(url, fromDate);

                Assert.That(feeds.Count(), Is.GreaterThan(latestFeeds.Count()));
            }
        }
All Usage Examples Of DotNetGroup.Services.Rss.RssService::GetFeeds