コード例 #1
0
ファイル: RssReader.cs プロジェクト: kmonassar/CSharpRSS
        /// <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)
        {
            try
            {
                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 (item.PublicationDate < feed.LastUpdate) 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;

                    feed.Episodes.Add(item);
                }

                feed.LastUpdate = DateTime.Now;
            }
            catch (Exception e)
            {
                MessageBox.Show("Ett fel har uppstått:\n\n" + e.Message);
            }
        }
コード例 #2
0
ファイル: RssReader.cs プロジェクト: kmonassar/CSharpRSS
        /// <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();

            try
            {
                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.LastUpdate = DateTime.MinValue;
            }
            catch (Exception e)
            {
                MessageBox.Show("Ett fel har uppstått:\n\n" + e.Message);
            }

            return feed;
        }
コード例 #3
0
        public Feed ReadFeed(Uri uri)
        {
            Feed feed = null;
            var feedItems = new List<FeedItem>();
            Category category = null;

            SyndicationFeed syndicationFeed;
            using (var xmlReader = XmlReader.Create(uri.AbsoluteUri))
            {
                syndicationFeed = SyndicationFeed.Load(xmlReader);
                xmlReader.Close();
            }

            if (syndicationFeed == null) return null;
            foreach (var item in syndicationFeed.Items)
            {
                var feedItem = new FeedItem();
                Guid id;

                feedItem.Id = Guid.TryParse(item.Id, out id) ? id : new Guid();
                feedItem.Title = item.Title.Text;
                feedItem.Mp3Url = item.Links.Count > 1 ? item.Links[1].Uri : item.Links[0].Uri;
                feedItem.PublishDate = item.PublishDate.DateTime;
                feedItem.Description = StripHTML(item.Summary.Text);
                feedItem.IsUsed = false;
                feedItems.Add(feedItem);
            }

            var items = new List<Data.IFeedItem>();
            feedItems.ForEach(x => items.Add(x));
            feed = new Feed(Guid.NewGuid(), syndicationFeed.Title.Text, items, uri, category,0);

            return feed;
        }
コード例 #4
0
ファイル: FeedUpdateTests.cs プロジェクト: goekboet/FDR
        public void canUpdateOldFeed()
        {
            var testFeed = new Feed() { Id = Guid.NewGuid(), Url = "http://rss.acast.com/ensvensktiger" };
            testFeed.update();

            var numberOfItemsToRemove = 3;
            var numberOfItems = testFeed.Items.Count;

            Assert.IsTrue(numberOfItems > numberOfItemsToRemove, "The feed contain less Items than we want to remove.");

            var removedItems = new FeedItem[numberOfItemsToRemove];
            while(numberOfItemsToRemove > 0)
            {
                removedItems[numberOfItemsToRemove - 1] = testFeed.Items[testFeed.Items.Count - 1];
                testFeed.Items.Remove(removedItems[numberOfItemsToRemove - 1]);
                numberOfItemsToRemove--;
            }
            Assert.IsTrue(testFeed.Items.Count == numberOfItems - removedItems.Length, "Testmethod did not remove correct number of items");
            foreach (FeedItem item in removedItems)
                Assert.IsFalse(testFeed.Items.Contains(item), "Removed item still in testItem");

            testFeed.LastFetchedFromServer = default(DateTime);
            testFeed.update();
            Assert.IsTrue(testFeed.Items.Count == numberOfItems, "Feed items should be as many as they were before update");
            foreach (FeedItem item in removedItems)
                Assert.IsTrue(testFeed.Items.Contains(item), "The removed item should have been put back into the feed after update");
        }
コード例 #5
0
ファイル: FeedUpdateTests.cs プロジェクト: goekboet/FDR
 public void canDetermineIfDue()
 {
     var fiveSeconds = new TimeSpan(0, 0, 5);
     var testFeed = new Feed() { Id = Guid.NewGuid(), Interval = fiveSeconds, LastFetchedFromServer = DateTime.Now };
     Assert.IsFalse(testFeed.dueForUpdate(), "False positive due for update");
     System.Threading.Thread.Sleep(6000);
     Assert.IsTrue(testFeed.dueForUpdate(), "False negative due for update");
 }
コード例 #6
0
 public void LoadFeed(Data.SerializerItem returFeed)
 {
     var feed = new Feed();
     AllFeeds.Add(feed);
     feed.Id = returFeed.Id;
     feed.Title = returFeed.Title;
     feed.Url = new Uri(returFeed.Url);
     returFeed.CollectionFeedItems.ForEach(x => feed.addFeedItem(x.Id, x.Title, new Uri(x.Mp3Url), x.PublishDate, x.IsUsed, x.Description));
     feed.setCategory(returFeed.Category.Id, returFeed.Category.Name);
     feed.UpdateInterval = returFeed.UpdateInterval;
 }
