示例#1
0
        public ActionResult GetNewSpecs()
        {
            var activeParserCategoriesIdList = _yandexMarketCategoryService.GetActive().Select(x => x.Id);
            var newSpecsOnly = _GetNewSpecs(activeParserCategoriesIdList);

            foreach (var specificationAttribute in newSpecsOnly)
            {
                specificationAttribute.Order();
            }


            return(Json(newSpecsOnly));
        }
        public ActionResult ImportProductList()
        {
            mIsStopProducsImport = false;

            _logger.Debug("--- ImportProductList START...");

            var productsToImportTotalCount = _yandexMarketProductService.GetByCategory(categoryId: 0, isNotImportedOnly: true, isActiveOnly: true).TotalCount;
            var parserCategories           = _yandexMarketCategoryService.GetActive();

            _logger.Debug("--- Will be import categories: " + parserCategories.Count + ". Products: " + productsToImportTotalCount);


            var totalImportedCounter = 0;

            var allSpecAttrList = _specificationAttributeService.GetSpecificationAttributes();

            int currentCategoryIndex = 1;

            // цикл по активным категориям
            foreach (var currentParserCategory in parserCategories)
            {
                var records = _yandexMarketProductService.GetByCategory(currentParserCategory.Id, isNotImportedOnly: true);

                var categoryProductCounter = 1;

                _logger.Debug("--- Start Category (" + currentCategoryIndex + " from " + parserCategories.Count + ") " + currentParserCategory.Name + ". Will be imported products: " + records.TotalCount);
                foreach (var curYaProduct in records)
                {
                    CheckStopAction();

                    var isImported = ImportYaProduct(curYaProduct, currentParserCategory.ShopCategoryId, allSpecAttrList);


                    if (totalImportedCounter % 10 == 0)                     // через каждые 5 записей выводить в лог сообщение
                    {
                        _logger.Debug("... imported products in current category: " + categoryProductCounter + ", in general: " + totalImportedCounter + " from " + productsToImportTotalCount + "...");
                    }

                    if (isImported)
                    {
                        categoryProductCounter++;
                        totalImportedCounter++;
                    }
                }

                _logger.Debug("--- End Category imported " + currentParserCategory.Name + ". In general: " + totalImportedCounter + " from " + productsToImportTotalCount);

                currentCategoryIndex++;
            }

            _priceManagerService.ApplyImportAll();
            _logger.Debug("--- ImportProductList for End.");

            return(Content("Success"));
        }
示例#3
0
        public ActionResult Parse(YandexMarketParserModel model)
        {
            mIsStopProducsImport = false;

            _logger.Debug("--- ALL PARSE START...");

            int foundNewProductsTotal  = 0;
            var activeParserCategories = _yandexMarketCategoryService.GetActive();

            foreach (var currentCategory in activeParserCategories)
            {
                CheckStopAction();

                _logger.Debug("---  PARSE START FOR CATEGORY " + currentCategory.Name + "...");

                if (!this.ModelState.IsValid)
                {
                    throw new Exception("ModelState.IsNOTValid");
                }

                if (model.IsClearCategoryProductsBeforeParsing)
                {
                    _logger.Debug("Deleting old products...");
                    _yandexMarketProductService.DeleteByCategory(currentCategory.Id);
                }


                var categoryName   = currentCategory.Name;
                var parser         = BaseParser.Create(categoryName, currentCategory.Id, model.ParseNotMoreThen, currentCategory.Url, _logger, _yandexMarketProductService);
                var newProductList = parser.Parse(ref mIsStopProducsImport);

                foundNewProductsTotal += newProductList.Count;
                _logger.Debug("+++ PARSE CATEGORY " + currentCategory.Name + " DONE. Found new products: " + newProductList.Count);
            }            // end for

            _logger.Debug("Found new products total: " + foundNewProductsTotal);
            _logger.Debug("+++ ALL PARSING DONE.");
            return(Json(new { Result = true }));
        }