コード例 #1
0
        public void removeFromPlayqueue(int itemId)
        {
            using (var db = new PlaylistDBContext())
            {
                PlaylistItem itemToRemove = db.Playlist.FirstOrDefault(item => item.ItemId == itemId);
                if (itemToRemove != null)
                {
                    PodcastEpisodeModel episode = null;
                    using (var episodeDb = new PodcastSqlModel())
                    {
                        episode = episodeDb.episodeForPlaylistItem(itemToRemove);
                        if (episode != null)
                        {
                            if (episode.isListened())
                            {
                                episode.markAsListened(episodeDb.settings().IsAutoDelete);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("Warning: Could not get episode for item id: " + itemToRemove.ItemId);
                        }
                    }

                    db.Playlist.DeleteOnSubmit(itemToRemove);
                    db.SubmitChanges();
                    App.mainViewModels.PlayQueue = new ObservableCollection <PlaylistItem>();
                }
            }
        }
コード例 #2
0
        public void playPlaylistItem(int tappedPlaylistItemId)
        {
            int episodeId = -1;

            using (var db = new PlaylistDBContext())
            {
                if (db.Playlist.Count() < 1)
                {
                    return;
                }

                episodeId = (int)db.Playlist.Where(item => item.ItemId == tappedPlaylistItemId).Select(item => item.EpisodeId).First();
            }

            PodcastEpisodeModel episode = null;

            using (var db = new PodcastSqlModel())
            {
                episode = db.Episodes.First(ep => ep.EpisodeId == episodeId);
            }

            if (episode != null)
            {
                play(episode, true);
            }
            else
            {
                Debug.WriteLine("Warning: Could not play episode: " + episodeId);
            }
        }
コード例 #3
0
        public PodcastEpisodeModel updateCurrentlyPlayingEpisode()
        {
            PlaylistItem plItem = null;

            using (var playlistDb = new PlaylistDBContext())
            {
                if (playlistDb.Playlist.Count() == 0)
                {
                    return(null);
                }

                plItem = playlistDb.Playlist.Where(item => item.IsCurrent).FirstOrDefault();
            }

            if (plItem != null)
            {
                using (var db = new PodcastSqlModel())
                {
                    PodcastEpisodeModel currentEpisode = db.Episodes.Where(ep => ep.EpisodeId == plItem.EpisodeId).FirstOrDefault();
                    CurrentlyPlayingEpisode = currentEpisode;
                    return(currentEpisode);
                }
            }

            return(null);
        }
コード例 #4
0
 public void removeFromPlayqueue(PodcastEpisodeModel episode)
 {
     using (var db = new PlaylistDBContext())
     {
         PlaylistItem plItem = db.Playlist.FirstOrDefault(item => item.EpisodeId == episode.EpisodeId);
         if (plItem != null)
         {
             removeFromPlayqueue(plItem);
         }
     }
 }
コード例 #5
0
        public void startPlaylistPlayback()
        {
            int playlistItemId = -1;

            using (var db = new PlaylistDBContext())
            {
                PlaylistItem firstItem = db.Playlist.OrderBy(item => item.OrderNumber).FirstOrDefault();
                playlistItemId = firstItem.ItemId;
            }

            playPlaylistItem(playlistItemId);
        }
コード例 #6
0
        public void sortPlaylist(int sortOrder)
        {
            using (var playlistDB = new PlaylistDBContext())
            {
                if (playlistDB.Playlist.Count() <= 1)
                {
                    return;
                }

                PodcastSqlModel            sqlContext        = new PodcastSqlModel();
                IEnumerable <PlaylistItem> newSortOrderQuery = null;
                List <PlaylistItem>        newSortOrder      = new List <PlaylistItem>();

                var query = playlistDB.Playlist.AsEnumerable().Join(episodes(sqlContext),
                                                                    item => item.EpisodeId,
                                                                    episode => episode.EpisodeId,
                                                                    (item, episode) => new { PlaylistItem = item, PodcastEpisodeModel = episode });
                switch (sortOrder)
                {
                // Oldest first
                case 0:
                    newSortOrderQuery = query.OrderBy(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished)
                                        .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable();
                    break;

                // Newest first.
                case 1:
                    newSortOrderQuery = query.OrderByDescending(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished)
                                        .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable();
                    break;
                }

                int i = 0;
                foreach (PlaylistItem item in newSortOrderQuery)
                {
                    PlaylistItem newItem = item;
                    newItem.OrderNumber = i++;
                    newSortOrder.Add(newItem);
                }

                playlistDB.Playlist.DeleteAllOnSubmit(playlistDB.Playlist);
                playlistDB.Playlist.InsertAllOnSubmit(newSortOrder);
                playlistDB.SubmitChanges();
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                App.mainViewModels.PlayQueue = new ObservableCollection <PlaylistItem>();
            });
        }
