Exemple #1
0
        public void ReadSentEmails()
        {
            var imapSettings  = SettingsBuilder.GetImapSettingsFromCompany(_company);
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(_company);
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            var emailProcessing = new EmailProcessingService(_log, _dbFactory,
                                                             emailService,
                                                             actionService,
                                                             _company,
                                                             _time);

            IList <IEmailRule> sentRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(_log, _time),
                new AddMatchIdsEmailRule(_log, _time),
                new SetAnswerIdEmailRule(_log, _time),
                new SetSentByEmailRule(_log, _time)
            };

            var email = new EmailReaderService(imapSettings, _log, _dbFactory, _time);

            email.ReadEmails(EmailHelper.SentFolder, DateTime.Now.AddDays(-15), null, imapSettings.AcceptingToAddresses, null);
            emailProcessing.ProcessEmails(email.EmailProcessResultList, sentRules);
        }
Exemple #2
0
        public void ReadInboxEmails()
        {
            var imapSettings  = SettingsBuilder.GetImapSettingsFromCompany(_company);
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(_company);
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            var emailProcessing = new EmailProcessingService(_log, _dbFactory,
                                                             emailService,
                                                             actionService,
                                                             _company,
                                                             _time);

            IList <IEmailRule> inboxRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(_log, _time),
                new AddMatchIdsEmailRule(_log, _time),
                new SetAnswerIdEmailRule(_log, _time), //NOTE: also using in Inbox for processing Amazon autocommunicate emails
                //new FeedbackBlackListEmailRule(_log, _time),
                new ReturnRequestEmailRule(_log, _time, emailService, actionService, _company, true, false),
                new OrderDeliveryInquiryEmailRule(_log, _time, emailService, actionService),
                new AddressNotChangedEmailRule(_log, _time, emailService, actionService),
                //new DhlInvoiceEmailRule(_log, _time, _dbFactory),
                //new AddCommentEmailRule(_log, actionService, _time),
                new PrepareBodyEmailRule(_log, _time),
            };

            var email = new EmailReaderService(imapSettings, _log, _dbFactory, _time);

            email.ReadEmails(EmailHelper.InboxFolder, DateTime.Now.AddDays(-5), imapSettings.AcceptingToAddresses, null, null);
            emailProcessing.ProcessEmails(email.EmailProcessResultList, inboxRules);
        }
Exemple #3
0
        protected override void RunCallback()
        {
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        log       = GetLogger();
            CompanyDTO company   = null;

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var companyAddress    = new CompanyAddressService(company);
            var addressService    = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var kioskBarcodeService = new KioskBarcodeService(dbFactory,
                                                              emailService,
                                                              time,
                                                              log);

            kioskBarcodeService.CheckOrders();

            log.Info("After check orders");
        }
Exemple #4
0
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        log       = GetLogger();

            var now = time.GetAppNowTime();

            if (!time.IsBusinessDay(now))
            {
                return;
            }

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var autoPurchaseTime = AppSettings.OverdueAutoPurchaseTime;

            var companyAddress = new CompanyAddressService(company);
            var addressService = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            //Checking email service, sent test message
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var checker = new AlertChecker(log, time, dbFactory, emailService, company);

            using (var db = dbFactory.GetRWDb())
            {
                checker.CheckOverdue(db, now, autoPurchaseTime);
            }
        }
Exemple #5
0
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        settings  = new SettingsService(dbFactory);
            var        log       = GetLogger();

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var companyAddress    = new CompanyAddressService(company);
            var addressService    = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);

            var actionService = new SystemActionService(log, time);
            var emailService  = new EmailService(log, emailSmtpSettings, addressService);

            var lastSyncDate = settings.GetOrdersAdjustmentDate(_api.Market, _api.MarketplaceId);

            using (var db = dbFactory.GetRWDb())
            {
                LogWrite("Last sync date=" + lastSyncDate);

                if (!lastSyncDate.HasValue ||
                    (time.GetUtcTime() - lastSyncDate) > _betweenProcessingInverval)
                {
                    var updater = new BaseOrderRefundService(_api, actionService, emailService, log, time);
                    updater.ProcessRefunds(db, null);
                    settings.SetOrdersAdjustmentDate(time.GetUtcTime(), _api.Market, _api.MarketplaceId);
                }
            }
        }
