/// <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;
            }
        }
        /// <summary>
        /// Called during startup, or library change, when the storage data is available
        /// </summary>
        /// <param name="message"></param>
        private static async void StorageDataAvailable()
        {
            // Save the libray being used locally to detect changes
            PlaylistsViewModel.LibraryId = ConnectionDetailsModel.LibraryId;

            // Get the Playlists and playlist names. Make sure a copy of the list is used as we're going to sort it
            PlaylistsViewModel.Playlists     = Playlists.GetPlaylistsForLibrary(PlaylistsViewModel.LibraryId).ToList();
            PlaylistsViewModel.PlaylistNames = PlaylistsViewModel.Playlists.Select(i => i.Name).ToList();

            // To generate the data to be displayed the Playlists need to be sorted. Not a simple sort of course, but the SongPlaylists followed by the
            // AlbumPlaylists
            await Task.Run(() =>
            {
                PlaylistsViewModel.AlbumPlaylists.Clear();
                PlaylistsViewModel.SongPlaylists.Clear();

                foreach (Playlist playlist in PlaylistsViewModel.Playlists)
                {
                    if (playlist is SongPlaylist songPlaylist)
                    {
                        PlaylistsViewModel.SongPlaylists.Add(songPlaylist);
                    }
                    else
                    {
                        PlaylistsViewModel.AlbumPlaylists.Add(( AlbumPlaylist )playlist);
                    }
                }

                // Sort the playlists by name
                PlaylistsViewModel.SongPlaylists.Sort((a, b) => a.Name.CompareTo(b.Name));
                PlaylistsViewModel.AlbumPlaylists.Sort((a, b) => a.Name.CompareTo(b.Name));

                // Now copy to the combined list
                PlaylistsViewModel.Playlists.Clear();
                PlaylistsViewModel.Playlists.AddRange(PlaylistsViewModel.SongPlaylists);
                PlaylistsViewModel.Playlists.AddRange(PlaylistsViewModel.AlbumPlaylists);
            });

            DataReporter?.DataAvailable();
        }