public TrackRepositoryPathCache(IMetadataRepository metadataRepository, IMetadataRepositoryCache metadataRepositoryCache, ITagReaderFactory tagReaderFactory, Guid userId, string path, Guid collectionId, bool populate, bool updateCollection) { var repositoryDelegate = new TrackRepositoryPathDelegate(userId, path, collectionId, populate, updateCollection); repositoryDelegate.Method = repositoryDelegate.CreateMethod(metadataRepository, metadataRepositoryCache, tagReaderFactory); RepositoryDelegate = repositoryDelegate; }
public MediaLibrary(IMetadataRepository metadataRepository, ILastFmClient lastFmClient, ISettingsRepository settingsRepository, ICoverArtRepository coverArtRepository, IMetadataRepositoryCache metadataRepositoryCache) { _metadataRepository = metadataRepository; _lastFmClient = lastFmClient; _coverArtRepository = coverArtRepository; _metadataRepositoryCache = metadataRepositoryCache; _settingsRepository = settingsRepository; }
public Func <CancellationToken, Task <MediaBundle <Track> > > CreateMethod(IMetadataRepository metadataRepository, IMetadataRepositoryCache metadataRepositoryCache, ITagReaderFactory tagReaderFactory) { return(async cancellationToken => { var mediaBundle = await metadataRepository.GetTrackAsync(UserId, Path, CollectionId, Populate, cancellationToken).ConfigureAwait(false); Track track = null; if (mediaBundle != null) { track = mediaBundle.Media; } else if (!UpdateCollection) { return null; } if (track != null && track.DateFileModified.ToUniversalTime() >= File.GetLastWriteTimeUtc(Path)) { return mediaBundle; } var now = DateTime.UtcNow; var dateAdded = now; Guid?trackId = null; if (track != null) { trackId = track.Id; dateAdded = track.DateAdded; } var tagReader = tagReaderFactory.CreateTagReader(Path); track = await metadataRepositoryCache.TagReaderToTrackModelAsync(UserId, tagReader, CollectionId, cancellationToken).ConfigureAwait(false); if (trackId.HasValue) { track.Id = trackId.Value; } track.CollectionId = CollectionId; track.DateAdded = dateAdded; track.DateModified = now; track.Visible = true; await metadataRepository.InsertOrUpdateTrackAsync(track, cancellationToken).ConfigureAwait(false); mediaBundle = new MediaBundle <Track> { Media = track, Dispositions = new List <Disposition>(), Playback = new List <Playback>() }; return mediaBundle; }); }