Ejemplo n.º 1
0
        private static Client GetClient()
        {
            var service = new WeightService();
            var adapter = new WeightServiceAdapter(service);

            return(new Client(adapter));
        }
 private Version()
 {
     _weightService       = new WeightService();
     _classVersionService = new ClassVersionService();
     _dataSetService      = new DataSetService();
     InitializeComponent();
 }
        protected override void RunCallback()
        {
            var dbFactory = new DbFactory();
            var time      = new TimeService(dbFactory);

            var serviceFactory = new ServiceFactory();

            var log           = GetLogger();
            var weightService = new WeightService();

            using (var db = dbFactory.GetRWDb())
            {
                var providers         = db.ShipmentProviders.GetByCompanyId(CompanyId);
                var shipmentProviders = serviceFactory.GetShipmentProviders(log,
                                                                            time,
                                                                            dbFactory,
                                                                            weightService,
                                                                            providers,
                                                                            null,
                                                                            null,
                                                                            null,
                                                                            null);

                var labelService = new LabelService(shipmentProviders, log, time, dbFactory, null, null, AddressService.Default);

                labelService.UpdateBalance(db,
                                           time.GetAppNowTime());
            }
        }
Ejemplo n.º 4
0
 public Principal()
 {
     _customerService     = new CustomerService();
     _classVersionService = new ClassVersionService();
     _weightService       = new WeightService();
     _notificationService = new NotificationService();
     InitializeComponent();
 }
Ejemplo n.º 5
0
        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 weightService  = new WeightService();
            var messageService = new SystemMessageService(log, time, dbFactory);

            var serviceFactory  = new ServiceFactory();
            var quantityManager = new QuantityManager(log, time);
            var rateProviders   = serviceFactory.GetShipmentProviders(log,
                                                                      time,
                                                                      dbFactory,
                                                                      weightService,
                                                                      company.ShipmentProviderInfoList,
                                                                      null,
                                                                      null,
                                                                      null,
                                                                      null);

            var actionService = new SystemActionService(log, time);

            var commentService = new OrderCommentService(dbFactory,
                                                         log,
                                                         time,
                                                         actionService);

            commentService.ProcessSystemAction();

            var rateService = new RateService(dbFactory,
                                              log,
                                              time,
                                              weightService,
                                              messageService,
                                              company,
                                              actionService,
                                              rateProviders);

            rateService.ProcessSystemAction(CancellationToken);


            var quantityDistribution = new QuantityDistributionService(dbFactory,
                                                                       quantityManager,
                                                                       log,
                                                                       time,
                                                                       QuantityDistributionHelper.GetDistributionMarkets(),
                                                                       DistributeMode.None);

            quantityDistribution.ProcessSystemAction(actionService);
        }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="shiftService"></param>
 /// <param name="doctorService"></param>
 /// <param name="patientService"></param>
 /// <param name="patientContactService"></param>
 /// <param name="dialysisService"></param>
 /// <param name="bloodPressureService"></param>
 /// <param name="weightService"></param>
 public SyncController(ShiftService shiftService, DoctorService doctorService, PatientService patientService, PatientContactService patientContactService,
                       DialysisService dialysisService, BloodPressureService bloodPressureService, WeightService weightService)
 {
     _shiftService          = shiftService;
     _doctorService         = doctorService;
     _patientService        = patientService;
     _patientContactService = patientContactService;
     _dialysisService       = dialysisService;
     _bloodPressureService  = bloodPressureService;
     _weightService         = weightService;
 }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="service"></param>
 public PatientController(PatientService service, WeightService weightService, BloodPressureService bloodPressureService, BloodSugarService bloodSugarService, WaterService waterService, HandRingService handRingService, DialysisService dialysisService, HospitalService hospitalService, DoctorService doctorService)
 {
     _service              = service;
     _weightService        = weightService;
     _bloodPressureService = bloodPressureService;
     _bloodSugarService    = bloodSugarService;
     _waterService         = waterService;
     _handRingService      = handRingService;
     _dialysisService      = dialysisService;
     _hospitalService      = hospitalService;
     _doctorService        = doctorService;
 }
        public void TestGetOneRateRates(string orderId)
        {
            var weightService  = new WeightService();
            var companyAddress = new CompanyAddressService(_company);

            using (var db = _dbFactory.GetRWDb())
            {
                var order                 = db.ItemOrderMappings.GetOrderWithItems(weightService, orderId, unmaskReferenceStyle: false, includeSourceItems: true);
                var shippingService       = ShippingUtils.InitialShippingServiceIncludeUpgrade(order.InitialServiceType, order.UpgradeLevel); //order.ShippingService
                var orderItemInfoes       = OrderHelper.BuildAndGroupOrderItems(order.Items);
                var sourceOrderItemInfoes = OrderHelper.BuildAndGroupOrderItems(order.SourceItems);

                var serviceFactory = new ServiceFactory();

                var rateProviders = serviceFactory.GetShipmentProviders(_log,
                                                                        _time,
                                                                        _dbFactory,
                                                                        weightService,
                                                                        _company.ShipmentProviderInfoList,
                                                                        AppSettings.DefaultCustomType,
                                                                        AppSettings.LabelDirectory,
                                                                        AppSettings.LabelDirectory,
                                                                        AppSettings.LabelDirectory);

                var fedexRateProvider = rateProviders.FirstOrDefault(r => r.Type == ShipmentProviderType.FedexOneRate);

                var rates = fedexRateProvider.GetLocalRate(
                    companyAddress.GetReturnAddress(order.GetMarketId()),
                    companyAddress.GetPickupAddress(order.GetMarketId()),
                    order.GetAddressDto(),
                    _time.GetAppNowTime(),
                    order.WeightD,
                    null,
                    order.IsInsured ? order.TotalPrice : 0,
                    order.IsSignConfirmation,
                    new OrderRateInfo()
                {
                    ShippingService    = shippingService,
                    InitialServiceType = order.InitialServiceType,
                    OrderNumber        = order.OrderId,
                    Items       = orderItemInfoes,
                    SourceItems = sourceOrderItemInfoes,
                    TotalPrice  = order.TotalPrice,
                    Currency    = order.TotalPriceCurrency,
                },
                    RetryModeType.Normal);


                _log.Info("Rates: " + rates.Rates.Count);
            }
        }
