internal MessageResponse ProcessHttpRequest(InputFileProperties inputFile)
        {
            try
            {
                if (inputFile == null)
                {
                    return(MessageResponse.error("File Not Found"));
                }

                var inputContent = GetInputFileContentAndLogRequest(inputFile);

                var sb = _psTool.ProcessDataFile(inputContent);

                var errorList = _psTool.GetErrors();
                if (errorList.Any())
                {
                    return(MessageResponse.error(errorList));
                }

                var encryptedData = AESHelper.EncryptAES(sb.ToString(), _configuration["AESKeyBLOB"]);
                return(MessageResponse.ok(encryptedData));
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(MessageResponse.error(e.Message));
            }
        }
        public async Task <MessageResponse> ProcessHttpRequest(HttpRequestMessage request)
        {
            if (!request.Content.IsMimeMultipartContent())
            {
                return(MessageResponse.info("Invalid media type - multipart"));
            }

            var provider = new MultipartFormDataMemoryStreamProvider();
            await request.Content.ReadAsMultipartAsync(provider);

            var inputFiles = provider.FileData;

            var primaryFilter = "*.*"; //TODO: get from httpRequest
            var primaryFiles  = GetInputFiles(provider, primaryFilter);

            var remitFilter     = "*.*"; //TODO: get from httpRequest
            var remittanceFiles = GetInputFiles(provider, remitFilter);

            var sbStandardFile = _psTool.ProcessMultiDataFile(primaryFiles, remittanceFiles);
            var listErrors     = _psTool.GetErrors();

            if (listErrors.Any())
            {
                return(MessageResponse.error(listErrors));
            }

            //Upload to storage
            var storageConnString = Vault.Current.StorageConnectionString;
            var decryptKey        = Vault.Current.AESKeyBLOB;
            var containerName     = "containerName";  //TODO: where?
            var blobOutputName    = "blobOutputName"; //TODO: how?

            BlobHelper.UploadFile(storageConnString, containerName, blobOutputName, sbStandardFile, decryptKey);

            //Send msg to importWorker
            var messageProperties = new BrokeredMessageProperties();

            messageProperties.Add("siteName", "SiteName");
            var sbConnectionString = Vault.Current.ServiceBusConnectionString;
            var queueName          = "queueName";//TODO:Where?

            MessageHelper.SendMessageToServiceBus(sbConnectionString, queueName, messageProperties);

            return(MessageResponse.ok(null));
        }
Esempio n. 3
0
        internal MessageResponse ProcessRequest(ConversionRequest request)
        {
            string errorMsg;

            if (!ValidateRequest(request, out errorMsg))
            {
                return(MessageResponse.info(errorMsg));
            }
            try
            {
                var storageConnString = AzureKeyVaultProvider.StorageConnectionString;
                var decryptKey        = AzureKeyVaultProvider.AESKeyBLOB;

                //download file
                var downloadResult = DownloadConversionFiles(request, storageConnString, decryptKey);
                if (!downloadResult.Success)
                {
                    return(MessageResponse.info(downloadResult.ErrorMessage));
                }

                _psTool.SetCurrentConversionRequest(request);
                var sbStandardFile = _psTool.ProcessDataFile(downloadResult.PrimaryFileContent, downloadResult.RemittanceFileContent);
                var listErrors     = _psTool.GetErrors();

                if (listErrors.Any())
                {
                    return(MessageResponse.error(listErrors));
                }

                BlobHelper.UploadFile(storageConnString, request.containerName, request.blobOutputName, sbStandardFile, decryptKey);
                return(MessageResponse.ok(request.blobOutputName));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return(MessageResponse.error(ex.Message));
            }
        }
        // request nay la send từ postman, qua hàm này request.Content.ReadAsMultipartAsync
        // nó sẽ lầy tên file từ body truyền trên postman
        // System.net.http ko xa2i tre6n .netcore
        // Doc them phan Upload large files with streaming
        // https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.0
        internal MessageResponse ProcessHttpRequest(MasterConversionRequest request)
        {
            try
            {
                // coi them vd cho .net framework
                // https://stackoverflow.com/questions/14937926/file-name-from-httprequestmessage-content

                //if (!request.Content.IsMimeMultipartContent())
                //    return MessageResponse.info("Invalid media type - multipart");
                //var provider = new MultipartFormDataMemoryStreamProvider();
                //await request.Content.ReadAsMultipartAsync(provider);
                //var inputContent = GetInputFileContentAndLogRequest(provider);
                if (request is null || request.FileData.Length == 0) //TODO length > maximum length
                {
                    return(MessageResponse.error("Bad request. File not found!"));
                }

                var inputContent = GetInputFileContentAndLogRequest(request);

                var sb = _psTool.ProcessDataFile(inputContent);

                var errorList = _psTool.GetErrors();
                if (errorList.Any())
                {
                    return(MessageResponse.error(errorList));
                }

                var encryptedData = AESHelper.EncryptAES(sb, AzureKeyVaultProvider.AESKeyBLOB);
                return(MessageResponse.ok(encryptedData));
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
                return(MessageResponse.error(e.Message));
            }
        }
