public void CreateFeedList(PodcastFeed podcastFeed) { var feedTab = new TabPage(); tabCtrlFeeds.TabPages.Add(feedTab); var feedList = new ListBox(); feedList.Dock = DockStyle.Fill; feedTab.Controls.Add(feedList); var rss = WebFetcher.FetchRss(podcastFeed.Url); var feed = RssParser.GetPodcastFeed(rss); podcastFeed.PodcastEpisodes = feed.PodcastEpisodes; feedTab.Text = podcastFeed.Name; foreach (PodcastEpisode podcast in podcastFeed.PodcastEpisodes) { feedList.Items.Add(podcast.Name); } ActiveRss.Add(podcastFeed.Id, rss); TabPages.Add(podcastFeed.Id, feedTab); UpdateClocks.Add(podcastFeed.Id, new UpdateClock(podcastFeed)); SetUpdateClocks(); UpdateClocks[podcastFeed.Id].Start(); }
public Task <Dictionary <string, PodcastFeed> > GetFeedsAsync() { if (hasAll) { return(Task.FromResult(_inMemory)); } else { FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 }; IQueryable <FeedDocument> feeds = _client.CreateDocumentQuery <FeedDocument>( UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), queryOptions); var allFeeds = feeds .ToList(); var dictionary = allFeeds.ToDictionary(fd => fd.Name, fd => { var feed = new PodcastFeed(fd.Url); feed.Refresh(); return(feed); }); _inMemory = dictionary; return(Task.FromResult(dictionary)); } }
public void SearchFunctionalTest(PodcastFeed expectedPodcastFeed) { IEnumerable <PodcastFeed> podcastFeeds = _podHead.Search(expectedPodcastFeed.Title); PodcastFeed feed = podcastFeeds.FirstOrDefault(p => p.Title == expectedPodcastFeed.Title); Assert.IsNotNull(feed); expectedPodcastFeed.AssertEqual(feed); }
public void LoadPodcastFeedFunctionalTest([ValueSource(nameof(PodcastTitlesTestData))] PodcastFeed podcastFeed, [Values(5, 10)] int episodeLimit) { bool result = podcastFeed.Load((uint)episodeLimit); Assert.IsTrue(result); Assert.GreaterOrEqual(episodeLimit, podcastFeed.PodcastEpisodes.Count()); podcastFeed.AssertEpisodes(); }
public void UpdateFeedList(PodcastFeed podcastFeed) { if (CheckForUpdate(podcastFeed)) { RemoveFeedList(podcastFeed); CreateFeedList(podcastFeed); } }
public async Task AddFeed([Summary("The name to give the feed")] string name, [Summary("The url of the rss feed")] string url) { var feed = new PodcastFeed(url); await _feedStorage.AddFeedAsync(name, feed); await ReplyAsync("Feed added"); }
public static void AssertEqual(this PodcastFeed podcastFeed, PodcastFeed otherPodcastFeed) { Assert.AreEqual(podcastFeed.Title, otherPodcastFeed.Title); Assert.AreEqual(podcastFeed.RssLink, otherPodcastFeed.RssLink); Assert.AreEqual(podcastFeed.SiteLink, otherPodcastFeed.SiteLink); Assert.AreEqual(podcastFeed.Description, otherPodcastFeed.Description); Assert.AreEqual(podcastFeed.Category, otherPodcastFeed.Category); Assert.AreEqual(podcastFeed.Feed, otherPodcastFeed.Feed); Assert.AreEqual(podcastFeed.ImageUrl, otherPodcastFeed.ImageUrl); }
public static void AssertEpisodes(this PodcastFeed podcastFeed) { foreach (PodcastEpisode episode in podcastFeed.PodcastEpisodes) { Assert.IsNotEmpty(episode.Title); Assert.IsNotEmpty(episode.Description); Assert.IsNotEmpty(episode.Link); Assert.IsNotEmpty(episode.PubDate); } }
public void TrySearchFunctionalTest(PodcastFeed expectedPodcastFeed) { bool success = _podHead.TrySearch(expectedPodcastFeed.Title, out IEnumerable <PodcastFeed> podcastFeeds, out string errorMessage); Assert.IsTrue(success); Assert.IsNull(errorMessage); PodcastFeed feed = podcastFeeds.FirstOrDefault(p => p.Title == expectedPodcastFeed.Title); Assert.IsNotNull(feed); expectedPodcastFeed.AssertEqual(feed); }
public void RemoveFeedList(PodcastFeed podcastFeed) { UpdateClocks[podcastFeed.Id].Stop(); var tabPage = TabPages[podcastFeed.Id]; tabCtrlFeeds.TabPages.Remove(tabPage); TabPages.Remove(podcastFeed.Id); UpdateClocks.Remove(podcastFeed.Id); ActiveRss.Remove(podcastFeed.Id); }
public async Task AddFeed([Summary("The name to give the feed")] string name, [Summary("The url of the rss feed")] string url) { var feed = new PodcastFeed(url); if (!await _feedStorage.TryAddFeedAsync(name, feed)) { await ReplyAsync($"Feed already added under name {name}"); } await ReplyAsync("Feed added"); }
//Returns true if a new version of the feed is found, otherwise false private bool CheckForUpdate(PodcastFeed podcastFeed) { var rss = WebFetcher.FetchRss(podcastFeed.Url); if (rss.Content == ActiveRss[podcastFeed.Id].Content) { return(false); } else { return(true); } }
public void GetChartsAndLoadFunctionalTest() { const int maxItems = 5; IEnumerable <PodcastFeed> podcastFeeds = _podHead.GetTopCharts(PodcastGenre.Comedy, maxItems); Assert.GreaterOrEqual(maxItems, podcastFeeds.Count()); PodcastFeed feed = podcastFeeds.First(); foreach (PodcastFeed podcastFeed in podcastFeeds) { podcastFeed.Load(); podcastFeed.AssertEpisodes(); } }
public void SearchAndLoadFunctionalTest(PodcastFeed expectedPodcastFeed) { IEnumerable <PodcastFeed> podcastFeeds = _podHead.Search(expectedPodcastFeed.Title); PodcastFeed feed = podcastFeeds.FirstOrDefault(p => p.Title == expectedPodcastFeed.Title); Assert.IsNotNull(feed); expectedPodcastFeed.AssertEqual(feed); foreach (PodcastFeed podcastFeed in podcastFeeds) { podcastFeed.Load(); //Cannot guarentee the result podcastFeed.AssertEpisodes(); } }
/// <summary> /// Retrieves and Loads Podcast Feeds by Search Term. /// In this example the search term happens to be the title of the podcast. /// </summary> private static void SearchForPodcast(string podcastTitle) { PodHead podHead = new PodHead(); //Get a collection of podcast feeds returned by the search. (May throw exceptions). IEnumerable <PodcastFeed> podcastFeeds = podHead.Search(podcastTitle, maxNumberOfFeeds: 5); //Get the podcast feed that matches the title, and print its data. PodcastFeed nprNewsPodcastFeed = podcastFeeds.FirstOrDefault(podcastFeed => podcastFeed.Title == podcastTitle); if (nprNewsPodcastFeed != null) { LoadPodcastEpisodes(nprNewsPodcastFeed); } }
/// <summary> /// Retrieves and Loads Podcast Feeds by Search Term. /// In this example the search term happens to be the title of the podcast. /// </summary> private static void TrySearchForPodcast(string podcastTitle) { PodHead podHead = new PodHead(); //Get a collection of podcast feeds returned by the search. if (podHead.TrySearch(podcastTitle, out IEnumerable <PodcastFeed> podcastFeeds, out string errorMessage, maxNumberOfFeeds: 5)) { //Get the podcast feed that matches the title, and print its data. PodcastFeed podcastFeed = podcastFeeds.FirstOrDefault(feed => feed.Title == podcastTitle); if (podcastFeed != null) { LoadPodcastEpisodes(podcastFeed); //Download latest episode DownloadEpisode(podcastFeed.PodcastEpisodes.First()); } }
public FeedGeneratorTests(ITestOutputHelper output) { _output = output; feed = new PodcastFeed() { Title = "Unit Test", Description = "Testing podcast", Episodes = new List <Podcast>() { new Podcast() { Title = "Episode 1", Description = "Episode 1 Description", DownloadUrl = "http://example.com/test.mp3", AddedAt = DateTime.UtcNow } } }; }
// GET: Feed public async Task <ActionResult> GetFeed() { var podcasts = await _context.Podcasts.OrderByDescending(p => p.AddedAt) .Take(30).ToListAsync(); var feed = new PodcastFeed() { Title = "Matt Misc Podcasts", Description = "Collection of one-off podcasts", Episodes = podcasts }; var memoryStream = new MemoryStream(); FeedGenerator.Generate(memoryStream, feed); memoryStream.Position = 0; return(new FileStreamResult(memoryStream, "application/rss+xml")); }
private void btnAdd_Click(object sender, EventArgs e) { var inputName = txtBoxNameOfFeed.Text; var inputUrl = txtBoxUrl.Text; var inputFreqency = txtBoxFrequency.Text; var inputCategory = (Category)comboBoxCategories.SelectedItem; bool allFieldsFilled; if ( inputName == "" || inputUrl == "" || inputFreqency == "" || inputCategory == null ) { allFieldsFilled = false; Alert.FieldsNotFilled(); } else { allFieldsFilled = true; } if (allFieldsFilled) { var podcastFeed = new PodcastFeed { Name = txtBoxNameOfFeed.Text, Url = txtBoxUrl.Text, UpdateInterval = Convert.ToInt32(txtBoxFrequency.Text), Category = inputCategory }; UnitOfWork.PodcastFeed.Add(podcastFeed); UpdateComboBoxFeeds(); Alert.FeedAdded(); txtBoxNameOfFeed.Clear(); txtBoxUrl.Clear(); txtBoxFrequency.Clear(); } }
public static PodcastFeed GetPodcastFeed(Rss rss) { var reader = XmlReader.Create(rss.Url); feed = SyndicationFeed.Load(reader); var podcastFeed = new PodcastFeed { Name = feed.Title.Text }; foreach (SyndicationItem feedItem in feed.Items) { podcastFeed.PodcastEpisodes.Add(new PodcastEpisode { Name = feedItem.Title.Text }); } return(podcastFeed); }
public async Task AddFeedAsync(string name, PodcastFeed feed) { try { var feedDocument = new FeedDocument { Name = name, Url = feed.Url.ToString() }; _inMemory.Add(name, feed); feed.Refresh(); await _client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), feedDocument); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }
public PodcastFeed Get(string feedUrl) { if (string.IsNullOrEmpty(feedUrl)) { throw new ArgumentNullException(nameof(feedUrl)); } var feed = rssService.GetFeedItems(feedUrl); // ATM we are only supporting single channel RSS var channel = feed?.GetRssChannels()?.FirstOrDefault(); var rssItems = channel?.GetRssItems(); if (rssItems == null) { return(null); } var feedResult = new PodcastFeed { FeedItems = (from rssItem in channel.GetRssItems() select new PodcastFeedItem { Title = rssItem.Title, Url = rssItem.Enclosure?.Url, SizeInBytes = rssItem.Enclosure?.Lenght, ExternalItemId = rssItem.GetGuid(), PublishDate = GetDisplayDate(rssItem.Date), Summary = rssItem.Description, Duration = GetDisplayDuration(rssItem.Duration), }).ToList(), Title = channel.Title, Category = channel.Category, Description = channel.Description, Url = channel.Link }; return(feedResult); }
public Task <PodcastFeed> GetFeedAsync(string name) { try { PodcastFeed feed; if (_inMemory.ContainsKey(name)) { feed = _inMemory[name]; feed.Refresh(); } else { FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 }; var feeds = _client.CreateDocumentQuery <FeedDocument>( UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), queryOptions) .Where(fd => fd.Name == name) .ToList(); feed = new PodcastFeed(feeds.SingleOrDefault()?.Url); } if (feed != null && !_inMemory.ContainsKey(name)) { _inMemory.Add(name, feed); feed.Refresh(); } return(Task.FromResult(feed)); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }