예제 #1
0
        /// <summary>
        /// Hämtar alla föremål från ett Feed-objekts RSS-URL som har ett &lt;pubDate&gt; som infaller senare än Feed-objektets LastUpdate och lägger till dem i Feed-objektets FeedItem-lista.
        /// </summary>
        public void UpdateFeedItems(Feed feed, bool forceUpdate)
        {
            Debug.WriteLine("Updating feed: \"" + feed.Title + "\".");

            if (!forceUpdate && feed.LastUpdate + new TimeSpan(feed.UpdateInterval) > DateTime.Now) return;

            Debug.WriteLine("Updating feed items for feed: \"" + feed.Title + "\".");

            XmlDocument document = new XmlDocument();
            document.Load(feed.FeedUrl);

            foreach (XmlNode node in document.DocumentElement.SelectNodes("channel/item"))
            {
                FeedItem item = new FeedItem();

                item.PublicationDate = RssDateToDateTime(InnerTextOrNull(node.SelectSingleNode("pubDate")));

                if (!forceUpdate && feed.Items.Count > 0 && item.PublicationDate < feed.Items[0].PublicationDate) break;

                item.Title = InnerTextOrNull(node.SelectSingleNode("title"));
                item.Link = InnerTextOrNull(node.SelectSingleNode("link"));
                item.Description = InnerTextOrNull(node.SelectSingleNode("description"));
                item.MediaUrl = ValueOrNull(node.SelectSingleNode("enclosure/@url"));

                item.HasBeenPlayed = false;

                Debug.WriteLine("Fetching feed item: " + item.Title);

                feed.Items.Add(item);
            }

            feed.LastUpdate = DateTime.Now;
        }
        public FeedItemDetails(Feed feed, FeedItem feedItem)
        {
            InitializeComponent();

            Feed = feed;
            FeedItem = feedItem;

            TextBlock_FeedTitle.Inlines.Add(Feed.Title);

            Hyperlink h = new Hyperlink();
            h.NavigateUri = new Uri(Feed.Link);
            h.RequestNavigate += new RequestNavigateEventHandler(Hyperlink_RequestNavigate);
            h.Inlines.Add(Feed.Link);
            TextBlock_FeedLink.Inlines.Add(h);

            TextBlock_FeedDescription.Inlines.Add(Feed.Description);
            if (Feed.Category.Name != null)
                TextBlock_FeedCategory.Inlines.Add(Feed.Category.Name);

            TextBlock_ItemTitle.Inlines.Add(FeedItem.Title);

            h = new Hyperlink();
            h.NavigateUri = new Uri(FeedItem.Link);
            h.RequestNavigate += new RequestNavigateEventHandler(Hyperlink_RequestNavigate);
            h.Inlines.Add(FeedItem.Link);
            TextBlock_ItemLink.Inlines.Add(h);

            TextBlock_ItemDescription.Inlines.Add(FeedItem.Description);
            TextBlock_ItemPubDate.Inlines.Add(FeedItem.PublicationDate.ToString());

            h = new Hyperlink();
            h.NavigateUri = new Uri(FeedItem.MediaUrl);
            h.RequestNavigate += new RequestNavigateEventHandler(Hyperlink_RequestNavigate);
            h.Click += new RoutedEventHandler(Hyperlink_SetFeedItemHasBeenPlayed);
            h.TextDecorations = null;
            h.Inlines.Add("play item");
            TextBlock_ItemActions.Inlines.Add("[");
            TextBlock_ItemActions.Inlines.Add(h);
            TextBlock_ItemActions.Inlines.Add("] ");

            Span s = new Span();
            if (FeedItem.HasBeenPlayed)
            {
                s.Foreground = Brushes.Green;
                s.Inlines.Add("Played");
            }
            else
            {
                s.Foreground = Brushes.Red;
                s.Inlines.Add("Unplayed");
            }
            TextBlock_ItemActions.Inlines.Add(s);
        }
예제 #3
0
        public List<Feed> Read(string filename)
        {
            List<Feed> feeds = new List<Feed>();

            if (!File.Exists(filename)) return feeds;

            XmlDocument document = new XmlDocument();
            document.Load(filename);

            foreach (XmlNode node in document.DocumentElement.SelectNodes("Feed"))
            {
                Feed feed = new Feed();

                feed.FeedUrl = InnerTextOrNull(node.SelectSingleNode("FeedUrl"));
                feed.Title = InnerTextOrNull(node.SelectSingleNode("Title"));
                feed.Link = InnerTextOrNull(node.SelectSingleNode("Link"));
                feed.Description = InnerTextOrNull(node.SelectSingleNode("Description"));
                feed.Category = new Category() { Name = InnerTextOrNull(node.SelectSingleNode("Category/Name")) };
                feed.UpdateInterval = LongOrDefault(node.SelectSingleNode("UpdateInterval"));
                feed.LastUpdate = DateTimeOrDefault(node.SelectSingleNode("LastUpdate"));

                List<FeedItem> items = new List<FeedItem>();

                foreach (XmlNode subNode in node.SelectNodes("Items/FeedItem"))
                {
                    FeedItem item = new FeedItem();

                    item.Title = InnerTextOrNull(subNode.SelectSingleNode("Title"));
                    item.Link = InnerTextOrNull(subNode.SelectSingleNode("Link"));
                    item.Description = InnerTextOrNull(subNode.SelectSingleNode("Description"));
                    item.MediaUrl = InnerTextOrNull(subNode.SelectSingleNode("MediaUrl"));
                    item.PublicationDate = DateTimeOrDefault(subNode.SelectSingleNode("PublicationDate"));
                    item.HasBeenPlayed = BoolOrFalse(subNode.SelectSingleNode("HasBeenPlayed"));

                    items.Add(item);
                }

                feed.Items = items;

                feeds.Add(feed);
            }

            return feeds;
        }