Example #1
0
        public JsonResult UpdateBrokerCommissionDefaults(long id, decimal amount)
        {
            decimal brokerCommission;
            decimal setupFeePercent;

            try {
                LoanCommissionDefaultsActionResult lcdar = this.serviceClient.Instance.GetLoanCommissionDefaults(
                    this.context.UserId,
                    id,
                    amount
                    );

                brokerCommission = lcdar.BrokerCommission;
                setupFeePercent  = lcdar.ManualSetupFee;
            } catch (Exception e) {
                log.Alert(
                    e,
                    "Failed to calculate loan default commission for cash request {0} and loan amount {1}.",
                    id,
                    amount
                    );

                brokerCommission = 0;
                setupFeePercent  = 0;
            }             // try

            return(Json(new { brokerCommission, setupFeePercent }, JsonRequestBehavior.AllowGet));
        }         // UpdateBrokerCommissionDefaults
Example #2
0
        public void Write(ASafeLog oLog)
        {
            DateTime oTime;

            if (!DateTime.TryParseExact(eventTime, "yyyy-MM-dd=HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out oTime))
            {
                oLog.Alert("Failed to parse entry time '{0}', using current UTC time instead.", eventTime);
                oTime = DateTime.UtcNow;
            }             // if failed to parse time

            Severity nSeverity;

            if (!Enum.TryParse <Severity>(severity, true, out nSeverity))
            {
                oLog.Alert("Failed to parse severity '{0}', using Info instead.", severity);
                nSeverity = Severity.Info;
            }             // if failed to parse severity

            oLog.Say(
                nSeverity,
                "FROM CLIENT at {0}, user '{1}', event id {2}: {3}",
                oTime.ToString("dd/MMM/yyyy HH:mm:ss", CultureInfo.InvariantCulture),
                userName, eventID, msg
                );
        } // Save
Example #3
0
        }         // FindType

        private static Type PureFindType(string sName, Assembly asm, bool bHasDot, ASafeLog oLog)
        {
            Type[] aryTypes;

            oLog = oLog.Safe();

            try {
                aryTypes = asm.GetTypes();
            }
            catch (ReflectionTypeLoadException rtle) {
                oLog.Alert(rtle, "Failed to retrieve types list of assembly '{0}' while looking for '{1}'.", asm.FullName, sName);

                if ((rtle.LoaderExceptions != null) && (rtle.LoaderExceptions.Length > 0))
                {
                    oLog.Debug("ReflectionTypeLoadException.LoaderExceptions - begin");

                    for (int i = 0; i < rtle.LoaderExceptions.Length; i++)
                    {
                        oLog.Debug(rtle.LoaderExceptions[i], "Inner exception #{0}.", i);
                    }

                    oLog.Debug("ReflectionTypeLoadException.LoaderExceptions - end.");
                }                 // if

                return(null);
            }
            catch (Exception e) {
                oLog.Alert(e, "Failed to retrieve types list of assembly '{0}' while looking for '{1}'.", asm.FullName, sName);
                return(null);
            }             // try

            foreach (Type t in aryTypes)
            {
                if (bHasDot)
                {
                    if ((t.AssemblyQualifiedName ?? string.Empty).StartsWith(sName))
                    {
                        return(t);
                    }
                }
                else
                {
                    if (t.Name.EndsWith(sName))
                    {
                        return(t);
                    }
                }         // if
            }             // for each type

            return(null);
        }         // PureFindType
Example #4
0
        }         // Main

        private static void ProcessDir(SortedDictionary <string, Stat> oStat, string sPath, ASafeLog oLog)
        {
            oLog.Info("Processing directory {0} started...", sPath);

            if (!Directory.Exists(sPath))
            {
                oLog.Alert("Directory not found: {0}.", sPath);
            }
            else
            {
                string[] aryFileNames = Directory.GetFiles(sPath, "EzBob.Web.log.201*.zip");

                FileNameComparer fnc = new FileNameComparer();

                Array.Sort <string>(aryFileNames, fnc);

                foreach (var sFileName in aryFileNames)
                {
                    ReadFromZip(oStat, sFileName, oLog);
                }

                string[] aryDirNames = Directory.GetDirectories(sPath);

                foreach (string sDirName in aryDirNames)
                {
                    oLog.Info("Subdirectory found: {0}.", sDirName);

                    ProcessDir(oStat, sDirName, oLog);
                }         // for each
            }             // if

            oLog.Info("Processing directory {0} complete.", sPath);
        }         // ProcessDir