コード例 #7
0
        private void workerSortPlaylist(object sender, DoWorkEventArgs args)
        {
            int selectedSortOrderIndex = (int)args.Argument;

            using (var playlistDB = new PlaylistDBContext())
            {
                if (playlistDB.Playlist.Count() <= 1)
                {
                    return;
                }

                PodcastSqlModel            sqlContext        = new PodcastSqlModel();
                IEnumerable <PlaylistItem> newSortOrderQuery = null;
                List <PlaylistItem>        newSortOrder      = new List <PlaylistItem>();

                var query = playlistDB.Playlist.AsEnumerable().Join(episodes(sqlContext),
                                                                    item => item.EpisodeId,
                                                                    episode => episode.EpisodeId,
                                                                    (item, episode) => new { PlaylistItem = item, PodcastEpisodeModel = episode });
                switch (selectedSortOrderIndex)
                {
                // Oldest first
                case 0:
                    newSortOrderQuery = query.OrderBy(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished)
                                        .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable();
                    break;

                // Newest first.
                case 1:
                    newSortOrderQuery = query.OrderByDescending(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished)
                                        .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable();
                    break;
                }

                int i = 0;
                foreach (PlaylistItem item in newSortOrderQuery)
                {
                    PlaylistItem newItem = item;
                    newItem.OrderNumber = i++;
                    newSortOrder.Add(newItem);
                }

                playlistDB.Playlist.DeleteAllOnSubmit(playlistDB.Playlist);
                playlistDB.Playlist.InsertAllOnSubmit(newSortOrder);
                playlistDB.SubmitChanges();
            }
        }
コード例 #8
0
        public void playPlaylistItem(int tappedPlaylistItemId)
        {
            int episodeId = -1;

            using (var db = new PlaylistDBContext())
            {
                if (db.Playlist.Count() < 1)
                {
                    return;
                }

                // Did we tap the item that is currently playing?
                PlaylistItem current = db.Playlist.FirstOrDefault(item => item.IsCurrent == true);
                if (current != null &&
                    current.ItemId == tappedPlaylistItemId)
                {
                    Debug.WriteLine("Tapped on the currently playing episode. I am not changing the track...");

                    // Always open the player UI when playlist item is tapped.
                    var handler = OnOpenPodcastPlayer;
                    if (handler != null)
                    {
                        OnOpenPodcastPlayer(this, new EventArgs());
                    }
                    return;
                }

                episodeId = (int)db.Playlist.Where(item => item.ItemId == tappedPlaylistItemId).Select(item => item.EpisodeId).First();
            }

            PodcastEpisodeModel episode = null;

            using (var db = new PodcastSqlModel())
            {
                episode = db.Episodes.First(ep => ep.EpisodeId == episodeId);
            }

            if (episode != null)
            {
                play(episode, true);
            }
            else
            {
                Debug.WriteLine("Warning: Could not play episode: " + episodeId);
            }
        }
コード例 #9
0
        public void addToPlayqueue(PodcastEpisodeModel episode, bool showNotification = true)
        {
            using (var db = new PlaylistDBContext())
            {
                addToPlayqueue(episode, db);
                db.SubmitChanges();
            }

            using (var db = new PodcastSqlModel())
            {
                sortPlaylist(db.settings().PlaylistSortOrder);
            }

            if (showNotification)
            {
                showAddedNotification(1);
            }
        }