Exemple #6
0
        protected override void RunCallback()
        {
            var        dbFactory = new DbFactory();
            CompanyDTO company   = null;

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var time           = new TimeService(dbFactory);
            var addressService = AddressService.Default;

            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);

            var emailService  = new EmailService(GetLogger(), emailSmtpSettings, addressService);
            var actionService = new SystemActionService(GetLogger(), time);

            emailService.ProcessEmailActions(dbFactory,
                                             time,
                                             company,
                                             actionService);

            emailService.AutoAnswerEmails(dbFactory,
                                          time,
                                          company);
        }
Exemple #7
0
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var companyAddress = new CompanyAddressService(company);
            var addressService = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            //Checking email service, sent test message
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var fromDate = time.GetAppNowTime().AddDays(-5);
            var emails   = new List <EmailOrderDTO>();

            using (var db = dbFactory.GetRDb())
            {
                emails = db.Emails.GetAllWithOrder(new EmailSearchFilter()
                {
                    ResponseStatus = (int)EmailResponseStatusFilterEnum.ResponseNeeded
                })
                         .Where(e => e.ReceiveDate > fromDate)
                         .ToList();
            }

            emailService.SendEmailStatusNotification(emails);
        }
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        log       = GetLogger();

            var now = time.GetAppNowTime();

            if (!time.IsBusinessDay(now))
            {
                return;
            }

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var companyAddress     = new CompanyAddressService(company);
            var quantityManager    = new QuantityManager(log, time);
            var actionService      = new SystemActionService(log, time);
            var addressService     = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            var emailSmtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService       = new EmailService(GetLogger(), emailSmtpSettings, addressService);
            var cacheService       = new CacheService(log, time, actionService, quantityManager);
            var barcodeService     = new BarcodeService(log, time, dbFactory);
            var itemHistoryService = new ItemHistoryService(log, time, dbFactory);

            var autoCreateWMListingService = new AutoCreateWalmartListingService(log,
                                                                                 time,
                                                                                 dbFactory,
                                                                                 cacheService,
                                                                                 barcodeService,
                                                                                 emailService,
                                                                                 null,
                                                                                 itemHistoryService,
                                                                                 AppSettings.IsDebug);
            var autoCreateEBayListingService = new AutoCreateEBayListingService(log,
                                                                                time,
                                                                                dbFactory,
                                                                                cacheService,
                                                                                barcodeService,
                                                                                emailService,
                                                                                itemHistoryService,
                                                                                AppSettings.IsDebug);
            var autoCreateAmazonUSPrimeService = new AutoCreateAmazonUSPrimeListingService(log,
                                                                                           time,
                                                                                           dbFactory,
                                                                                           itemHistoryService);

            //autoCreateWMListingService.CreateListings();
            //log.Info("Walmart listings were created");

            //autoCreateEBayListingService.CreateListings();
            //log.Info("eBay listings were created");

            autoCreateAmazonUSPrimeService.CreateListings();
            log.Info("Amazon US Prime listings were created");
        }
Exemple #9
0
        public void CheckAutoResponse()
        {
            var smtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(_company);
            var emailService = new EmailService(_log, smtpSettings, _addressService);

            emailService.AutoAnswerEmails(_dbFactory,
                                          _time,
                                          _company);
        }
