public void ConfigureTracks(string albumName, TrackedMediaPropertyTable table) { if (albumName == Catalog) { table.Register <ProductMediaFile>(x => x.MediaFileId); table.Register <ProductAttributeOption>(x => x.MediaFileId); table.Register <ProductVariantAttributeValue>(x => x.MediaFileId); table.Register <SpecificationAttributeOption>(x => x.MediaFileId); table.Register <Category>(x => x.MediaFileId); table.Register <Manufacturer>(x => x.MediaFileId); } else if (albumName == Content) { table.Register <BlogPost>(x => x.MediaFileId); table.Register <BlogPost>(x => x.PreviewMediaFileId); table.Register <NewsItem>(x => x.MediaFileId); table.Register <NewsItem>(x => x.PreviewMediaFileId); table.Register <Store>(x => x.LogoMediaFileId); } else if (albumName == Downloads) { table.Register <Download>(x => x.MediaFileId); } else if (albumName == Messages) { // TODO: (mm) (mc) These props are localizable table.Register <MessageTemplate>(x => x.Attachment1FileId); table.Register <MessageTemplate>(x => x.Attachment2FileId); table.Register <MessageTemplate>(x => x.Attachment3FileId); } }
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); } } }