コード例 #10
0
        internal static PodcastEpisodeModel refreshEpisodeFromAudioAgent(PodcastEpisodeModel episode)
        {
            List <PlaylistItem> playlistItems = null;

            using (var playlistdb = new PlaylistDBContext())
            {
                playlistItems = playlistdb.Playlist.ToList();
            }

            PodcastEpisodeModel e = null;

            using (var db = new PodcastSqlModel())
            {
                e = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == episode.EpisodeId);

                bool deleteListened = false;
                if (playlistItems.Count > 0)
                {
                    deleteListened = db.settings().IsAutoDelete;
                }

                foreach (PlaylistItem i in playlistItems)
                {
                    if (i.EpisodeId != episode.EpisodeId)
                    {
                        continue;
                    }

                    Debug.WriteLine("Updating episode '" + e.EpisodeName + "' playpos to: " + i.SavedPlayPosTick);
                    e.SavedPlayPos = i.SavedPlayPosTick;

                    // Update play state to listened as appropriate.
                    if (e.isListened())
                    {
                        e.markAsListened(deleteListened);
                    }

                    db.SubmitChanges();
                }
            }

            return(e);
        }
コード例 #11
0
        private void addToPlayqueue(PodcastEpisodeModel e, PlaylistDBContext dbContext)
        {
            PlaylistItem existingItem = dbContext.Playlist.FirstOrDefault(item => item.EpisodeId == e.EpisodeId);

            if (existingItem != null)
            {
                Debug.WriteLine("Item already in playlist.");
                return;
            }

            dbContext.Playlist.InsertOnSubmit(new PlaylistItem
            {
                EpisodeId           = e.EpisodeId,
                EpisodeName         = e.EpisodeName,
                EpisodeLocation     = (!String.IsNullOrEmpty(e.EpisodeFile) ? e.EpisodeFile : e.EpisodeDownloadUri),
                PodcastLogoLocation = e.PodcastSubscriptionInstance.PodcastLogoLocalLocation,
                PodcastName         = e.PodcastSubscriptionInstance.PodcastName
            });
        }
コード例 #12
0
        public void addToPlayqueue(Collection <PodcastEpisodeModel> episodes)
        {
            using (var db = new PlaylistDBContext())
            {
                foreach (PodcastEpisodeModel e in episodes)
                {
                    addToPlayqueue(e, db);
                }
                db.SubmitChanges();
            }

            using (var db = new PodcastSqlModel())
            {
                sortPlaylist(db.settings().PlaylistSortOrder);
            }

            App.mainViewModels.PlayQueue = new ObservableCollection <PlaylistItem>();
            showAddedNotification(episodes.Count);
        }
コード例 #13
0
        public void clearPlayQueue()
        {
            List <int> itemsToRemove = new List <int>();

            using (var db = new PlaylistDBContext())
            {
                List <PlaylistItem> playlist = db.Playlist.ToList();
                foreach (PlaylistItem item in playlist)
                {
                    if (item.IsCurrent == false)
                    {
                        itemsToRemove.Add(item.ItemId);
                    }
                }
            }

            foreach (int id in itemsToRemove)
            {
                removeFromPlayqueue(id);
            }

            App.mainViewModels.PlayQueue = new ObservableCollection <PlaylistItem>();
        }
コード例 #14
0
        public static long getPlayposFromAudioAgentForEpisode(PodcastEpisodeModel episode)
        {
            using (var playlistdb = new PlaylistDBContext())
            {
                List <PlaylistItem> playlistItems = playlistdb.Playlist.ToList();
                using (var db = new PodcastSqlModel())
                {
                    foreach (PlaylistItem i in playlistItems)
                    {
                        PodcastEpisodeModel e = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == i.EpisodeId);
                        if (e == null || e.EpisodeId != episode.EpisodeId)
                        {
                            continue;
                        }

                        Debug.WriteLine("Found play pos for episode: " + episode.EpisodeId + ", pos: " + i.SavedPlayPosTick);
                        return(i.SavedPlayPosTick);
                    }
                }
            }

            Debug.WriteLine("Warning: No play pos found for episode: " + episode.EpisodeId);
            return(0);
        }