Exemple #10
0
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        log       = GetLogger();

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var companyAddress = new CompanyAddressService(company);
            var addressService = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            //Checking email service, sent test message
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var supportNotificatons = new List <ISupportNotification>()
            {
                new ListingCreationIssuesNotification(dbFactory, emailService, log, time),
                new QtyDistributionSupportNotification(dbFactory, emailService, log, time),
                new SubstractQtySupportNotification(dbFactory, emailService, log, time),
                new UnprocessedRefundSupportNotification(dbFactory, emailService, log, time)
            };

            log.Info("Notification count: " + supportNotificatons.Count());

            var currentDate          = time.GetAppNowTime();
            var nowTime              = new TimeSpan(currentDate.Hour, currentDate.Minute, currentDate.Second);
            var notificationToLaunch = supportNotificatons.Where(n => n.When.Any(w => Math.Abs((w - nowTime).TotalSeconds) < 30)).ToList();

            if (notificationToLaunch.Count > 0)
            {
                log.Info("Notification count: " + notificationToLaunch.Count());

                foreach (var notification in notificationToLaunch)
                {
                    try
                    {
                        log.Info("Begin check " + notification.Name);
                        notification.Check();
                        log.Info("End check " + notification.Name);
                    }
                    catch (Exception ex)
                    {
                        log.Error("Notification error: " + notification.Name, ex);
                    }
                }
            }
        }
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        log       = GetLogger();

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var companyAddress = new CompanyAddressService(company);
            var addressService = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            var settings       = new SettingsService(dbFactory);

            //Checking email service, sent test message
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var lastSendDate = settings.GetSendDhlInvoiceNotification();

            var sizeMappingService = new SizeMappingService(log, time, dbFactory);
            var newIssues          = sizeMappingService.CheckItemsSizeMappingIssue();

            if (newIssues.Any())
            {
                var body = String.Join("<br/>",
                                       newIssues.Select(i => i.ASIN + ", marketSize: " + i.Size + ", styleSize: " + i.StyleSize));
                emailService.SendSystemEmailToAdmin("New size mapping issues, count: " + newIssues.Count,
                                                    body);

                log.Info("New issues: " + body);
            }
            else
            {
                log.Info("No new issues");
            }

            if (time.GetAppNowTime().DayOfWeek == DayOfWeek.Saturday)
            {
                var issueSummary = sizeMappingService.GetItemsSummaryWithSizeMappingIssue();
                var body         = String.Join("<br/>",
                                               issueSummary.Select(i => i.ASIN + ", marketSize: " + i.Size + ", styleSize: " + i.StyleSize));
                emailService.SendSystemEmailToAdmin("Size mapping issue summary, count: " + issueSummary.Count,
                                                    body);

                log.Info("Summary issues: " + body);
            }
        }
        protected override void RunCallback()
        {
            var dbFactory           = new DbFactory();
            var time                = new TimeService(dbFactory);
            var log                 = GetLogger();
            var actionService       = new SystemActionService(GetLogger(), time);
            var orderHistoryService = new OrderHistoryService(log, time, dbFactory);
            var serviceFactory      = new ServiceFactory();
            var weightService       = new WeightService();
            var pdfMaker            = new PdfMakerByIText(GetLogger());
            var batchManager        = new BatchManager(log, time, orderHistoryService, weightService);

            CompanyDTO company = null;

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var addressService    = AddressService.Default;
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);


            var labelBatchService = new LabelBatchService(dbFactory,
                                                          actionService,
                                                          GetLogger(),
                                                          time,
                                                          weightService,
                                                          serviceFactory,
                                                          emailService,
                                                          batchManager,
                                                          pdfMaker,
                                                          addressService,
                                                          orderHistoryService,
                                                          AppSettings.DefaultCustomType,
                                                          AppSettings.LabelDirectory,
                                                          AppSettings.ReserveDirectory,
                                                          AppSettings.TemplateDirectory,
                                                          new LabelBatchService.Config()
            {
                PrintErrorsToEmails = new[] { company.SellerEmail, company.SellerWarehouseEmailAddress },
                PrintErrorsCCEmails = new[] { EmailHelper.RaananEmail, EmailHelper.SupportDgtexEmail },
            },
                                                          AppSettings.IsSampleLabels);

            labelBatchService.ProcessPrintBatchActions(null);
        }
        protected override void RunCallback()
        {
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        log       = GetLogger();
            CompanyDTO company;

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var addressService    = AddressService.Default;
            var actionService     = new SystemActionService(log, time);
            var settings          = new SettingsService(dbFactory);
            var emailService      = new EmailService(log, emailSmtpSettings, addressService);

            var lastSyncDate = settings.GetOrdersAdjustmentDate(_api.Market, _api.MarketplaceId);

            LogWrite("Last sync date=" + lastSyncDate);

            if (!lastSyncDate.HasValue ||
                (time.GetUtcTime() - lastSyncDate) > _betweenProcessingInverval)
            {
                var updater = new AdjustmentDataUpdater(actionService,
                                                        emailService,
                                                        log,
                                                        time,
                                                        dbFactory);
                var unprocessedFeed = updater.GetUnprocessedFeedId(_api.MarketplaceId);
                if (unprocessedFeed != null)
                {
                    LogWrite("Update unprocessed feed");
                    updater.UpdateSubmittedFeed(_api,
                                                unprocessedFeed,
                                                AppSettings.FulfillmentResponseDirectory);
                }
                else
                {
                    LogWrite("Submit new feed");
                    updater.SubmitFeed(_api, CompanyId, null, AppSettings.FulfillmentRequestDirectory);
                    settings.SetOrdersAdjustmentDate(time.GetUtcTime(), _api.Market, _api.MarketplaceId);
                }
            }
        }
