public static void ParseBalance(string selector, StreamReader content, ref PaymentCard card)
        {
            var htmlDocument = new HtmlDocument();
            htmlDocument.Load(content);
            var html = htmlDocument.DocumentNode;

            var balanceHtml = html.CssSelect(selector).First().InnerHtml;
            var balanceArray = balanceHtml.Replace("  ", "-").Split('-');

            var balance = String.Join(null, Regex.Split(balanceArray[0], "[^\\d]"));
            card.Balance = Decimal.Parse(balance);
            card.Currency = balanceArray[1];
        }
        public static void ParseCardHistory(string selector, StreamReader content, ref PaymentCard card)
        {
            var htmlDocument = new HtmlDocument();

            htmlDocument.Load(content);
            var html = htmlDocument.DocumentNode;

            var historyRow = html.CssSelect(selector).ElementAt(1);

            if (historyRow != null)
            {
                // get status
                var statusElement = historyRow.CssSelect("td").ElementAt(1).CssSelect("b > font").FirstOrDefault(); //:eq(1) > b > font
                if (statusElement != null)
                {
                    card.Status = statusElement.InnerText.Trim();
                }

                // get register date
                var registerDateElement = historyRow.CssSelect("td").ElementAt(2);
                if (registerDateElement != null)
                {
                    DateTime registerDate;
                    DateTime.TryParse(registerDateElement.InnerText.Trim(), out registerDate);
                    card.RegisterDate = registerDate;
                }

                // get cancel date
                var cancelDateElement = historyRow.CssSelect("td").ElementAt(3);
                if (cancelDateElement != null)
                {
                    DateTime cancelDate;
                    DateTime.TryParse(cancelDateElement.InnerText.Trim(), out cancelDate);
                    card.CancelDate = cancelDate;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Obtain the list of transactions for payment card starting from specified date.
        /// </summary>
        /// <param name="card">Payment Card to get transactions for</param>
        /// <param name="startDate">Start date to obtain transactions from</param>
        public IEnumerable<AccountTransaction> GetTransactions(PaymentCard card, DateTime startDate)
        {
            if (card == null)
                throw new ArgumentNullException("card");
            // verify start data is in the past and not a today date
            if (startDate >= DateTime.UtcNow)
                throw new ArgumentOutOfRangeException("startDate", startDate, "Start Date must be before today date.");
            if (startDate == DateTime.MinValue) startDate = card.RegisterDate;

            // set card with parameter id active
            var cardChanged = _bankRequests.ChangeCurrentCard(card.Id);
            // get 20 latest transactions
            if (cardChanged)
            {
                //var latestTransactions = _bankRequests.GetLatestCardTransactions().ToList();

                //// check if there is a date in these transactions older than start date
                //if (latestTransactions.Any(t => t.OperationDate.Date < startDate))
                //{
                //    // if  true return the list of transactions
                //    return latestTransactions.Where(t => t.OperationDate.Date >= startDate);
                //}
                // if false get report periods

                var reports = _bankRequests.GetListOfUsedStatements(startDate);
                var transactions = new List<AccountTransaction>();
                // run reports and create them when necessary
                foreach (var reportRow in reports)
                {
                    if (!reportRow.Exists)
                    {
                        //_bankRequests.CreateReport(reportRow.StartDate, reportRow.EndDate);
                    }
                    transactions.AddRange(_bankRequests.GetReport(reportRow.Id).Transactions);
                }
                return transactions;
            }

            return new List<AccountTransaction>();
        }
        public static IEnumerable<PaymentCard> ParseCardList(string selector, StreamReader content)
        {
            var cards = new List<PaymentCard>();
            var htmlDocument = new HtmlDocument();
            htmlDocument.Load(content);
            var html = htmlDocument.DocumentNode;

            var cardsHtml = html.CssSelect(selector);
            foreach (var cardHtml in cardsHtml.Where(card => card.HasAttributes))
            {
                var card = new PaymentCard
                               {
                                   Id =
                                       cardHtml.Attributes["Value"] != null
                                           ? cardHtml.Attributes["Value"].Value
                                           : String.Empty,
                                   Name = cardHtml.NextSibling.CssSelect("i").First().InnerText
                               };

                Log.InfoFormat("Card name: {0}", card.Name);

                if (card.Id != null)
                {
                    Log.InfoFormat("Card id: {0}", card.Id);
                }
                cards.Add(card);
            }
            return cards;
        }