private void CallMetadataAndCompleteHandlers(Action <object, int> completeHandler, int filesAdded) { Task.Run(() => ArtistAdded?.Invoke(this, EventArgs.Empty)); Task.Run(() => AlbumAdded?.Invoke(this, EventArgs.Empty)); Task.Run(() => SongAdded?.Invoke(this, EventArgs.Empty)); Task.Run(() => completeHandler(this, filesAdded)); }
public void AddAlbumToCache(Album album, IAudioFileMetadata metadata) { if (album == null) { throw new ArgumentNullException("album"); } var albumId = album.Id; if (CheckCacheForAlbum(albumId)) { logger.WarnFormat("Not processing album with id {0} into album art cache as it is already in the album art cache.", albumId); return; } if (!metadata.HasAlbumArt) { logger.WarnFormat("Not processing album with id {0} into album art cache as the song does not contain album art data.", albumId); return; } var stopwatch = Stopwatch.StartNew(); try { var albumIdString = album.Id.ToString(); var path = Path.Combine(_cachePath, albumIdString); metadata.GetAlbumArt(i => { i.Save(path); }); if (!File.Exists(path)) { throw new FileNotFoundException("Image class failed to save image to file"); } var fileInfo = new FileInfo(path); if (fileInfo.Length == 0) { File.Delete(path); throw new Exception("File generated by Image class was empty, empty generated file has been deleted"); } stopwatch.Stop(); logger.InfoFormat("Added album with id {0} into album art cache.", albumIdString); logger.DebugFormat("Adding album into album art cache took {0}ms. Album id: {1}", stopwatch.ElapsedMilliseconds, albumIdString); Task.Run(() => AlbumAdded?.Invoke(this, EventArgs.Empty)); } catch (Exception ex) { logger.Error(string.Format("Error adding album with id {0} into album art cache.", albumId), ex); } }