Ejemplo n.º 1
0
        public ActionResult <Guid> Post(
            PostRequestDto dto)
        {
            var(linkString, saveAsFileName) = dto;
            var linkResult = Link.Create(linkString);

            if (linkResult.IsFailure)
            {
                return(BadRequest(linkResult.Error));
            }

            var link             = linkResult.Value;
            var saveAsFileResult =
                SaveAsFile.Create(
                    link,
                    _completedDownloadsDirectory,
                    saveAsFileName);

            if (saveAsFileResult.IsFailure)
            {
                return(BadRequest(saveAsFileResult.Error));
            }

            var job =
                _notificationsManager.AddNotificationEventHandlers(
                    _downloadManager.CreateDownloadJob(link, saveAsFileResult.Value));

            var(_, isFailure, error) = _downloadStarter.Start(job);
            return(isFailure ? Problem(error) : Ok(job.Id.Value));
        }
Ejemplo n.º 2
0
            public object Create(
                object request,
                ISpecimenContext context)
            {
                if (request is not Type type)
                {
                    return(new NoSpecimen());
                }

                if (type == typeof(Link))
                {
                    return(Link.Create(
                               $"https://{context.Create<string>()}/{context.Create<string>()}")
                           .Value);
                }

                if (type == typeof(SaveAsFile))
                {
                    return(SaveAsFile.Create(
                               context.Create <Link>(),
                               context.Create <CompletedDownloadsDirectory>())
                           .Value);
                }

                return(new NoSpecimen());
            }