public async Task <Either <BaseError, List <JellyfinMediaSource> > > Handle(
        SynchronizeJellyfinMediaSources request,
        CancellationToken cancellationToken)
    {
        List <JellyfinMediaSource> mediaSources = await _mediaSourceRepository.GetAllJellyfin();

        foreach (JellyfinMediaSource mediaSource in mediaSources)
        {
            await _channel.WriteAsync(new SynchronizeJellyfinAdminUserId(mediaSource.Id), cancellationToken);

            await _channel.WriteAsync(new SynchronizeJellyfinLibraries(mediaSource.Id), cancellationToken);
        }

        return(mediaSources);
    }
예제 #2
0
    private async Task SynchronizeSources(
        SynchronizeJellyfinMediaSources request,
        CancellationToken cancellationToken)
    {
        using IServiceScope scope = _serviceScopeFactory.CreateScope();
        IMediator mediator = scope.ServiceProvider.GetRequiredService <IMediator>();

        Either <BaseError, List <JellyfinMediaSource> > result = await mediator.Send(request, cancellationToken);

        result.Match(
            sources =>
        {
            if (sources.Any())
            {
                _logger.LogInformation("Successfully synchronized jellyfin media sources");
            }
        },
            error =>
        {
            _logger.LogWarning(
                "Unable to synchronize jellyfin media sources: {Error}",
                error.Value);
        });
    }