Ejemplo n.º 1
0
        private void HandleResponse(string response, int serviceLogId, int customerId)
        {
            var xmlDoc = new XmlDocument();

            var stream = new MemoryStream();
            var writer = new StreamWriter(stream);

            writer.Write(response.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
            writer.Flush();
            stream.Position = 0;
            xmlDoc.Load(stream);

            XmlNodeList caisDetailsList = xmlDoc.SelectNodes("//CAISDetails");

            if (caisDetailsList != null)
            {
                log.Info("Found {0} financial account blocks for customer {1}");
                var  financialAccounts = new List <FinancialAccount>();
                bool hadError          = false;
                foreach (XmlElement currentCaisDetails in caisDetailsList)
                {
                    try
                    {
                        FinancialAccount financialAccount = HandleOneCaisDetailsBlock(currentCaisDetails);
                        financialAccounts.Add(financialAccount);
                    }
                    catch (Exception ex)
                    {
                        hadError = true;
                        log.Error("Exception while parsing data for ServiceLogId:{0}. No data will be created. The exception:{1}", serviceLogId, ex);
                    }
                }

                if (!hadError && financialAccounts.Count > 0)
                {
                    UpdateFinancialAccounts(financialAccounts, serviceLogId, customerId);
                }
            }
        }
Ejemplo n.º 2
0
        private FinancialAccount HandleOneCaisDetailsBlock(XmlElement currentCaisDetails)
        {
            var result = new FinancialAccount();

            XmlNode accountStatusCodeNode = currentCaisDetails.SelectSingleNode("AccountStatus");
            string  accountStatusCode     = null;

            if (accountStatusCodeNode != null)
            {
                accountStatusCode = accountStatusCodeNode.InnerText;
            }

            result.StartDate = ReadDateFromNode(currentCaisDetails.SelectSingleNode("CAISAccStartDate"));

            string dateType;

            result.AccountStatus = GetAccountStatusString(accountStatusCode, out dateType);
            result.DateType      = dateType;

            if (accountStatusCode == "F" || accountStatusCode == "S")
            {
                result.SettlementOrDefaultDate = ReadDateFromNode(currentCaisDetails.SelectSingleNode("SettlementDate"));
            }

            result.LastUpdateDate = ReadDateFromNode(currentCaisDetails.SelectSingleNode("LastUpdatedDate"));

            XmlNode accountStatusCodesNode = currentCaisDetails.SelectSingleNode("AccountStatusCodes");
            string  statusCodes            = string.Empty;

            if (accountStatusCodesNode != null)
            {
                statusCodes = accountStatusCodesNode.InnerText;
            }

            for (int i = 0; i < 12; i++)
            {
                result.StatusCodes.Add(statusCodes.Length > i ? statusCodes.Substring(i, 1) : string.Empty);
            }

            result.CreditLimit           = ReadAmountFromNode(currentCaisDetails.SelectSingleNode("CreditLimit"));
            result.Balance               = ReadAmountFromNode(currentCaisDetails.SelectSingleNode("Balance"));
            result.CurrentDefaultBalance = ReadAmountFromNode(currentCaisDetails.SelectSingleNode("CurrentDefBalance"));

            XmlNode status1To2Node = currentCaisDetails.SelectSingleNode("Status1To2");

            if (status1To2Node != null)
            {
                int status1To2;
                if (int.TryParse(status1To2Node.InnerText, out status1To2))
                {
                    result.Status1To2 = status1To2;
                }
            }

            XmlNode statusTo3Node = currentCaisDetails.SelectSingleNode("StatusTo3");

            if (statusTo3Node != null)
            {
                int statusTo3;
                if (int.TryParse(statusTo3Node.InnerText, out statusTo3))
                {
                    result.StatusTo3 = statusTo3;
                }
            }

            XmlNode worstStatusNode = currentCaisDetails.SelectSingleNode("WorstStatus");

            if (worstStatusNode != null)
            {
                result.WorstStatus = worstStatusNode.InnerText;
            }

            XmlNode accountTypeNode = currentCaisDetails.SelectSingleNode("AccountType");

            if (accountTypeNode != null)
            {
                result.AccountType = accountTypeNode.InnerText;
            }

            return(result);
        }