Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] DataObjects.Domain.File model)
        {
            var response = ServerResponse.OK;

            if (string.IsNullOrEmpty(model.Source))
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.EmptySourceUrl)));
            }

            string protocol = _fileManager.GetProtocolFromSource(model.Source);

            if (string.IsNullOrEmpty(protocol))
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.InvalidProtocol)));
            }

            var isValidSourceUrl = RequestValidator.CheckURLValid(model.Source, protocol);

            if (!isValidSourceUrl)
            {
                return(Ok(_errorMapper.MapToError(ServerResponse.BadRequest, Resource.InvalidSourceUrl)));
            }

            switch (protocol)
            {
            case Protocol.Http:
                response = await _fileDownloader.DownloadDataFromHttpToLocalDisk(model.Source, protocol);

                break;

            case Protocol.Https:
                response = await _fileDownloader.DownloadDataFromHttpsToLocalDisk(model.Source, protocol);

                break;

            case Protocol.ftp:
                response = await _fileDownloader.DownloadDataFromFtpToLocalDisk(model.Source, protocol);

                break;

            case Protocol.sftp:
                response = await _fileDownloader.DownloadDataFromSftpToLocalDisk(model.Source, protocol);

                break;

            case Protocol.tcp:
                response = await _fileDownloader.DownloadDataFromTcpToLocalDisk(model.Source, protocol);

                break;

            case Protocol.pipe:
                response = await _fileDownloader.DownloadDataFromPipeToLocalDisk(model.Source, protocol);

                break;
            }
            return(Ok(response));
        }
 public static Entities.File ToCommand(this DataObjects.Domain.File model)
 {
     return(new Entities.File()
     {
         FileId = model.FileId,
         Source = model.Source,
         Destination = model.Destination,
         DownloadStartedDate = model.DownloadStartedDate,
         DownloadEndedDate = model.DownloadEndedDate,
         IsLargeData = Convert.ToBoolean(model.IsLargeData),
         IsSlow = Convert.ToBoolean(model.IsSlow),
         PercentageOfFailure = model.PercentageOfFailure,
         DownloadSpeed = model.DownloadSpeed,
         ElapsedTime = model.ElapsedTime,
         ProtocolId = model.ProtocolId,
         StatusId = model.StatusId
     });
 }