コード例 #15
0
        public PodcastEpisodeModel updateCurrentlyPlayingEpisode()
        {
            PlaylistItem plItem = null;
            using (var playlistDb = new PlaylistDBContext())
            {
                if (playlistDb.Playlist.Count() == 0)
                {
                    return null;
                }

                plItem = playlistDb.Playlist.Where(item => item.IsCurrent).FirstOrDefault();
            }

            if (plItem != null)
            {
                using (var db = new PodcastSqlModel())
                {
                    PodcastEpisodeModel currentEpisode = db.Episodes.Where(ep => ep.EpisodeId == plItem.EpisodeId).FirstOrDefault();
                    CurrentlyPlayingEpisode = currentEpisode;
                    return currentEpisode;
                }
            }

            return null;
        }
コード例 #16
0
        public void startPlaylistPlayback()
        {
            int playlistItemId = -1;
            using (var db = new PlaylistDBContext())
            {
                PlaylistItem firstItem = db.Playlist.OrderBy(item => item.OrderNumber).FirstOrDefault();
                playlistItemId = firstItem.ItemId;
            }

            playPlaylistItem(playlistItemId);
        }
コード例 #17
0
 public void removeFromPlayqueue(PodcastEpisodeModel episode)
 {
     using (var db = new PlaylistDBContext())
     {
         PlaylistItem plItem = db.Playlist.FirstOrDefault(item => item.EpisodeId == episode.EpisodeId);
         if (plItem != null)
         {
             removeFromPlayqueue(plItem);
         }
     }
 }