Example #5
0
        }         // FireToBackground

        protected void FireToBackground(string description, Action task, Action <Exception> onFailedToExecute = null)
        {
            if (task == null)
            {
                return;
            }

            string taskID = Guid.NewGuid()
                            .ToString("N");

            ASafeLog log = Log;

            log.Debug("Starting background task '{1}' with id '{0}'...", taskID, description);

            try {
                Task.Run(() => {
                    try {
                        task();

                        log.Debug("Background task '{1}' (id: '{0}') completed successfully.", taskID, description);
                    } catch (Exception e) {
                        log.Alert(e, "Background task '{1}' (id: '{0}') failed.", taskID, description);
                    }                     // try
                });
            } catch (Exception e) {
                Log.Alert(e, "Failed to fire task '{1}' (id: '{0}') to background.", taskID, description);

                if (onFailedToExecute != null)
                {
                    onFailedToExecute(e);
                }
            }     // try
        }         // FireToBackground
Example #6
0
        private void ProcessRow(SafeReader sr)
        {
            string sRowType = sr["RowType"];

            RowTypes nRowType;

            if (!Enum.TryParse(sRowType, out nRowType))
            {
                m_oLog.Alert("Failed to parse DataSharing row type '{0}'.", sRowType);
                return;
            }             // if

            switch (nRowType)
            {
            case RowTypes.Funnel:
                m_oFunnel.Add(sr.Fill <FunnelRow>());
                break;

            case RowTypes.RejectReason:
                RejectReasonRow rrr = sr.Fill <RejectReasonRow>();
                m_oRejectReasons.Add(rrr);
                m_nRejectReasonTotal += rrr.Counter;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }     // switch
        }         // ProcessRow
Example #7
0
        }         // ProcessFile

        private static void ProcessFile(
            OneUploadLimitation oLimits,
            string sFileName,
            SortedDictionary <string, string> oPassed,
            SortedDictionary <string, string> oErrors,
            ASafeLog oLog
            )
        {
            try {
                oLog.Info("Examining file {0}...", sFileName);

                var fi = new FileInfo(sFileName);

                var os = new List <string>();

                if (fi.Length > oLimits.FileSize)
                {
                    os.Add("file size " + fi.Length.ToString("N0", CultureInfo.InvariantCulture));
                }

                var oBuf = new byte[256];

                FileStream ins   = File.OpenRead(sFileName);
                var        nRead = ins.Read(oBuf, 0, oBuf.Length);
                ins.Close();

                string sMimeType = oLimits.DetectFileMimeType(oBuf, sFileName, nRead, oLog);

                if (string.IsNullOrWhiteSpace(sMimeType))
                {
                    os.Add("MIME type");
                }

                string sMsg;

                if (os.Count > 0)
                {
                    sMsg = string.Join(" and ", os);
                    oErrors[sFileName] = sMsg;
                }
                else
                {
                    sMsg = "size " + fi.Length.ToString("N0", CultureInfo.InvariantCulture) + " bytes of type " + sMimeType;
                    oPassed[sFileName] = sMsg;
                }

                oLog.Info("File {0} has {1}.", sFileName, os.Count == 0 ? "passed with " + sMsg : "failed due to " + sMsg);
            }
            catch (Exception e) {
                oLog.Alert(e, "Failed to process file {0}", sFileName);
            } // try
        }     // ProcessFile
