예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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.");
            }
        }
예제 #4
0
        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();
            }
        }