private bool uploadFile(frmLMSMain sender, HttpRequestMessageProperty httpRequest, string jobID, string fileRefID, string fileName) { sender.UploadStatus += "\n\nUploading the request file.\n"; try { FileTransferServicePortClient client = new FileTransferServicePortClient(FTconfigName); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest); UploadFileRequest uploadReq = new UploadFileRequest(); uploadReq.fileAttachment = getFileAttachment(fileName); uploadReq.fileReferenceId = fileRefID; uploadReq.taskReferenceId = jobID; uploadReq.fileFormat = "gzip"; UploadFileResponse uploadResponse = client.uploadFile(uploadReq); if (uploadResponse.ack.ToString().Equals("Success")) { sender.UploadStatus += uploadResponse.timestamp + " :: " + fileName + " has been successfully uploaded to the server.\n"; return true; } else { sender.UploadStatus += uploadResponse.timestamp + " :: " + "Could not upload file to Server\n"; if (uploadResponse.errorMessage != null) { ErrorAdmin.updateResponseStatus(uploadResponse, sender, true); } return false; } } } catch (Exception ex) { sender.UploadStatus += ex + "\n"; return false; } }
//Helper function to update the UI to show the error messsages returned by the FT functions public static void updateResponseStatus(FT.BaseServiceResponse resp, frmLMSMain sender, bool isUpload) { // add any error messages received if (resp.errorMessage != null) { foreach (FT.ErrorData error in resp.errorMessage) { //Route the error message to the control on the appropriate Tab Page if(isUpload) sender.UploadStatus += error.message + "\n"; else sender.DownloadStatus += error.message + "\n"; } } }
private string startDownloadJob(frmLMSMain sender, HttpRequestMessageProperty httpRequest, string ReportType) { string txt = ""; sender.DownloadStatus = "Calling startDownloadJob\n"; try { BulkDataExchangeServicePortClient client = new BulkDataExchangeServicePortClient(BDXconfigName); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest); StartDownloadJobRequest req = new StartDownloadJobRequest(); req.downloadJobType = ReportType; // Generate a UUID. UUID must be unique. Once used, you can't use it again req.UUID = System.Guid.NewGuid().ToString(); StartDownloadJobResponse resp = client.startDownloadJob(req); // update the status of the request (success / fail) and any messages returned // add any error messages received if (resp.errorMessage != null) { ErrorAdmin.updateResponseStatus(resp, sender, false); } if (resp.jobId != null) { txt += resp.timestamp + " :: " + ReportType + " with jobID: " + resp.jobId + " has been created.\n"; Console.WriteLine(txt); sender.DownloadStatus += txt; return resp.jobId; } else return ""; } } catch(Exception ex) { sender.DownloadStatus += ex + "\n"; return ""; } }
private bool startUploadJob(frmLMSMain sender, HttpRequestMessageProperty httpRequest, string jobID) { string txt = ""; sender.UploadStatus += "\nCalling startUploadJob.\n"; try { BulkDataExchangeServicePortClient client = new BulkDataExchangeServicePortClient(BDXconfigName); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest); StartUploadJobRequest req = new StartUploadJobRequest(); req.jobId = jobID.Trim(); StartUploadJobResponse resp = client.startUploadJob(req); // update the status of the request (success / fail) and any messages returned if (resp.ack == BDX.AckValue.Success) { txt += "Job with JobID " + jobID + " has been successfully scheduled. \n"; txt += "\n" + resp.timestamp; Console.WriteLine(txt); sender.UploadStatus += txt; return true; } else { txt = resp.timestamp + " :: " + "This job might have already been scheduled.\n"; Console.WriteLine(txt); sender.UploadStatus += txt; if (resp.errorMessage != null) { ErrorAdmin.updateResponseStatus(resp, sender, true); } return false; } } } catch (Exception ex) { sender.UploadStatus += ex + "\n"; return false; } }
private string getJobStatus(frmLMSMain sender, bool isUpload, HttpRequestMessageProperty httpRequest, string jobID) { string txt = ""; string fileRefID = ""; if (isUpload) sender.UploadStatus += "\nCalling getJobStatus every minute to see if the job has completed.\n"; else sender.DownloadStatus += "\nCalling getJobStatus every minute to see if the job has completed.\n"; try { BulkDataExchangeServicePortClient client = new BulkDataExchangeServicePortClient(BDXconfigName); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest); while (fileRefID == "") { //Sleep between successive requests Thread.Sleep(60000); GetJobStatusRequest req = new GetJobStatusRequest(); req.jobId = jobID.Trim(); GetJobStatusResponse resp = client.getJobStatus(req); // update the status of the request (success / fail) and any messages returned if (resp.errorMessage != null) { ErrorAdmin.updateResponseStatus(resp, sender, isUpload); } if (resp.jobProfile != null) { foreach (JobProfile jobProfile in resp.jobProfile) { if (jobProfile.fileReferenceId != null) { txt = resp.timestamp + " :: " + "Job Type: " + jobProfile.jobType + "::Job ID: " + jobProfile.jobId + "::" + "FileRefID: " + jobProfile.fileReferenceId + "::" + "Job Status: " + jobProfile.jobStatus + "\n\n"; fileRefID = jobProfile.fileReferenceId; Console.WriteLine(txt); if (isUpload) sender.UploadStatus += txt; else sender.DownloadStatus += txt; } else { txt = resp.timestamp + " :: " + "Job Type: " + jobProfile.jobType + "::Job ID: " + jobProfile.jobId + "::" + "Job Status: " + jobProfile.jobStatus + "\n";; Console.WriteLine(txt); if (isUpload) sender.UploadStatus += txt; else sender.DownloadStatus += txt; } } } } return fileRefID; } } catch (Exception ex) { if (isUpload) sender.UploadStatus += ex + "\n"; else sender.DownloadStatus += ex + "\n"; return ""; } }
private void downloadFile(frmLMSMain sender, bool isUpload, HttpRequestMessageProperty httpRequest, string jobID, string fileRefID, string fileName) { string txt = ""; if (isUpload) sender.UploadStatus += "Downloading the response file.\n"; else sender.DownloadStatus += "Downloading the report file.\n"; try { FileTransferServicePortClient client = new FileTransferServicePortClient(FTconfigName); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest); DownloadFileRequest downloadReq = new DownloadFileRequest(); downloadReq.fileReferenceId = fileRefID; downloadReq.taskReferenceId = jobID; DownloadFileResponse downloadResponse = client.downloadFile(downloadReq); if (downloadResponse.ack.ToString().Equals("Success")) { FileAttachment attachment = downloadResponse.fileAttachment; saveFileAttachment(attachment, fileName); txt += downloadResponse.timestamp + " :: " + "File was successfully downloaded to " + fileName; Console.WriteLine(txt); if (isUpload) sender.UploadStatus += txt; else sender.DownloadStatus += txt; } else { txt = downloadResponse.timestamp + " :: " + "Problem downloading the file."; Console.WriteLine(txt); if (isUpload) sender.UploadStatus += txt; else sender.DownloadStatus += txt; if (downloadResponse.errorMessage != null) { ErrorAdmin.updateResponseStatus(downloadResponse, sender, isUpload); } } } } catch (Exception ex) { if (isUpload) sender.UploadStatus += ex + "\n"; else sender.DownloadStatus += ex + "\n"; } }
private CreateUploadJobResponse createUploadJob(frmLMSMain sender, HttpRequestMessageProperty httpRequest, string JobType) { string txt = ""; try { sender.UploadStatus += "Calling createUploadJob\n"; BulkDataExchangeServicePortClient client = new BulkDataExchangeServicePortClient(BDXconfigName); using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest); //Create the request CreateUploadJobRequest req = new CreateUploadJobRequest(); //Supply additional parameters // The UUID must be unique. Once used, you can't use it again req.UUID = System.Guid.NewGuid().ToString(); req.uploadJobType = JobType; req.fileType = FileType.XML; //Get the response CreateUploadJobResponse resp = client.createUploadJob(req); // update the status of the request (success / fail) and any messages returned if (resp.errorMessage != null) { ErrorAdmin.updateResponseStatus(resp, sender, true); } if (resp.ack == BDX.AckValue.Success) { txt += resp.timestamp + " :: " + JobType + " has been created with Job ID:" + resp.jobId + " and FileRefID: " + resp.fileReferenceId; Console.WriteLine(txt); sender.UploadStatus += txt; } return resp; } } catch (Exception ex) { Console.WriteLine(ex); sender.UploadStatus += ex + "\n"; CreateUploadJobResponse errResp = null; return errResp; } }
public void UploadEndtoEnd(frmLMSMain sender, string JobType, string ReqfileName, string RespfileName) { string fileRefID = ""; try { //set the endpoint config names setBDXconfigName(); setFTconfigName(); //setHTTPHeaders HttpRequestMessageProperty httpRequest = this.setHTTPHeaders(); //Step 1. createUploadJob modifyHTTPHeaders(httpRequest, BDXService, "createUploadJob"); CreateUploadJobResponse resp = createUploadJob(sender, httpRequest, JobType); if ((resp != null) && (resp.ack.ToString().Equals("Success"))) { //Step 2. uploadFile modifyHTTPHeaders(httpRequest, FTService, "uploadFile"); if(uploadFile(sender, httpRequest, resp.jobId, resp.fileReferenceId, ReqfileName)) { //Step 3. startUploadJob modifyHTTPHeaders(httpRequest, BDXService, "startUploadJob"); if(startUploadJob(sender, httpRequest, resp.jobId)) { //Step 4. getJobStatus modifyHTTPHeaders(httpRequest, BDXService, "getJobStatus"); fileRefID = getJobStatus(sender, true, httpRequest, resp.jobId); if(fileRefID != "") { //Step 5. downloadFile modifyHTTPHeaders(httpRequest, FTService, "downloadFile"); downloadFile(sender, true, httpRequest, resp.jobId, fileRefID, RespfileName); } } } } } catch(Exception ex) { sender.UploadStatus += ex + "\n"; } }
public void DownloadEndtoEnd(frmLMSMain sender, string ReportType, string fileName) { string jobID, fileRefID = ""; try { //Set the endpoint config names setBDXconfigName(); setFTconfigName(); //setHTTPHeaders HttpRequestMessageProperty httpRequest = setHTTPHeaders(); //Step 1. startDownloadJob modifyHTTPHeaders(httpRequest, BDXService, "startDownloadJob"); jobID = startDownloadJob(sender, httpRequest, ReportType); if (jobID != "") { //Step 2. getJobStatus modifyHTTPHeaders(httpRequest, BDXService ,"getJobStatus"); fileRefID = getJobStatus(sender, false, httpRequest, jobID); if(fileRefID != "") { //Step 3. downloadFile modifyHTTPHeaders(httpRequest, FTService ,"downloadFile"); downloadFile(sender, false, httpRequest, jobID, fileRefID, fileName); } } } catch(Exception ex) { sender.DownloadStatus += ex + "\n"; } }