public YandexMarketCategoryRecord Parse(ref bool isStopProducsImport) { this.mLogger.Debug("Start Parsing Category ..."); YandexMarketCategoryRecord resultCategory = null; try { this.mDriver = new InternetExplorerDriver(); this.mDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(60)); // —сылка на список товаров this.mDriver.Navigate().GoToUrl(this.UrlCategoryForParsing); resultCategory = GetParserCategory(); } catch (Exception ex) { this.mLogger.Debug(ex.Message, ex); throw; } finally { this.mDriver.Quit(); } this.mLogger.Debug("End Parsing."); return(resultCategory); }
private YandexMarketCategoryRecord InsertParserCategoryHierarhy(YandexMarketCategoryRecord yaCategory) { var oldYaCategory = this._yandexMarketCategoryService.GetAll() .SingleOrDefault(x => x.Name == yaCategory.Name && x.ParentId == yaCategory.ParentId); if (oldYaCategory != null) { return(oldYaCategory); } // Создаем только листья, категории-контейнеры для других категорий нам не нужны для парсенья if (yaCategory.Children.Count == 0) { _yandexMarketCategoryService.Insert(yaCategory); } foreach (var currentYaCategory in yaCategory.Children) { currentYaCategory.ParentId = yaCategory.Id; InsertParserCategoryHierarhy(currentYaCategory); } return(yaCategory); }
private YandexMarketCategoryRecord ProcessCategory(JsonCategory category, JsonCategory[] categoriesArray) { var newCategory = new YandexMarketCategoryRecord() { IsActive = true, Name = category.name, ParentId = int.Parse(category.pid), Url = ToFulUrl(category.url), Id = int.Parse(category.id), Children = new List <YandexMarketCategoryRecord>(), }; if (newCategory.Url == UrlCategoryForCompare) { mNeededCategory = newCategory; } if (category.have_children) { var children = categoriesArray.Where(x => x.pid == category.id); foreach (var child in children) { var newChild = ProcessCategory(child, categoriesArray); newCategory.Children.Add(newChild); } } return(newCategory); }
protected override YandexMarketCategoryRecord GetParserCategory() { var resultCategoriesHierarchy = new List <YandexMarketCategoryRecord>(); string source = mDriver.PageSource; var indexStart = source.IndexOf("var CATEGORIES = [", System.StringComparison.Ordinal) + "var CATEGORIES = [".Length - 1; var indexEnd = source.IndexOf("}];", indexStart, System.StringComparison.Ordinal); var categoriesText = source.Substring(indexStart, indexEnd - indexStart + 2); var categoriesArray = JsonConvert.DeserializeObject <JsonCategory[]>(categoriesText); // всем елементам меню верхнего уровня foreach (var currentCategory in categoriesArray.Where(x => x.level == 0)) { var category = ProcessCategory(currentCategory, categoriesArray); resultCategoriesHierarchy.Add(category); if (category.Url == UrlCategoryForCompare) { mNeededCategory = category; } } return(mNeededCategory); }
/// <summary> /// Deletes a tax rate /// </summary> /// <param name="category">Tax rate</param> public virtual void Delete(YandexMarketCategoryRecord category) { if (category == null) { throw new ArgumentNullException("YandexMarketCategoryRecord"); } this._categoryRepository.Delete(category); this._cacheManager.RemoveByPattern(YANDEXMARKETCATEGORY_PATTERN_KEY); }
public ActionResult Add(YandexMarketParserModel model) { var newItem = new YandexMarketCategoryRecord() { Name = model.AddCategoryName }; _yandexMarketCategoryService.Insert(newItem); return(Json(new { Result = true })); }
public ActionResult Add(YandexMarketParserModel model) { var newItem = new YandexMarketCategoryRecord() { Name = model.AddParserCategoryName, Url = model.AddParserCategoryUrl, ShopCategoryId = model.AddShopCategoryId, IsActive = model.AddIsActive, }; this._yandexMarketCategoryService.Insert(newItem); return(Json(new { Result = true })); }
private Category InsertShopCategoryHierarhy(YandexMarketCategoryRecord yaCategory) { var oldShopCategory = this._shopCategoryService.GetAllCategoriesByParentCategoryId(yaCategory.ParentId).SingleOrDefault(x => x.Name == yaCategory.Name); if (oldShopCategory != null) { return(oldShopCategory); } var newShopCategory = new Category() { Name = yaCategory.Name, ParentCategoryId = yaCategory.ParentId, Published = true, CategoryTemplateId = 1, PageSize = 4, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow, PageSizeOptions = "8, 4, 20, 50", PriceRanges = "-10;10-30;30-70;70-100;100-150;150-200; 200-300;300-500;500-800;800-1000;1000-1500;1500-2000;2000-3000;3000-5000;5000-8000;8000-12000;12000-15000;15000-;", AllowCustomersToSelectPageSize = true, }; _shopCategoryService.InsertCategory(newShopCategory); yaCategory.ShopCategoryId = newShopCategory.Id; var seName = newShopCategory.ValidateSeName("", newShopCategory.Name, true); _urlRecordService.SaveSlug(newShopCategory, seName, 0); foreach (var currentCategory in yaCategory.Children) { currentCategory.ParentId = newShopCategory.Id; InsertShopCategoryHierarhy(currentCategory); } return(newShopCategory); }
private List <YandexMarketCategoryRecord> GetTestData() { var resultProductList = new List <YandexMarketCategoryRecord>(); var level_0_1 = new YandexMarketCategoryRecord() { Id = 1, IsActive = true, Name = "level_0_1", ParentId = 0, ShopCategoryId = 0, Url = "someUrl", Children = new List <YandexMarketCategoryRecord>() }; resultProductList.Add(level_0_1); var level_1_1 = new YandexMarketCategoryRecord() { Id = 2, IsActive = true, Name = "level_1_1", ParentId = 1, ShopCategoryId = 0, Url = "someUrl", Children = new List <YandexMarketCategoryRecord>() }; var level_0_2 = new YandexMarketCategoryRecord() { Id = 3, IsActive = true, Name = "level_0_2", ParentId = 0, ShopCategoryId = 0, Url = "someUrl", Children = new List <YandexMarketCategoryRecord>() }; resultProductList.Add(level_0_2); var level_1_2 = new YandexMarketCategoryRecord() { Id = 4, IsActive = true, Name = "level_1_2", ParentId = 3, ShopCategoryId = 0, Url = "someUrl", Children = new List <YandexMarketCategoryRecord>() }; level_0_2.Children.Add(level_1_2); level_0_1.Children.Add(level_1_1); return(resultProductList); }