private bool PopulateHeader(OfxHeader ofxHeader, ref string linha) { bool isPopulate = true; if (linha.IndexOf("OFXHEADER") >= 0) { ofxHeader.Ofxheader = Convert.ToInt32(GetValue(linha)); } else if (linha.IndexOf("DATA") >= 0) { ofxHeader.Data = GetValue(linha); } else if (linha.IndexOf("VERSION") >= 0) { ofxHeader.Version = GetValue(linha); } else if (linha.IndexOf("SECURITY") >= 0) { ofxHeader.Security = GetValue(linha); } else if (linha.IndexOf("ENCODING") >= 0) { ofxHeader.Encoding = GetValue(linha); } else if (linha.IndexOf("CHARSET") >= 0) { ofxHeader.Charset = GetValue(linha); } else if (linha.IndexOf("COMPRESSION") >= 0) { ofxHeader.Compression = GetValue(linha); } else if (linha.IndexOf("OLDFILEUID") >= 0) { ofxHeader.Oldfileuid = GetValue(linha); } else if (linha.IndexOf("NEWFILEUID") >= 0) { ofxHeader.Newfileuid = GetValue(linha); } else { isPopulate = false; } return(isPopulate); }
public OfxHeader Parse(string ofxSourceFile) { StreamReader sr = File.OpenText(ofxSourceFile); bool isTrue = true; OfxHeader ofxHeader = new OfxHeader(); while (isTrue) { string linha = sr.ReadLine(); linha = linha.Trim(); if (!PopulateHeader(ofxHeader, ref linha)) { linha = sr.ReadLine(); isTrue = PopulateBody(ofxHeader, ref linha, sr); } } return(ofxHeader); }
private bool PopulateBody(OfxHeader ofxHeader, ref string linha, StreamReader sr) { bool isPopulate = true; if (linha.IndexOf("OFX") >= 0) { ofxHeader.OfxBody = new OfxBody(); linha = sr.ReadLine(); if (linha.IndexOf("SIGNONMSGSRSV1") >= 0) { ofxHeader.OfxBody.Signonmsgsrsv1 = new Signonmsgsrsv1(); linha = sr.ReadLine(); if (linha.IndexOf("SONRS") >= 0) { ofxHeader.OfxBody.Signonmsgsrsv1.Sonrs = new Sonrs(); linha = sr.ReadLine(); if (linha.IndexOf("STATUS") >= 0) { ofxHeader.OfxBody.Signonmsgsrsv1.Sonrs.SonrsStatus = GetStatus(ref linha, sr); } linha = sr.ReadLine(); ofxHeader.OfxBody.Signonmsgsrsv1.Sonrs.Dtserver = linha.Substring(10, linha.Length - 10); linha = sr.ReadLine(); ofxHeader.OfxBody.Signonmsgsrsv1.Sonrs.Language = linha.Substring(10, linha.Length - 10); linha = sr.ReadLine(); linha = sr.ReadLine(); linha = sr.ReadLine(); } } if (linha.IndexOf("BANKMSGSRSV1") >= 0) { ofxHeader.OfxBody.Bankmsgsrsv1 = new Bankmsgsrsv1(); linha = sr.ReadLine(); ofxHeader.OfxBody.Bankmsgsrsv1.Stmttrnrs = new Stmttrnrs(); linha = sr.ReadLine(); ofxHeader.OfxBody.Bankmsgsrsv1.Stmttrnrs.Trnuid = Convert.ToInt32(linha.Substring(10, linha.Length - 10)); linha = sr.ReadLine(); ofxHeader.OfxBody.Bankmsgsrsv1.Stmttrnrs.Status = GetStatus(ref linha, sr); linha = sr.ReadLine(); ofxHeader.OfxBody.Bankmsgsrsv1.Stmttrnrs.Stmtrs = new Stmtrs(); linha = sr.ReadLine(); ofxHeader.OfxBody.Bankmsgsrsv1.Stmttrnrs.Stmtrs.Curdef = linha.Substring(8, linha.Length - 8); linha = sr.ReadLine(); ofxHeader.OfxBody.Bankmsgsrsv1.Stmttrnrs.Stmtrs.Bankacctfrom = GetBankacctfrom(ref linha, sr); linha = sr.ReadLine(); ofxHeader.OfxBody.Bankmsgsrsv1.Stmttrnrs.Stmtrs.Banktranlist = GetBanktranlist(ref linha, sr); ofxHeader.OfxBody.Bankmsgsrsv1.Stmttrnrs.Stmtrs.Ledgerbal = GetLedgerbal(ref linha, sr); isPopulate = false; } } else { isPopulate = false; } return(isPopulate); }