public List<FeedItem> ReadFeedItems(Uri uri) { var feedItems = new List<Data.IFeedItem>(); SyndicationFeed syndicationFeed; using (var xmlReader = XmlReader.Create(uri.AbsoluteUri)) { syndicationFeed = SyndicationFeed.Load(xmlReader); xmlReader.Close(); } foreach (var item in syndicationFeed.Items) { var feedItem = new FeedItem(); var id = Guid.NewGuid(); feedItem.Id = Guid.TryParse(item.Id, out id) ? new Guid(item.Id) : id; feedItem.Title = item.Title.Text; feedItem.Mp3Url = item.Links[0].Uri; feedItem.PublishDate = item.PublishDate.DateTime; feedItems.Add(feedItem); } var ret = new List<FeedItem>(); feedItems.ForEach(x => ret.Add(new FeedItem() { Id = x.Id, Mp3Url = x.Mp3Url, PublishDate = x.PublishDate, Title = x.Title })); return ret; }
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"); }
/// <summary> /// Hämtar alla föremål från ett Feed-objekts RSS-URL som har ett <pubDate> 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); } }
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; }
public FeedItemViewModel(FeedItem item) { PlayerView = new PlayerViewModel(item.Url); PlayerView.PropertyChanged += updateLastPlayedTimeStamp; Item = item; }
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; }
public void addFeedItem(Guid ID, string title, Uri Mp3Url, DateTime PublishDate, bool IsUsed, string Description) { var Item = new FeedItem { Id = Id, Title = title, Mp3Url = Mp3Url, PublishDate = PublishDate, IsUsed = IsUsed, Description = Description }; CollectionFeedItems.Add(Item); }
public void canCompareFeedItems() { var IdY = "IdY"; var IdZ = "IdZ"; var feedItem1 = new FeedItem() { Id = IdZ, Title = "FeedItem1" }; var feedItem2 = new FeedItem() { Id = IdZ, Title = "FeedItem2" }; var feedItem3 = new FeedItem() { Id = IdY, Title = "FeedItem3" }; Assert.IsTrue(feedItem1.Equals(feedItem2), "Object.Equals() false negative for Feed"); Assert.IsFalse(feedItem2.Equals(feedItem3), "Object.Equals() false positive for Feed"); Assert.IsFalse(feedItem2 == feedItem3, "== operator overload false positive for feed"); Assert.IsTrue(feedItem2 != feedItem3, "== operator overload false negative for feed"); Assert.IsTrue(feedItem1 != feedItem3, "!= operator overload false positive for feed"); Assert.IsFalse(feedItem1 != feedItem2, "!= operator overload false negative for feed"); //Assert.IsFalse(feedItem1.Equals(new Object(), "false positive comparing feed to object"); }
/// <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; }
public ShowPodcastInfoForm(FeedItem feedItem) { InitializeComponent(); FeedItem = feedItem; }
public void AddListentedTo(FeedItem item) { ListenedToPods.Add(item.Title); ListenedToPods = ListenedToPods.Distinct().ToList(); }
public void addFeedItem(FeedItem newItem) { FeedItems.Add(newItem); }
public void PlayFile(FeedItem item) { string itemPath = GetFilepath(item); System.Diagnostics.Process.Start(GetFilepath(item) + @"\" + GetDownloadFileName(item)); }