コード例 #18
0
        public void removeFromPlayqueue(int itemId)
        {
            using (var db = new PlaylistDBContext())
            {
                PlaylistItem itemToRemove = db.Playlist.FirstOrDefault(item => item.ItemId == itemId);
                if (itemToRemove != null)
                {
                    PodcastEpisodeModel episode = null;
                    using (var episodeDb = new PodcastSqlModel())
                    {
                        episode = episodeDb.episodeForPlaylistItem(itemToRemove);
                        if (episode != null)
                        {
                            if (episode.isListened())
                            {
                                episode.markAsListened(episodeDb.settings().IsAutoDelete);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("Warning: Could not get episode for item id: " + itemToRemove.ItemId);
                        }
                    }

                    db.Playlist.DeleteOnSubmit(itemToRemove);
                    db.SubmitChanges();
                    App.mainViewModels.PlayQueue = new ObservableCollection<PlaylistItem>();
                }
            }
        }
コード例 #19
0
        public void playPlaylistItem(int tappedPlaylistItemId)
        {
            int episodeId = -1;
            using (var db = new PlaylistDBContext())
            {
                if (db.Playlist.Count() < 1)
                {
                    return;
                }

                // Did we tap the item that is currently playing?
                PlaylistItem current = db.Playlist.FirstOrDefault(item => item.IsCurrent == true);
                if (current != null
                    && current.ItemId == tappedPlaylistItemId)
                {
                    Debug.WriteLine("Tapped on the currently playing episode. I am not changing the track...");

                    // Always open the player UI when playlist item is tapped.
                    var handler = OnOpenPodcastPlayer;
                    if (handler != null)
                    {
                        OnOpenPodcastPlayer(this, new EventArgs());
                    }
                    return;
                }

                episodeId = (int)db.Playlist.Where(item => item.ItemId == tappedPlaylistItemId).Select(item => item.EpisodeId).First();
            }

            PodcastEpisodeModel episode = null;
            using (var db = new PodcastSqlModel())
            {
                episode = db.Episodes.First(ep => ep.EpisodeId == episodeId);
            }

            if (episode != null)
            {
                play(episode, true);
            }
            else
            {
                Debug.WriteLine("Warning: Could not play episode: " + episodeId);
            }
        }
コード例 #20
0
        public void clearPlayQueue()
        {
            List<int> itemsToRemove = new List<int>();
            using (var db = new PlaylistDBContext())
            {
                List<PlaylistItem> playlist = db.Playlist.ToList();
                foreach (PlaylistItem item in playlist)
                {
                    if (item.IsCurrent == false)
                    {
                        itemsToRemove.Add(item.ItemId);
                    }
                }
            }

            foreach (int id in itemsToRemove)
            {
                removeFromPlayqueue(id);
            }

            App.mainViewModels.PlayQueue = new ObservableCollection<PlaylistItem>();
        }
コード例 #21
0
        public void addToPlayqueue(Collection<PodcastEpisodeModel> episodes)
        {
            using (var db = new PlaylistDBContext())
            {
                foreach (PodcastEpisodeModel e in episodes)
                {
                    addToPlayqueue(e, db);
                }
                db.SubmitChanges();
            }

            using (var db = new PodcastSqlModel())
            {
                sortPlaylist(db.settings().PlaylistSortOrder);
            }

            App.mainViewModels.PlayQueue = new ObservableCollection<PlaylistItem>();
            showAddedNotification(episodes.Count);
        }
コード例 #22
0
        public void playPlaylistItem(int tappedPlaylistItemId)
        {
            int episodeId = -1;
            using (var db = new PlaylistDBContext())
            {
                if (db.Playlist.Count() < 1)
                {
                    return;
                }

                episodeId = (int)db.Playlist.Where(item => item.ItemId == tappedPlaylistItemId).Select(item => item.EpisodeId).First();
            }

            PodcastEpisodeModel episode = null;
            using (var db = new PodcastSqlModel())
            {
                episode = db.Episodes.First(ep => ep.EpisodeId == episodeId);
            }

            if (episode != null)
            {
                play(episode, true);
            }
            else
            {
                Debug.WriteLine("Warning: Could not play episode: " + episodeId);
            }
        }
コード例 #23
0
        public void sortPlaylist(int sortOrder)
        {
            using (var playlistDB = new PlaylistDBContext())
            {
                if (playlistDB.Playlist.Count() <= 1)
                {
                    return;
                }

                PodcastSqlModel sqlContext = new PodcastSqlModel();
                IEnumerable<PlaylistItem> newSortOrderQuery = null;
                List<PlaylistItem> newSortOrder = new List<PlaylistItem>();

                var query = playlistDB.Playlist.AsEnumerable().Join(episodes(sqlContext),
                                                                    item => item.EpisodeId,
                                                                    episode => episode.EpisodeId,
                                                                    (item, episode) => new { PlaylistItem = item, PodcastEpisodeModel = episode });
                switch (sortOrder)
                {
                    // Oldest first
                    case 0:
                        newSortOrderQuery = query.OrderBy(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished)
                                            .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable();
                        break;
                    // Newest first.
                    case 1:
                        newSortOrderQuery = query.OrderByDescending(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished)
                                            .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable();
                        break;
                }

                int i = 0;
                foreach (PlaylistItem item in newSortOrderQuery)
                {
                    PlaylistItem newItem = item;
                    newItem.OrderNumber = i++;
                    newSortOrder.Add(newItem);
                }

                playlistDB.Playlist.DeleteAllOnSubmit(playlistDB.Playlist);
                playlistDB.Playlist.InsertAllOnSubmit(newSortOrder);
                playlistDB.SubmitChanges();
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                App.mainViewModels.PlayQueue = new ObservableCollection<PlaylistItem>();
            });
        }
コード例 #24
0
ファイル: App.xaml.cs プロジェクト: kypeli/Podcatcher
        public static long getPlayposFromAudioAgentForEpisode(PodcastEpisodeModel episode)
        {
            using (var playlistdb = new PlaylistDBContext())
            {
                List<PlaylistItem> playlistItems = playlistdb.Playlist.ToList();
                using (var db = new PodcastSqlModel())
                {
                    foreach (PlaylistItem i in playlistItems)
                    {
                        PodcastEpisodeModel e = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == i.EpisodeId);
                        if (e == null || e.EpisodeId != episode.EpisodeId)
                        {
                            continue;
                        }

                        Debug.WriteLine("Found play pos for episode: " + episode.EpisodeId + ", pos: " + i.SavedPlayPosTick);
                        return i.SavedPlayPosTick;
                    }
                }
            }

            Debug.WriteLine("Warning: No play pos found for episode: " + episode.EpisodeId);
            return 0;
        }
