protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                ChannelCreationTask channelCreationTask = await _channelCreationTaskUnloader.Dequeue();

                ChannelCreation channelCreation = channelCreationTask.ChannelCreation;
                DateTime        createdAt       = channelCreationTask.CreatedAt;
                string          ownerId         = channelCreationTask.OwnerId;

                IEnumerable <Track> tracks = (await _youTubeService.ExtractYouTubeVideos(channelCreation.StartingMedia))
                                             .Select(video => video.ToTrack());

                using (IServiceScope serviceScope = _serviceProvider.CreateScope())
                {
                    IChannelRepository channelRepository = serviceScope.ServiceProvider.GetService <IChannelRepository>();

                    Channel createdChannel = await channelRepository.CreateChannel(channelCreation.Name,
                                                                                   channelCreation.Description,
                                                                                   createdAt,
                                                                                   ownerId,
                                                                                   tracks);

                    _channelTrackingStarter.StartTrackingChannel(createdChannel.Id);

                    IChannelCreatedNotifierHubProxy channelCreatedNotifier = serviceScope.ServiceProvider.GetService <IChannelCreatedNotifierHubProxy>();
                    await channelCreatedNotifier.NotifyChannelCreated(ownerId, createdChannel);

                    UserManager <AppUser> userManager = serviceScope.ServiceProvider.GetService <UserManager <AppUser> >();
                    AppUser owner = await userManager.FindByIdAsync(ownerId);

                    owner.IsCreatingChannel = false;
                    await userManager.UpdateAsync(owner);
                }
            }
        }
示例#2
0
 public void Enqueue(ChannelCreationTask creationTask)
 {
     _creationTaskQueue.Enqueue(creationTask);
 }