Ejemplo n.º 1
0
        static void downloadFile(bool isUpload, HttpRequestMessageProperty httpRequest, string jobID, string fileRefID, string fileName)
        {
            //Downloading the response 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"))
                    {
                        //log into database
                        FileAttachment attachment = downloadResponse.fileAttachment;
                        saveFileAttachment(attachment, fileName);
                        LMSMessage += Environment.NewLine + " response file successfully downloaded:";
                    }
                    else
                    {
                        throw new Exception(downloadResponse.errorMessage[0].message);
                        // "Problem downloading the file.";
                    }

                }
            }
            catch (Exception ex)
            {
                LMSMessage += Environment.NewLine + " downloadFile:" + ex.Message;
            }
        }
Ejemplo n.º 2
0
        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";
                }
        }