Exemple #14
0
        protected override void Init()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }
            var addressService = AddressService.Default;

            //Checking email service, sent test message
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var info = new SystemEmailInfo(addressService, "[commercentric.com] Launched emails thread", "Support", "*****@*****.**");

            emailService.SendEmail(info, CallSource.Service);
        }
Exemple #15
0
        public virtual ActionResult RequestFeedbacks(string orderIds)
        {
            LogI("RequestFeedbacks, orderIds=" + orderIds);

            var by      = AccessManager.UserId;
            var company = AccessManager.Company;

            ValueResult <List <string> > result = ValueResult <List <string> > .Success(
                "Message has been successfully sent",
                new List <string>());

            var ids = orderIds.Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            foreach (var orderId in ids)
            {
                try
                {
                    var emailService = new EmailService(LogService, SettingsBuilder.GetSmtpSettingsFromCompany(company), AddressService);

                    var sendResult = OrderFeedbackViewModel.SendFeedback(Db,
                                                                         emailService,
                                                                         orderId,
                                                                         Time.GetUtcTime(),
                                                                         by);

                    if (sendResult.Status == CallStatus.Success)
                    {
                        result.Data.Add(orderId);
                    }
                }
                catch (Exception ex)
                {
                    LogE("RequestFeedbacks", ex);
                }
            }

            return(new JsonResult()
            {
                Data = result,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #16
0
        public virtual ActionResult RequestFeedback(string orderId)
        {
            LogI("RequestFeedback, orderId=" + orderId);

            ValueResult <List <string> > result;

            try
            {
                var by           = AccessManager.UserId;
                var company      = AccessManager.Company;
                var emailService = new EmailService(LogService, SettingsBuilder.GetSmtpSettingsFromCompany(company), AddressService);

                var sendResult = OrderFeedbackViewModel.SendFeedback(Db,
                                                                     emailService,
                                                                     orderId,
                                                                     Time.GetUtcTime(),
                                                                     by);

                if (sendResult.Status == CallStatus.Success)
                {
                    result = ValueResult <List <string> > .Success("Message has been successfully sent", new List <string>() { orderId });
                }
                else
                {
                    result = ValueResult <List <string> > .Error("Can't send email. Details: " + sendResult.Message);
                }
            }
            catch (Exception ex)
            {
                LogE("RequestFeedback", ex);
                result = ValueResult <List <string> > .Error("Can't send email. Error=" + ex.Message);
            }

            return(new JsonResult
            {
                Data = result,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public virtual ActionResult SendEmail(ComposeEmailViewModel model)
        {
            try
            {
                var by           = AccessManager.UserId;
                var company      = AccessManager.Company;
                var emailService = new EmailService(LogService, SettingsBuilder.GetSmtpSettingsFromCompany(company), AddressService);

                model.SendEmail(Db,
                                LogService,
                                emailService,
                                QuantityManager,
                                Time.GetAppNowTime(),
                                by);

                return(Json(new MessagesResult(true).Success("Message has been successfully sent")));
            }
            catch (Exception ex)
            {
                LogE("Reply All", ex);
                return(Json(new MessagesResult(false).Error("Can't send email. Details: " + ex.Message)));
            }
        }
        protected override void RunCallback()
        {
            CompanyDTO company        = null;
            var        dbFactory      = new DbFactory();
            var        time           = new TimeService(dbFactory);
            var        log            = GetLogger();
            var        addressService = AddressService.Default;

            var now = time.GetAppNowTime();

            if (!time.IsBusinessDay(now))
            {
                return;
            }

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var weightService  = new WeightService();
            var messageService = new SystemMessageService(log, time, dbFactory);

            var dhlEcommerceSwitchService = new DhlECommerceSwitchService(log,
                                                                          time,
                                                                          company,
                                                                          dbFactory,
                                                                          emailService,
                                                                          weightService,
                                                                          messageService);

            dhlEcommerceSwitchService.SwitchToECommerce();
        }
Exemple #19
0
        protected override void RunCallback()
        {
            var dbFactory = new DbFactory();
            var time      = new TimeService(dbFactory);
            var log       = GetLogger();
            var settings  = new SettingsService(dbFactory);

            var now = time.GetAppNowTime();

            if (!time.IsBusinessDay(now))
            {
                return;
            }

            log.Info("Checking Same Day");

            CompanyDTO company = null;

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var companyAddress    = new CompanyAddressService(company);
            var addressService    = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var checker = new AlertChecker(log, time, dbFactory, emailService, company);

            using (var db = dbFactory.GetRWDb())
            {
                checker.CheckSameDay(db);
                settings.SetSameDayLastCheck(time.GetUtcTime());
            }
        }
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        log       = GetLogger();

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }
            var time              = new TimeService(dbFactory);
            var addressService    = AddressService.Default;
            var emailImapSettings = SettingsBuilder.GetImapSettingsFromCompany(company,
                                                                               Int32.Parse(AppSettings.Support_MaxProcessMessageErrorsCount),
                                                                               Int32.Parse(AppSettings.Support_ProcessMessageThreadTimeoutSecond));
            var emailSmtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailReaderService = new EmailReaderService(
                emailImapSettings,
                GetLogger(),
                dbFactory,
                time);
            var emailService  = new EmailService(log, emailSmtpSettings, addressService);
            var systemActions = new SystemActionService(log, time);


            var emailProcessingService = new EmailProcessingService(
                log,
                dbFactory,
                emailService,
                systemActions,
                company,
                time);

            //Inbox Folder
            emailReaderService.ReadEmails(EmailHelper.InboxFolder, null, emailImapSettings.AcceptingToAddresses, null, CancellationToken);
            IList <IEmailRule> inboxRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(log, time),
                new AddMatchIdsEmailRule(log, time),
                new SetAnswerIdEmailRule(log, time), //NOTE: also using in Inbox for processing Amazon autocommunicate emails
                new CancellationEmailRule(log, time, emailService, systemActions, company),
                new RemoveSignatureEmailRule(log, time, emailService, systemActions),
                new FeedbackBlackListEmailRule(log, time),
                new ReturnRequestEmailRule(log, time, emailService, systemActions, company, true, false),
                new OrderDeliveryInquiryEmailRule(log, time, emailService, systemActions),
                new AddressNotChangedEmailRule(log, time, emailService, systemActions),
                new DhlInvoiceEmailRule(log, time, dbFactory),
                new AddCommentEmailRule(log, systemActions, time),
                new PrepareBodyEmailRule(log, time),
            };

            emailProcessingService.ProcessEmails(emailReaderService.EmailProcessResultList, inboxRules);

            //Sent Folder
            emailReaderService.ReadEmails(EmailHelper.SentFolder, null, null, emailImapSettings.AcceptingToAddresses, CancellationToken);
            IList <IEmailRule> sentRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(log, time),
                new AddMatchIdsEmailRule(log, time),
                new SetAnswerIdEmailRule(log, time),
                new SetSentByEmailRule(log, time)
            };

            emailProcessingService.ProcessEmails(emailReaderService.EmailProcessResultList, sentRules);

            //Update Settings
            var settingService = new SettingsService(dbFactory);

            using (var db = dbFactory.GetRWDb())
            {
                settingService.SetUnansweredMessageCount(db.Emails.GetUnansweredEmailCount());
            }
        }
Exemple #21
0
        protected override void RunCallback()
        {
            _api.Connect();

            var dbFactory = new DbFactory();
            var time      = new TimeService(dbFactory);
            var log       = GetLogger();

            var syncInfo = new DbSyncInformer(dbFactory,
                                              log,
                                              time,
                                              SyncType.Orders,
                                              _api.MarketplaceId,
                                              _market,
                                              String.Empty);

            using (var db = dbFactory.GetRWDb())
            {
                var serviceFactory = new ServiceFactory();

                var settings       = new SettingsService(dbFactory);
                var company        = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
                var companyAddress = new CompanyAddressService(company);

                var shipmentProviders = company.ShipmentProviderInfoList;
                var addressProviders  = company.AddressProviderInfoList;

                var addressCheckServiceList = serviceFactory.GetAddressCheckServices(log,
                                                                                     time,
                                                                                     dbFactory,
                                                                                     addressProviders);
                var addressService = new AddressService(addressCheckServiceList, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));

                var actionService   = new SystemActionService(log, time);
                var priceService    = new PriceService(dbFactory);
                var quantityManager = new QuantityManager(log, time);
                var emailService    = new EmailService(log,
                                                       SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels),
                                                       addressService);

                var weightService  = new WeightService();
                var messageService = new SystemMessageService(log, time, dbFactory);

                var rateProviders = serviceFactory.GetShipmentProviders(log,
                                                                        time,
                                                                        dbFactory,
                                                                        weightService,
                                                                        shipmentProviders,
                                                                        null,
                                                                        null,
                                                                        null,
                                                                        null);

                var htmlScraper         = new HtmlScraperService(log, time, dbFactory);
                var orderHistoryService = new OrderHistoryService(log, time, dbFactory);
                var validatorService    = new OrderValidatorService(log,
                                                                    dbFactory,
                                                                    emailService,
                                                                    settings,
                                                                    orderHistoryService,
                                                                    actionService,
                                                                    priceService,
                                                                    htmlScraper,
                                                                    addressService,
                                                                    companyAddress.GetReturnAddress(MarketIdentifier.Empty()),
                                                                    rateProviders.FirstOrDefault(r => r.Type == ShipmentProviderType.Stamps),
                                                                    time,
                                                                    company);

                var cacheService = new CacheService(log, time, actionService, quantityManager);

                var orderSyncFactory = new OrderSyncFactory();

                if (settings.GetOrdersSyncEnabled() != false)
                {
                    if (!syncInfo.IsSyncInProgress()) //NOTE: for now it a few minutes ~10
                    {
                        if (!IsPrintLabelsInProgress(db, actionService, time))
                        {
                            try
                            {
                                var marketplaceId = _api.MarketplaceId;

                                LogWrite("Set OrderSyncInProgress");
                                syncInfo.SyncBegin(null);

                                var synchronizer = orderSyncFactory.GetForMarket(_api,
                                                                                 GetLogger(),
                                                                                 company,
                                                                                 settings,
                                                                                 syncInfo,
                                                                                 rateProviders,
                                                                                 quantityManager,
                                                                                 emailService,
                                                                                 validatorService,
                                                                                 orderHistoryService,
                                                                                 cacheService,
                                                                                 actionService,
                                                                                 companyAddress,
                                                                                 time,
                                                                                 weightService,
                                                                                 messageService);

                                var isFullSync = !_lastFullSync.HasValue || (time.GetUtcTime() - _lastFullSync) > _fullSyncInterval;

                                var syncResult = synchronizer.Sync(isFullSync ? OrderSyncModes.Full : OrderSyncModes.Fast, CancellationToken);

                                if (isFullSync)
                                {
                                    _lastFullSync = time.GetUtcTime();
                                }

                                var statusList = new List <string>()
                                {
                                    OrderStatusEnum.Unshipped.Str()
                                };
                                if (_market == MarketType.Walmart ||
                                    _market == MarketType.WalmartCA)
                                {
                                    statusList.Add(OrderStatusEnum.Pending.Str());
                                }

                                var dbOrderIdList = (from o in db.Orders.GetAll()
                                                     join sh in db.OrderShippingInfos.GetAll() on o.Id equals sh.OrderId
                                                     where (sh.IsActive || sh.IsVisible) &&
                                                     statusList.Contains(o.OrderStatus) &&
                                                     o.Market == (int)_market &&
                                                     (o.MarketplaceId == marketplaceId || String.IsNullOrEmpty(marketplaceId))
                                                     select o.AmazonIdentifier).Distinct().ToList();
                                //var dbOrders = db.ItemOrderMappings.GetOrdersWithItemsByStatus(weightService, statusList.ToArray(), _market, marketplaceId).ToList();
                                //dbOrders = dbOrders.Where(o => o.ShippingInfos != null && o.ShippingInfos.Any(sh => sh.IsActive || sh.IsVisible)).ToList();


                                var unshippedMarketOrderIdList = syncResult.ProcessedOrders
                                                                 .Where(o => statusList.Contains(o.OrderStatus))
                                                                 .Select(o => o.OrderId)
                                                                 .ToList();

                                if (syncResult.SkippedOrders != null)
                                {
                                    unshippedMarketOrderIdList.AddRange(syncResult.SkippedOrders
                                                                        .Where(o => statusList.Contains(o.OrderStatus))
                                                                        .Select(o => o.OrderId)
                                                                        .ToList());
                                }

                                unshippedMarketOrderIdList = unshippedMarketOrderIdList.Distinct().ToList();

                                //var dbOrderIdList = dbOrders.Select(o => o.OrderId).Distinct().ToList();
                                LogDiffrents(unshippedMarketOrderIdList, dbOrderIdList, "Missing order: ");

                                if (unshippedMarketOrderIdList.Count != dbOrderIdList.Count ||
                                    !syncResult.IsSuccess)
                                {
                                    emailService.SendSystemEmailToAdmin("PA Orders Sync has issue",
                                                                        "Market: " + _api.Market + " - " + _api.MarketplaceId + "<br/>" +
                                                                        "Sync message: " + syncResult.Message + "<br/>" +
                                                                        "Missing orders: " + (unshippedMarketOrderIdList.Count - dbOrderIdList.Count));
                                }

                                //NOTE: otherwise if we have missed order (older than 2 hours that was hidden in next lite iteration)
                                if (isFullSync)
                                {
                                    settings.SetOrderCountOnMarket(unshippedMarketOrderIdList.Count, _market, marketplaceId);
                                    settings.SetOrderCountInDB(dbOrderIdList.Count, _market, marketplaceId);
                                }

                                if (syncResult.IsSuccess)
                                {
                                    settings.SetOrderSyncDate(time.GetUtcTime(), _market, marketplaceId);
                                }
                            }
                            catch (Exception ex)
                            {
                                emailService.SendSystemEmailToAdmin("PA Orders Sync has error",
                                                                    "Market: " + _api.Market + " - " + _api.MarketplaceId + "<br/>" +
                                                                    "Sync message: " + ExceptionHelper.GetAllMessages(ex));
                                LogError("RunCallback", ex);
                            }
                            finally
                            {
                                syncInfo.SyncEnd();
                            }
                        }
                        else
                        {
                            LogWrite("Labels printing in-progress");
                        }
                    }
                    else
                    {
                        LogWrite("Order Sync already runned");
                    }
                }
            }
        }
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        log       = GetLogger();

            var now = time.GetAppNowTime();

            if (!time.IsBusinessDay(now))
            {
                return;
            }

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }
            var fromAddressList = new CompanyAddressService(company);

            var serviceFactory = new ServiceFactory();
            var pdfMaker       = new PdfMakerByIText(GetLogger());
            var actionService  = new SystemActionService(log, time);
            var addressService = new AddressService(null,
                                                    fromAddressList.GetReturnAddress(MarketIdentifier.Empty()),
                                                    fromAddressList.GetPickupAddress(MarketIdentifier.Empty()));
            var emailSmtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService      = new EmailService(GetLogger(), emailSmtpSettings, addressService);

            var weightService = new WeightService();

            var orderHistoryService = new OrderHistoryService(log, time, dbFactory);
            var batchManager        = new BatchManager(log, time, orderHistoryService, weightService);
            var labelBatchService   = new LabelBatchService(dbFactory,
                                                            actionService,
                                                            log,
                                                            time,
                                                            weightService,
                                                            serviceFactory,
                                                            emailService,
                                                            batchManager,
                                                            pdfMaker,
                                                            AddressService.Default,
                                                            orderHistoryService,
                                                            AppSettings.DefaultCustomType,
                                                            AppSettings.LabelDirectory,
                                                            AppSettings.ReserveDirectory,
                                                            AppSettings.TemplateDirectory,
                                                            new LabelBatchService.Config()
            {
                PrintErrorsToEmails = new[] { company.SellerEmail, company.SellerWarehouseEmailAddress },
                PrintErrorsCCEmails = new[] { EmailHelper.RaananEmail, EmailHelper.SupportDgtexEmail },
            },
                                                            AppSettings.IsSampleLabels);

            var autoPurchaseService = new LabelAutoBuyService(dbFactory,
                                                              log,
                                                              time,
                                                              batchManager,
                                                              labelBatchService,
                                                              actionService,
                                                              emailService,
                                                              weightService,
                                                              company.Id);

            autoPurchaseService.PurchaseAmazonNextDay();
        }
