Esempio n. 1
0
        protected virtual IEnumerable <AlbumInfo> LoadAllAlbums()
        {
            var setFolders = _dbContext.Set <MediaFolder>();

            var dbAlbums = setFolders
                           .AsNoTracking()
                           .OfType <MediaAlbum>()
                           .Select(x => new { x.Id, x.Name })
                           .ToDictionary(x => x.Name);

            foreach (var lazyProvider in _albumProviders)
            {
                var provider = lazyProvider.Value;
                var albums   = provider.GetAlbums().DistinctBy(x => x.Name).ToArray();

                foreach (var album in albums)
                {
                    var info = new AlbumInfo
                    {
                        Name          = album.Name,
                        ProviderType  = provider.GetType(),
                        IsSystemAlbum = typeof(SystemAlbumProvider) == provider.GetType(),
                        DisplayHint   = provider.GetDisplayHint(album) ?? new AlbumDisplayHint()
                    };

                    if (provider is IMediaTrackDetector detector)
                    {
                        var propertyTable = new TrackedMediaPropertyTable(album.Name);
                        detector.ConfigureTracks(album.Name, propertyTable);

                        info.IsTrackDetector   = true;
                        info.TrackedProperties = propertyTable.GetProperties();
                    }

                    if (dbAlbums.TryGetValue(album.Name, out var dbAlbum))
                    {
                        info.Id = dbAlbum.Id;
                    }
                    else
                    {
                        setFolders.Add(album);
                        _dbContext.SaveChanges();
                        info.Id = album.Id;
                    }

                    yield return(info);
                }
            }
        }
        public AlbumFileSystemAdapter(
            AlbumInfo album,
            IMediaService mediaService,
            IFolderService folderService,
            IMediaStorageProvider storageProvider)
        {
            _mediaService    = mediaService;
            _folderService   = folderService;
            _storageProvider = storageProvider;

            Album = album;
            Node  = _folderService.GetNodeById(album.Id);

            _rootPath = Node.Value.Path;
        }