コード例 #7
0
ファイル: DetailsViewModel.cs プロジェクト: goekboet/FDR
 public DetailsViewModel(Feed feed)
 {
     ConfirmFeed = new RelayCommand(confirmFeed, canConfirm);
     CancelFeed = new RelayCommand(cancelFeed);
     GetFeed = new RelayCommand(updateFeed, canGet);
     SetInterval = new RelayCommand(setInterval);
     repository = DataConnection.getCategories();
     Categories = repository.GetAll() as List<Category>;
     FeedItemList = new ObservableCollection<FeedItem>();
     IsFetched = true;
     setInputValues(feed);
     fillFeedItemList();
 }
コード例 #8
0
ファイル: FeedReader.cs プロジェクト: kmonassar/CSharpRSS
        public List<Feed> Read(string filename)
        {
            List<Feed> feeds = new List<Feed>();

            try
            {
                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("Episodes/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.Episodes = items;

                    feeds.Add(feed);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Ett fel har uppstått:\n\n" + e.Message);
            }

            return feeds;
        }
コード例 #9
0
ファイル: RssReader.cs プロジェクト: goekboet/FDR
        /// <summary>
        /// Kallar på Read om rss-flödet uppdaterat efter denna feed senast kollade efter uppdateringar
        /// </summary>
        /// <param name="feed">Den feed som vill uppdatera</param>
        /// <returns>En uppdaterad feed. Om rss-flödet som parameter-feedens url pekar på inte har blivit uppdaterad sedan denna feed uppdaterade senast är
        /// parameter feeden och return feeden samma objekt. </returns>
        public Feed checkForUpdates(Feed feed)
        {
            Feed updatedFeed;
            if (feed.Url == null) throw new ArgumentException("feed url not set");
            if (!UrlValidator.Validate(feed.Url)) throw new ArgumentException("Invalid feed url");

            var syndicationFeed = fetchFeed(feed.Url);
            if (syndicationFeed.LastUpdatedTime.DateTime < feed.LastFetchedFromServer)
                updatedFeed = feed;
            else
                updatedFeed = Read(feed);

            return updatedFeed;
        }
コード例 #10
0
ファイル: DetailsViewModel.cs プロジェクト: goekboet/FDR
        public DetailsViewModel()
        {
            cacheFeed = new Feed() { Id = Guid.NewGuid(), Name = "", Url = "", Category = Guid.Empty,
                Items = new List<FeedItem>(), Description = "", Interval = new TimeSpan(0,1,0,0)};

            ConfirmFeed = new RelayCommand(confirmFeed, canConfirm);
            CancelFeed = new RelayCommand(cancelFeed);
            GetFeed = new RelayCommand(getFeed, canGet);
            SetInterval = new RelayCommand(setInterval);
            repository = DataConnection.getCategories();
            Categories = repository.GetAll() as List<Category>;
            FeedItemList = new ObservableCollection<FeedItem>();
            IsFetched = false;
            fillFeedItemList();
        }
コード例 #11
0
ファイル: FeedUpdateTests.cs プロジェクト: goekboet/FDR
        public void canUpdateNewFeed()
        {
            var newFeed = new Feed() { Id = Guid.NewGuid(), Url = "http://rss.acast.com/ensvensktiger" };

            Assert.IsTrue(newFeed.LastFetchedFromServer == default(DateTime), "LastFetchFromServer not null for new Feed");
            Assert.IsNull(newFeed.Items, "Items not null for new Feed");
            Assert.IsTrue(newFeed.LastUpdateOnServer == default(DateTime), "LastUpdateOnServer not null for new Feed");
            Assert.IsNull(newFeed.Name, "Name not null for new Feed");

            newFeed.update();

            Assert.IsNotNull(newFeed.LastFetchedFromServer, "LastFetchFromServer is null for updated Feed");
            Assert.IsNotNull(newFeed.Items, "Items is null for updated Feed");
            Assert.IsNotNull(newFeed.LastUpdateOnServer, "LastUpdateOnServer is null for updated Feed");
        }
コード例 #12
0
 private void textBoxUrl_LostFocus(object sender, RoutedEventArgs e)
 {
     var rssReader = new RssReader();
     try
     {
         FeedOut = rssReader.ReadFeed(new Uri(textBoxUrl.Text));
         labelTitleShow.Content = FeedOut.Title + ", episodes: " + FeedOut.CollectionFeedItems.Count;
     }
     catch (UriFormatException ex)
     {
         labelTitleShow.Content = ex.Message;
         FeedOut = null;
     }
     catch (Exception ex)
     {
         labelTitleShow.Content = ex.Message;
         FeedOut = null;
     }
 }
コード例 #13
0
ファイル: EntityTest.cs プロジェクト: goekboet/FDR
        public void canCompareFeeds()
        {
            var IdY = Guid.NewGuid();
            var IdZ = Guid.NewGuid();

            var feed1 = new Feed() { Id = IdZ, Name = "Feed X" };
            var feed2 = new Feed() { Id = IdZ, Name = "Feed Y" };
            var feed3 = new Feed() { Id = IdY, Name = "Feed Z" };

            Assert.IsTrue(feed1.Equals(feed2), "Object.Equals() false negative for Feed");
            Assert.IsFalse(feed1.Equals(feed3), "Object.Equals() false positive for Feed");

            Assert.IsFalse(feed2 == feed3, "== operator overload false positive for feed");
            Assert.IsTrue(feed2 != feed3, "== operator overload false negative for feed");
            Assert.IsTrue(feed1 != feed3, "!= operator overload false positive for feed");
            Assert.IsFalse(feed1 != feed2, "!= operator overload false negative for feed");

            //Assert.IsFalse(feed1.Equals(new Object(), "false positive comparing feed to object");
        }
コード例 #14
0
ファイル: RssReader.cs プロジェクト: goekboet/FDR
        /// <summary>
        /// Dena klass är en hjälpklass till Feed för att den ska kunna uppdatera sina fält via en url till en RSS-feed 
        /// </summary>
        /// <param name="feed">Den feed som innehåller url till RSS-flödet</param>
        /// <returns>En feed som är befolkad med värden från RSS-flödet</returns>
        public Feed Read(Feed feed)
        {
            var syndicationFeed = fetchFeed(feed.Url);
            var feedItems = new List<FeedItem>();

            var fetchedFeed = new Feed() { Id = feed.Id, Url = feed.Url };
            fetchedFeed.Name = (syndicationFeed.Title == null) ? "Namnlös" : syndicationFeed.Title.Text;
            fetchedFeed.LastUpdateOnServer = syndicationFeed.LastUpdatedTime.DateTime;
            fetchedFeed.Description = (syndicationFeed.Description == null) ? "" : syndicationFeed.Description.Text;

            foreach (SyndicationItem syndicationItem in syndicationFeed.Items)
            {
                var feedItem = new FeedItem();
                feedItem.Id = (syndicationItem.Id == null) ? "Okänd" : syndicationItem.Id;
                feedItem.Title = (syndicationItem.Title == null) ? "Okänd" : syndicationItem.Title.Text;
                feedItem.Url = (syndicationItem.Links.Count == 0) ? "Okänd" : getPodcastLink(syndicationItem.Links);
                feedItem.publishDate = (syndicationItem.PublishDate == null) ? default(DateTime) : syndicationItem.PublishDate.DateTime;
                feedItems.Add(feedItem);
            }
            fetchedFeed.Items = feedItems;

            return fetchedFeed;
        }
コード例 #15
0
ファイル: MantainFeed.cs プロジェクト: kmonassar/CSharpRSS
 static void ChangeUpdateInterval(Feed feed, long newUpdateInterval)
 {
     feed.UpdateInterval = newUpdateInterval;
 }
コード例 #16
0
ファイル: EntityTest.cs プロジェクト: goekboet/FDR
        public void canEvaluateContains()
        {
            var IdX = Guid.NewGuid();
            var IdY = Guid.NewGuid();
            var IdZ = Guid.NewGuid();
            var IdU = Guid.NewGuid();

            var category1 = new Category() { Id = IdX, Name = "Category X" };
            var category2 = new Category() { Id = IdX, Name = "Category Y" };
            var category3 = new Category() { Id = IdY, Name = "Category Y" };
            var category4 = new Category() { Id = IdZ, Name = "Category Z " };
            var category5 = new Category() { Id = IdU, Name = "another category" };

            var categories = new List<IEntity>();
            categories.Add(category1);
            categories.Add(category3);
            categories.Add(category4);

            var feed1 = new Feed() { Id = IdZ, Name = "Feed X" };
            var feed2 = new Feed() { Id = IdZ, Name = "Feed Y" };
            var feed3 = new Feed() { Id = IdY, Name = "Feed Z" };
            var feed4 = new Feed() { Id = IdX, Name = "Feed X" };
            var feed5 = new Feed() { Id = IdU, Name = "Feed me" };

            var feeds = new List<IEntity>();
            feeds.Add(feed1);
            feeds.Add(feed4);
            feeds.Add(feed3);

            Assert.IsTrue(categories.Contains(category2), "We consider a collection that contains an entity with the same ID as comparator as containing it.");
            Assert.IsFalse(categories.Contains(category5), "Contains false positive");

            Assert.IsTrue(feeds.Contains(feed2), "We consider a collection that contains an entity with the same ID as comparator as containing it.");
            Assert.IsFalse(feeds.Contains(feed5), "Contains false positive");

            Assert.IsFalse(feeds.Contains(category4), "Contains false positive");
        }
コード例 #17
0
        public Object DeepClone()
        {
            Feed deepFeed = new Feed(this.FeedTitle, this.FeedCategory, this.UpdateInterval, this.Url);

            return(deepFeed);
        }
コード例 #18
0
ファイル: DetailsViewModel.cs プロジェクト: goekboet/FDR
 private void setInputValues(Feed feed)
 {
     cacheFeed = feed;
     Name = feed.Name;
     Url = feed.Url;
     Category = repository.Find(feed.Category);
     Interval = feed.Interval;
 }
コード例 #19
0
 public EditPodcastFeedForm(Feed originalFeed, List<Category> categories)
 {
     InitializeComponent();
     OriginalFeed = originalFeed;
     Categories = categories;
 }
コード例 #20
0
ファイル: FeedViewModel.cs プロジェクト: goekboet/FDR
		private void SetupFeedItemList(Feed feed)
		{
			FeedItems = new ObservableCollection<FeedItemViewModel>();
			foreach (FeedItem item in feed.Items)
			{
				var itemView = new FeedItemViewModel(item);
				itemView.PropertyChanged += feedItemChanged;
				FeedItems.Add(itemView);
			}
			DataConnection.getFeeds().CollectionChanged += updateView;

			FeedItemViewSource = new CollectionViewSource();
			FeedItemViewSource.Source = FeedItems;
			FeedItemViewSource.SortDescriptions.Add(new SortDescription("PublishDate", ListSortDirection.Descending));
			FeedItemViewSource.View.Refresh();
		}
コード例 #21
0
        private void textBoxURL_Leave(object sender, EventArgs e)
        {
            var rssReader = new RssReader();

            try
            {
                labelTitle.Text = "Title:";
                NewFeed = rssReader.ReadFeed(new Uri(textBoxURL.Text));
                textBoxTitle.Text = NewFeed.Title;
                labelEpisodes.Text = "Episodes: " + NewFeed.CollectionFeedItems.Count;

            }
            catch (UriFormatException ex)
            {
                labelTitle.Text = ex.Message;
                NewFeed = null;
            }
            catch (Exception ex)
            {
                labelTitle.Text = ex.Message;
                NewFeed = null;
            }
        }
コード例 #22
0
ファイル: FeedViewModel.cs プロジェクト: goekboet/FDR
		public FeedViewModel(Feed feed)
		{
			this.feed = feed;
			SetupFeedItemList(feed);
			SetupCommands();
		}
コード例 #23
0
ファイル: MantainFeed.cs プロジェクト: kmonassar/CSharpRSS
 static void ChangeCategory(Feed feed, Category newCategory)
 {
     feed.Category = newCategory;
 }
コード例 #24
0
ファイル: wpfFeed.xaml.cs プロジェクト: kmonassar/CSharpRSS
        private void FillEpisodes(Feed feed)
        {
            libEpisodes.Items.Clear();

            foreach (FeedItem fi in feed.Episodes)
            {
                libEpisodes.Items.Add(fi.Title);
            }
        }
コード例 #25
0
 public void removeCategory(Feed selectedFeed)
 {
     this.FeedCategory = null;
 }
コード例 #26
0
        private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs, Feed feed)
        {
            var rssReader = new RssReader();
            var newFeedItems = rssReader.ReadFeedItems(feed.Url);

            foreach (var f in AllFeeds)
            {
                if (feed.Equals(f))
                {
                    var i = newFeedItems.Count - f.CollectionFeedItems.Count;
                    f.CollectionFeedItems = new List<IFeedItem>(newFeedItems);
                    MessageBox.Show(i + " new episodes for " + f.Title);
                }
            }
        }
コード例 #27
0
ファイル: MantainFeed.cs プロジェクト: kmonassar/CSharpRSS
 static void ChangeUrl(Feed feed, string newUrl)
 {
     feed.FeedUrl = newUrl;
 }
コード例 #28
0
ファイル: Details.xaml.cs プロジェクト: goekboet/FDR
 public Details(Feed feed)
 {
     InitializeComponent();
     this.DataContext = new DetailsViewModel(feed);
     setIntervalRadioButton(feed.Interval);
 }