Ejemplo n.º 1
0
        protected override DTO.ServiceResponse ProcessScrape(string outputPath, string debugID)
        {
            DTO.ServiceResponse response = null;
            string statementFilePath     = Path.Combine(outputPath, "statement.qfx");
            string noStatementFilePath   = Path.Combine(outputPath, "empty_statement.txt");

            if (File.Exists(statementFilePath))
            {
                string statementOfx            = File.ReadAllText(statementFilePath);
                Parse.OfxToXmlParser parser    = new Parse.OfxToXmlParser(statementOfx);
                XElement             parsedOfx = parser.Parse();

                Parse.OfxResponseBuilder responseBuilder = new Parse.OfxResponseBuilder();
                response = responseBuilder.BuildStatementResponse(parsedOfx, m_statementParameters.DateStart, m_statementParameters.DateEnd);
            }
            else if (File.Exists(noStatementFilePath))
            {
                response = new DTO.StatementResponse(HttpStatusCode.OK);
            }
            else
            {
                response = new DTO.ResponseError(HttpStatusCode.BadRequest)
                {
                    friendly_error = "An error occured when atempting to get account statement.",
                    detailed_error = "statement file missing"
                };
            }

            return(response);
        }
Ejemplo n.º 2
0
        public void ParseStatement()
        {
            string   raw    = File.ReadAllText("files/BANKMSGSRSV1.ofx");
            var      parser = new Parse.OfxToXmlParser(raw);
            XElement parsed = parser.Parse();

            Assert.AreEqual("+2703.71", parsed.Element("LEDGERBAL").Element("BALAMT").Value);
        }
Ejemplo n.º 3
0
        public void ParseOfx()
        {
            string   raw    = File.ReadAllText("files/ACCTINFORS_CHECKING.ofx");
            var      parser = new Parse.OfxToXmlParser(raw);
            XElement parsed = parser.Parse();

            Assert.AreEqual("CHECKING", parsed.Element("ACCTINFORS").Element("ACCTINFO").Element("ACCTTYPE").Value);
            Assert.AreEqual("MYACCESS CHECKING", parsed.Element("ACCTINFORS").Element("ACCTINFO").Element("DESC").Value);
        }
Ejemplo n.º 4
0
        public void TestBuildResponseForCreditCard()
        {
            string   raw    = File.ReadAllText("files/ACCTINFORS_CREDIT_CARD.ofx");
            var      parser = new Parse.OfxToXmlParser(raw);
            XElement parsed = parser.Parse();

            var fetcher = new OfxAccountsFetcher(null);

            DTO.AccountsResponse response = (DTO.AccountsResponse)fetcher.BuildResponse(parsed);

            Assert.AreEqual(2, response.accounts.Count);
            Assert.AreEqual("CREDIT CARD", response.accounts [0].description);
        }
Ejemplo n.º 5
0
        public void TestBuildResponseForChecking()
        {
            string   raw    = File.ReadAllText("files/ACCTINFORS_CHECKING.ofx");
            var      parser = new Parse.OfxToXmlParser(raw);
            XElement parsed = parser.Parse();

            var fetcher = new OfxAccountsFetcher(null);

            DTO.AccountsResponse response = (DTO.AccountsResponse)fetcher.BuildResponse(parsed);

            Assert.AreEqual(1, response.accounts.Count);
            Assert.AreEqual("MYACCESS CHECKING", response.accounts [0].description);
        }
Ejemplo n.º 6
0
        public bool Fetch()
        {
            List <string> missingParameters = ParameterRequired.GetMissingParameters(m_parameters);

            if (missingParameters.Count > 0)
            {
                this.Response = new DTO.ResponseError(HttpStatusCode.BadRequest)
                {
                    friendly_error = "The bank could not be contacted because of missing information.",
                    detailed_error = string.Concat("Missing parameter(s): ", string.Join(", ", missingParameters))
                };
            }
            else
            {
                try {
                    Directory.CreateDirectory(m_debugWorkingPath);

                    //request body
                    this.OfxRequestBody = this.BuildOfxRequest();

                    File.WriteAllText(Path.Combine(m_debugWorkingPath, "request.ofx"), this.OfxRequestBody);

                    //get raw ofx response
                    this.OfxResponseBody = SendRequestAndGetResponse(this.OfxRequestBody, m_parameters.OFX_URL);

                    File.WriteAllText(Path.Combine(m_debugWorkingPath, "response.ofx"), this.OfxResponseBody);

                    //parse ofx to xml
                    Parse.OfxToXmlParser parser = new Parse.OfxToXmlParser(this.OfxResponseBody);
                    this.ParsedOfx = parser.Parse();

                    //build response
                    this.Response = this.BuildResponse(this.ParsedOfx);
                } catch (System.UriFormatException uriEx) {
                    this.Response = new DTO.ResponseError(HttpStatusCode.BadRequest)
                    {
                        friendly_error = "The bank could not be contacted.",
                        detailed_error = uriEx.Message
                    };
                } catch (WebException e) {
                    using (WebResponse response = e.Response) {
                        HttpWebResponse httpResponse = (HttpWebResponse)response;
                        using (Stream data = response.GetResponseStream())
                            using (var reader = new StreamReader(data)) {
                                this.OfxResponseBody = reader.ReadToEnd();
                                this.Response        = new DTO.ResponseError((HttpStatusCode)((int)httpResponse.StatusCode))
                                {
                                    friendly_error = "An error occured when communicating with the bank.",
                                    detailed_error = this.OfxResponseBody
                                };
                            }
                    }
                } catch (Parse.OfxStatusException statusEx) {
                    this.Response = new DTO.ResponseError(HttpStatusCode.BadRequest)
                    {
                        friendly_error = string.Concat("Bank response: " + statusEx.Message),
                        detailed_error = string.Format("{0} ({1})", statusEx.Message, statusEx.Code)
                    };
                } catch (Parse.OfxParseException pex) {
                    this.Response = new DTO.ResponseError(HttpStatusCode.InternalServerError)
                    {
                        friendly_error = "An error occured when reading the response from the bank.",
                        detailed_error = pex.Message
                    };
                } catch (Exception ex) {
                    this.Response = new DTO.ResponseError(HttpStatusCode.InternalServerError)
                    {
                        friendly_error = "An error occured when processing the response from the bank.",
                        detailed_error = ex.Message
                    };
                }
            }

            bool isError = (this.Response is DTO.ResponseError);

            if (!isError)
            {
                if (ConfigurationManager.AppSettings["keep_scrape_debug_output"] == "false")
                {
                    Directory.Delete(m_debugWorkingPath, true);
                }
            }

            return(isError);
        }