Example #1
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 #2
0
        private static void ActionTest(int x, string s, AConnection oDB, ASafeLog log)
        {
            log.Info("ActionTest started...");

            var sp = new UpdateBroker(oDB, log);

            sp.ExecuteNonQuery();

            /*
             *
             * var sp = new BrokerLoadCustomerList(oDB, log) { Email = "*****@*****.**", };
             *
             * sp.ForEachResult<BrokerLoadCustomerList.ResultRow>(oRow => {
             *      log.Debug("Result row: {0}", oRow);
             *      return ActionResult.Continue;
             * });
             */

            if (ms_nActionTestCounter < 3)
            {
                ms_nActionTestCounter++;
                throw new ForceRetryException("just a force retry");
            }             // if

            log.Info("ActionTest: x = {0}", x);
            log.Info("ActionTest: s = {0}", s);
            log.Info("ActionTest complete.");
        }
Example #3
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 #4
0
        private string SendRequest(string path, object model)
        {
            var request = new RestRequest(path, Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.AddBody(model);
            var response = _client.Post(request);

            _log.Info("Mandrill service call.\n Request: \n {0} \n Response: \n {1}", request.Parameters[0], response.Content);

            if (response.StatusCode == HttpStatusCode.InternalServerError)
            {
                var error = JsonConvert.DeserializeObject <ErrorResponseModel>(response.Content);
                throw new MandrillException(error, string.Format("InternalServerError. Post failed {0}", path));
            }

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw response.ErrorException;
            }

            return(response.Content);
        }
Example #5
0
        public void TestMailbee()
        {
            _cfg = new Conf(_log);
            _cfg.Init();

            try
            {
                Global.LicenseKey = _cfg.MailBeeLicenseKey;
            }
            catch (MailBeeLicenseException e)
            {
                _log.Error("License key is invalid: {0}", e);
                //Mailer.Mailer.SendMail(_cfg.TestAddress, _cfg.TestPassword, "EzAutoresonder Error", e.ToString(), "*****@*****.**");
            }             // try

            _imap = new Imap {
                SslMode = MailBee.Security.SslStartupMode.OnConnect
            };

            // Connect to IMAP server
            _imap.Connect(_cfg.Server, _cfg.Port);
            _log.Info("Connected to the server");

            // Log into IMAP account
            _imap.Login("", "");           //todo enter a login
            _log.Info("Logged into the server");

            // Select Inbox folder
            _imap.ExamineFolder("Inbox");
            var uids = (UidCollection)_imap.Search(true, "UNSEEN", null);

            if (uids.Count > 0)
            {
                // Download all the messages found by Search method
                MailMessageCollection msgs = _imap.DownloadMessageHeaders(uids.ToString(), true);

                // Iterate througn the messages collection and display info about them
                foreach (MailMessage msg in msgs)
                {
                    Console.WriteLine("Message #" + msg.IndexOnServer.ToString(CultureInfo.InvariantCulture) +
                                      " has subject: " + msg.Subject + "  from: " + msg.From.Email + " received on: " +
                                      msg.DateReceived);
                }
            }
        }
