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 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("/", "")); }
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); }