/// <summary> /// Save xml string as camt052 file /// </summary> public static string Save(string Account, string UMS, Encoding encoding = null) { encoding = encoding ?? Encoding.UTF8; string dir = Helper.GetProgramBaseDir(); dir = Path.Combine(dir, "camt052"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string filename = Path.Combine(dir, Helper.MakeFilenameValid(Account + "_" + DateTime.Now + "-" + Guid.NewGuid() + ".camt052")); // camt052 if (!File.Exists(filename)) { using (File.Create(filename)) { }; } File.AppendAllText(filename, UMS, encoding); return(filename); }
/// <summary> /// Save xml string as camt052 file /// </summary> public static string Save(string Account, string UMS) { string documents = "", dir = ""; dir = Path.Combine(documents, Program.Buildname); dir = Path.Combine(dir, "camt052"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string filename = Path.Combine(dir, Helper.MakeFilenameValid(Account + "_" + DateTime.Now + "-" + Guid.NewGuid() + ".camt052")); // camt052 if (!File.Exists(filename)) { using (File.Create(filename)) { }; File.AppendAllText(filename, UMS); } else { File.AppendAllText(filename, UMS); } return(filename); }
public static List <SWIFTStatement> Serialize(string STA, string Account) { int LineCounter = 0; string swiftTag = ""; string swiftData = ""; SWIFTStatements = new List <SWIFTStatement>(); SWIFTStatement = null; if (STA == null || STA.Length == 0) { return(SWIFTStatements); } string documents = "", dir = ""; documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dir = Path.Combine(documents, Program.Buildname); dir = Path.Combine(dir, "STA"); string filename = Path.Combine(dir, Helper.MakeFilenameValid(Account + "_" + DateTime.Now + ".STA")); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // STA if (!File.Exists(filename)) { using (File.Create(filename)) { }; File.AppendAllText(filename, STA); } else { File.AppendAllText(filename, STA); } while (STA.Length > 0) { string line = Read(ref STA); LineCounter++; if ((line.Length > 0) && (!line.StartsWith("-"))) { // A swift chunk starts with a swiftTag, which is between colons if (line.StartsWith(":")) { // Process previously read swift chunk if (swiftTag.Length > 0) { Data(swiftTag, swiftData); } int posColon = line.IndexOf(":", 2); swiftTag = line.Substring(1, posColon - 1); swiftData = line.Substring(posColon + 1); } else { // The swift chunk is spread over several lines swiftData = swiftData + line; } } } if (swiftTag.Length > 0) { Data(swiftTag, swiftData); } // If there are remaining unprocessed statements - add them if (SWIFTStatement != null) { SWIFTStatements.Add(SWIFTStatement); SWIFTStatement = null; } // Parse SEPA purposes foreach (var stmt in SWIFTStatements) { foreach (var tx in stmt.SWIFTTransactions) { if (string.IsNullOrWhiteSpace(tx.description)) { continue; } // Collect all occuring SEPA purposes ordered by their position List <Tuple <int, SWIFTTransaction.SEPAPurpose> > indices = new List <Tuple <int, SWIFTTransaction.SEPAPurpose> >(); foreach (SWIFTTransaction.SEPAPurpose sepaPurpose in Enum.GetValues(typeof(SWIFTTransaction.SEPAPurpose))) { string prefix = $"{sepaPurpose}+"; var idx = tx.description.IndexOf(prefix); if (idx >= 0) { indices.Add(Tuple.Create(idx, sepaPurpose)); } } indices = indices.OrderBy(v => v.Item1).ToList(); // Then get the values for (int i = 0; i < indices.Count; i++) { var beginIdx = indices[i].Item1 + $"{indices[i].Item2}+".Length; var endIdx = i < indices.Count - 1 ? indices[i + 1].Item1 : tx.description.Length; var value = tx.description.Substring(beginIdx, endIdx - beginIdx); tx.SEPAPurposes[indices[i].Item2] = value; } } } if (Trace.Enabled) { foreach (SWIFTStatement statement in SWIFTStatements) { var ID = statement.id; var Date = statement.date.ToShortDateString(); var AccountCode = statement.accountCode; var BanksortCode = statement.bankCode; var Currency = statement.currency; var StartBalance = statement.startBalance.ToString(); var EndBalance = statement.endBalance.ToString(); foreach (SWIFTTransaction transaction in statement.SWIFTTransactions) { var PartnerName = transaction.partnerName; var AccountCode_ = transaction.accountCode; var BankCode = transaction.bankCode; var Description = transaction.description; var Text = transaction.text; var TypeCode = transaction.typecode; var Amount = transaction.amount.ToString(); var UMS = "++STARTUMS++" + "ID: " + ID + " ' " + "Date: " + Date + " ' " + "AccountCode: " + AccountCode + " ' " + "BanksortCode: " + BanksortCode + " ' " + "Currency: " + Currency + " ' " + "StartBalance: " + StartBalance + " ' " + "EndBalance: " + EndBalance + " ' " + "PartnerName: " + PartnerName + " ' " + "BankCode: " + BankCode + " ' " + "Description: " + Description + " ' " + "Text: " + Text + " ' " + "TypeCode: " + TypeCode + " ' " + "Amount: " + Amount + " ' " + "++ENDUMS++"; dir = Path.Combine(documents, Program.Buildname); dir = Path.Combine(dir, "MT940"); string filename_ = Path.Combine(dir, Helper.MakeFilenameValid(Account + "_" + DateTime.Now + ".MT940")); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // MT940 if (!File.Exists(filename_)) { using (File.Create(filename_)) { }; File.AppendAllText(filename_, UMS); } else { File.AppendAllText(filename_, UMS); } } } } return(SWIFTStatements); }
public static List <SWIFTStatement> Serialize(string STA, string Account) { int LineCounter = 0; string swiftTag = ""; string swiftData = ""; SWIFTStatements = new List <SWIFTStatement>(); SWIFTStatement = null; if (STA == null || STA.Length == 0) { return(SWIFTStatements); } string documents = "", dir = ""; documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dir = Path.Combine(documents, Program.Buildname); dir = Path.Combine(dir, "STA"); string filename = Path.Combine(dir, Helper.MakeFilenameValid(Account + "_" + DateTime.Now + ".STA")); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // STA if (!File.Exists(filename)) { using (File.Create(filename)) { }; File.AppendAllText(filename, STA); } else { File.AppendAllText(filename, STA); } while (STA.Length > 0) { string line = Read(ref STA); LineCounter++; if ((line.Length > 0) && (!line.StartsWith("-"))) { // A swift chunk starts with a swiftTag, which is between colons if (line.StartsWith(":")) { // Process previously read swift chunk if (swiftTag.Length > 0) { Data(swiftTag, swiftData); } int posColon = line.IndexOf(":", 2); swiftTag = line.Substring(1, posColon - 1); swiftData = line.Substring(posColon + 1); } else { // The swift chunk is spread over several lines swiftData = swiftData + line; } } } if (swiftTag.Length > 0) { Data(swiftTag, swiftData); } if (Trace.Enabled) { foreach (SWIFTStatement statement in SWIFTStatements) { var ID = statement.id; var Date = statement.date.ToShortDateString(); var AccountCode = statement.accountCode; var BanksortCode = statement.bankCode; var Currency = statement.currency; var StartBalance = statement.startBalance.ToString(); var EndBalance = statement.endBalance.ToString(); foreach (SWIFTTransaction transaction in statement.SWIFTTransactions) { var PartnerName = transaction.partnerName; var AccountCode_ = transaction.accountCode; var BankCode = transaction.bankCode; var Description = transaction.description; var Text = transaction.text; var TypeCode = transaction.typecode; var Amount = transaction.amount.ToString(); var UMS = "++STARTUMS++" + "ID: " + ID + " ' " + "Date: " + Date + " ' " + "AccountCode: " + AccountCode + " ' " + "BanksortCode: " + BanksortCode + " ' " + "Currency: " + Currency + " ' " + "StartBalance: " + StartBalance + " ' " + "EndBalance: " + EndBalance + " ' " + "PartnerName: " + PartnerName + " ' " + "BankCode: " + BankCode + " ' " + "Description: " + Description + " ' " + "Text: " + Text + " ' " + "TypeCode: " + TypeCode + " ' " + "Amount: " + Amount + " ' " + "++ENDUMS++"; dir = Path.Combine(documents, Program.Buildname); dir = Path.Combine(dir, "MT940"); string filename_ = Path.Combine(dir, Helper.MakeFilenameValid(Account + "_" + DateTime.Now + ".MT940")); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // MT940 if (!File.Exists(filename_)) { using (File.Create(filename_)) { }; File.AppendAllText(filename_, UMS); } else { File.AppendAllText(filename_, UMS); } } } } return(SWIFTStatements); }
public static List <SwiftStatement> Serialize(string STA, string Account, bool writeToFile = false, bool pending = false) { int LineCounter = 0; string swiftTag = ""; string swiftData = ""; SWIFTStatements = new List <SwiftStatement>(); SWIFTStatement = null; if (STA == null || STA.Length == 0) { return(SWIFTStatements); } string dir = null; if (writeToFile) { dir = FinTsConfig.ProgramBaseDir; dir = Path.Combine(dir, "STA"); string filename = Path.Combine(dir, Helper.MakeFilenameValid(Account + "_" + DateTime.Now + ".STA")); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // STA if (!File.Exists(filename)) { using (File.Create(filename)) { }; File.AppendAllText(filename, STA); } else { File.AppendAllText(filename, STA); } } while (STA.Length > 0) { string line = Read(ref STA); LineCounter++; if (line.Trim() == "-") // end of block { // Process previously read swift chunk if (swiftTag.Length > 0) { Data(swiftTag, swiftData); } swiftTag = string.Empty; swiftData = string.Empty; continue; } if (line.Length > 0) { // A swift chunk starts with a swiftTag, which is between colons if (Regex.IsMatch(line, @"^:[\w]+:")) { // Process previously read swift chunk if (swiftTag.Length > 0) { Data(swiftTag, swiftData); } int posColon = line.IndexOf(":", 2); swiftTag = line.Substring(1, posColon - 1); swiftData = line.Substring(posColon + 1); } else { // The swift chunk is spread over several lines swiftData = swiftData + "\r\n" + line; } } } if (swiftTag.Length > 0) { Data(swiftTag, swiftData); } // If there are remaining unprocessed statements - add them if (SWIFTStatement != null) { SWIFTStatements.Add(SWIFTStatement); // Process missing input dates foreach (var tx in SWIFTStatement.SwiftTransactions) { if (tx.InputDate == default) { tx.InputDate = SWIFTStatement.EndDate; } } SWIFTStatement = null; } // Set pending if (pending) { foreach (var stmt in SWIFTStatements) { stmt.Pending = true; } } // Parse SEPA purposes foreach (var stmt in SWIFTStatements) { foreach (var tx in stmt.SwiftTransactions) { if (string.IsNullOrWhiteSpace(tx.Description)) { continue; } // Collect all occuring SEPA purposes ordered by their position List <Tuple <int, SepaPurpose> > indices = new List <Tuple <int, SepaPurpose> >(); foreach (SepaPurpose sepaPurpose in Enum.GetValues(typeof(SepaPurpose))) { string prefix = $"{sepaPurpose}+"; var idx = tx.Description.IndexOf(prefix); if (idx >= 0) { indices.Add(Tuple.Create(idx, sepaPurpose)); } } indices = indices.OrderBy(v => v.Item1).ToList(); // Then get the values for (int i = 0; i < indices.Count; i++) { var beginIdx = indices[i].Item1 + $"{indices[i].Item2}+".Length; var endIdx = i < indices.Count - 1 ? indices[i + 1].Item1 : tx.Description.Length; var value = tx.Description.Substring(beginIdx, endIdx - beginIdx); tx.SepaPurposes[indices[i].Item2] = value; } } } if (Trace.Enabled) { foreach (SwiftStatement statement in SWIFTStatements) { var ID = statement.Id; var AccountCode = statement.AccountCode; var BanksortCode = statement.BankCode; var Currency = statement.Currency; var StartDate = $"{statement.StartDate:d}"; var StartBalance = statement.StartBalance.ToString(); var EndDate = $"{statement.EndDate:d}"; var EndBalance = statement.EndBalance.ToString(); foreach (SwiftTransaction transaction in statement.SwiftTransactions) { var PartnerName = transaction.PartnerName; var AccountCode_ = transaction.AccountCode; var BankCode = transaction.BankCode; var Description = transaction.Description; var Text = transaction.Text; var TypeCode = transaction.TypeCode; var Amount = transaction.Amount.ToString(); var UMS = "++STARTUMS++" + "ID: " + ID + " ' " + "AccountCode: " + AccountCode + " ' " + "BanksortCode: " + BanksortCode + " ' " + "Currency: " + Currency + " ' " + "StartDate: " + StartDate + " ' " + "StartBalance: " + StartBalance + " ' " + "EndDate: " + EndDate + " ' " + "EndBalance: " + EndBalance + " ' " + "PartnerName: " + PartnerName + " ' " + "BankCode: " + BankCode + " ' " + "Description: " + Description + " ' " + "Text: " + Text + " ' " + "TypeCode: " + TypeCode + " ' " + "Amount: " + Amount + " ' " + "++ENDUMS++"; dir = FinTsConfig.ProgramBaseDir; dir = Path.Combine(dir, "MT940"); string filename_ = Path.Combine(dir, Helper.MakeFilenameValid(Account + "_" + DateTime.Now + ".MT940")); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // MT940 if (!File.Exists(filename_)) { using (File.Create(filename_)) { }; File.AppendAllText(filename_, UMS); } else { File.AppendAllText(filename_, UMS); } } } } return(SWIFTStatements); }