public IEnumerable <DimVal> GetTopLevelBrowseDimVals() { var result = new List <DimVal>(); var usedDimensionIds = new List <long>(); var sections = EndecaUtils.GetRefinements(new List <long> { 0, EndecaSectionId }, null, false, true) .GetDimension(EndecaSectionId).Refinements; foreach (var sectionDimVal in sections.Cast <DimVal>()) { // Replacing var dimensionValueLinks = GetDimensionValueLinks(828847, sectionDimVal, null, false); var sectionValue = sectionDimVal; var dimensionId = TopCategoryId; var dims = ProcessDimVals(sectionValue, dimensionId, string.Empty, string.Empty, false, null, false); foreach (var dimVal in dims) { if (!usedDimensionIds.Contains(dimVal.Id)) { result.Add(dimVal); usedDimensionIds.Add(dimVal.Id); } } } return(result); }
private void DoBrandUpdates() { Log.Info("Starting to work on brands."); ResetCounters(); // First get all the Indigo brands. var indigoBrands = _indigoBrandService.GetAllBrands().ToList(); // Load all the brands from Endeca var brands = EndecaUtils.GetPageLinks(EndecaBrandEnId, false, true).ToList(); if (brands.Any()) { var time = DateTime.Now; var processedIds = new List <long>(); foreach (var brand in brands) { var id = brand.DimensionValue.Id; if (processedIds.Contains(id)) { continue; } processedIds.Add(id); var name = EndecaUtils.GetLocalizedTitle(brand.DimensionValue, false); var newBrand = new IndigoBrand { DateCreated = time, EndecaDimensionId = id, Name = name }; var match = indigoBrands.FirstOrDefault(i => i.EndecaDimensionId == id); if (match == null) { _indigoBrandService.Insert(newBrand); _newItemCount++; } else { if (match.Name.Equals(name, StringComparison.OrdinalIgnoreCase)) { _unmodifiedItemCount++; } else { _indigoBrandService.Delete(match.IndigoBrandId); _indigoBrandService.Insert(newBrand); _modifiedItemCount++; } indigoBrands.Remove(match); } } // If there are any items remaining in the Indigo list, then display a message and move on if (indigoBrands.Any()) { Log.InfoFormat("There are {0} brands that weren't found in Endeca. Keeping those brands in the database and moving on.", indigoBrands.Count); } } Log.InfoFormat("Completed working on brands. There were {0} new, {1} modified and {2} unchanged brands.", _newItemCount, _modifiedItemCount, _unmodifiedItemCount); }
public IEnumerable <DimVal> ProcessDimVals(DimVal dimFirst, long dimensionId, string idTrail, string breadcrumbTrail, bool appendBreadcrumbTrail, int?indigoParentCategoryId, bool enforceUpdate, DimVal dimSecond = null, bool isFrench = false) { var result = new List <DimVal>(); if (string.IsNullOrWhiteSpace(breadcrumbTrail)) { breadcrumbTrail = string.Empty; } if (string.IsNullOrWhiteSpace(idTrail)) { idTrail = string.Empty; } DimVal dimensionValue = dimSecond; var sectionValue = dimFirst; var dimValList = dimensionValue == null ? new List <DimVal> { sectionValue } : new List <DimVal> { sectionValue, dimensionValue }; var dimension = EndecaUtils.GetRefinements(new List <long> { EndecaSectionId, dimensionId }, dimValList, false, false) .GetDimension(dimensionId); if (dimension != null && dimension.Refinements != null && dimension.Refinements.Count > 0) { var dimensionRefinements = dimension.Refinements; if (dimensionRefinements.Count > 0) { var placeHolderBreadcrumbTrail = breadcrumbTrail; var placeHolderIdTrail = idTrail; foreach (var dimRef in dimensionRefinements) { var dimVal = (DimVal)dimRef; idTrail += IdTrailSplitter + dimVal.Id; breadcrumbTrail += BreadcrumbTrailSplitter + dimVal.Name; IIndigoCategory match = null; var hasChanged = enforceUpdate; if (appendBreadcrumbTrail) { Log.Debug(idTrail + ":" + breadcrumbTrail); match = _existingIndigoCategories.FirstOrDefault(ic => ic.EndecaBreadcrumbId.Equals(idTrail, StringComparison.OrdinalIgnoreCase)); if (match == null) { var indigoCategory = GetIndigoCategory(indigoParentCategoryId, dimVal.Name, dimVal.GetFrenchName(), idTrail, (int)dimVal.Id, breadcrumbTrail, false); match = _indigoCategoryService.Insert(indigoCategory); _newItemCountDelta++; } else { // Check if the name has changed. If so, update this category and its entire branch as the breadcrumb values have changed if (hasChanged || !(string.Equals(dimVal.Name, match.Name, StringComparison.OrdinalIgnoreCase) && string.Equals(dimVal.GetFrenchName(), match.NameFr, StringComparison.OrdinalIgnoreCase))) { hasChanged = true; match.Name = dimVal.Name; match.NameFr = dimVal.GetFrenchName(); match.BreadcrumbPath = breadcrumbTrail; match.IsModified = true; match.IsDeleted = false; match = _indigoCategoryService.Update(match); _modifiedItemCountDelta++; } else if (match.IsDeleted) { match.IsDeleted = false; match = _indigoCategoryService.Update(match); _modifiedItemCountDelta++; } else { _unmodifiedItemCountDelta++; } _existingIndigoCategories.Remove(match); } } result.Add(dimVal); var parentId = (appendBreadcrumbTrail) ? match.IndigoCategoryId : indigoParentCategoryId; var linkInfoListNew = ProcessDimVals(sectionValue, dimensionId, idTrail, breadcrumbTrail, appendBreadcrumbTrail, parentId, hasChanged, dimVal, isFrench).ToList(); if (linkInfoListNew.Any()) { result.AddRange(linkInfoListNew); } breadcrumbTrail = placeHolderBreadcrumbTrail; idTrail = placeHolderIdTrail; } } } return(result); }