Esempio n. 1
0
        private async Task <Album> GetAlbumForTag(IAudioFileMetadata tag)
        {
            if (string.IsNullOrWhiteSpace(tag.Album))
            {
                return(null);
            }

            await _dbContextMutex.WaitAsync();

            var existingAlbum = OrderedAlbums.FirstOrDefault(a => a.Name.Equals(tag.Album, StringComparison.CurrentCulture));

            if (existingAlbum != null)
            {
                _dbContextMutex.Release();

                logger.WarnFormat("Not adding album with name '{0}' as another album with the same name already exists in the database", tag.Album);
                return(existingAlbum);
            }

            var newAlbum = new Album()
            {
                Name = tag.Album, hasAlbumArt = tag.HasAlbumArt ? 1 : 0
            };

            logger.DebugFormat("New album: {0}", newAlbum.Name);

            _dukeboxData.Albums.Add(newAlbum);
            _allAlbumsCache.Add(newAlbum);
            _dbContextMutex.Release();

            return(newAlbum);
        }
Esempio n. 2
0
        public List <ITrack> GetTracksForAlbum(long albumId)
        {
            var album = OrderedAlbums.First(a => a.Id == albumId);

            if (album == null)
            {
                throw new Exception(string.Format("Album with ID {0} cannot be found in the database", albumId));
            }

            return(GetTracksForAlbum(album));
        }