Ejemplo n.º 1
0
        private OFXDocument Parse(string data)
        {
            var ofxDocument = new OFXDocument();

            var xmlDocument = new XmlDocument();

            if (data.IndexOf("OFXHEADER") == -1)
            {
                throw new InvalidDataException();
            }

            var ofx = data.Remove(0, data.IndexOf("<"));

            var header = data;

            ofx = ConvertSGMLTOXML(ofx);

            xmlDocument.LoadXml(ofx);

            var mapper = new XmlMapper();

            mapper.SetValueResolver((propertyInfo, value) =>
            {
                if (propertyInfo.PropertyType == typeof(DateTime))
                {
                    if (value.Length < 8)
                    {
                        return("");
                    }

                    return(string.Format("{0}-{1}-{2}", value.Substring(0, 4), value.Substring(4, 2), value.Substring(6, 2)));
                }
                else if (propertyInfo.PropertyType == typeof(decimal))
                {
                    return(value.Replace(",", "."));
                }

                return(value);
            });

            mapper.Map(xmlDocument, ofxDocument);

            return(ofxDocument);
        }