Ejemplo n.º 9
0
        public void UpgradeOrderList(IList <long> orderIds)
        {
            var syncInfo       = new EmptySyncInformer(_log, SyncType.Orders);
            var serviceFactory = new ServiceFactory();
            var weightService  = new WeightService();
            var messageService = new SystemMessageService(_log, _time, _dbFactory);

            var rateProviders = serviceFactory.GetShipmentProviders(_log,
                                                                    _time,
                                                                    _dbFactory,
                                                                    weightService,
                                                                    _company.ShipmentProviderInfoList,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    null);

            var companyAddress = new CompanyAddressService(_company);

            var synchronizer = new AmazonOrdersSynchronizer(_log,
                                                            _company,
                                                            syncInfo,
                                                            rateProviders,
                                                            companyAddress,
                                                            _time,
                                                            weightService,
                                                            messageService);

            using (var db = _dbFactory.GetRWDb())
            {
                IList <DTOOrder> dtoOrders = db.ItemOrderMappings.GetSelectedOrdersWithItems(weightService, orderIds.ToArray(), includeSourceItems: true).ToList();
                foreach (var dtoOrder in dtoOrders)
                {
                    _log.Info("Upgrade order: " + dtoOrder.OrderId);
                    //Update into DB, after success update
                    var order = db.Orders.GetById(dtoOrder.Id);
                    order.UpgradeLevel = 1;
                    db.Commit();
                    dtoOrder.UpgradeLevel = 1;

                    if (synchronizer.UIUpdate(db, dtoOrder, false, false, false, null))
                    {
                        _log.Info("Success");
                    }
                    else
                    {
                        _log.Info("Failed");
                    }
                }
            }
        }
