public TranslatedBaiFile(BaiFile data) { Groups = new List <Group>(); // Translate myself, and walk the file if (!data.FileHeader.Trim().EndsWith("/")) { throw new NotImplementedException("Bai file is not properly formatted, I don't know how to handle this"); } if (!data.FileTrailer.Trim().EndsWith("/")) { throw new NotImplementedException("Bai file is not properly formatted, I don't know how to handle this"); } var fields = data.FileHeader.Trim().Split(','); if (fields.Length != 9) { throw new NotImplementedException("Bai file does not have proper number of FileHeader elements, I don't know how to handle this"); } HeaderRecordCode = fields[0]; SenderIdentification = fields[1]; ReceiverIdentification = fields[2]; FileIdentificationNumber = fields[5]; PhysicalRecordLength = fields[6]; BlockSize = fields[7]; VersionNumber = fields[8].Replace("/", ""); if (VersionNumber != "2") { throw new NotImplementedException("Bai file not version 2 format, I don't know how to handle this!"); } // Handle date 3, 4 FileCreationDateTime = BaiFileHelpers.DateTimeFromFields(fields[3], fields[4]); // End of Header foreach (var group in data.Groups) { Groups.Add(new Group(group)); } // Beginning of Trailer fields = data.FileTrailer.Split(','); if (fields.Length != 4) { throw new NotImplementedException("Bai file does not have proper number of FileTrailer elements, I don't know how to handle this"); } TrailerRecordCode = fields[0]; FileControlTotal = fields[1]; NumberOfGroups = int.Parse(fields[2]); NumberOfRecords = int.Parse(fields[3].Replace("/", "")); }
public Group(BaiGroup data) { Accounts = new List <Account>(); if (!data.GroupHeader.Trim().EndsWith("/")) { throw new NotImplementedException("Bai file is not properly formatted, I don't know how to handle this"); } if (!data.GroupTrailer.Trim().EndsWith("/")) { throw new NotImplementedException("Bai file is not properly formatted, I don't know how to handle this"); } var fields = data.GroupHeader.Trim().Split(','); if (fields.Length != 8) { throw new NotImplementedException("Bai file does not have proper number of GroupHeader elements, I don't know how to handle this"); } HeaderRecordCode = fields[0]; UltimateReceiverIdentification = fields[1]; OriginatorIdentification = fields[2]; GroupStatus = BaiFileHelpers.GetGroupStatus(fields[3]); AsOfDateTime = BaiFileHelpers.DateTimeFromFields(fields[4], fields[5]); CurrencyCode = BaiFileHelpers.GetCurrencyCode(fields[6]); AsOfDateModifier = BaiFileHelpers.GetAsOfDateModifier(fields[7]); foreach (var account in data.Accounts) { Accounts.Add(new Account(account, CurrencyCode)); } fields = data.GroupTrailer.Split(','); if (fields.Length != 4) { throw new NotImplementedException("Bai file does not have proper number of FileTrailer elements, I don't know how to handle this"); } TrailerRecordCode = fields[0]; GroupControlTotal = fields[1]; NumberOfAccounts = int.Parse(fields[2]); NumberOfRecords = int.Parse(fields[3].Replace("/", "")); }
public static FundType GetNext(Stack stack, string currencyCode) { if (stack.Count < 4) { return(null); } var typeCode = stack.Pop().ToString(); var amount = stack.Pop().ToString(); var itemCount = stack.Pop().ToString(); var fundsType = stack.Pop().ToString(); switch (fundsType.ToUpper()) { case "S": var immediate = stack.Pop().ToString(); var oneDay = stack.Pop().ToString(); var moreDays = stack.Pop().ToString(); return(new FundType(typeCode, amount, itemCount, fundsType, immediate, oneDay, moreDays)); case "D": // next field is the number of distripution pairs // number of days, avalible amount var info = new Dictionary <int, decimal>(); var count = int.Parse(stack.Pop().ToString()); for (var i = 0; i < count; i++) { var key = int.Parse(stack.Pop().ToString()); var v = BaiFileHelpers.GetAmount(stack.Pop().ToString(), currencyCode); info.Add(key, v); } return(new FundType(typeCode, amount, itemCount, fundsType, count.ToString(), info)); case "V": var date = stack.Pop().ToString(); var time = stack.Pop().ToString(); var value = BaiFileHelpers.DateTimeFromFields(date, time); return(new FundType(typeCode, amount, itemCount, fundsType, value)); } return(new FundType(typeCode, amount, itemCount, fundsType)); }
public Detail(BaiDetail data, string currencyCode) { TextList = new List <string>(); TextDictionary = new Dictionary <string, string>(); var list = new List <string> { data.TransactionDetail }; list.AddRange(data.DetailContinuation); var lineData = ""; foreach (var section in list) { var line = section.Trim(); // Some / are optional? //if (!line.EndsWith("/")) throw new Exception("I got a line without a trailing /"); if (line.StartsWith("16")) { line = line.Replace("/", ""); } else if (line.StartsWith("88")) { line = line.Substring(2);//.Replace("/", " "); } else { throw new Exception("I got a bad line: " + line); } lineData += line; } // Now try to figure out what's left ;-) var stack = new Stack(lineData.Split(',').Reverse().ToArray()); RecordCode = stack.Pop().ToString(); TypeCode = stack.Pop().ToString(); Amount = stack.Pop().ToString(); FundsType = stack.Pop().ToString(); switch (FundsType.ToUpper()) { case "S": Immediate = stack.Pop().ToString(); OneDay = stack.Pop().ToString(); TwoOrMoreDays = stack.Pop().ToString(); break; case "D": // next field is the number of distripution pairs // number of days, avalible amount // currencyCode would be used here throw new Exception("I don't want to deal with this one yet - " + currencyCode); case "V": var date = stack.Pop().ToString(); var time = stack.Pop().ToString(); AvalibleDate = BaiFileHelpers.DateTimeFromFields(date, time); break; } BankReferenceNumber = stack.Pop().ToString(); CustomerReferenceNumber = stack.Pop().ToString(); // What's left on the stack? Text = LeftoverStackToString(stack); CreateTextList(); CreateTextDictionary(); }