Ejemplo n.º 1
0
        /// <summary>
        /// assemble an html string for the web browser to display the contents of the selected feed item
        /// </summary>
        /// <returns></returns>
        public string BuildHtmlForSelectedItem(RssItem item)
        {
            string html;

            // is your preview window not showing up? Make sure the PreviewEnabled setting
            // is set to "true" in the Settings.xml configuration file.

            // retrieve the HTML from the included file
            using (var stream = Application.GetResourceStream(new Uri("Resources/preview.html", UriKind.Relative)).Stream)
            using (var reader = new StreamReader(stream))
            {
                html = reader.ReadToEnd();
            }

            // replace bits of the HTML via tokens with data from our settings and selected feed item
            var content = item.Content;
            if (content.Trim().Length == 0)
            {
                content = AppResources.NoFeedContent;
            }

            html = html.Replace("{{body.foreground}}", ForegroundColor);
            html = html.Replace("{{body.background}}", BackgroundColor);
            html = html.Replace("{{head.title}}", item.Title);
            html = html.Replace("{{body.content}}", content);

            return html;
        }
Ejemplo n.º 2
0
        public void LoadRssFeed(XDocument doc, RssFeed feed)
        {
            SetMediaImage(feed, doc);
            feed.Description = doc.Root.Element("channel").GetSafeElementString("description");
            feed.Items = new ObservableCollection<RssItem>();
            feed.Link = doc.Root.Element("channel").GetSafeElementString("link");

            foreach (var item in doc.Descendants("item"))
            {
                var newItem = new RssItem()
                                  {
                                      Title = item.GetSafeElementString("title"),
                                      Link = item.GetSafeElementString("link"),
                                      Description = item.GetSafeElementString("description"),
                                      PublishDate = item.GetSafeElementDate("pubDate"),
                                      Guid = item.GetSafeElementString("guid")
                                  };

                var content = item.Descendants(NS_RSSCONTENT + "encoded");
                foreach (var xElement in content)
                {
                    newItem.Content = xElement.Value;
                }

                feed.Items.Add(newItem);
            }

            var lastItem = feed.Items.OrderByDescending(i => i.PublishDate).FirstOrDefault();
            if (lastItem != null)
            {
                feed.LastBuildDate = lastItem.PublishDate;
            }
        }
        public void NavigateToFeedItem(RssItem selectedItem)
        {
            if (selectedItem == null)
            {
                return;
            }

            var item = this.rssFeed.Items.FirstOrDefault(x => x.Guid == selectedItem.Guid);

            ParameterSink.Parameter = item;

            this.navigationService.UriFor<RssFeedDetailViewModel>().Navigate();
        }
Ejemplo n.º 4
0
        public void LoadAtomFeed(XDocument doc, RssFeed feed)
        {
            SetMediaImage(feed, doc);
            feed.Description = doc.Root.GetSafeElementString("summary");
            feed.Items = new ObservableCollection<RssItem>();
            feed.LastBuildDate = doc.Root.GetSafeElementDate("updated");
            feed.Link = doc.Root.GetLink("self");

            foreach (var item in doc.Root.Elements(doc.Root.GetDefaultNamespace() + "entry"))
            {
                var newItem = new RssItem()
                                  {
                                      Title = item.GetSafeElementString("title"),
                                      Description = item.GetSafeElementString("description"),
                                      PublishDate = item.GetSafeElementDate("published"),
                                      Guid = item.GetSafeElementString("id"),
                                      Link = item.GetLink("alternate")
                                  };
                feed.Items.Add(newItem);
            }
        }