예제 #1
0
        /// <summary>
        /// Duplicate a playlist in the other libraries
        /// </summary>
        /// <param name="playlistToDuplicate"></param>
        public static void DuplicatePlaylist(Playlist playlistToDuplicate)
        {
            // Duplicate the playlist in all libraries except the one it is in
            foreach (Library library in Libraries.LibraryCollection)
            {
                if (library.Id != playlistToDuplicate.LibraryId)
                {
                    // If a playlist with the same name already exists then delete it. This is being deleted rather than being reused just in case it
                    // is the wrong type of playlist
                    Playlist existingPlaylist = Playlists.PlaylistCollection
                                                .Where(playlist => (playlist.Name == playlistToDuplicate.Name) && (playlist.LibraryId == library.Id)).SingleOrDefault();

                    if (existingPlaylist != null)
                    {
                        Playlists.DeletePlaylist(existingPlaylist);
                    }

                    if (playlistToDuplicate is SongPlaylist playlist)
                    {
                        DuplicateSongPlaylistAsync(playlist, library.Id);
                    }
                    else
                    {
                        DuplicateAlbumPlaylistAsync(( AlbumPlaylist )playlistToDuplicate, library.Id);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Delete the specified playlist and its contents
        /// </summary>
        /// <param name="thePlaylist"></param>
        public static void DeletePlaylist(Playlist thePlaylist)
        {
            // Delete the playlist and then refresh the data held by the model
            Playlists.DeletePlaylist(thePlaylist);

            // Refresh the playlists held by the model and report the change
            StorageDataAvailable();
        }
        /// <summary>
        /// Clear the contents of the specified library
        /// </summary>
        /// <param name="libraryToClear"></param>
        /// <returns></returns>
        public static void ClearLibrary(Library libraryToClear)
        {
            int libId = libraryToClear.Id;

            // Delete all the artists in the library and their associated ArtistAlbum entries
            List <Artist> artists = Artists.ArtistCollection.Where(art => art.LibraryId == libId).ToList();

            Artists.DeleteArtists(artists);

            ArtistAlbums.DeleteArtistAlbums(
                ArtistAlbums.ArtistAlbumCollection.Where(artAlb => artists.Any(art => art.Id == artAlb.ArtistId)).Distinct().ToList());

            // Delete all the albums in the library and any tags associated with them
            List <Album> albums = Albums.AlbumCollection.Where(alb => alb.LibraryId == libId).ToList();

            Albums.DeleteAlbums(albums);

            // We can use the FilterManagementController to carry out the Tag deletions.
            new AlbumsDeletedMessage()
            {
                DeletedAlbumIds = albums.Select(alb => alb.Id).ToList()
            }.Send();

            // Delete all the user playlists and thier contents
            Playlists.GetPlaylistsForLibrary(libId).ForEach(play => Playlists.DeletePlaylist(play));

            // Delete the contents of the NowPlayingList but keep the playlist itself
            Playlist nowPlaying = Playlists.GetNowPlayingPlaylist(libId);

            nowPlaying.Clear();
            nowPlaying.SongIndex = -1;

            // Delete all the songs in each of the sources associated with the library
            List <Source> sources = Sources.GetSourcesForLibrary(libId);

            foreach (Source source in sources)
            {
                Songs.DeleteSongs(Songs.GetSourceSongs(source.Id));
                source.Songs = null;
            }
        }