Ejemplo n.º 10
0
        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);
        }
 public HomeController(IMemoryCache memoryCache,
                       ILogger <HomeController> log,
                       TickerService tickerService,
                       WeightService weightService,
                       CurrencyService currencyService,
                       IOptions <ExplorerSettings> settings,
                       IOptions <ChainSettings> chainSettings)
 {
     this.memoryCache     = memoryCache;
     this.log             = log;
     this.settings        = settings.Value;
     this.chainSettings   = chainSettings.Value;
     this.tickerService   = tickerService;
     this.weightService   = weightService;
     this.currencyService = currencyService;
 }
Ejemplo n.º 12
0
        protected override void RunCallback()
        {
            CompanyDTO company        = null;
            var        dbFactory      = new DbFactory();
            var        time           = new TimeService(dbFactory);
            var        log            = GetLogger();
            var        weightService  = new WeightService();
            var        messageService = new SystemMessageService(log, time, dbFactory);
            var        serviceFactory = new ServiceFactory();

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

            var actionService = new SystemActionService(log, time);
            var rateProviders = serviceFactory.GetShipmentProviders(log,
                                                                    time,
                                                                    dbFactory,
                                                                    weightService,
                                                                    company.ShipmentProviderInfoList,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    null);


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

            var rateService = new RateService(dbFactory,
                                              log,
                                              time,
                                              weightService,
                                              messageService,
                                              company,
                                              actionService,
                                              rateProviders);

            rateService.RefreshAmazonRates();
            rateService.RefreshSuspiciousFedexRates();
        }
        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();
        }
Ejemplo n.º 14
0
 public WeightServiceAdapter(WeightService service)
 {
     this.service = service;
 }
Ejemplo n.º 15
0
 public WeightDetail()
 {
     _dataSetService = new DataSetService();
     _weightService  = new WeightService();
     InitializeComponent();
 }
Ejemplo n.º 16
0
        public void CallProcessEBayOrders(string orderNumber)
        {
            var syncInfo             = new DbSyncInformer(_dbFactory, _log, _time, SyncType.Orders, "", MarketType.eBay, String.Empty);
            var settings             = new SettingsService(_dbFactory);
            var dbFactory            = new DbFactory();
            var quantityManager      = new QuantityManager(_log, _time);
            var priceService         = new PriceService(dbFactory);
            var serviceFactory       = new ServiceFactory();
            var addressCheckServices = serviceFactory.GetAddressCheckServices(_log,
                                                                              _time,
                                                                              dbFactory,
                                                                              _company.AddressProviderInfoList);
            var companyAddress = new CompanyAddressService(_company);
            var addressService = new AddressService(addressCheckServices, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            var weightService  = new WeightService();
            var messageService = new SystemMessageService(_log, _time, _dbFactory);

            var rateProviders = serviceFactory.GetShipmentProviders(_log,
                                                                    _time,
                                                                    dbFactory,
                                                                    weightService,
                                                                    _company.ShipmentProviderInfoList,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    null);

            var stampsRateProvider = rateProviders.FirstOrDefault(r => r.Type == ShipmentProviderType.Stamps);

            var orderHistoryService = new OrderHistoryService(_log, _time, _dbFactory);
            var validatorService    = new OrderValidatorService(_log, _dbFactory, _emailService, settings, orderHistoryService, _actionService, priceService, _htmlScraper, addressService,
                                                                companyAddress.GetReturnAddress(MarketIdentifier.Empty()), stampsRateProvider, _time, _company);

            var actionService = new SystemActionService(_log, _time);
            var cacheService  = new CacheService(_log, _time, actionService, quantityManager);


            using (var db = _dbFactory.GetRWDb())
            {
                //if (!syncInfo.IsSyncInProgress())
                {
                    try
                    {
                        syncInfo.SyncBegin(null);

                        var synchronizer = new EBayOrdersSynchronizer(_log,
                                                                      _eBayApi,
                                                                      _company,
                                                                      settings,
                                                                      syncInfo,
                                                                      rateProviders,
                                                                      quantityManager,
                                                                      _emailService,
                                                                      validatorService,
                                                                      orderHistoryService,
                                                                      cacheService,
                                                                      _actionService,
                                                                      companyAddress,
                                                                      _time,
                                                                      weightService,
                                                                      messageService);

                        if (String.IsNullOrEmpty(orderNumber))
                        {
                            synchronizer.Sync(OrderSyncModes.Full, null);
                        }
                        else
                        {
                            synchronizer.ProcessSpecifiedOrder(db, orderNumber);
                        }
                    }
                    finally
                    {
                        syncInfo.SyncEnd();
                    }
                }
            }
        }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="service"></param>
 public WeightController(WeightService service)
 {
     _service = service;
 }
        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();
        }
