Ejemplo n.º 1
0
    private async Task <Validation <BaseError, RequestParameters> > Validate(IScanLocalLibrary request)
    {
        Validation <BaseError, LocalLibrary> libraryResult = await LocalLibraryMustExist(request);

        Validation <BaseError, string> ffprobePathResult = await ValidateFFprobePath();

        Validation <BaseError, string> ffmpegPathResult = await ValidateFFmpegPath();

        Validation <BaseError, int> refreshIntervalResult = await ValidateLibraryRefreshInterval();

        try
        {
            return((libraryResult, ffprobePathResult, ffmpegPathResult, refreshIntervalResult)
                   .Apply(
                       (library, ffprobePath, ffmpegPath, libraryRefreshInterval) => new RequestParameters(
                           library,
                           ffprobePath,
                           ffmpegPath,
                           request.ForceScan,
                           libraryRefreshInterval)));
        }
        finally
        {
            // ensure we unlock the library if any validation is unsuccessful
            foreach (LocalLibrary library in libraryResult.SuccessToSeq())
            {
                if (ffprobePathResult.IsFail || ffmpegPathResult.IsFail || refreshIntervalResult.IsFail)
                {
                    _entityLocker.UnlockLibrary(library.Id);
                }
            }
        }
    }
Ejemplo n.º 2
0
 private async Task <Validation <BaseError, RequestParameters> > Validate(IScanLocalLibrary request) =>
 (await LocalLibraryMustExist(request), await ValidateFFprobePath())
Ejemplo n.º 3
0
 Handle(IScanLocalLibrary request) =>
 Validate(request)
 .MapT(parameters => PerformScan(parameters).Map(_ => parameters.LocalLibrary.Name))
 .Bind(v => v.ToEitherAsync());
Ejemplo n.º 4
0
 private Task <Either <BaseError, string> > Handle(IScanLocalLibrary request, CancellationToken cancellationToken) =>
 Validate(request)
 .MapT(parameters => PerformScan(parameters, cancellationToken).Map(_ => parameters.LocalLibrary.Name))
 .Bind(v => v.ToEitherAsync());
Ejemplo n.º 5
0
 private Task <Validation <BaseError, LocalLibrary> > LocalLibraryMustExist(
     IScanLocalLibrary request) =>
 _libraryRepository.Get(request.LibraryId)
 .Map(maybeLibrary => maybeLibrary.Map(ms => ms as LocalLibrary))
 .Map(v => v.ToValidation <BaseError>($"Local library {request.LibraryId} does not exist."));