public async Task <RemoveTracksResult> RemoveTracksFromCollectionAsync(IList <TrackViewModel> selectedTracks) { RemoveTracksResult result = await this.trackRepository.RemoveTracksAsync(selectedTracks.Select(t => t.Track).ToList()); if (result == RemoveTracksResult.Success) { this.CollectionChanged(this, new EventArgs()); } return(result); }
public async Task <RemoveTracksResult> RemoveTracksAsync(IList <Track> tracks) { RemoveTracksResult result = RemoveTracksResult.Success; await Task.Run(() => { try { try { using (var conn = this.factory.GetConnection()) { IList <string> pathsToRemove = tracks.Select((t) => t.Path).ToList(); conn.Execute("BEGIN TRANSACTION"); foreach (string path in pathsToRemove) { // Add to table RemovedTrack, only if not already present. conn.Execute("INSERT INTO RemovedTrack(DateRemoved, Path, SafePath) SELECT ?,?,? WHERE NOT EXISTS (SELECT 1 FROM RemovedTrack WHERE SafePath=?)", DateTime.Now.Ticks, path, path.ToSafePath(), path.ToSafePath()); // Remove from QueuedTrack conn.Execute("DELETE FROM QueuedTrack WHERE SafePath=?", path.ToSafePath()); // Remove from Track conn.Execute("DELETE FROM Track WHERE SafePath=?", path.ToSafePath()); } conn.Execute("COMMIT"); } } catch (Exception ex) { LogClient.Error("Could remove tracks from the database. Exception: {0}", ex.Message); result = RemoveTracksResult.Error; } } catch (Exception ex) { LogClient.Error("Could not connect to the database. Exception: {0}", ex.Message); result = RemoveTracksResult.Error; } }); return(result); }
public async Task <RemoveTracksResult> RemoveTracksFromCollectionAsync(IList <PlayableTrack> selectedTracks) { RemoveTracksResult result = await this.trackRepository.RemoveTracksAsync(selectedTracks); if (result == RemoveTracksResult.Success) { // Delete orphaned Albums await this.albumRepository.DeleteOrphanedAlbumsAsync(); // Delete orphaned Artists await this.artistRepository.DeleteOrphanedArtistsAsync(); // Delete orphaned Genres await this.genreRepository.DeleteOrphanedGenresAsync(); this.CollectionChanged(this, new EventArgs()); } return(result); }
public async Task <RemoveTracksResult> RemoveTracksAsync(IList <TrackInfo> tracks) { RemoveTracksResult result = RemoveTracksResult.Success; await Task.Run(() => { try { using (var conn = this.factory.GetConnection()) { List <string> pathsToRemove = tracks.Select((t) => t.Path).ToList(); List <string> alreadyRemovedPaths = conn.Table <RemovedTrack>().Select((t) => t).ToList().Select((t) => t.Path).ToList(); List <string> pathsToRemoveNow = pathsToRemove.Except(alreadyRemovedPaths).ToList(); conn.Execute("BEGIN TRANSACTION"); foreach (string path in pathsToRemoveNow) { // Add to table RemovedTrack conn.Execute("INSERT INTO RemovedTrack(DateRemoved, Path) VALUES(?,?)", DateTime.Now.Ticks, path); // Remove from QueuedTrack conn.Execute("DELETE FROM QueuedTrack WHERE Path=?", path); // Remove from Track conn.Execute("DELETE FROM Track WHERE Path=?", path); } conn.Execute("COMMIT"); } } catch (Exception ex) { LogClient.Instance.Logger.Error("Could not connect to the database. Exception: {0}", ex.Message); result = RemoveTracksResult.Error; } }); return(result); }
protected async Task RemoveTracksFromDiskAsync(IList <TrackViewModel> selectedTracks) { string title = ResourceUtils.GetString("Language_Remove_From_Disk"); string body = ResourceUtils.GetString("Language_Are_You_Sure_To_Remove_Song_From_Disk"); if (selectedTracks != null && selectedTracks.Count > 1) { body = ResourceUtils.GetString("Language_Are_You_Sure_To_Remove_Songs_From_Disk"); } if (this.dialogService.ShowConfirmation(0xe11b, 16, title, body, ResourceUtils.GetString("Language_Yes"), ResourceUtils.GetString("Language_No"))) { RemoveTracksResult result = await this.collectionService.RemoveTracksFromDiskAsync(selectedTracks); if (result == RemoveTracksResult.Error) { this.dialogService.ShowNotification(0xe711, 16, ResourceUtils.GetString("Language_Error"), ResourceUtils.GetString("Language_Error_Removing_Songs_From_Disk"), ResourceUtils.GetString("Language_Ok"), true, ResourceUtils.GetString("Language_Log_File")); } else { await this.playbackService.DequeueAsync(selectedTracks); } } }
public async Task <RemoveTracksResult> RemoveTracksFromDiskAsync(IList <PlayableTrack> selectedTracks) { RemoveTracksResult result = await this.trackRepository.RemoveTracksAsync(selectedTracks); if (result == RemoveTracksResult.Success) { // If result is Success: we can assume that all selected tracks were removed from the collection, // as this happens in a transaction in trackRepository. If removing 1 or more tracks fails, the // transaction is rolled back and no tracks are removed. foreach (var track in selectedTracks) { // When the track is playing, the corresponding file is handled by the CSCore. // To delete the file properly, PlaybackService must release this handle. await this.playbackService.StopIfPlayingAsync(track); // Delete file from disk FileUtils.SendToRecycleBinSilent(track.Path); } this.CollectionChanged(this, new EventArgs()); } return(result); }