Ejemplo n.º 19
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="service"></param>
 public PatientController(PatientService service, WeightService weightService)
 {
     _service       = service;
     _weightService = weightService;
 }
Ejemplo n.º 20
0
        public void Setup()
        {
            Database.SetInitializer <AmazonContext>(null);
            XmlConfigurator.Configure(new FileInfo(AppSettings.log4net_Config));

            _dbFactory = new DbFactory();
            _time      = new TimeService(_dbFactory);
            _settings  = new SettingsService(_dbFactory);

            _styleHistoryService = new StyleHistoryService(_log, _time, _dbFactory);
            _styleManager        = new StyleManager(_log, _time, _styleHistoryService);
            _actionService       = new SystemActionService(_log, _time);
            _quantityManager     = new QuantityManager(_log, _time);
            _priceManager        = new PriceManager(_log, _time, _dbFactory, _actionService, _settings);
            _cacheService        = new CacheService(_log, _time, _actionService, _quantityManager);
            _barcodeService      = new BarcodeService(_log, _time, _dbFactory);
            _weightService       = new WeightService();

            IEmailSmtpSettings smtpSettings = new EmailSmtpSettings();

            using (var db = new UnitOfWork())
            {
                _company = db.Companies.GetFirstWithSettingsAsDto();

                if (AppSettings.IsDebug)
                {
                    smtpSettings = SettingsBuilder.GetSmtpSettingsFromAppSettings();
                }
                else
                {
                    smtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(_company);
                }

                _addressService = AddressService.Default;
                _emailService   = new EmailService(_log, smtpSettings, _addressService);

                //todo check itemHist
                _autoCreateNonameListingService = new AutoCreateNonameListingService(_log,
                                                                                     _time,
                                                                                     _dbFactory,
                                                                                     _cacheService,
                                                                                     _barcodeService,
                                                                                     _emailService, null,
                                                                                     AppSettings.IsDebug);

                var marketplaces = new MarketplaceKeeper(_dbFactory, true);
                marketplaces.Init();

                var shipmentPrividers = db.ShipmentProviders.GetByCompanyId(_company.Id);

                var apiFactory = new MarketFactory(marketplaces.GetAll(), _time, _log, _dbFactory, AppSettings.JavaPath);

                var weightService = new WeightService();

                var serviceFactory = new ServiceFactory();
                var rateProviders  = serviceFactory.GetShipmentProviders(_log,
                                                                         _time,
                                                                         _dbFactory,
                                                                         weightService,
                                                                         shipmentPrividers,
                                                                         null,
                                                                         null,
                                                                         null,
                                                                         null);

                _magentoApi    = (Magento20MarketApi)apiFactory.GetApi(_company.Id, MarketType.Magento, MarketplaceKeeper.ShopifyDWS);
                _shopifyDWSApi = (ShopifyApi)apiFactory.GetApi(_company.Id, MarketType.Shopify, MarketplaceKeeper.ShopifyDWS);
                _eBayApi       = (eBayApi)apiFactory.GetApi(_company.Id, MarketType.eBay, "");
                _amazonApi     = (AmazonApi)apiFactory.GetApi(_company.Id, MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId);
                _walmartApi    = (WalmartApi)apiFactory.GetApi(_company.Id, MarketType.Walmart, "");
            }
        }
