Пример #1
0
        public void AddItem(RssItem item)
        {
            if (this.Items.Any(x => x.UniqueId == item.UniqueId))
            {
                return;
            }

            this.Items.Add(item);
        }
Пример #2
0
        /// <summary>
        /// using Windows.Web.Syndication
        /// </summary>
        /// <param name="feedUriString"></param>
        /// <returns></returns>
        private async Task<RssSource> ForgeRssSource(string feedUriString)
        {

            AddSourceProgressRing.IsActive = true;
            Windows.Web.Syndication.SyndicationClient client = new SyndicationClient();
            Uri feedUri = new Uri(feedUriString);

            try
            {
                SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);

                // This code is executed after RetrieveFeedAsync returns the SyndicationFeed.
                // Process the feed and copy the data you want into the FeedData and FeedItem classes.
                RssSource feedData = new RssSource(feedUri.ToString());

                if (feed.Title != null && feed.Title.Text != null)
                {
                    feedData.Title = feed.Title.Text;
                }
                if (feed.Subtitle != null && feed.Subtitle.Text != null)
                {
                    feedData.Description = feed.Subtitle.Text;
                }
                if (feed.Items != null && feed.Items.Count > 0)
                {
                    // Use the date of the latest post as the last updated date.
                    feedData.LastBuildTime = feed.Items[0].PublishedDate.DateTime;
                    feedData.CreateTime = feed.LastUpdatedTime.UtcDateTime;

                    foreach (SyndicationItem item in feed.Items)
                    {
                        RssItem feedItem = null;

                        // Handle the differences between RSS and Atom feeds.
                        if (feed.SourceFormat == SyndicationFormat.Atom10)
                        {
                            if (item.Id != null)
                            {
                                feedItem = new RssItem(item.Id, feedData);
                                feedItem.Link = new Uri(item.Id);
                            }
                            if (item.Content != null && item.Content.Text != null)
                            {
                                feedItem.Content = item.Content.Text;
                            }
                            
                        }
                        else if (feed.SourceFormat == SyndicationFormat.Rss20)
                        {
                            if (item.Links != null && item.Links.Count > 0)
                            {
                                feedItem = new RssItem(item.Links[0].Uri.ToString(), feedData);
                                feedItem.Link = item.Links[0].Uri;
                            }
                            if (item.Summary != null && item.Summary.Text != null)
                            {
                                feedItem.Content = item.Summary.Text;
                            }
                            
                        }

                        if (item.Title != null && item.Title.Text != null)
                        {
                            feedItem.Title = item.Title.Text;
                        }
                        if (item.PublishedDate != null)
                        {
                            feedItem.CreateTime = item.PublishedDate.DateTime;
                        }

                        if (item.Authors != null && item.Authors.Count > 0)
                        {
                            feedItem.Author = item.Authors[0].Name.ToString();
                        }
                        
                        feedData.AddItem(feedItem);
                    }
                }
                AddSourceProgressRing.IsActive = false;

                return feedData;
            }
            catch (Exception)
            {

                AddSourceProgressRing.IsActive = false;
                return null;
            }
        }