Esempio n. 1
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 }));
        }