Esempio n. 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);
        }
Esempio n. 3
0
        private void Button_AddNewFeed_Click(object sender, RoutedEventArgs e)
        {
            RssReader rssReader = new RssReader();
            Feed feed = new Feed();

            try
            {
                feed = rssReader.ReadBasicFeed(TextBox_FeedUrl.Text);
                Feeds.Add(feed);
                rssReader.UpdateFeedItems(feed, true);
                MessageBox.Show("A new feed (" + feed.Title + ") was successfully added.");
                BuildFeedList();
            }
            catch (Exception exception){ DisplayErrorMessage(exception.Message); }
            finally { TextBox_FeedUrl.Clear(); }
        }
Esempio n. 4
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;
        }
Esempio n. 5
0
        /// <summary>
        /// Hämtar grundläggande information om ett Feed-objekt från en RSS-fil, exempelvis titel och beskrivning. Hämtar INTE avnsnitt.
        /// </summary>
        public Feed ReadBasicFeed(string url)
        {
            Feed feed = new Feed();

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

            XmlNode node = document.DocumentElement.SelectSingleNode("channel");

            feed.FeedUrl = url;
            feed.Title = InnerTextOrNull(node.SelectSingleNode("title"));
            feed.Link = InnerTextOrNull(node.SelectSingleNode("link"));
            feed.Description = InnerTextOrNull(node.SelectSingleNode("description"));

            feed.Category = new Category();
            feed.UpdateInterval = TimeSpan.TicksPerDay;
            feed.LastUpdate = DateTime.MinValue;

            return feed;
        }
Esempio n. 6
0
        public EditFeed(List<Category> categories, Feed feed)
        {
            InitializeComponent();

            Categories = categories;
            Feed = feed;

            TextBox_FeedUrl.Text = Feed.FeedUrl;
            TextBox_Title.Text = Feed.Title;
            TextBox_Link.Text = Feed.Link;
            TextBox_Description.Text = Feed.Description;

            foreach(Category category in Categories)
            {
                // Ignorerar alla kategorier som är null så att inga föremål med tomma värden blir tillagda
                if (!string.IsNullOrEmpty(category.Name))
                    ComboBox_Category.Items.Add(category.Name);
            }

            ComboBox_Category.SelectedItem = Feed.Category.Name;

            TextBox_UpdateInterval.Text = "" + (Feed.UpdateInterval / TimeSpan.TicksPerMinute);
        }
Esempio n. 7
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)
 {
     UpdateFeedItems(feed, false);
 }