// Compare saved playlists(from local PC) and current playlists(from Spotify) and saves the result set to 'compareResults' list. private async void Compare_Playlists() { List <PlaylistTrack> compareResult = new List <PlaylistTrack>(); // For tracks List <Playlist_Full> compareResults = new List <Playlist_Full>(); // For playlists // Get saved playlists from documents bool result = await GetSavedPlaylists(); // If there is a saved playlists and if Spotify playlists are taken from server. if (result && fullPlaylists.Count > 0) { // Loop through each plasylist taken from spotify web API and compare if this playlist saved before. foreach (Playlist_Full newPlaylist in fullPlaylists) { Playlist_Full savedPlaylist = savedPlaylists.Find(pList => pList.id == newPlaylist.id); if (savedPlaylist == null) { continue; } compareResult = Compare_PlaylistTracks(newPlaylist.trackList, savedPlaylist.trackList); compareResults.Add(new Playlist_Full(new Playlist_Simplified(newPlaylist.id, newPlaylist.name + " -CompareResult", newPlaylist.tracks), compareResult)); } } CompareResults = compareResults; }
// Gets the saved playlist's from directory, converts them to 'Playlist_Full' objects and puts 'savedPlaylists' list. private async Task <bool> GetSavedPlaylists() { IsProgressing = true; // Clearing the savedPlaylists list to prevent appending. savedPlaylists.Clear(); string path_myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string folderName = "SpotifyPlaylists"; // Get all paths inside directory. string[] filePaths = Directory.GetFiles(Path.Combine(path_myDocuments, folderName), "*.json", SearchOption.TopDirectoryOnly); // Loop through all .json files, converts from .json to 'Playlist_Full' objects then adds to 'savedPlaylists' list. for (int i = 0; i < filePaths.Length; i++) { string jsonText = File.ReadAllText(filePaths[i]); Playlist_Full playlist = JsonConvert.DeserializeObject <Playlist_Full>(jsonText); savedPlaylists.Add(playlist); } IsProgressing = false; return(true); }