public IIndigoCategory Update(IIndigoCategory indigoCategory)
        {
            indigoCategory.ModifiedBy = System.Configuration.ConfigurationManager.AppSettings["TaxonomyMapper_ModifiedBy"];
#if !TEST
            return(_indigoCategoryService.Update(indigoCategory));
#else
            return(indigoCategory);
#endif
        }
Exemplo n.º 2
0
        private void DoCategoryUpdates()
        {
            Log.Info("Starting working on category updates.");
            _existingIndigoCategories = _indigoCategoryService.GetAllIndigoCategories().ToList();
            // These values get used for log reporting purposes
            SetInitialCategoryTypeCounts();
            var topLevelBrowseSectionDimVals = GetTopLevelBrowseDimVals();

            foreach (var topLevelBrowseSection in topLevelBrowseSectionDimVals)
            {
                var  match      = _existingIndigoCategories.FirstOrDefault(ic => ic.EndecaBreadcrumbId.Equals(topLevelBrowseSection.Id.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase));
                bool hasChanged = false;
                if (match == null)
                {
                    var indigoCategory = GetIndigoCategory(null, topLevelBrowseSection.Name, topLevelBrowseSection.GetFrenchName(),
                                                           topLevelBrowseSection.Id.ToString(CultureInfo.InvariantCulture), (int)topLevelBrowseSection.Id,
                                                           topLevelBrowseSection.Name, 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 (!(topLevelBrowseSection.Name).Equals(match.Name, StringComparison.OrdinalIgnoreCase) &&
                        (topLevelBrowseSection.GetFrenchName().Equals(match.NameFr, StringComparison.OrdinalIgnoreCase)))
                    {
                        hasChanged           = true;
                        match.Name           = topLevelBrowseSection.Name;
                        match.NameFr         = topLevelBrowseSection.GetFrenchName();
                        match.BreadcrumbPath = topLevelBrowseSection.Name;
                        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);
                }


                var breadcrumbTrail = topLevelBrowseSection.Name;
                ProcessDimVals(topLevelBrowseSection, EndecaCategoryId, topLevelBrowseSection.Id.ToString(CultureInfo.InvariantCulture), breadcrumbTrail, true, match.IndigoCategoryId, hasChanged);
            }

            // At this point, the indigo categories that are left are the ones that have been "modified" (e.g. they aren't part of the current tree anymore)
            // Set their isModified flags to true
            foreach (var indigoCategory in _existingIndigoCategories)
            {
                if (indigoCategory.IsDeleted)
                {
                    continue;
                }

                indigoCategory.IsModified = false;
                indigoCategory.IsDeleted  = true;
                indigoCategory.ModifiedBy = ModifiedByValue;
                _indigoCategoryService.Update(indigoCategory);
                _deletedItemCountDelta++;
            }

            Log.InfoFormat("Completed working on categories.");
            Log.InfoFormat("Before the run, there were {0} new, {1} modified, {2} deleted and {3} unchanged categories in the database.", _newItemCount, _modifiedItemCount, _deletedItemCount, _unmodifiedItemCount);
            Log.InfoFormat("During the run, there were {0} newly added, {1} newly modified, {2} newly deleted categories out of the {3} categories retrieved from Endeca.", _newItemCountDelta, _modifiedItemCountDelta, _deletedItemCountDelta, _unmodifiedItemCountDelta);
        }