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)); }
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)); } }
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; } }
public async Task <MessageResponse> Index() { MessageResponse res = new MessageResponse(); try { Logger.Info("Initial execute import vendor master data"); if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { return(MessageResponse.info("Invalid media type - multipart")); } string root = Environment.GetEnvironmentVariable("TEMP"); var provider = new MultipartFormDataStreamProvider(root); await Request.ReadAsMultipartAsync(provider); string sitename = string.Empty; int CaseAction = 0; ArrayList DataSetCreateVendor = null; ArrayList DataSetCreateAddress = null; ArrayList DataSetUpdateVendor = null; ArrayList DataSetUpdateAddress = null; string containerName = string.Empty; string blobName = string.Empty; bool decrypt = false; bool isGetFromBlob = false; // Show all the key-value pairs. foreach (var key in provider.FormData.AllKeys) { foreach (var val in provider.FormData.GetValues(key)) { switch (key) { case "CaseAction": CaseAction = Int32.Parse(val.ToString()); Logger.Info("CaseAction : " + val.ToString()); break; case "VendorCreate": DataSetCreateVendor = new ArrayList(val.ToString().Split(',')); DataSetCreateVendor.Add("Line"); Logger.Info("VendorCreate[] : " + val.ToString()); break; case "AddressCreate": DataSetCreateAddress = new ArrayList(val.ToString().Split(',')); DataSetCreateAddress.Add("Line"); DataSetCreateAddress.Add("VendorKey"); Logger.Info("AddressCreate[] : " + val.ToString()); break; case "VendorUpdate": DataSetUpdateVendor = new ArrayList(val.ToString().Split(',')); DataSetUpdateVendor.Add("Line"); Logger.Info("VendorUpdate[] : " + val.ToString()); break; case "AddressUpdate": DataSetUpdateAddress = new ArrayList(val.ToString().Split(',')); DataSetUpdateAddress.Add("Line"); DataSetUpdateAddress.Add("VendorKey"); Logger.Info("AddressUpdate[] : " + val.ToString()); break; case "ContainerName": containerName = val.ToString(); Logger.Info("containerName : " + val.ToString()); break; case "BlobName": blobName = val.ToString(); Logger.Info("blobName : " + val.ToString()); break; case "Decrypt": decrypt = bool.Parse(val.ToString()); Logger.Info("decrypt : " + val.ToString()); break; case "isGetFromBlob": isGetFromBlob = bool.Parse(val.ToString()); Logger.Info("isGetFromBlob : " + val.ToString()); break; } } } ObjParameter result = GetByteFile(provider, isGetFromBlob, containerName, blobName); Logger.Info("End parse parameter from request"); ExcelService excel = new ExcelService(result.byteArr, result.filename); res = excel.ReadDataFromExcel(); Logger.Info("Done execute import vendor master data"); return(res); } catch (Exception e) { Trace.WriteLine(e.ToString()); Logger.Error("Error : " + e.ToString()); res.code = (int)HttpStatusCode.InternalServerError; res.messages.Add(AppHelper.GetErrorMessage(e)); return(res); } }