public async Task <TracksSource> Source(string tempo, string genres, [FromServices] ITracksSourcesRepository sourcesRepository) { TracksSource src = await sourcesRepository.GetRandomTracksSource(new TracksCriteria(tempo, genres)); return(src == null ? new TracksSource { Id = -10000 } : src); }
public async Task <List <Track> > GrabAndSaveTracks(TracksCriteria criteria) { TracksSource tracksSource = await _tracksSourceRepository.GetRandomTracksSource(criteria); List <Track> tracks = await _grabber.GrabRandomTracks(tracksSource); await _tracksRepository.SaveTracks(tracks); return(tracks); }
public Task <List <Track> > GrabRandomTracks(TracksSource tracksSource) { switch (tracksSource.SourceType) { case TracksSourceType.YandexTracks: return(GrabTracksFromList(tracksSource.Value)); default: throw new NotSupportedException($"Source {tracksSource.SourceType.ToString()} is not supported by YandexTracksGrabber."); } }
public async Task <List <Track> > GrabRandomTracks(TracksSource tracksSource) { SemaphoreSlim semaphore = _semaphores.GetSemaphoreForService(tracksSource.Service); await semaphore.WaitAsync(); try { IServiceTracksGrabber grabber = _grabbersProvider(tracksSource.Service); DateTime expirationDatetime = DateTime.Now.Add(grabber.LinkLifeTime); List <Track> tracks = await grabber.GrabRandomTracks(tracksSource); foreach (var track in tracks) { track.TracksSource = tracksSource; track.ExpirationDatetime = expirationDatetime; } return(tracks); } finally { semaphore.Release(); } }