Example #1
0
        /// <summary>
        /// Executes a task
        /// </summary>
        public void Execute()
        {
            //IImportManager importManager = EngineContext.Current.Resolve<IImportManager>();
            //IExportManager exportManager = EngineContext.Current.Resolve<IExportManager>();
            INebimIntegrationImportService nebimIntegrationImportService = EngineContext.Current.Resolve <INebimIntegrationImportService>();
            var logger                   = EngineContext.Current.Resolve <ILogger>();
            var settingService           = EngineContext.Current.Resolve <ISettingService>();
            var nebimIntegrationSettings = EngineContext.Current.Resolve <NebimIntegrationSettings>();

            //all products sync, task interval is 5 minutes!
            //products sync will be executed between 4:00-4:09 am(UTC)
            #region Products Sync
            //check product sync enabled
            if (!nebimIntegrationSettings.ProductsSyncEnabled)
            {
                return;
            }
            int intervalMinutes = 20;
            if (DateTime.UtcNow.TimeOfDay < new TimeSpan(0, nebimIntegrationSettings.ProductsSyncStartTimeMinutes, 0))
            {
                return;
            }
            if (DateTime.UtcNow.TimeOfDay > new TimeSpan(0, nebimIntegrationSettings.ProductsSyncStartTimeMinutes + intervalMinutes, 0))
            {
                return;
            }
            //ensure previous executaion is 1 hour ago!
            DateTime lastUpdateTime = DateTime.FromBinary(nebimIntegrationSettings.LastProductsSyncTime);
            lastUpdateTime = DateTime.SpecifyKind(lastUpdateTime, DateTimeKind.Utc);
            if (lastUpdateTime.AddHours(1) < DateTime.UtcNow)
            {
                logger.Information("Task:Product sync started");
                //do products sync
                nebimIntegrationImportService.ImportAllProducts();

                //save new update time value
                nebimIntegrationSettings.LastProductsSyncTime = DateTime.UtcNow.ToBinary();
                settingService.SaveSetting(nebimIntegrationSettings);
                logger.Information("Task:Product sync finished");
            }


            #endregion Products Sync


            #region Orders Sync

            //logger.Information("Task:Orders sync started");
            //nebimIntegrationService.AddUpdateOrdersToNebim();
            //logger.Information("Task:Orders sync finished");

            #endregion Orders Sync
        }
 public ExternalIntegrationController(IProductService productService,
                                      IProductTemplateService productTemplateService,
                                      ICategoryService categoryService, IManufacturerService manufacturerService,
                                      IWorkContext workContext, ILanguageService languageService,
                                      ILocalizationService localizationService, ILocalizedEntityService localizedEntityService,
                                      ISpecificationAttributeService specificationAttributeService, IPictureService pictureService,
                                      ITaxCategoryService taxCategoryService, IProductTagService productTagService,
                                      ICopyProductService copyProductService, IPdfService pdfService,
                                      IExportManager exportManager, IImportManager importManager,
                                      ICustomerActivityService customerActivityService,
                                      IPermissionService permissionService, AdminAreaSettings adminAreaSettings, ICurrencyService currencyService,
                                      CurrencySettings currencySettings, IMessageTemplateService messageTemplateService,
                                      INebimIntegrationService nebimIntegrationService, INebimIntegrationImportService nebimIntegrationImportService, IOrderService orderService)
 {
     this._productService                = productService;
     this._productTemplateService        = productTemplateService;
     this._categoryService               = categoryService;
     this._manufacturerService           = manufacturerService;
     this._workContext                   = workContext;
     this._languageService               = languageService;
     this._localizationService           = localizationService;
     this._localizedEntityService        = localizedEntityService;
     this._specificationAttributeService = specificationAttributeService;
     this._pictureService                = pictureService;
     this._taxCategoryService            = taxCategoryService;
     this._productTagService             = productTagService;
     this._copyProductService            = copyProductService;
     this._pdfService                    = pdfService;
     this._exportManager                 = exportManager;
     this._importManager                 = importManager;
     this._customerActivityService       = customerActivityService;
     this._permissionService             = permissionService;
     this._adminAreaSettings             = adminAreaSettings;
     this._currencyService               = currencyService;
     this._currencySettings              = currencySettings;
     this._messageTemplateService        = messageTemplateService;
     this._nebimIntegrationService       = nebimIntegrationService;
     this._nebimIntegrationImportService = nebimIntegrationImportService;
     this._orderService                  = orderService;
 }