Пример #1
0
        private async Task<FeedData> GetFeedAsync(string feedUriString)
        {
            SyndicationClient client = new SyndicationClient();
            Uri feedUri = new Uri(feedUriString);

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

                FeedData feedData = new FeedData();
                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)
                {
                    feedData.PubDate = feed.Items[0].PublishedDate.DateTime;

                    foreach (SyndicationItem item in feed.Items)
                    {
                        FeedItem feedItem = new FeedItem();
                        if (item.Title != null && item.Title.Text != null)
                            feedItem.Title = item.Title.Text;
                        if (item.PublishedDate != null)
                            feedItem.PubDate = item.PublishedDate.DateTime;
                        if (item.Authors != null && item.Authors.Count > 0)
                            feedItem.Author = item.Authors[0].Name.ToString();

                        if (feed.SourceFormat == SyndicationFormat.Atom10)
                        {
                            if (item.Content != null && item.Content.Text != null)
                                feedItem.Content = item.Content.Text;
                            if (item.Id != null)
                                feedItem.Link = new Uri("http://www.microsoft.com");
                        }
                        else if (feed.SourceFormat == SyndicationFormat.Rss20)
                        {
                            if (item.Summary != null && item.Summary.Text != null)
                                feedItem.Content = item.Summary.Text;
                            if (item.Links != null && item.Links.Count > 0)
                                feedItem.Link = item.Links[0].Uri;
                        }

                        feedData.Items.Add(feedItem);
                    }
                }
                return feedData;
            }
            catch (Exception)
            {
                return null;
            }
        }
Пример #2
0
        private async Task <FeedData> GetFeedAsync(string feedUriString)
        {
            // using 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 it and copy the data we want into our FeedData and FeedItem classes.
                FeedData feedData = new FeedData();

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

                foreach (SyndicationItem item in feed.Items)
                {
                    FeedItem feedItem = new FeedItem();
                    feedItem.Title   = item.Title.Text;
                    feedItem.PubDate = item.PublishedDate.DateTime;
                    feedItem.Author  = item.Authors[0].Name.ToString();
                    // Handle the differences between RSS and Atom feeds.
                    if (feed.SourceFormat == SyndicationFormat.Atom10)
                    {
                        feedItem.Content = item.Content.Text;
                        feedItem.Link    = new Uri("http://windowsteamblog.com" + item.Id);
                    }
                    else if (feed.SourceFormat == SyndicationFormat.Rss20)
                    {
                        feedItem.Content = item.Summary.Text;
                        feedItem.Link    = item.Links[0].Uri;
                    }
                    feedData.Items.Add(feedItem);
                }
                return(feedData);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            // Run the PopInThemeAnimation
            Windows.UI.Xaml.Media.Animation.Storyboard sb =
                this.FindName("PopInStoryboard") as Windows.UI.Xaml.Media.Animation.Storyboard;
            if (sb != null)
            {
                sb.Begin();
            }

            // TODO: Assign a bindable group to this.DefaultViewModel["Group"]
            // TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"]
            string   feedTitle = (string)navigationParameter;
            FeedData feedData  = FeedDataSource.GetFeed(feedTitle);

            if (feedData != null)
            {
                this.DefaultViewModel["Feed"]  = feedData;
                this.DefaultViewModel["Items"] = feedData.Items;
            }

            if (pageState == null)
            {
                // When this is a new page, select the first item automatically unless logical page
                // navigation is being used (see the logical page navigation #region below.)
                if (!this.UsingLogicalPageNavigation() && this.itemsViewSource.View != null)
                {
                    this.itemsViewSource.View.MoveCurrentToFirst();
                }
                else
                {
                    this.itemsViewSource.View.MoveCurrentToPosition(-1);
                }
            }
            else
            {
                // Restore the previously saved state associated with this page
                if (pageState.ContainsKey("SelectedItem") && this.itemsViewSource.View != null)
                {
                    // TODO: Invoke this.itemsViewSource.View.MoveCurrentTo() with the selected
                    //       item as specified by the value of pageState["SelectedItem"]
                    string   itemTitle    = (string)pageState["SelectedItem"];
                    FeedItem selectedItem = FeedDataSource.GetItem(itemTitle);
                    this.itemsViewSource.View.MoveCurrentTo(selectedItem);
                }
            }
        }
Пример #4
0
        private async Task<FeedData> GetFeedAsync(string feedUriString) {
            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.
                FeedData feedData = new FeedData();

                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.PubDate = feed.Items[0].PublishedDate.DateTime;

                    foreach (SyndicationItem item in feed.Items) {
                        FeedItem feedItem = new FeedItem();
                        if (item.Title != null && item.Title.Text != null) {
                            feedItem.Title = item.Title.Text;
                        }
                        if (item.PublishedDate != null) {
                            feedItem.PubDate = item.PublishedDate.DateTime;
                        }
                        if (item.Authors != null && item.Authors.Count > 0) {
                            feedItem.Author = item.Authors[0].Name.ToString();
                        }
                        // Handle the differences between RSS and Atom feeds.
                        if (feed.SourceFormat == SyndicationFormat.Atom10) {
                            if (item.Content != null && item.Content.Text != null) {
                                feedItem.Content = item.Content.Text;
                            }
                            if (item.Id != null) {
                                feedItem.Link = new Uri("http://windowsteamblog.com" + item.Id);
                            }
                        }
                        else if (feed.SourceFormat == SyndicationFormat.Rss20) {
                            if (item.Summary != null && item.Summary.Text != null) {
                                feedItem.Content = item.Summary.Text;
                            }
                            if (item.Links != null && item.Links.Count > 0) {
                                feedItem.Link = item.Links[0].Uri;
                            }
                        }
                        feedData.Items.Add(feedItem);
                    }
                }
                return feedData;
            }
            catch (Exception) {
                return null;
            }
        }
Пример #5
0
            private async Task<FeedData> GetFeedAsync(string feedUriString)
            {
                // using 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 it and copy the data we want into our FeedData and FeedItem classes.
                    FeedData feedData = new FeedData();

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

                    foreach (SyndicationItem item in feed.Items)
                    {
                        FeedItem feedItem = new FeedItem();
                        feedItem.Title = item.Title.Text.Replace("<p>", " ").Replace("</p>", " ").Replace("&quot;", " ");
                        feedItem.PubDate = item.PublishedDate.DateTime;
                       //feedItem.Author = item.Authors[0].Name.ToString();
                        // Handle the differences between RSS and Atom feeds.
                        if (feed.SourceFormat == SyndicationFormat.Atom10)
                        {
                            if (item.Content != null)
                                feedItem.Content = item.Content.Text.Replace("<p>", " ").Replace("</p>", " ").Replace("&quot;", " ");
                            feedItem.Link = new Uri(item.Id);
                        }
                        else if (feed.SourceFormat == SyndicationFormat.Rss20)
                        {
                            
                            feedItem.Content = item.Summary.Text;
                            feedItem.Content=Regex.Replace(feedItem.Content, "<.*?>", "")
                                .Replace("&quot;", "");
                            feedItem.Link = item.Links[0].Uri;
                        }
                        feedData.Items.Add(feedItem);
                    }
                    return feedData;
                }
                catch (Exception)
                {
                    return null;
                }
            }