/// <summary> /// Gets the story details. /// </summary> /// <param name="stories">The stories.</param> /// <returns>List<Publication>.</returns> private List <Publication> GetStoryDetails(List <Publication> stories) { if (skipDetails) { return(stories); } Parallel.ForEach(stories.OrderBy(o => int.Parse(o.publishedOn)), story => { try { using (WebClient cli = new WebClient()) story.UrlData = cli.DownloadString(story.Url); OnNewsDetail(this, NewsDetailEventArgs.Create(story, watch)); } catch (Exception) { //TODO: need to log errors return; } }); OnNewsDetailComplete(this, NewsCompleteEventArgs.Create(stories, watch)); return(stories); }
/// <summary> /// Gets the stories. /// </summary> /// <param name="web">The web.</param> /// <returns>List<Models.Publication>.</returns> private List <Publication> GetStories(WebClient web, Func <Publication, bool> filter) { var stories = GetStories(web).Where(filter).ToList(); TransformStories(stories, web); stories.ForEach(item => OnNewsSummary(this, NewsSummaryEventArgs.Create(item, watch))); OnNewsSummaryComplete(this, NewsCompleteEventArgs.Create(stories, watch)); GetStoryDetails(stories); return(stories.OrderByDescending(order => order.publishedOn).ToList()); }
/// <summary> /// Gets the latest news. /// </summary> public void RequestLatestNews() { List <Publication> stories; watch.Start(); OnNewsStart(this, StopWatchEventArgs.Create(watch)); var filter = DateTime.Now.AddDays(-1).ToUnixTime(); filter = StartDate; // for debugging using (WebClient web = new WebClient()) { stories = GetStories(web, w => int.Parse(w.publishedOn) > filter); } OnNewsComplete(this, NewsCompleteEventArgs.Create(stories, watch)); if (stories.Count() == 0) { return; } StartDate = stories.Max(m => int.Parse(m.publishedOn)); StoryCount = stories.Count(); }