private BaiFile _Parse() { var bai = new BaiFile(); var group = new BaiGroup("--default--"); var account = new BaiAccount("--default--"); var detail = new BaiDetail("--default--"); var continuation = ContinuationType.Account; foreach (var data in _data.Select((value, index) => new { value, index })) { var line = data.value; if (data.index == 0 && line.StartsWith("01")) { bai.FileHeader = line; } else if (data.index == _data.Length - 1 && line.StartsWith("99")) { bai.FileTrailer = line; } else if (line.StartsWith("02")) { continuation = ContinuationType.Group; group = new BaiGroup(line); } else if (line.StartsWith("98")) { group.GroupTrailer = line; bai.Groups.Add(group); } else if (line.StartsWith("03")) { continuation = ContinuationType.Account; account = new BaiAccount(line); detail = new BaiDetail("--default--"); } else if (line.StartsWith("49")) { if (detail.TransactionDetail != "--default--") { account.Details.Add(detail); } account.AccountTrailer = line; group.Accounts.Add(account); } else if (line.StartsWith("16")) { if (detail.TransactionDetail != "--default--") { account.Details.Add(detail); } continuation = ContinuationType.Detail; detail = new BaiDetail(line); } else if (line.StartsWith("88")) { switch (continuation) { case ContinuationType.Group: group.GroupContinuation.Add(line); break; case ContinuationType.Account: account.AccountContinuation.Add(line); break; case ContinuationType.Detail: detail.DetailContinuation.Add(line); break; } } else { throw new NotImplementedException("I don't know what to do with this line: " + line); } } return(bai); }
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(); }
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(); }