Example #1
0
        public void Parse(XmlNode oRoot, ASafeLog log)
        {
            if (ReferenceEquals(m_oFieldGroup, null))
            {
                throw new OwnException("Cannot parse: field group is not specified.");
            }

            var oLog = new SafeLog(log);

            oLog.Debug("Parsing group {0}", m_oFieldGroup.Name);

            if (!string.IsNullOrWhiteSpace(m_oFieldGroup.PathToParent))
            {
                XmlNodeList lst = oRoot.SelectNodes(m_oFieldGroup.PathToParent);

                if (lst != null)
                {
                    oLog.Debug("{0} nodes found matching PathToParent", lst.Count);

                    foreach (XmlNode oNode in lst)
                    {
                        ParseOne(oNode, oLog);
                    }
                }         // if nodes found
            }             // if path to parent specified
            else
            {
                ParseOne(oRoot, oLog);
            }
        }         // Parse
Example #2
0
        }         // indexer

        private static void Init(SafeLog oLog)
        {
            lock (typeof(PostcodeToRegion)) {
                oLog.Msg("Initialising UK postcode to region mapping...");

                ms_oPostcodeToRegion = new SortedDictionary <string, string>();

                string[] aryLines = new StreamReader(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream("Ezbob.Utils.uk.postcode.regions.txt")
                    ).ReadToEnd().Split('\n');

                oLog.Debug("{0} rows read from source file.", aryLines.Length);

                string sRegion = string.Empty;

                foreach (string sLine in aryLines)
                {
                    string sCurLine = sLine.Trim();

                    if (string.IsNullOrWhiteSpace(sCurLine) || sCurLine.StartsWith("#"))
                    {
                        continue;
                    }

                    int nPos = sCurLine.IndexOf('=');

                    if (nPos < 0)
                    {
                        sRegion = sCurLine;
                    }
                    else
                    {
                        string sPostcode = sCurLine.Substring(0, nPos).Trim();

                        if (sPostcode != string.Empty && sRegion != string.Empty)
                        {
                            string sNormalPostcode = sPostcode.ToUpper();

                            ms_oPostcodeToRegion[sNormalPostcode] = sRegion;
                            oLog.Debug("UK postcode {0} -> {1} region", sNormalPostcode, sRegion);
                        }         // if
                    }             // if
                }                 // for each line

                oLog.Msg("Initialising UK postcode to region mapping complete.");
            }     // lock
        }         // Init
Example #3
0
        }         // static constructor

        public RequestedTransaction(string sRawData, ASafeLog oLog)
        {
            m_oLog = new SafeLog(oLog);

            string[] aryFields = sRawData.Split(',');

            if (aryFields.Length != 3)
            {
                throw new Exception("Wrong number of fields in " + sRawData);
            }

            Date       = DateTime.ParseExact(aryFields[0], "dd/mm/yyyy", ms_oCulture, DateTimeStyles.None).Date;
            LoanID     = Convert.ToInt32(aryFields[1]);
            PaidAmount = Convert.ToDecimal(aryFields[2]);

            m_oLog.Debug("{0} -> {1}", sRawData, this);
        }         // constructor
Example #4
0
        private decimal?Calculate()
        {
            decimal nPct = Cfg.OfferAmountPct(BusinessScore);

            if (nPct == 0)
            {
                Log.Debug("No percent found for business score {0}.", BusinessScore);
                return(null);
            }             // if

            Log.Debug("Percent for business score {0} is {1}.", BusinessScore, nPct.ToString("P2"));

            decimal nCalculatedOffer = TotalCurrentAssets * nPct;

            var ci = new CultureInfo("en-GB", false);

            Log.Debug("Calculated offer (total current assets * percent) is {0}", nCalculatedOffer.ToString("C2", ci));

            nCalculatedOffer = (int)(Math.Round(nCalculatedOffer / minLoanAmount, 0, MidpointRounding.AwayFromZero) * minLoanAmount);
            Log.Debug("Rounded offer is {0}", nCalculatedOffer.ToString("C2", ci));

            if (nCalculatedOffer < Cfg.MinOfferAmount)
            {
                Log.Debug("The offer is less than {0}, not offering.", Cfg.MinOfferAmount.ToString("C2", ci));
                return(null);
            }             // if

            decimal nOfferBeforeCap = (int)(Math.Round((RequestedAmount * Cfg.OfferCapPct) / minLoanAmount, 0, MidpointRounding.AwayFromZero) * minLoanAmount);

            decimal nCap = nOfferBeforeCap.Min(Cfg.ImmediateMaxAmount);

            Log.Debug(
                "Offer cap is {0} = min({1}, {2} * {4} = {3})",
                nCap.ToString("C2", ci),
                Cfg.ImmediateMaxAmount.ToString("C2", ci),
                RequestedAmount.ToString("C2", ci),
                nOfferBeforeCap.ToString("C2", ci),
                Cfg.OfferCapPct.ToString("P2", ci)
                );

            decimal nOffer = nCap.Min(nCalculatedOffer);

            Log.Debug(
                "And the offer is {0} = min({1}, {2})",
                nOffer.ToString("C2", ci),
                nCalculatedOffer.ToString("C2", ci),
                nCap.ToString("C2", ci)
                );

            if (nOffer > FundsAvailable - OpenCashRequests)
            {
                Log.Debug(
                    "The offer is withdrawn: not enough funds available: offer = {0}, funds = {1}.",
                    nOffer.ToString("C2", ci),
                    (FundsAvailable - OpenCashRequests).ToString("C2", ci)
                    );
                return(null);
            }             // if

            return(nOffer);
        }         // Calculate