public ChannelController(UserManager <AppUser> userManager, IChannelRepository channelRepository, IChannelTrackRepository channelTrackRepository, IChannelTaskLoader channelTaskLoader, IRadioHubProxy radioHubProxy, IChannelTrackingStopper channelTrackingStopper, IYouTubeService youTubeService) { _userManager = userManager; _channelRepository = channelRepository; _channelTrackRepository = channelTrackRepository; _channelTaskLoader = channelTaskLoader; _radioHubProxy = radioHubProxy; _channelTrackingStopper = channelTrackingStopper; _youTubeService = youTubeService; }
private async Task NextTrack() { using (IServiceScope scope = _serviceProvider.CreateScope()) { IChannelTrackRepository channelTrackRepository = scope.ServiceProvider.GetService <IChannelTrackRepository>(); await channelTrackRepository.MoveToNextTrack(_currentChannel); _currentTrack = channelTrackRepository.CurrentChannelTrackFor(_currentChannel).Track; await _radioHubProxy.UpdateTrack(_currentChannel, _currentTrack); } _timer.Stop(); _timer.Interval = _currentTrack.Length.TotalMilliseconds; _timer.Start(); _stopwatch.Restart(); }
private async Task NextTrack() { _timer.Stop(); _stopwatch.Stop(); using (IServiceScope scope = _serviceProvider.CreateScope()) { IChannelTrackRepository channelTrackRepository = scope.ServiceProvider.GetService <IChannelTrackRepository>(); Track track = await channelTrackRepository.MoveToNextTrack(_channelId); _trackId = track.Id; _timer.Interval = track.Length.TotalMilliseconds; } await _radioHubProxy.UpdateTrack(_channelId, _trackId); _timer.Start(); _stopwatch.Restart(); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { ChannelUpdateTask channelUpdateTask = await _channelUpdateTaskUnloader.Dequeue(); IEnumerable <Track> tracks = (await Task.WhenAll(channelUpdateTask.NewMediaUrls.Select(_youTubeService.ExtractYouTubeVideos))) .SelectMany(videoArray => videoArray.Select(video => video.ToTrack())); using (IServiceScope serviceScope = _serviceProvider.CreateScope()) { IChannelTrackRepository channelTrackRepository = serviceScope.ServiceProvider.GetService <IChannelTrackRepository>(); await channelTrackRepository.AddNewTracks(channelUpdateTask.ChannelId, tracks); IChannelRepository channelRepository = serviceScope.ServiceProvider.GetService <IChannelRepository>(); await channelRepository.UpdateChannelNotEditing(channelUpdateTask.ChannelId); Channel channel = channelRepository.GetChannelByIdOrDefault(channelUpdateTask.ChannelId); IChannelUpdatedNotifierHubProxy channelUpdatedNotifierHubProxy = serviceScope.ServiceProvider.GetService <IChannelUpdatedNotifierHubProxy>(); await channelUpdatedNotifierHubProxy.NotifyChannelUpdated(channel.OwnerId, channel); } } }
public TrackController(IChannelRepository channelRepository, IChannelTrackRepository channelTrackRepository) { _channelRepository = channelRepository; _channelTrackRepository = channelTrackRepository; }