public void AutoBuySameDay()
        {
            var orderHistoryService = new OrderHistoryService(_log, _time, _dbFactory);
            var batchManager        = new BatchManager(_log, _time, orderHistoryService, _weightService);
            var actionService       = new SystemActionService(_log, _time);
            var serviceFactory      = new ServiceFactory();

            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(),
                                                          AppSettings.IsSampleLabels);

            var autoPurchaseService = new LabelAutoBuyService(_dbFactory,
                                                              _log,
                                                              _time,
                                                              batchManager,
                                                              labelBatchService,
                                                              actionService,
                                                              _emailService,
                                                              _weightService,
                                                              _company.Id);

            autoPurchaseService.PurchaseForSameDay();
        }
예제 #2
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 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 weigthService       = new WeightService();
            var orderHistoryService = new OrderHistoryService(log, time, dbFactory);
            var batchManager        = new BatchManager(log, time, orderHistoryService, weigthService);

            var labelBatchService = new LabelBatchService(dbFactory,
                                                          actionService,
                                                          log,
                                                          time,
                                                          weigthService,
                                                          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);


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

            autoPurchaseService.PurchaseForSameDay();
        }