public Account(BaiAccount data, string currencyCode) { FundsTypes = new List<FundType>(); Details = new List<Detail>(); var list = new List<string> {data.AccountIdentifier}; list.AddRange(data.AccountContinuation); var factory = new AccountFundTypeFactory(list); IdentifierRecordCode = factory.RecordCode; CustomerAccountNumber = factory.CustomerAccountNumber; CurrencyCode = factory.CurrencyCode; var fundType = factory.GetNext(); while (fundType != null) { FundsTypes.Add(fundType); fundType = factory.GetNext(); } // Time to get the details foreach (var detail in data.Details) { Details.Add(new Detail(detail, currencyCode)); } var fields = data.AccountTrailer.Split(','); if (fields.Length != 3) throw new NotImplementedException("Bai file does not have proper number of AccountTrailer elements, I don't know how to handle this"); TrailerRecordCode = fields[0]; AccountControlTotal = BaiFileHelpers.GetAmount(fields[1], CurrencyCode); NumberOfRecords = int.Parse(fields[2].Replace("/", "")); }
public Account(BaiAccount data, string currencyCode) { FundsTypes = new List <FundType>(); Details = new List <Detail>(); var list = new List <string> { data.AccountIdentifier }; list.AddRange(data.AccountContinuation); var factory = new AccountFundTypeFactory(list); IdentifierRecordCode = factory.RecordCode; CustomerAccountNumber = factory.CustomerAccountNumber; CurrencyCode = factory.CurrencyCode; var fundType = factory.GetNext(); while (fundType != null) { FundsTypes.Add(fundType); fundType = factory.GetNext(); } // Time to get the details foreach (var detail in data.Details) { Details.Add(new Detail(detail, currencyCode)); } var fields = data.AccountTrailer.Split(','); if (fields.Length != 3) { throw new NotImplementedException("Bai file does not have proper number of AccountTrailer elements, I don't know how to handle this"); } TrailerRecordCode = fields[0]; AccountControlTotal = BaiFileHelpers.GetAmount(fields[1], CurrencyCode); NumberOfRecords = int.Parse(fields[2].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); }