private void ImportFile(Ofx ofx) { var stacks = new Stack(); var transaction = new OfxTransaction(); using var reader = new StreamReader(streamFile); string line; while ((line = reader.ReadLine()) != null) { if (!line.StartsWith("<")) { continue; } var tag = line.Substring(1, line.IndexOf('>') - 1).Replace("/", ""); if (line.StartsWith("</") && line.EndsWith(">")) { if (stacks.Pop().ToString() != line.Replace("/", "").ToUpper()) { ofx.ErrorMessage = "Invalid File"; break; } if (tag == OfxTag.TransactionTags.STMTTRN.ToString()) { ofx.Transactions.Add(transaction); transaction = new OfxTransaction(); } continue; } if (line.StartsWith("<") && line.EndsWith(">")) { stacks.Push(line.ToUpper()); continue; } if (Enum.TryParse(tag, out OfxTag.BankAccTags bankAccTags)) { FillBank(ofx.Bank, bankAccTags, line); continue; } if (Enum.TryParse(tag, out OfxTag.TransactionTags transactionTags)) { FillTransaction(transaction, transactionTags, line); continue; } } if (stacks.Count > 0) { ofx.ErrorMessage = "Invalid File"; } }
private void MergeOfxs(Ofx ofx1, Ofx ofx2) { var minDate = ofx1.Transactions.Min(x => x.Date); var maxDate = ofx1.Transactions.Max(x => x.Date); var newOfx2 = ofx2.Transactions.Where(x => x.Date <minDate || x.Date> maxDate).ToList(); ofx1.Transactions.AddRange(newOfx2); }
public Ofx Parse() { var ofx = new Ofx { Bank = new OfxBank(), Transactions = new List <OfxTransaction>(), ErrorMessage = string.Empty, }; if (streamFile == null) { ofx.ErrorMessage = "OFX file not found"; return(ofx); } ImportFile(ofx); return(ofx); }
public void setUp() { ofx = new Ofx(); accounts = new List <Account>(); T1 = new Transaction(); T1.date = new DateTime(2000, 1, 1); T1.desc = "T1"; T1.type = TransType.Payment; T1.value = 1000; T1.balance = 10000; T2 = new Transaction(); T2.date = new DateTime(2010, 12, 31); T2.desc = "T2"; T2.type = TransType.Payment; T2.value = 2000; T2.balance = 12000; }
public string SaveOfxFile(Ofx ofx) { var jsonFile = JsonManager.ObjectToJson(ofx); return(repositoryManager.CreateFile(jsonFile)); }