Exemplo n.º 1
0
        /// <summary>
        /// Returns list of all transactions in OFX document
        /// </summary>
        /// <param name="doc">OFX document</param>
        /// <returns>List of transactions found in OFX document</returns>
        private void ImportTransations(OFX ofx, XmlDocument doc)
        {
            string xpath = GetXPath(ofx.AccType, OFXSection.TRANSACTIONS);

            ofx.StatementStart = doc.GetValue(xpath + "/DTSTART").ToDate();
            ofx.StatementEnd   = doc.GetValue(xpath + "/DTEND").ToDate();

            var transactionNodes = doc.SelectNodes(xpath + "/STMTTRN");

            ofx.Transactions = new List <OFXTransaction>();

            foreach (XmlNode node in transactionNodes)
            {
                ofx.Transactions.Add(new OFXTransaction(node, ofx.Currency));
            }
        }
Exemplo n.º 2
0
        private OFX Parse(string ofxString)
        {
            var ofx = new OFX {
                AccType = GetAccountType(ofxString)
            };

            //Load into xml document
            var doc = new XmlDocument();

            doc.Load(new StringReader(ofxString));

            XmlNode currencyNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.CURRENCY));

            if (currencyNode != null)
            {
                ofx.Currency = currencyNode.FirstChild.Value;
            }
            else
            {
                throw new OFXParseException("Currency not found");
            }

            //Get sign on node from OFX file
            XmlNode signOnNode = doc.SelectSingleNode(Resources.SignOn);

            //If exists, populate signon obj, else throw parse error
            if (signOnNode != null)
            {
                ofx.SignOn = new OFXSignOn(signOnNode);
            }
            else
            {
                throw new OFXParseException("Sign On information not found");
            }

            //Get Account information for ofx doc
            XmlNode accountNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.ACCOUNTINFO));

            //If account info present, populate account object
            if (accountNode != null)
            {
                ofx.Account = new OFXAccount(accountNode, ofx.AccType);
            }
            else
            {
                throw new OFXParseException("Account information not found");
            }

            //Get list of transactions
            ImportTransations(ofx, doc);

            //Get balance info from ofx doc
            XmlNode ledgerNode    = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/LEDGERBAL");
            XmlNode avaliableNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/AVAILBAL");

            //If balance info present, populate balance object
            if (ledgerNode != null && avaliableNode != null)
            {
                ofx.Balance = new OFXBalance(ledgerNode, avaliableNode);
            }
            else
            {
                throw new OFXParseException("Balance information not found");
            }

            return(ofx);
        }