/// <summary> /// Provides all available feeds async. /// </summary> /// <param name="token">Cancelation token</param> /// <returns>Feed's or empty list in case of fail.</returns> public async Task <IEnumerable <Feed> > GetFeedsAsync(CancellationToken token) { IEnumerable <Feed> feeds = new List <Feed>(); try { var rowFeeds = await _client.GetStringAsync(new Uri("https://news.microsoft.com/feed/")); feeds = _parser.Parse(rowFeeds); await _storage.SaveFeedsAsync(new ReadOnlyCollection <Feed>(feeds.ToList()), CancellationToken.None); var allFeeds = await _storage.GetAllFeeds().FirstOrDefaultAsync(); var oldNews = allFeeds.Where(l2 => feeds.All(l1 => l1.Id != l2.Id)); oldNews.Select(async item => { // Remove old feeds. await _storage.DeleteFeedAsync(item.Id, token); await _storage.DeleteFeedArticleAsync(item.Id, token); }).ToList(); } catch { // nothing to do here. } return(feeds); }
public async Task <Feed> Execute() { var httpClient = new HttpClient(_httpMessageHandler); try { var responseString = await httpClient.GetStringAsync(FeedUrl) .ConfigureAwait(false); var feed = _feedParser.Parse(responseString); return(feed); } catch { return(null); } }