public RssItem GetFeed() { // To save on hitting bandwidth let's only hit the server 1 in 10 times if (timesUpdated > 10) { timesUpdated = 0; } RssItem item = null; if (timesUpdated < 1) { var client = new RssClient(); var feed = client.GetRssFeed(new Uri(this.feedUrl)); this.feedItems = feed?.Items; item = feed?.Items?.FirstOrDefault(); } else { if (this.feedItems != null) { int i = this.randomGenerator.Next(this.feedItems.Count() - 1); item = this.feedItems.Skip(i).FirstOrDefault(); } } timesUpdated++; return item; }
public RssItem GetFeed() { // To save on hitting bandwidth let's only hit the server 1 in 10 times if (timesUpdated > 10) { timesUpdated = 0; } RssItem item = null; if (timesUpdated < 1) { var client = new RssClient(); var feed = client.GetRssFeed(new Uri(this.feedUrl)); this.feedItems = feed?.Items; item = feed?.Items?.FirstOrDefault(); } else { if (this.feedItems != null) { int i = this.randomGenerator.Next(this.feedItems.Count() - 1); item = this.feedItems.Skip(i).FirstOrDefault(); } } timesUpdated++; return(item); }
public async Task LoadItemsAsync() { var client = new RssClient(); var tcs = new TaskCompletionSource<RssFeed>(); client.GetRssFeed(new Uri(FeedUrl), tcs.SetResult); var feed = await tcs.Task; Items = feed.Items.Select(item => new RssItem() { Title = item.Title, Description = item.Description, Link = item.Link }); }
public async Task LoadItemsAsync() { var client = new RssClient(); var tcs = new TaskCompletionSource <RssFeed>(); client.GetRssFeed(new Uri(FeedUrl), tcs.SetResult); var feed = await tcs.Task; Items = feed.Items.Select(item => new RssItem() { Title = item.Title, Description = item.Description, Link = item.Link }); }
public async Task <IActionResult> Index() { var rssFeed = await _rssClient.GetRssFeed(); return(Ok(rssFeed)); }