Example #8
0
        private static void TestAddBrokers(AConnection oDB, ASafeLog oLog)
        {
            var oBrokers = new List <BrokerData> {
                // In Excel:
                // =CONCATENATE("new BrokerData(""",F2, """, """, A2,""", """, B2, """, """, C2, """, """, D2, """, """, E2, """),")
            };

            foreach (BrokerData bd in oBrokers)
            {
                try {
                    bd.Signup(oDB, oLog);
                } catch (Exception e) {
                    oLog.Alert(e, "Failed to create a broker {0}", bd.Email);
                }         // try
            }             // for each
        }
Example #9
0
        }         // IsDir

        private static void ProcessDir(OneUploadLimitation oLimits, string sPath, SortedDictionary <string, string> oPassed, SortedDictionary <string, string> oErrors, ASafeLog oLog)
        {
            IEnumerable <string> lst;

            try {
                lst = Directory.EnumerateFileSystemEntries(sPath);
            }
            catch (Exception e) {
                oLog.Alert(e, "Failed to enumerate objects in {0}.", sPath);
                return;
            }             // try

            foreach (string sFileName in lst)
            {
                if (IsDir(sFileName))
                {
                    ProcessDir(oLimits, sFileName, oPassed, oErrors, oLog);
                }
                else
                {
                    ProcessFile(oLimits, sFileName, oPassed, oErrors, oLog);
                }
            }     // for each
        }         // ProcessFile
Example #10
0
        }         // Load

        private static ExperianLtd Load(IEnumerable <SafeReader> lst, ASafeLog oLog)
        {
            var oResult = new ExperianLtd();

            var oKidMap = new SortedTable <string, long, AExperianLtdDataRow>();

            foreach (SafeReader sr in lst)
            {
                string sType = sr["DatumType"];

                if (sType == "Metadata")
                {
                    oResult.ReceivedTime = sr["InsertDate"];
                    continue;
                }                 // if

                Type oType = typeof(ExperianLtd).Assembly.GetType(typeof(ExperianLtd).Namespace + "." + sType);

                if (oType == null)
                {
                    oLog.Alert("Could not find type '{0}'.", sType);
                    continue;
                }                 // if

                AExperianLtdDataRow oRow;

                if (oType == typeof(ExperianLtd))
                {
                    oRow = oResult;
                }
                else
                {
                    ConstructorInfo ci = oType.GetConstructors().FirstOrDefault();

                    if (ci == null)
                    {
                        oLog.Alert("Parsing Experian company data into {0} failed: no constructor found.", oType.Name);
                        continue;
                    }                     // if

                    oRow = (AExperianLtdDataRow)ci.Invoke(new object[] { oLog });
                }                 // if

                sr.Fill(oRow);

                oRow.ID       = sr["ID"];
                oRow.ParentID = sr["ParentID"];

                oKidMap[sType, oRow.ID] = oRow;

                string sParentType = sr["ParentType"];

                if (string.IsNullOrWhiteSpace(sParentType))
                {
                    // oLog.Debug("No parent row. This row: id {0} of type {1}.", oRow.ID, sType);
                    continue;
                }                 // if

                AExperianLtdDataRow oParent = oKidMap[sParentType, oRow.ParentID];

                if (oParent == null)
                {
                    oLog.Alert(
                        "No parent row found.\n\tThis row: id {0} of type {1}.\n\tParent row: id {2} of type {3}.",
                        oRow.ID, sType, oRow.ParentID, sParentType
                        );
                }
                else
                {
                    oParent.AddChild(oRow);
                    // Log.Debug("\n\tThis row: id {0} of type {1}.\n\tParent row: id {2} of type {3}.", oRow.ID, sType, oRow.ParentID, sParentType);
                }         // if
            }             // for each row

            return(oResult);
        }         // Load
