/// <summary> /// Import categories to elasatic search /// DEPRECATED. Do not use anymore. Use ImportDepartments instead. /// </summary> public void ImportCategories() { try { DateTime start = DateTime.Now; _eventLog.WriteInformationLog(String.Format("ETL: Import Process Starting: Import categories to CS {0}", start.ToString())); var parentCategories = _stagingRepository.ReadParentCategories(); var childCategories = _stagingRepository.ReadSubCategories(); var categories = new BlockingCollection <ElasticSearchCategoryUpdate>(); //Parent Categories //Parallel.ForEach(parentCategories.AsEnumerable(), row => foreach (DataRow row in parentCategories.Rows) { categories.Add(new ElasticSearchCategoryUpdate() { index = new ESCategoryRootData() { _id = row.GetString("CategoryId"), data = new ESCategoryData() { parentcategoryid = null, name = row.GetString("CategoryName"), ppicode = row.GetString("PPICode"), subcategories = PopulateSubCategories(row.GetString("CategoryId"), childCategories) } } }); } ; //Sub Categories //Parallel.ForEach(childCategories.AsEnumerable(), row => foreach (DataRow row in childCategories.Rows) { categories.Add(new ElasticSearchCategoryUpdate() { index = new ESCategoryRootData() { _id = row.GetString("CategoryId"), data = new ESCategoryData() { parentcategoryid = row.GetString("ParentCategoryId"), name = row.GetString("CategoryName"), ppicode = row.GetString("PPICode") } } }); } _elasticSearchRepository.Create(string.Concat(categories.Select(c => c.ToJson()))); TimeSpan took = DateTime.Now - start; _eventLog.WriteInformationLog(String.Format("ETL: Import Process Finished: Import categories to CS. Process took {0}", took.ToString())); } catch (Exception e) { _eventLog.WriteErrorLog(String.Format("ETL: Error importing categories to CS -- whole process failed. {0} -- {1}", e.Message, e.StackTrace)); } }
private MSCommerceCatalogCollection2CatalogCategory[] GenerateCategories() { List <MSCommerceCatalogCollection2CatalogCategory> categories = new List <MSCommerceCatalogCollection2CatalogCategory>(); var prefixesToExclude = Configuration.CategoryPrefixesToExclude.Split(',') .ToList(); var dataTable = stagingRepository.ReadParentCategories(); var childTable = stagingRepository.ReadSubCategories(); foreach (DataRow cat in dataTable.Rows) { var newSubCat = new MSCommerceCatalogCollection2CatalogCategory() { name = cat.GetString("CategoryId"), Definition = "Category" }; newSubCat.DisplayName = CreateDisplayName(cat.GetString("CategoryName")); categories.Add(newSubCat); } foreach (DataRow subCat in childTable.Rows) { if (prefixesToExclude.Contains(subCat.GetString("CategoryId") .Substring(0, 2))) { continue; } var newSubCat = new MSCommerceCatalogCollection2CatalogCategory() { name = subCat.GetString("CategoryId"), Definition = "Category" }; newSubCat.DisplayName = CreateDisplayName(subCat.GetString("CategoryName")); newSubCat.ParentCategory = new ParentCategory[1] { new ParentCategory() { Value = string.Format("{0}000", subCat.GetString("CategoryId", true) .Substring(0, 2)) } }; categories.Add(newSubCat); } return(categories.ToArray()); }