Esempio n. 5
0
        public MessageResponse convert(ConversionRequest reqValue)
        {
            LOGGER.Info("Conversion processing...");
            if (reqValue == null || string.IsNullOrEmpty(reqValue.blobHeaderName) || string.IsNullOrEmpty(reqValue.blobOutputName) || string.IsNullOrEmpty(reqValue.containerName))
            {
                return(MessageResponse.info("[blobHeaderName, blobOutputName, containerName] are required."));
            }
            string BlobContainer           = reqValue.containerName.Trim();
            string BlobInputName           = reqValue.blobHeaderName.Trim();
            string BlobOutputName          = reqValue.blobOutputName.Trim();
            string AESKey                  = Vault.Current.AESKeyBLOB;
            string storageConnectionString = Vault.Current.StorageConnectionString;


            //validate parameter
            if (string.IsNullOrEmpty(BlobContainer))
            {
                return(MessageResponse.info("Blob container is required."));
            }
            if (string.IsNullOrEmpty(BlobInputName))
            {
                return(MessageResponse.info("Blob file input is required."));
            }
            if (string.IsNullOrEmpty(BlobOutputName))
            {
                return(MessageResponse.info("Blob file output is required."));
            }
            if (string.IsNullOrEmpty(AESKey))
            {
                return(MessageResponse.info("AESKEY to encrypt/decrypt file is required."));
            }

            try
            {
                // Retrieve reference to a previously created container.
                CloudBlobContainer blobContainer       = BlobHelper.GetCloudBlobContainer(storageConnectionString, BlobContainer);
                Task <bool>        IsExitBlobContainer = blobContainer.ExistsAsync();
                if (blobContainer == null || !IsExitBlobContainer.Result)
                {
                    return(MessageResponse.info(string.Format("Can't find the BLOB container [{0}].", BlobContainer)));
                }

                // Retrieve reference to a blob named "myblob".
                CloudBlockBlob blockBlobInput       = blobContainer.GetBlockBlobReference(BlobInputName);
                Task <bool>    IsExitblockBlobInput = blockBlobInput.ExistsAsync();
                if (blockBlobInput == null || !IsExitblockBlobInput.Result)
                {
                    return(MessageResponse.info(string.Format("Can't find the BLOB file [{0}].", BlobInputName)));
                }

                //download file
                byte[] fileInput = BlobHelper.DownloadFileToArrayByte(blockBlobInput, AESKey);
                if (fileInput == null)
                {
                    return(MessageResponse.info(string.Format("Can't find the content of the BLOB file [{0}].", BlobInputName)));
                }

                //do conversion
                StringBuilder sbStandardFile = this.doConvert(fileInput);

                //no error: write the file standard
                if (this.ListErrorVendor == null || this.ListErrorVendor.Count == 0)
                {
                    //upload the file standard file to azure
                    BlobHelper.UploadFile(blobContainer, BlobOutputName, sbStandardFile, AESKey);

                    //return the blob output name of file saved
                    //LOGGER.Info(string.Format("File [{0}] converted to the file [{1}] and saved successfully in the BLOB container [{2}]", BlobInputName, BlobOutputName, BlobContainer));
                    return(MessageResponse.ok(reqValue.blobOutputName));
                }


                //report errors if have
                if (this.ListErrors == null)
                {
                    this.ListErrors = new List <string>();
                }
                if (this.ListErrorVendor.Count > 0)
                {
                    this.ListErrors.AddRange(this.ListErrorVendor);
                }
                return(MessageResponse.error(this.ListErrors));
            }
            catch (Exception ex)
            {
                LOGGER.Error(ex);
                throw;
            }
        }