Example #11
0
        }                                                 // IsValid

        public QuickOfferModel GetOffer(bool bSaveOfferToDB, AConnection oDB, ASafeLog oLog)
        {
            if (RequestedAmount < Cfg.MinOfferAmount)
            {
                oLog.Debug("Requested amount (£{0}) is less than minimal offer amount (£{1}), not offering.", RequestedAmount, Cfg.MinOfferAmount);
                return(null);
            }             // if

            oDB.ForEachRowSafe(
                (sr, bRowsetStart) => {
                minLoanAmount = sr["MinLoanAmount"];
                return(ActionResult.SkipAll);
            },
                "GetBankBasedApprovalConfigs",
                CommandSpecies.StoredProcedure
                );

            decimal?nOffer = Calculate();

            if (!nOffer.HasValue)
            {
                return(null);
            }

            int nOfferID = default(int);

            decimal nRequestedAmount = RequestedAmount.Min(Cfg.PotentialMaxAmount);

            var oOffer = new QuickOfferModel {
                ID                 = nOfferID,
                Amount             = nOffer.Value,
                Aml                = Aml,
                BusinessScore      = BusinessScore,
                IncorporationDate  = IncorporationDate.Value,
                TangibleEquity     = TangibleEquity,
                TotalCurrentAssets = TotalCurrentAssets,

                ImmediateTerm         = Cfg.ImmediateTermMonths,
                ImmediateInterestRate = Cfg.ImmediateInterestRate,
                ImmediateSetupFee     = Cfg.ImmediateSetupFee,

                PotentialAmount       = nRequestedAmount,
                PotentialTerm         = Cfg.PotentialTermMonths,
                PotentialInterestRate = Cfg.LoanPct(BusinessScore, nRequestedAmount),
                PotentialSetupFee     = Cfg.PotentialSetupFee,
            };

            if (bSaveOfferToDB && (Cfg.Enabled != QuickOfferEnabledStatus.Silent))
            {
                try {
                    var oID = new QueryParameter("@QuickOfferID")
                    {
                        Type      = DbType.Int32,
                        Direction = ParameterDirection.Output,
                    };

                    oDB.ExecuteNonQuery(
                        "QuickOfferSave",
                        CommandSpecies.StoredProcedure,
                        new QueryParameter("@Now", DateTime.UtcNow),
                        new QueryParameter("@CustomerID", CustomerID),
                        new QueryParameter("@Amount", oOffer.Amount),
                        new QueryParameter("@Aml", oOffer.Aml),
                        new QueryParameter("@BusinessScore", oOffer.BusinessScore),
                        new QueryParameter("@IncorporationDate", oOffer.IncorporationDate),
                        new QueryParameter("@TangibleEquity", oOffer.TangibleEquity),
                        new QueryParameter("@TotalCurrentAssets", oOffer.TotalCurrentAssets),

                        new QueryParameter("@ImmediateTerm", oOffer.ImmediateTerm),
                        new QueryParameter("@ImmediateInterestRate", oOffer.ImmediateInterestRate),
                        new QueryParameter("@ImmediateSetupFee", oOffer.ImmediateSetupFee),
                        new QueryParameter("@PotentialAmount", oOffer.PotentialAmount),
                        new QueryParameter("@PotentialTerm", oOffer.PotentialTerm),
                        new QueryParameter("@PotentialInterestRate", oOffer.PotentialInterestRate),
                        new QueryParameter("@PotentialSetupFee", oOffer.PotentialSetupFee),
                        oID
                        );

                    if (int.TryParse(oID.SafeReturnedValue, out nOfferID))
                    {
                        oLog.Msg("Quick offer id is {0}", nOfferID);
                        oOffer.ID = nOfferID;
                    }
                    else
                    {
                        oLog.Warn("Failed to parse quick offer id from {0}", oID.Value.ToString());
                    }
                }
                catch (Exception e) {
                    oLog.Alert(e, "Failed to save a quick offer to DB.");
                }         // try
            }             // if

            return(oOffer);
        }         // GetOffer