void deleteSubscriptionFromDB(object sender, DoWorkEventArgs e) { PodcastSubscriptionModel podcastModel = e.Argument as PodcastSubscriptionModel; using (var db = new PodcastSqlModel()) { PodcastSubscriptionModel dbSubscription = db.Subscriptions.First(s => s.PodcastId == podcastModel.PodcastId); dbSubscription.cleanupForDeletion(); db.deleteSubscription(dbSubscription); } e.Result = podcastModel; }
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 OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { if (m_subscription == null) { int podcastId = int.Parse(NavigationContext.QueryString["podcastId"]); using (var db = new PodcastSqlModel()) { m_subscription = db.subscriptionModelForIndex(podcastId); } } this.DataContext = m_subscription; }
private void MenuItemPin_Click(object sender, RoutedEventArgs e) { PodcastSubscriptionModel subscriptionToPin = (sender as MenuItem).DataContext as PodcastSubscriptionModel; // Copy the logo file to tile's shared location. String tileImageLocation = "Shared/ShellContent/" + subscriptionToPin.PodcastLogoLocalLocation.Split('/')[1]; using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (myIsolatedStorage.FileExists(subscriptionToPin.PodcastLogoLocalLocation) == false) { Debug.WriteLine("Podcast logo not found. Cannot pin."); App.showNotificationToast("Podcast logo not found. Cannot pin."); return; } if (myIsolatedStorage.FileExists(tileImageLocation) == false) { myIsolatedStorage.CopyFile(subscriptionToPin.PodcastLogoLocalLocation, tileImageLocation); } } // Setup data for the live tile. StandardTileData tileData = new StandardTileData(); tileData.BackgroundImage = new Uri("isostore:/" + tileImageLocation, UriKind.Absolute); tileData.Title = subscriptionToPin.PodcastName; IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; String subscriptionLatestEpisodeKey = App.LSKEY_BG_SUBSCRIPTION_LATEST_EPISODE + subscriptionToPin.PodcastId; if (settings.Contains(subscriptionLatestEpisodeKey) == false) { settings.Add(subscriptionLatestEpisodeKey, ""); // Create empty key so we know the subscription is pinned. } subscriptionToPin.EpisodesManager.updatePinnedInformation(); try { Uri tileUri = new Uri(string.Format("/Views/PodcastEpisodes.xaml?podcastId={0}&forceUpdate=true", subscriptionToPin.PodcastId), UriKind.Relative); Debug.WriteLine(string.Format("Pinning to start: Image: {0} Title: {1} Navigation uri: {2}", tileData.BackgroundImage, tileData.Title, tileUri)); ShellTile.Create(tileUri, tileData); } catch (InvalidOperationException) { Debug.WriteLine("Could not pin to start screen. The subscription is already pinned."); } }
void m_subscriptionsManager_OnPodcastSubscriptionsChanged(object source, SubscriptionManagerArgs e) { switch (e.state) { case PodcastSubscriptionsManager.SubscriptionsState.RefreshingSubscription: PodcastSubscriptionModel subscription = e.subscription; subscription.SubscriptionStatus = "Refreshing..."; break; case PodcastSubscriptionsManager.SubscriptionsState.FinishedRefreshing: this.SubscriptionsList.StopPullToRefreshLoading(true, true); break; } }
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { using (var db = new PodcastSqlModel()) { PodcastSubscriptionModel sub = db.Subscriptions.First(s => s.PodcastId == m_subscription.PodcastId); sub.NewEpisodesCount = 0; db.SubmitChanges(); } PodcastSubscriptionsManager.getInstance().NewPlayableEpisode -= new PodcastSubscriptionsManager.EpisodesEventHandler(m_subscription_NewPlayableEpisode); App.episodeDownloadManager.OnPodcastEpisodeDownloadStateChanged -= new PodcastDownloadManagerHandler(episodeDownloadManager_PodcastEpisodeDownloadStateChanged); PodcastPlaybackManager.getInstance().OnPodcastStartedPlaying -= new EventHandler(PodcastEpisodes_OnPodcastPlaystateChanged); PodcastPlaybackManager.getInstance().OnPodcastStoppedPlaying -= new EventHandler(PodcastEpisodes_OnPodcastPlaystateChanged); }
public IEnumerable <PodcastEpisodeModel> playableEpisodesForSubscription(PodcastSubscriptionModel subscription) { var query = from PodcastEpisodeModel episode in Episodes where (episode.PodcastId == subscription.PodcastId && episode.EpisodeFile != "" && (episode.EpisodePlayState == PodcastEpisodeModel.EpisodePlayStateEnum.Downloaded || episode.EpisodePlayState == PodcastEpisodeModel.EpisodePlayStateEnum.Playing || episode.EpisodePlayState == PodcastEpisodeModel.EpisodePlayStateEnum.Listened || episode.EpisodePlayState == PodcastEpisodeModel.EpisodePlayStateEnum.Paused || episode.EpisodeDownloadState == PodcastEpisodeModel.EpisodeDownloadStateEnum.Downloading || episode.EpisodeDownloadState == PodcastEpisodeModel.EpisodeDownloadStateEnum.Queued)) orderby episode.EpisodePublished descending select episode; return(query); }
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { PodcastSubscriptionModel subscriptionDataContext = this.DataContext as PodcastSubscriptionModel; PodcastSubscriptionModel subscription = null; using (var db = new PodcastSqlModel()) { subscription = db.subscriptionModelForIndex(m_podcastId); subscription.SubscriptionSelectedKeepNumEpisodesIndex = subscriptionDataContext.SubscriptionSelectedKeepNumEpisodesIndex; subscription.IsSubscribed = subscriptionDataContext.IsSubscribed; subscription.IsAutoDownload = subscriptionDataContext.IsAutoDownload; subscription.SubscriptionIsDeleteEpisodes = subscriptionDataContext.SubscriptionIsDeleteEpisodes; db.SubmitChanges(); } }
private void subscriptionManager_OnPodcastChannelAdded(PodcastSubscriptionModel s) { Debug.WriteLine("Subscription added"); List <PodcastSubscriptionModel> subs = m_subscriptions.ToList(); subs.Add(s); subs.Sort(PodcastSubscriptionSortComparator); m_subscriptions = new ObservableCollection <PodcastSubscriptionModel>(subs); this.SubscriptionsList.ItemsSource = m_subscriptions; NoSubscriptionsLabel.Visibility = Visibility.Collapsed; // Update all episodes to the latest list. App.mainViewModels.LatestEpisodesListProperty = new ObservableCollection <PodcastEpisodeModel>(); }
public async void deleteSubscription(PodcastSubscriptionModel podcastSubscriptionModel) { OnPodcastChannelDeleteStarted(this, null); await Task.Run(() => { using (var db = new PodcastSqlModel()) { PodcastSubscriptionModel dbSubscription = db.Subscriptions.First(s => s.PodcastId == podcastSubscriptionModel.PodcastId); dbSubscription.cleanupForDeletion(); db.deleteSubscription(dbSubscription); } }); OnPodcastChannelDeleteFinished(this, null); OnPodcastChannelRemoved(podcastSubscriptionModel); }
private void workerUpdateEpisodesCompleted(object sender, RunWorkerCompletedEventArgs e) { // Ugly. if (App.forceReloadOfEpisodeData) { PodcastSubscriptionModel sub = e.Result as PodcastSubscriptionModel; if (sub == null) { Debug.WriteLine("Warning: Could not get subscription from e.Result!"); return; } sub.reloadUnplayedPlayedEpisodes(); sub.reloadPartiallyPlayedEpisodes(); } refreshNextSubscription(); }
public void insertEpisodesForSubscription(PodcastSubscriptionModel subscriptionModel, List <PodcastEpisodeModel> newPodcastEpisodes) { if (newPodcastEpisodes.Count < 1) { return; } Debug.WriteLine("Writing {0} new episodes to SQL.", newPodcastEpisodes.Count); foreach (PodcastEpisodeModel episode in newPodcastEpisodes) { episode.PodcastId = subscriptionModel.PodcastId; Episodes.InsertOnSubmit(episode); subscriptionModel.Episodes.Add(episode); } SubmitChanges(); }
private void subscriptionManager_OnPodcastChannelPlayedCountChanged(PodcastSubscriptionModel s) { Debug.WriteLine("Play status changed."); List <PodcastSubscriptionModel> subs = m_subscriptions.ToList(); foreach (PodcastSubscriptionModel sub in subs) { if (sub.PodcastId == s.PodcastId) { Deployment.Current.Dispatcher.BeginInvoke(() => { sub.reloadUnplayedPlayedEpisodes(); sub.reloadPartiallyPlayedEpisodes(); }); break; } } }
private void PodcastSubscriptionsManager_OnPodcastAddedFinished(object source, SubscriptionManagerArgs e) { PodcastSubscriptionModel subscriptionModel = e.subscription; Debug.WriteLine("Podcast added successfully. Name: " + subscriptionModel.PodcastName); subscriptionModel.EpisodesManager.updatePodcastEpisodes(); if (e.isImportingFromExternalService) { m_activeExternalImportsCount--; if (m_activeExternalImportsCount <= 0) { if (OnExternalServiceImportFinished != null) { OnExternalServiceImportFinished(this, null); } } } }
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { PodcastSubscriptionModel subscriptionDataContext = this.DataContext as PodcastSubscriptionModel; PodcastSubscriptionModel subscription = null; using (var db = new PodcastSqlModel()) { subscription = db.subscriptionModelForIndex(m_subscription.PodcastId); subscription.SubscriptionSelectedKeepNumEpisodesIndex = subscriptionDataContext.SubscriptionSelectedKeepNumEpisodesIndex; subscription.IsSubscribed = subscriptionDataContext.IsSubscribed; subscription.IsAutoDownload = subscriptionDataContext.IsAutoDownload; subscription.SubscriptionIsDeleteEpisodes = subscriptionDataContext.SubscriptionIsDeleteEpisodes; db.SubmitChanges(); } m_subscription = null; NavigationService.GoBack(); }
private void setupPlayerUIContent(PodcastEpisodeModel currentEpisode) { if (currentEpisode == null) { return; } Debug.WriteLine("Setting up player UI."); if (currentEpisode.EpisodeName == PodcastEpisodeName.Text) { return; } using (var db = new PodcastSqlModel()) { PodcastSubscriptionModel s = db.Subscriptions.Where(sub => sub.PodcastId == currentEpisode.PodcastId).FirstOrDefault(); PodcastLogo.Source = s.PodcastLogo; PodcastEpisodeName.Text = currentEpisode.EpisodeName; } }
public void cleanListenedEpisodes(PodcastSubscriptionModel podcastSubscriptionModel) { using (var db = new PodcastSqlModel()) { float listenedEpisodeThreshold = 0.0F; listenedEpisodeThreshold = (float)db.settings().ListenedThreashold / (float)100.0; var queryDelEpisodes = db.Episodes.Where(episode => episode.PodcastId == podcastSubscriptionModel.PodcastId).AsEnumerable() .Where(ep => (ep.EpisodePlayState == PodcastEpisodeModel.EpisodePlayStateEnum.Listened || (ep.EpisodeFile != "" && ((ep.TotalLengthTicks > 0 && ep.SavedPlayPos > 0) && ((float)((float)ep.SavedPlayPos / (float)ep.TotalLengthTicks) > listenedEpisodeThreshold)))) ).AsEnumerable(); foreach (var episode in queryDelEpisodes) { episode.deleteDownloadedEpisode(); } } }
private void updatePrimary(PodcastEpisodeModel currentEpisode) { ShellTile PrimaryTile = ShellTile.ActiveTiles.First(); if (PrimaryTile != null) { StandardTileData tile = new StandardTileData(); String tileImageLocation = ""; String podcastLogoLocalLocation = ""; // Copy the logo file to tile's shared location. using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var db = new PodcastSqlModel()) { PodcastSubscriptionModel sub = db.Subscriptions.First(s => s.PodcastId == currentEpisode.PodcastId); podcastLogoLocalLocation = sub.PodcastLogoLocalLocation; tile.BackTitle = sub.PodcastName; } if (myIsolatedStorage.FileExists(podcastLogoLocalLocation) == false) { // Cover art does not exist, we cannot do anything. Give up, don't put it to Live tile. Debug.WriteLine("Podcasts cover art not found."); return; } tileImageLocation = "Shared/ShellContent/" + podcastLogoLocalLocation.Split('/')[1]; if (myIsolatedStorage.FileExists(tileImageLocation) == false) { myIsolatedStorage.CopyFile(podcastLogoLocalLocation, tileImageLocation); } } tile.BackBackgroundImage = new Uri("isostore:/" + tileImageLocation, UriKind.Absolute); PrimaryTile.Update(tile); } }
private void PlayHistoryItemTapped(object sender, System.Windows.Input.GestureEventArgs e) { PodcastEpisodeModel episode = DataContext as PodcastEpisodeModel; if (episode == null) { App.showNotificationToast("You don't subscribe to the podcast anymore."); return; } using (var db = new PodcastSqlModel()) { PodcastSubscriptionModel sub = db.Subscriptions.FirstOrDefault(s => s.PodcastId == episode.PodcastId); if (sub == null) { App.showNotificationToast("You don't subscribe to the podcast anymore."); return; } } (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri(string.Format("/Views/PodcastEpisodes.xaml?podcastId={0}", episode.PodcastId), UriKind.Relative)); }
private void MenuItemMarkAsListened_Click(object sender, RoutedEventArgs e) { PodcastEpisodeModel podcastEpisode = this.DataContext as PodcastEpisodeModel; PodcastSubscriptionModel subscription = null; // We need this to update the play states for this subscription. bool delete = false; using (var db = new PodcastSqlModel()) { PodcastEpisodeModel sqlepisode = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == podcastEpisode.EpisodeId); subscription = db.Subscriptions.FirstOrDefault(sub => sub.PodcastId == sqlepisode.PodcastId); PodcastSubscriptionsManager.getInstance().podcastPlaystateChanged(subscription); delete = db.settings().IsAutoDelete; sqlepisode.SavedPlayPos = 0; sqlepisode.EpisodePlayState = PodcastEpisodeModel.EpisodePlayStateEnum.Listened; db.SubmitChanges(); } podcastEpisode.markAsListened(delete); }
private void MenuItemRefresh_Click(object sender, RoutedEventArgs e) { PodcastSubscriptionModel subscriptionToRefresh = (sender as MenuItem).DataContext as PodcastSubscriptionModel; PodcastSubscriptionsManager.getInstance().refreshSubscription(subscriptionToRefresh); }
public static PodcastSubscriptionModel podcastModelFromRSS(string podcastRss, String itunesNamespace = "") { XDocument rssXmlDoc; try { rssXmlDoc = XDocument.Parse(podcastRss); } catch (System.Exception e) { Debug.WriteLine("ERROR: Cannot parse podcast RSS feed. Status: " + e.ToString()); return(null); } bool validFeed = true; XNamespace namespaceDef = itunesNamespace; var query = (from channel in rssXmlDoc.Descendants("channel") select new { Title = (string)channel.Element("title"), Description = (string)channel.Element("description"), ImageUrl = channel.Element(namespaceDef + "image"), Link = (string)channel.Element("link") }).FirstOrDefault(); if (query == null && itunesNamespace != "http://www.itunes.com/DTDs/Podcast-1.0.dtd") { return(podcastModelFromRSS(podcastRss, "http://www.itunes.com/DTDs/Podcast-1.0.dtd")); } if (query == null) { Debug.WriteLine("ERROR: Cannot get all necessary fields from the podcast RSS."); return(null); } if (String.IsNullOrEmpty(query.Link)) { Debug.WriteLine("Warning: Podcast URL is empty in RSS feed."); } string imageUrl = ""; if (query.ImageUrl == null) { // We try with three different iTunes namespaces to get the logo image. When we get here, we have // tried once - with empty namespace. // Then we try with two more. // If we then haven't found a logo, we hit the default branch. switch (itunesNamespace) { case "": return(podcastModelFromRSS(podcastRss, "http://www.itunes.com/dtds/podcast-1.0.dtd")); case "http://www.itunes.com/dtds/podcast-1.0.dtd": return(podcastModelFromRSS(podcastRss, "http://www.itunes.com/DTDs/Podcast-1.0.dtd")); default: Debug.WriteLine("ERROR: Podcast logo URL in RSS is invalid."); imageUrl = ""; break; } } else { // Find the logo URL as the attribute of the 'image' element. XElement logoXmlElement = query.ImageUrl; if (logoXmlElement.Attribute("href") != null) { imageUrl = logoXmlElement.Attribute("href").Value; } // Find the logo URL as the child element of the 'image' element. else if (logoXmlElement.Element("url") != null) { imageUrl = logoXmlElement.Element("url").Value; } else { imageUrl = ""; } } if (validFeed == false) { Debug.WriteLine("ERROR: Cannot get all necessary fields from the podcast RSS."); return(null); } PodcastSubscriptionModel podcastModel = new PodcastSubscriptionModel(); podcastModel.PodcastName = query.Title; podcastModel.PodcastDescription = query.Description; if (string.IsNullOrEmpty(imageUrl) == false) { podcastModel.PodcastLogoUrl = new Uri(imageUrl, UriKind.Absolute); } podcastModel.PodcastShowLink = query.Link; if (string.IsNullOrEmpty(query.Link)) { podcastModel.PodcastShowLink = query.Title; } Debug.WriteLine("Got podcast subscription:" + "\n\t* Name:\t\t\t\t\t" + podcastModel.PodcastName + "\n\t* Description:\t\t\t" + podcastModel.PodcastDescription + "\n\t* LogoUrl:\t\t\t\t" + podcastModel.PodcastLogoUrl ); return(podcastModel); }
private int PodcastSubscriptionSortComparator(PodcastSubscriptionModel s1, PodcastSubscriptionModel s2) { return(s1.PodcastName.CompareTo(s2.PodcastName)); }
public void addSubscription(PodcastSubscriptionModel podcastModel) { Subscriptions.InsertOnSubmit(podcastModel); SubmitChanges(); }
private void refreshNextSubscription() { SubscriptionManagerArgs stateChangedArgs = new SubscriptionManagerArgs(); if (m_subscriptions.Count < 1) { if (OnPodcastSubscriptionsChanged == null) { return; } Debug.WriteLine("No more episodes to refresh. Done."); stateChangedArgs.state = PodcastSubscriptionsManager.SubscriptionsState.FinishedRefreshing; // Update all episodes to the latest list. App.mainViewModels.LatestEpisodesListProperty = new ObservableCollection <PodcastEpisodeModel>(); OnPodcastSubscriptionsChanged(this, stateChangedArgs); return; } PodcastSubscriptionModel subscription = m_subscriptions[0]; m_subscriptions.RemoveAt(0); if (subscription.IsSubscribed == false) { Debug.WriteLine("Not subscribed to {0}, no refresh.", subscription.PodcastName); refreshNextSubscription(); } Uri refreshUri = new Uri(subscription.PodcastRSSUrl, UriKind.Absolute); Debug.WriteLine("Refreshing subscriptions for '{0}', using URL: {1}", subscription.PodcastName, refreshUri); NetworkCredential nc = null; if (String.IsNullOrEmpty(subscription.Username) == false) { nc = new NetworkCredential(); nc.UserName = subscription.Username; Debug.WriteLine("Using username to refresh subscription: {0}", nc.UserName); } if (String.IsNullOrEmpty(subscription.Password) == false) { nc.Password = subscription.Password; Debug.WriteLine("User password to refresh subscription."); } WebClient wc = new WebClient(); if (nc != null) { wc.Credentials = nc; } wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_RefreshPodcastRSSCompleted); wc.DownloadStringAsync(refreshUri, subscription); if (OnPodcastSubscriptionsChanged != null) { stateChangedArgs.state = SubscriptionsState.RefreshingSubscription; stateChangedArgs.subscription = subscription; OnPodcastSubscriptionsChanged(this, stateChangedArgs); } }
async private void wc_DownloadPodcastRSSCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null || e.Cancelled) { try { string foo = e.Result; } catch (WebException ex) { if (needsAuthentication(ex)) { if (MessageBox.Show("Subscribing to this podcast requires authentication. Do you want to give username and password to continue?", "Attention", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { SubscriptionManagerArgs authArgs = new SubscriptionManagerArgs(); authArgs.podcastFeedRSSUri = ex.Response.ResponseUri; OnPodcastChannelRequiresAuthentication(this, authArgs); return; } } } PodcastSubscriptionFailedWithMessage("Could not fetch the podcast feed."); return; } string podcastRss = e.Result; PodcastSubscriptionModel podcastModel = PodcastFactory.podcastModelFromRSS(podcastRss); if (podcastModel == null) { PodcastSubscriptionFailedWithMessage("Podcast feed is invalid."); return; } AddSubscriptionOptions options = e.UserState as AddSubscriptionOptions; string rssUrl = options.rssUrl; bool importingFromExternalService = options.isImportingFromExternalService; bool isPodcastInDB = false; using (var db = new PodcastSqlModel()) { isPodcastInDB = db.isPodcastInDB(rssUrl); } if (isPodcastInDB) { if (!importingFromExternalService) { PodcastSubscriptionFailedWithMessage("You have already subscribed to that podcast."); } if (importingFromExternalService) { m_activeExternalImportsCount--; if (m_activeExternalImportsCount <= 0) { if (OnExternalServiceImportFinished != null) { OnExternalServiceImportFinished(this, null); } } } return; } podcastModel.CachedPodcastRSSFeed = podcastRss; podcastModel.PodcastLogoLocalLocation = localLogoFileName(podcastModel); podcastModel.PodcastRSSUrl = rssUrl; if (String.IsNullOrEmpty(options.username) == false) { podcastModel.Username = options.username; } if (String.IsNullOrEmpty(options.password) == false) { podcastModel.Password = options.password; } using (var db = new PodcastSqlModel()) { db.addSubscription(podcastModel); } await podcastModel.fetchChannelLogo(); SubscriptionManagerArgs addArgs = new SubscriptionManagerArgs(); addArgs.subscription = podcastModel; addArgs.isImportingFromExternalService = importingFromExternalService; OnPodcastChannelAddFinished(this, addArgs); OnPodcastChannelAdded(podcastModel); }
public void refreshSubscription(PodcastSubscriptionModel subscription) { m_subscriptions = new List <PodcastSubscriptionModel>(); m_subscriptions.Add(subscription); refreshNextSubscription(); }