void LoadNews()
 {
     StatusStringOn();
     rssItem = (App.Current as App).News;
     news = new News(rssItem);
     news.Loaded += new NewsLoaded(news_Loaded);
 }
Beispiel #2
0
        /// <summary>
        /// Gets the RSS items.
        /// </summary>
        /// <param name="rssFeed">The RSS feed.</param>
        /// <param name="onGetRssItemsCompleted">The on get RSS items completed.</param>
        /// <param name="onError">The on error.</param>
        public static void GetRssItems(string rssFeed, Action<IEnumerable<RssItem>> onGetRssItemsCompleted = null, Action<Exception> onError = null, Action onFinally = null)
        {
            WebClient webClient = new WebClient();

            // register on download complete event
            webClient.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
            {
                try
                {
                    // report error
                    if (e.Error != null)
                    {
                        if (onError != null)
                        {
                            onError(e.Error);
                        }
                        return;
                    }

                    // convert rss result to model
                    List<RssItem> rssItems = new List<RssItem>();
                    Stream stream = e.Result;
                    XmlReader response = XmlReader.Create(stream);
                    SyndicationFeed feeds = SyndicationFeed.Load(response);
                    foreach (SyndicationItem f in feeds.Items)
                    {
                        #region Categories

                        string Categories = String.Empty;
                        foreach (SyndicationCategory cat in f.Categories)
                            Categories += "[" + cat.Name + "], ";
                        if (Categories != String.Empty)
                            Categories = Categories.Remove(Categories.Length - 2);
                        #endregion

                        RssItem rssItem = new RssItem(f.Title.Text, f.Summary.Text, f.PublishDate.ToString(), f.Links[0].Uri.AbsoluteUri, Categories);
                        rssItems.Add(rssItem);
                    }

                    // notify completed callback
                    if (onGetRssItemsCompleted != null)
                    {
                        onGetRssItemsCompleted(rssItems);
                    }
                }
                finally
                {
                    // notify finally callback
                    if (onFinally != null)
                    {
                        onFinally();
                    }
                }
            };

            webClient.OpenReadAsync(new Uri(rssFeed));
        }
Beispiel #3
0
        /// <summary>
        /// Gets the RSS items.
        /// </summary>
        /// <param name="rssFeed">The RSS feed.</param>
        /// <param name="onGetRssItemsCompleted">The on get RSS items completed.</param>
        /// <param name="onError">The on error.</param>
        public static void GetRssItems(string rssFeed, Action <IEnumerable <RssItem> > onGetRssItemsCompleted = null, Action <Exception> onError = null, Action onFinally = null)
        {
            WebClient webClient = new WebClient();

            // register on download complete event
            webClient.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
            {
                try
                {
                    // report error
                    if (e.Error != null)
                    {
                        if (onError != null)
                        {
                            onError(e.Error);
                        }
                        return;
                    }

                    // convert rss result to model
                    List <RssItem>  rssItems = new List <RssItem>();
                    Stream          stream   = e.Result;
                    XmlReader       response = XmlReader.Create(stream);
                    SyndicationFeed feeds    = SyndicationFeed.Load(response);
                    foreach (SyndicationItem f in feeds.Items)
                    {
                        #region Categories

                        string Categories = String.Empty;
                        foreach (SyndicationCategory cat in f.Categories)
                        {
                            Categories += "[" + cat.Name + "], ";
                        }
                        if (Categories != String.Empty)
                        {
                            Categories = Categories.Remove(Categories.Length - 2);
                        }
                        #endregion

                        RssItem rssItem = new RssItem(f.Title.Text, f.Summary.Text, f.PublishDate.ToString(), f.Links[0].Uri.AbsoluteUri, Categories);
                        rssItems.Add(rssItem);
                    }

                    // notify completed callback
                    if (onGetRssItemsCompleted != null)
                    {
                        onGetRssItemsCompleted(rssItems);
                    }
                }
                finally
                {
                    // notify finally callback
                    if (onFinally != null)
                    {
                        onFinally();
                    }
                }
            };

            webClient.OpenReadAsync(new Uri(rssFeed));
        }
Beispiel #4
0
 public News(RssItem rssItem)
 {
     this.rssItem = rssItem;
     LoadNews();
 }