コード例 #25
0
ファイル: App.xaml.cs プロジェクト: kypeli/Podcatcher
        public static void refreshEpisodesFromAudioAgent()
        {
            Debug.WriteLine("Refreshing episode information that has been updated from AudioPlayer.");

            using (var playlistdb = new PlaylistDBContext())
            {
                int playlistItemsCount = 0;
                int listenedItemsCount = 0;
                List<PlaylistItem> playlistItems = playlistdb.Playlist.ToList();

                playlistItemsCount = playlistItems.Count;
                using (var db = new PodcastSqlModel())
                {
                    bool deleteListened = false;
                    if (playlistItems.Count > 0)
                    {
                        deleteListened = db.settings().IsAutoDelete;
                    }

                    foreach (PlaylistItem i in playlistItems)
                    {
                        PodcastEpisodeModel e = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == i.EpisodeId);
                        if (e == null)
                        {
                            Debug.WriteLine("Warning: Could not fetch episode with ID: " + i.EpisodeId);
                            continue;
                        }

                        if (i.SavedPlayPosTick > 0)
                        {
                            Debug.WriteLine("Updating episode '" + e.EpisodeName + "' playpos to: " + i.SavedPlayPosTick);
                            e.SavedPlayPos = i.SavedPlayPosTick;

                            try
                            {
                                db.SubmitChanges();
                            }
                            catch (ChangeConflictException)
                            {
                                Debug.WriteLine("ChangeConflictException: Could not submit changes");
                            }

                            // Update play state to listened as appropriate.
                            if (e.isListened())
                            {
                                e.markAsListened(deleteListened);
                                PodcastPlaybackManager.getInstance().removeFromPlayqueue(e);
                                listenedItemsCount++;
                            }

                            e.PodcastSubscription.reloadPartiallyPlayedEpisodes();
                            e.PodcastSubscription.reloadUnplayedPlayedEpisodes();
                        }
                    }
                }

                // If all items in the play queue were listened, then we shouldn't show an episodep laying anymore.
                if (playlistItemsCount == listenedItemsCount)
                {
                    PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode = null;
                }
            }
        }
コード例 #26
0
ファイル: App.xaml.cs プロジェクト: kypeli/Podcatcher
        internal static PodcastEpisodeModel refreshEpisodeFromAudioAgent(PodcastEpisodeModel episode)
        {
            List<PlaylistItem> playlistItems = null;
            using (var playlistdb = new PlaylistDBContext())
            {
                playlistItems = playlistdb.Playlist.ToList();
            }

            PodcastEpisodeModel e = null;
            using (var db = new PodcastSqlModel())
            {
                e = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == episode.EpisodeId);

                bool deleteListened = false;
                if (playlistItems.Count > 0)
                {
                    deleteListened = db.settings().IsAutoDelete;
                }

                foreach (PlaylistItem i in playlistItems)
                {
                    if (i.EpisodeId != episode.EpisodeId)
                    {
                        continue;
                    }

                    Debug.WriteLine("Updating episode '" + e.EpisodeName + "' playpos to: " + i.SavedPlayPosTick);
                    e.SavedPlayPos = i.SavedPlayPosTick;

                    // Update play state to listened as appropriate.
                    if (e.isListened())
                    {
                        e.markAsListened(deleteListened);
                    }

                    db.SubmitChanges();
                }
            }

            return e;
        }
コード例 #27
0
        private void addToPlayqueue(PodcastEpisodeModel e, PlaylistDBContext dbContext)
        {
            PlaylistItem existingItem = dbContext.Playlist.FirstOrDefault(item => item.EpisodeId == e.EpisodeId);
            if (existingItem != null)
            {
                Debug.WriteLine("Item already in playlist.");
                return;
            }

            dbContext.Playlist.InsertOnSubmit(new PlaylistItem
            {
                EpisodeId = e.EpisodeId,
                EpisodeName = e.EpisodeName,
                EpisodeLocation = (!String.IsNullOrEmpty(e.EpisodeFile) ? e.EpisodeFile : e.EpisodeDownloadUri),
                PodcastLogoLocation = e.PodcastSubscriptionInstance.PodcastLogoLocalLocation,
                PodcastName = e.PodcastSubscriptionInstance.PodcastName
            });
        }
