private void EndGetResponse(IAsyncResult result) { try{ var state = result.AsyncState as MainViewModel.RequestState; WebResponse response = state.Request.EndGetResponse(result); Rss.Structure.RssFeed rss = RssHelper.ReadRss(response.GetResponseStream()); if (rss.Channel == null) { Deployment.Current.Dispatcher.BeginInvoke(() => UrlStatus = invalidRssFeed); } else { Deployment.Current.Dispatcher.BeginInvoke(() => UrlStatus = validRssFeed); if (!isolatedStorageSettings.Contains(RssFeedKey)) { isolatedStorageSettings[RssFeedKey] = new RssFeed(); } var rssFeed = isolatedStorageSettings[RssFeedKey] as RssFeed; rssFeed.RssLink = state.Address; rssFeed.RssTitle = rss.Channel.Title.ToLower(); rssFeed.LastUpdated = DateTime.Now; rssFeed.Stories = new ObservableCollection <RssStory>(RssFeed.CloneStories(rss)); } } catch (Exception exception) { Debug.Assert(exception != null); Deployment.Current.Dispatcher.BeginInvoke(() => UrlStatus = invalidRssFeed); } }
private void EndGetResponse(IAsyncResult result) { try { var state = result.AsyncState as RequestState; WebResponse response = state.Request.EndGetResponse(result); Rss.Structure.RssFeed rss = RssHelper.ReadRss(response.GetResponseStream()); Deployment.Current.Dispatcher.BeginInvoke(() => IsDataLoaded = true); Deployment.Current.Dispatcher.BeginInvoke(() => UpdateRssFeed(rss, state.RssFeed)); } catch (Exception exception) { Deployment.Current.Dispatcher.BeginInvoke(() => IsDataLoaded = true); Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(exception.Message)); } }
public static List <RssStory> CloneStories(Rss.Structure.RssFeed rss) { var stories = new List <RssStory>(); foreach (var rssItem in rss.Channel.Item) { var rssStory = new RssStory(); rssStory.Description = StripTagsCharArray(rssItem.Description); rssStory.StoryLink = rssItem.Link.Url; rssStory.Title = StripTagsCharArray(rssItem.Title); stories.Add(rssStory); } return(stories); }
private void UpdateRssFeed(Rss.Structure.RssFeed rss, RssFeed rssFeed) { var miniRss = new RssFeed(rss); rssFeed.Stories.Clear(); foreach (RssStory story in miniRss.Stories) { rssFeed.Stories.Add(story); } _applicationSettings.Remove(rssFeed.RssTitle); rssFeed.RssTitle = miniRss.RssTitle.ToLower(); NotifyPropertyChanged("StorySources"); NotifyPropertyChanged("Stories"); rssFeed.LastUpdated = DateTime.Now; _applicationSettings[RssFeedsKey] = new Collection <RssFeed> (StorySources); _applicationSettings.Save(); }
public RssFeed(Rss.Structure.RssFeed rss) : base() { this.Stories = new ObservableCollection <RssStory>(CloneStories(rss)); this.RssTitle = rss.Channel.Title; this.LastUpdated = DateTime.Now; }