Ejemplo n.º 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");
                    }
                }
            }
        }
 public CreateWeightVersion()
 {
     _weightService = new WeightService();
     InitializeComponent();
 }
        public void TestGetLabel(string orderId)
        {
            var weightService  = new WeightService();
            var companyAddress = new CompanyAddressService(_company);

            using (var db = _dbFactory.GetRWDb())
            {
                var order                 = db.ItemOrderMappings.GetOrderWithItems(weightService, orderId, unmaskReferenceStyle: false, includeSourceItems: true);
                var shippingService       = ShippingUtils.InitialShippingServiceIncludeUpgrade(order.InitialServiceType, order.UpgradeLevel); //order.ShippingService
                var orderItemInfoes       = OrderHelper.BuildAndGroupOrderItems(order.Items);
                var sourceOrderItemInfoes = OrderHelper.BuildAndGroupOrderItems(order.SourceItems);

                var serviceFactory = new ServiceFactory();

                var rateProviders = serviceFactory.GetShipmentProviders(_log,
                                                                        _time,
                                                                        _dbFactory,
                                                                        weightService,
                                                                        _company.ShipmentProviderInfoList,
                                                                        AppSettings.DefaultCustomType,
                                                                        AppSettings.LabelDirectory,
                                                                        AppSettings.LabelDirectory,
                                                                        AppSettings.LabelDirectory);

                var fimsProvider = rateProviders.FirstOrDefault(r => r.Type == ShipmentProviderType.FIMS);

                //var rates = fedexRateProvider.GetLocalRate(
                //        companyAddress.GetReturnAddress(order.GetMarketId()),
                //        companyAddress.GetPickupAddress(order.GetMarketId()),
                //        order.GetAddressDto(),
                //        _time.GetAppNowTime(),
                //        order.WeightD,
                //        order.IsInsured ? order.TotalPrice : 0,
                //        order.IsSignConfirmation,
                //        new OrderRateInfo()
                //        {
                //            ShippingService = shippingService,
                //            InitialServiceType = order.InitialServiceType,
                //            OrderNumber = order.OrderId,
                //            Items = orderItemInfoes,
                //            SourceItems = sourceOrderItemInfoes,
                //            TotalPrice = order.TotalPrice,
                //            Currency = order.TotalPriceCurrency,
                //        },
                //        RetryModeType.Normal);

                var shipmentInfo = new OrderShippingInfoDTO()
                {
                    OrderAmazonId      = order.OrderId,
                    WeightD            = order.WeightD,
                    IsInsured          = order.IsInsured,
                    TotalPrice         = order.TotalPrice,
                    TotalPriceCurrency = order.TotalPriceCurrency,

                    IsSignConfirmation = order.IsSignConfirmation,

                    Items = orderItemInfoes.Select(oi => new DTOOrderItem()
                    {
                        ItemOrderId = oi.ItemOrderId,
                        ItemPrice   = oi.ItemPrice,
                        Weight      = oi.Weight,
                        Quantity    = oi.Quantity,
                    }).ToList(),
                    ShippingMethod = new ShippingMethodDTO()
                    {
                    },
                };

                var shipDate = db.Dates.GetOrderShippingDate(null);

                var boughtInTheCountry = MarketBaseHelper.GetMarketCountry((MarketType)order.Market, order.MarketplaceId);
                //var callResult = labelProvider.CreateShipment(shipmentInfo,
                //    returnAddress,
                //    pickupAddress,
                //    toAddress,
                //    shipDate.Date,
                //    model.Notes,
                //    !model.ShippingMethod.IsSupportReturnToPOBox,
                //    sampleMode,
                //    fromUI: true);


                var labels = fimsProvider.CreateShipment(
                    shipmentInfo,
                    companyAddress.GetReturnAddress(order.GetMarketId()),
                    companyAddress.GetPickupAddress(order.GetMarketId()),
                    order.GetAddressDto(),
                    boughtInTheCountry,
                    shipDate,
                    "",
                    false,
                    false,
                    false);


                _log.Info("Labels: " + labels.Data.LabelFileList.Count);
            }
        }