public async Task<string> GetAlbumCoverForSong(string album, string artist) { CachedAlbumCover result = null; if (!await databaseConnection.TryRunInTransactionAsync(connection => { result = connection.Table<CachedAlbumCover>().Where(p => p.Artist == artist && p.Album == album).FirstOrDefault(); if (result == null) { result = new CachedAlbumCover(album, artist); connection.Insert(result); } })) return null; if (result.ImageFileName == null) { var song = this.Songs.FirstOrDefault(p => p.Album == album && p.AlbumArtist == artist); if (song != null) { await result.Load(song.FileName); if (!await databaseConnection.TryRunInTransactionAsync(connection => connection.Update(result))) return null; } } return result.ImageFileName; }
public async Task<StorageFile> GetAlbumCoverFileNameForSong(string album, string artist) { CachedAlbumCover result = null; await databaseConnection.TryRunInTransactionAsync(connection => { result = connection.Table<CachedAlbumCover>().Where(p => p.Artist == artist && p.Album == album).FirstOrDefault(); if (result == null) { result = new CachedAlbumCover(album, artist); connection.Insert(result); } }); if (result.ImageFileName == null) { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(Guid.NewGuid().ToString()); result.ImageFileName = file.Path; await databaseConnection.UpdateAsync(result); return file; } return await StorageFile.GetFileFromPathAsync(result.ImageFileName); }