public void WriteErrorLog(string title, OperationResult op)
 {
     string ErrorMessages = "";
     foreach (var message in op.MessageList)
     {
         ErrorMessages += "\t" + message + "\n";
     }
     Write(title + "\n" + ErrorMessages);
 }
        public OperationResult GenerateTextFile(string transactionData,
                                                string ftpServerRtgs,
                                                string ftpUser,
                                                string ftpPassword,
                                                string fileName)
        {
            var op = new OperationResult();

            if (string.IsNullOrWhiteSpace(transactionData)) op.AddMessage("Transaction Data is Null");
            if (string.IsNullOrWhiteSpace(ftpServerRtgs)) op.AddMessage("Destination Path is Null");
            if (string.IsNullOrWhiteSpace(ftpUser)) op.AddMessage("FTP User is Null");
            if (string.IsNullOrWhiteSpace(ftpPassword)) op.AddMessage("FTP Password is Null");
            if (op.MessageList.Count() > 0) op.Success = false;

            if (op.Success)
            {
                try
                {
                    var tempFile = AppDomain.CurrentDomain.BaseDirectory + fileName;
                    System.IO.File.WriteAllText(tempFile, transactionData);

                    UploadFileToFTP(tempFile: tempFile,
                                    fileName: fileName,
                                    ftpServerRtgs: ftpServerRtgs,
                                    ftpUser: ftpUser,
                                    ftpPassword: ftpPassword,
                                    op: op);
                }
                catch (Exception ex)
                {
                    op.Success = false;
                    op.AddMessage(ex.Message);
                }
            }

            return op;
        }
        private void UpdateGeneratedTransactionStatus(OutgoingSingleCreditController outgoingSingleCreditController,
                                                        string transactionCode, OperationResult op)
        {
            outgoingSingleCreditController.UpdateGeneratedTransactionStatus(transactionCode, op);

            if (op.Success)
            {
                log.Write("Text file " + transactionCode + " has been sent to RTGS");
            }
            else
            {
                log.WriteErrorLog("Update generated transaction status failed.", op);
            }
        }
        public void UploadFileToFTP(string tempFile,
                                    string fileName,
                                    string ftpServerRtgs,
                                    string ftpUser,
                                    string ftpPassword,
                                    OperationResult op)
        {
            using (WebClient client = new WebClient())
            {
                client.Credentials = new NetworkCredential(ftpUser, ftpPassword);
                client.UploadFile(ftpServerRtgs + "/" + fileName, "STOR", tempFile);
            }

            System.IO.File.Delete(tempFile);
        }
 public void UpdateGeneratedTransactionStatus(string transactionCode, OperationResult op)
 {
     try
     {
         var outgoingSingleCreditRepository = new OutgoingSingleCreditRepository(connectionString);
         outgoingSingleCreditRepository.GenerateOutgoingSingleCredit(transactionCode);
     }
     catch (Exception ex)
     {
         op.Success = false;
         op.AddMessage(ex.Message);
     }
 }