using System.Threading.Channels; using ErsatzTV.Core; using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.Repositories; namespace ErsatzTV.Application.Emby; public class SynchronizeEmbyMediaSourcesHandler : IRequestHandler>> { private readonly IMediaSourceRepository _mediaSourceRepository; private readonly ChannelWriter _scannerWorkerChannel; public SynchronizeEmbyMediaSourcesHandler( IMediaSourceRepository mediaSourceRepository, ChannelWriter scannerWorkerChannel) { _mediaSourceRepository = mediaSourceRepository; _scannerWorkerChannel = scannerWorkerChannel; } public async Task>> Handle( SynchronizeEmbyMediaSources request, CancellationToken cancellationToken) { List mediaSources = await _mediaSourceRepository.GetAllEmby(); foreach (EmbyMediaSource mediaSource in mediaSources) { // await _channel.WriteAsync(new SynchronizeEmbyAdminUserId(mediaSource.Id), cancellationToken); await _scannerWorkerChannel.WriteAsync(new SynchronizeEmbyLibraries(mediaSource.Id), cancellationToken); } return mediaSources; } }