コード例 #28
0
        public void addToPlayqueue(PodcastEpisodeModel episode, bool showNotification = true)
        {
            using (var db = new PlaylistDBContext())
            {
                addToPlayqueue(episode, db);
                db.SubmitChanges();
            }

            using (var db = new PodcastSqlModel())
            {
                sortPlaylist(db.settings().PlaylistSortOrder);
            }

            if (showNotification)
            {
                showAddedNotification(1);
            }
        }
コード例 #29
0
        private void workerSortPlaylist(object sender, DoWorkEventArgs args)
        {
            int selectedSortOrderIndex = (int)args.Argument;
            using (var playlistDB = new PlaylistDBContext())
            {
                if (playlistDB.Playlist.Count() <= 1)
                {
                    return;
                }

                PodcastSqlModel sqlContext = new PodcastSqlModel();
                IEnumerable<PlaylistItem> newSortOrderQuery = null;
                List<PlaylistItem> newSortOrder = new List<PlaylistItem>();

                var query = playlistDB.Playlist.AsEnumerable().Join(episodes(sqlContext),
                                                                    item => item.EpisodeId,
                                                                    episode => episode.EpisodeId,
                                                                    (item, episode) => new { PlaylistItem = item, PodcastEpisodeModel = episode });
                switch (selectedSortOrderIndex)
                {
                    // Oldest first
                    case 0:
                        newSortOrderQuery = query.OrderBy(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished)
                                            .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable();
                        break;
                    // Newest first.
                    case 1:
                        newSortOrderQuery = query.OrderByDescending(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished)
                                            .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable();
                        break;
                }

                int i = 0;
                foreach (PlaylistItem item in newSortOrderQuery)
                {
                    PlaylistItem newItem = item;
                    newItem.OrderNumber = i++;
                    newSortOrder.Add(newItem);
                }

                playlistDB.Playlist.DeleteAllOnSubmit(playlistDB.Playlist);
                playlistDB.Playlist.InsertAllOnSubmit(newSortOrder);
                playlistDB.SubmitChanges();
            }
        }
コード例 #30
0
        public static void refreshEpisodesFromAudioAgent()
        {
            Debug.WriteLine("Refreshing episode information that has been updated from AudioPlayer.");

            using (var playlistdb = new PlaylistDBContext())
            {
                int playlistItemsCount            = 0;
                int listenedItemsCount            = 0;
                List <PlaylistItem> playlistItems = playlistdb.Playlist.ToList();

                playlistItemsCount = playlistItems.Count;
                using (var db = new PodcastSqlModel())
                {
                    bool deleteListened = false;
                    if (playlistItems.Count > 0)
                    {
                        deleteListened = db.settings().IsAutoDelete;
                    }

                    foreach (PlaylistItem i in playlistItems)
                    {
                        PodcastEpisodeModel e = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == i.EpisodeId);
                        if (e == null)
                        {
                            Debug.WriteLine("Warning: Could not fetch episode with ID: " + i.EpisodeId);
                            continue;
                        }

                        if (i.SavedPlayPosTick > 0)
                        {
                            Debug.WriteLine("Updating episode '" + e.EpisodeName + "' playpos to: " + i.SavedPlayPosTick);
                            e.SavedPlayPos = i.SavedPlayPosTick;

                            try
                            {
                                db.SubmitChanges();
                            }
                            catch (ChangeConflictException)
                            {
                                Debug.WriteLine("ChangeConflictException: Could not submit changes");
                            }

                            // Update play state to listened as appropriate.
                            if (e.isListened())
                            {
                                e.markAsListened(deleteListened);
                                PodcastPlaybackManager.getInstance().removeFromPlayqueue(e);
                                listenedItemsCount++;
                            }

                            e.PodcastSubscription.reloadPartiallyPlayedEpisodes();
                            e.PodcastSubscription.reloadUnplayedPlayedEpisodes();
                        }
                    }
                }

                // If all items in the play queue were listened, then we shouldn't show an episodep laying anymore.
                if (playlistItemsCount == listenedItemsCount)
                {
                    PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode = null;
                }
            }
        }