async protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { string podcastUrl = (string)NavigationContext.QueryString["podcastUrl"]; try { Uri podcastUri = new Uri(podcastUrl); String podcastPageXML = await new HttpClient().GetStringAsync(podcastUri); PodcastSubscriptionModel subscription = PodcastFactory.podcastModelFromRSS(podcastPageXML); PodcastName.Text = subscription.PodcastName; PodcastIcon.Source = new BitmapImage(subscription.PodcastLogoUrl); PodcastDescription.Text = subscription.PodcastDescription; } catch (UriFormatException) { Console.WriteLine("Malformed podcast address."); App.showErrorToast("Cannot show information. Malformed web address."); } catch (HttpRequestException) { Console.WriteLine("Could not connect to the XML feed."); App.showErrorToast("Cannot fetch podcast information."); } }
protected override void GivenThat() { base.GivenThat(); _controlFile = TestControlFileFactory.CreateControlFile(); PodcastFactory = new PodcastFactory(); }
void wc_RefetchedRSSForLogoCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { Debug.WriteLine("Malformed podcast address."); return; } PodcastSubscriptionModel subscription = PodcastFactory.podcastModelFromRSS((string)e.Result); PodcastLogoUrl = subscription.PodcastLogoUrl; fetchChannelLogo(); }
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { Debug.WriteLine("Malformed podcast address."); } PodcastSubscriptionModel subscription = PodcastFactory.podcastModelFromRSS((string)e.Result); PodcastName.Text = subscription.PodcastName; PodcastIcon.Source = new BitmapImage(subscription.PodcastLogoUrl); PodcastDescription.Text = subscription.PodcastDescription; }
protected override void GivenThat() { base.GivenThat(); ViewModel.Podcasts.Add(new PodcastViewModel(new PodcastInfo(ControlFile))); CreatedPodcast = new PodcastInfo(ControlFile) { Folder = "created", Feed = new FeedInfo(ControlFile) }; PodcastFactory.Stub(f => f.CreatePodcast(null)) .Return(CreatedPodcast); DialogService.Stub(s => s.ShowEditPodcastDialog(null)) .IgnoreArguments() .WhenCalled(invocation => { CreatedPodcastViewModel = (PodcastViewModel)invocation.Arguments[0]; EditedPodcast = CreatedPodcastViewModel.Podcast; }) .Return(EditPodcastDialogReturn); }
public void updatePodcastEpisodes() { Debug.WriteLine("Updating episodes for podcast: " + m_subscriptionModel.PodcastName); bool subscriptionAddedNow = true; List <PodcastEpisodeModel> episodes = null; using (var db = new PodcastSqlModel()) { episodes = db.episodesForSubscription(m_subscriptionModel); } DateTime latestEpisodePublishDate = new DateTime(); if (episodes.Count > 0) { // The episodes are in descending order as per publish date. // So take the first episode and we have the latest known publish date. latestEpisodePublishDate = episodes[0].EpisodePublished; // If we already have episodes, this subscription is not being added now. subscriptionAddedNow = false; } episodes = null; Debug.WriteLine("\nStarting to parse episodes for podcast: " + m_subscriptionModel.PodcastName); List <PodcastEpisodeModel> newPodcastEpisodes = PodcastFactory.newPodcastEpisodes(m_subscriptionModel.CachedPodcastRSSFeed, latestEpisodePublishDate); m_subscriptionModel.CachedPodcastRSSFeed = ""; if (newPodcastEpisodes == null) { Debug.WriteLine("WARNING: Got null list of new episodes."); return; } using (var db = new PodcastSqlModel()) { PodcastSubscriptionModel sub = db.Subscriptions.FirstOrDefault(s => s.PodcastId == m_subscriptionModel.PodcastId); if (sub == null) { Debug.WriteLine("Subscription NULL. Probably already deleted."); return; } PodcastEpisodeModel[] newEpisodesSet = new PodcastEpisodeModel[newPodcastEpisodes.Count]; newPodcastEpisodes.CopyTo(newEpisodesSet); // Let's check for duplicate episode names. This can happen if the subscription updates the "pubDate" // of the most recent episode in the feed, in which case the most recent one (at least) can become a duplicate entry. foreach (PodcastEpisodeModel newEpisode in newEpisodesSet.AsEnumerable()) { if (sub.Episodes.OrderByDescending(ep => ep.EpisodePublished).Take(10).ToArray().FirstOrDefault(ep => ep.EpisodeName == newEpisode.EpisodeName) != null) { Debug.WriteLine("Episode already found in the subscription, removing: " + newEpisode.EpisodeName); newPodcastEpisodes.Remove(newEpisode); } } db.insertEpisodesForSubscription(m_subscriptionModel, newPodcastEpisodes); // Indicate new episodes to the UI only when we are not adding the feed. // I.e. we want to show new episodes only when we refresh the feed at restart. if (subscriptionAddedNow == false) { int numOfNewPodcasts = newPodcastEpisodes.Count; Debug.WriteLine("Got {0} new episodes.", numOfNewPodcasts); Deployment.Current.Dispatcher.BeginInvoke(() => { m_subscriptionModel.addNumOfNewEpisodes(numOfNewPodcasts); }); sub.addNumOfNewEpisodes(numOfNewPodcasts); db.SubmitChanges(); } } if (m_subscriptionModel.IsAutoDownload && newPodcastEpisodes.Count > 0) { Deployment.Current.Dispatcher.BeginInvoke(() => { PodcastEpisodesDownloadManager.getInstance().addEpisodesToDownloadQueue(newPodcastEpisodes); }); } if (newPodcastEpisodes.Count > 0) { // Update subscription's information if it's pinned to home screen. updatePinnedInformation(); Deployment.Current.Dispatcher.BeginInvoke(() => { // This will call the setter for episode model in the UI that will notify the UI that the content has changed. m_subscriptionModel.EpisodesPublishedDescending = new ObservableCollection <PodcastEpisodeModel>(); }); } }
protected override void When() { CreatedPodcast = PodcastFactory.CreatePodcast(_controlFile); }