Example #6
0
        }         // SendMail

        public static void SendMail(MailAddress oFrom, string fromPassword, string subject, string mailBody, string toAddress, ExcelPackage wb = null, ASafeLog oLog = null, int retries = 5)
        {
            string body    = mailBody;
            var    ostream = new MemoryStream();

            var smtp = new SmtpClient {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(oFrom.Address, fromPassword)
            };

            using (var message = new MailMessage()) {
                message.From       = oFrom;
                message.Subject    = subject;
                message.Body       = body;
                message.IsBodyHtml = true;

                foreach (string sAddr in toAddress.Split(','))
                {
                    message.To.Add(sAddr);
                }

                if (wb != null)
                {
                    message.Attachments.Clear();
                    wb.SaveAs(ostream);
                    ostream.Position = 0;
                    var attachment = new Attachment(ostream, subject + ".xlsx", "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                    message.Attachments.Add(attachment);
                }                 // if workbook is not null

                int tryCounter = 0;

                while (tryCounter < retries)
                {
                    try {
                        smtp.Send(message);
                        tryCounter = retries;
                    }
                    catch (Exception e) {
                        oLog.Error(string.Format("Error sending mail: {0}", e));
                        ++tryCounter;

                        if (tryCounter < retries)
                        {
                            oLog.Info("Will wait 5 seconds and retry to send the mail");
                            Thread.Sleep(TimeSpan.FromSeconds(5));
                        } // if
                    }     // try
                }         // while retries left
            }             // using

            ostream.Close();
        } // SendMail
Example #7
0
        private static void TestParsedValues(AConnection oDB, ASafeLog oLog)
        {
            oLog.Info("Using row - begin");

            oDB.ForEachRowSafe((sr, bRowsetStart) => {
                int nCustomerID = sr["Id"];
                string sName    = sr["Name"];
                bool bIsOffline = sr[2];
                DateTime dt     = sr["GreetingMailSentDate", new DateTime(2014, 12, 12)];

                oLog.Info("{0}: {1} - {2} {3}", nCustomerID, sName, bIsOffline, dt);

                return(ActionResult.Continue);
            }, "SELECT Id, Name, IsOffline, GreetingMailSentDate FROM Customer ORDER BY Id", CommandSpecies.Text);

            oLog.Info("Using row - end");

            oLog.Info("Using reader - begin");
            oDB.ForEachRow(TestParsedValuesPrint, "SELECT Id, Name, IsOffline, GreetingMailSentDate FROM Customer ORDER BY Id", CommandSpecies.Text);
            oLog.Info("Using reader - end");
        }
Example #8
0
        public static void SendMail(
            MailAddress oFrom,
            string fromPassword,
            string subject,
            string mailBody,
            string toAddress,
            ASafeLog oLog,
            int retries = 5
            )
        {
            var smtp = new SmtpClient {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(oFrom.Address, fromPassword)
            };

            using (var message = new MailMessage()) {
                message.From       = oFrom;
                message.Subject    = subject;
                message.Body       = mailBody;
                message.IsBodyHtml = true;

                foreach (string sAddr in toAddress.Split(','))
                {
                    message.To.Add(sAddr);
                }

                int tryCounter = 0;

                while (tryCounter < retries)
                {
                    try {
                        smtp.Send(message);
                        tryCounter = retries;
                    }
                    catch (Exception e) {
                        oLog.Error(string.Format("Error sending mail: {0}", e));
                        ++tryCounter;

                        if (tryCounter < retries)
                        {
                            oLog.Info("Will wait 5 seconds and retry to send the mail");
                            Thread.Sleep(TimeSpan.FromSeconds(5));
                        } // if
                    }     // try
                }         // while retries left
            }             // using
        }                 // SendMail
Example #9
0
 public static void InitBasePaths(AConnection db, ASafeLog log)
 {
     basePaths = new List <string>();
     db.ForEachRowSafe(sr => basePaths.Add(sr["Value"]), LoadBasePathsQuery, CommandSpecies.Text);
     log.Info("Base paths are:\n\t{0}", string.Join("\n\t", basePaths));
 }         // InitBasePaths
Example #10
0
        public JsonResult ChangeCreditLine(
            long id,
            int productID,
            int productTypeID,
            int productSubTypeID,
            int loanType,
            int loanSource,
            double amount,
            decimal interestRate,
            int repaymentPeriod,
            string offerStart,
            string offerValidUntil,
            bool allowSendingEmail,
            int discountPlan,
            decimal?brokerSetupFeePercent,
            decimal?manualSetupFeePercent,
            bool isCustomerRepaymentPeriodSelectionAllowed,
            int isLoanTypeSelectionAllowed,
            bool spreadSetupFee,
            bool feesManuallyUpdated
            )
        {
            CashRequest cr = this.cashRequestsRepository.Get(id);

            if (cr.Id <= 0)
            {
                log.Error("No cash request found");
                return(Json(true));
            }             // if

            new Transactional(() => {
                LoanType loanT    = this.loanTypes.Get(loanType);
                LoanSource source = this.loanSources.Get(loanSource);

                cr.LoanType = loanT;

                int step = CurrentValues.Instance.GetCashSliderStep;
                int sum  = (int)Math.Round(amount / step, MidpointRounding.AwayFromZero) * step;
                cr.ManagerApprovedSum      = sum;
                cr.LoanSource              = source;
                cr.InterestRate            = interestRate;
                cr.RepaymentPeriod         = repaymentPeriod;
                cr.ApprovedRepaymentPeriod = cr.RepaymentPeriod;
                cr.OfferStart              = FormattingUtils.ParseDateWithCurrentTime(offerStart);
                cr.OfferValidUntil         = FormattingUtils.ParseDateWithCurrentTime(offerValidUntil);

                cr.BrokerSetupFeePercent = brokerSetupFeePercent;
                cr.ManualSetupFeePercent = manualSetupFeePercent;
                cr.UwUpdatedFees         = feesManuallyUpdated;

                cr.EmailSendingBanned = !allowSendingEmail;
                cr.LoanTemplate       = null;

                cr.IsLoanTypeSelectionAllowed = isLoanTypeSelectionAllowed;
                cr.IsCustomerRepaymentPeriodSelectionAllowed = isCustomerRepaymentPeriodSelectionAllowed;

                cr.DiscountPlan      = this.discounts.Get(discountPlan);
                cr.SpreadSetupFee    = spreadSetupFee;
                cr.ProductSubTypeID  = productSubTypeID;
                Customer c           = cr.Customer;
                c.OfferStart         = cr.OfferStart;
                c.OfferValidUntil    = cr.OfferValidUntil;
                c.ManagerApprovedSum = sum;

                this.cashRequestsRepository.SaveOrUpdate(cr);
                this.customerRepository.SaveOrUpdate(c);
            }).Execute();

            var decision = this.serviceClient.Instance.AddDecision(this.context.UserId, cr.Customer.Id, new NL_Decisions {
                UserID         = this.context.UserId,
                DecisionTime   = DateTime.UtcNow,
                DecisionNameID = (int)DecisionActions.Waiting,
                Notes          = "Waiting; oldCashRequest: " + cr.Id
            }, cr.Id, null);

            // TODO: save feesManuallyUpdated in new loan structure (EZ-4829)

            log.Info("NL decisionID: {0}, oldCashRequestID: {1}, Error: {2}", decision.Value, cr.Id, decision.Error);

            NL_OfferFees offerFee = new NL_OfferFees()
            {
                LoanFeeTypeID          = (int)NLFeeTypes.SetupFee,
                Percent                = manualSetupFeePercent ?? 0,
                OneTimePartPercent     = 1,
                DistributedPartPercent = 0
            };

            if (cr.SpreadSetupFee != null && cr.SpreadSetupFee == true)
            {
                offerFee.LoanFeeTypeID          = (int)NLFeeTypes.ServicingFee;
                offerFee.OneTimePartPercent     = 0;
                offerFee.DistributedPartPercent = 1;
            }
            NL_OfferFees[] ofeerFees = { offerFee };

            var offer = this.serviceClient.Instance.AddOffer(this.context.UserId, cr.Customer.Id, new NL_Offers {
                DecisionID = decision.Value,
                LoanTypeID = loanType,
                RepaymentIntervalTypeID = (int)DbConstants.RepaymentIntervalTypes.Month,
                LoanSourceID            = loanSource,
                StartTime             = FormattingUtils.ParseDateWithCurrentTime(offerStart),
                EndTime               = FormattingUtils.ParseDateWithCurrentTime(offerValidUntil),
                RepaymentCount        = repaymentPeriod,
                Amount                = (decimal)amount,
                MonthlyInterestRate   = interestRate,
                CreatedTime           = DateTime.UtcNow,
                BrokerSetupFeePercent = brokerSetupFeePercent ?? 0,
                Notes                             = "offer from ChangeCreditLine, ApplicationInfoController",
                DiscountPlanID                    = discountPlan,
                IsLoanTypeSelectionAllowed        = isLoanTypeSelectionAllowed == 1,
                IsRepaymentPeriodSelectionAllowed = isCustomerRepaymentPeriodSelectionAllowed,
                SendEmailNotification             = allowSendingEmail,
                ProductSubTypeID                  = productSubTypeID
                                                    // SetupFeeAddedToLoan = 0 // default 0 TODO EZ-3515
                                                    // InterestOnlyRepaymentCount =
                                                    //IsAmountSelectionAllowed = 1 default 1 always allowed
            }, ofeerFees);

            log.Info("NL--- offerID: {0}, decisionID: {1} oldCashRequestID: {2}, Error: {3}", offer.Value, decision.Value, cr.Id, offer.Error);


            log.Debug("update offer for customer {0} all the offer is changed", cr.Customer.Id);

            return(Json(true));
        }         // ChangeCreditLine