Exemple #23
0
        protected override void RunCallback()
        {
            var        dbFactory = new DbFactory();
            CompanyDTO company;

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var time                = new TimeService(dbFactory);
            var log                 = GetLogger();
            var serviceFactory      = new ServiceFactory();
            var actionService       = new SystemActionService(GetLogger(), time);
            var notificationService = new NotificationService(GetLogger(), time, dbFactory);
            var companyAddress      = new CompanyAddressService(company);
            var addressService      = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));

            var emailService = new EmailService(GetLogger(),
                                                SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels),
                                                addressService);


            var ruleList = new List <ITrackingRule>()
            {
                new NeverShippedTrackingRule(GetLogger(), notificationService, time),
                new GetStuckTrackingRule(GetLogger(), notificationService, time),
                new NoticeLeftTrackingRule(GetLogger(), actionService, addressService, time),
                new UndeliverableAsAddressedTrackingRule(GetLogger(), actionService, addressService, emailService, time)
            };

            var trackingService = new TrackingManager(GetLogger(),
                                                      actionService,
                                                      addressService,
                                                      emailService,
                                                      time,
                                                      ruleList);

            var trackingProviderTypes = new List <ShipmentProviderType>()
            {
                ShipmentProviderType.Stamps,
                ShipmentProviderType.Dhl,
                //ShipmentProviderType.DhlECom,
                ShipmentProviderType.FedexOneRate,
            };

            using (var db = dbFactory.GetRWDb())
            {
                foreach (var trackingProviderType in trackingProviderTypes)
                {
                    try
                    {
                        var trackingProvider = serviceFactory.GetTrackingProviderByType(trackingProviderType,
                                                                                        company,
                                                                                        company.ShipmentProviderInfoList,
                                                                                        dbFactory,
                                                                                        log,
                                                                                        time);

                        if (trackingProvider == null)
                        {
                            continue;
                        }

                        LogWrite("UpdateAllShippedOrderStatus " + trackingProviderType);
                        UpdateAllShippedOrderStatus(trackingService,
                                                    time,
                                                    db,
                                                    trackingProvider,
                                                    company);
                    }
                    catch (Exception ex)
                    {
                        LogError("TrackingProviderType: " + trackingProviderType, ex);
                    }
                }
            }
        }