private void LoadData()
            {
                var indigoCategories = _indigoCategoryService.GetAllIndigoCategories().OrderBy(ic => ic.ParentId.HasValue).ToList();
                var googleCategories = _googleCategoryService.GetAllGoogleCategories().ToList();

                _excludedBrowseCategoryIds = GetExcludedBrowseCategoryIds();

                // Loop through all Indigo categories and create the list of "composite" models which also contains Google info
                // and add them to the Indigo categories dictionary
                foreach (var indigoCategory in indigoCategories.Where(ic => AllowDeletedCategories || !ic.IsDeleted))
                {
                    IGoogleCategory googleCategory = null;
                    if (indigoCategory.GoogleCategoryId.HasValue)
                    {
                        googleCategory = googleCategories.SingleOrDefault(gc => gc.GoogleCategoryId == indigoCategory.GoogleCategoryId.Value);
                    }
                    var compositeModel = new IndigoBreadcrumbCategory(indigoCategory, googleCategory);
                    // Set the parent level category id on the composite model
                    if (compositeModel.ParentId.HasValue)
                    {
                        var crumbs   = compositeModel.Breadcrumb.Split(new[] { BreadcrumbTrailSplitter }, StringSplitOptions.RemoveEmptyEntries);
                        var parentId = compositeModel.ParentId;
                        var id       = 0;
                        while (parentId.HasValue)
                        {
                            var parent = indigoCategories.First(ic => ic.IndigoCategoryId == parentId.Value);
                            parentId = parent.ParentId;
                            id       = parent.IndigoCategoryId;
                        }
                        compositeModel.ParentLevelIndigoCategoryId = id;
                        compositeModel.Crumbs = crumbs;
                    }
                    else
                    {
                        compositeModel.ParentLevelIndigoCategoryId = compositeModel.IndigoCategoryId;
                        compositeModel.Crumbs = new[] { compositeModel.Breadcrumb };
                    }

                    _indigoCategoriesByIndigoCategoryId.AddOrUpdate(compositeModel.IndigoCategoryId, compositeModel, (i, model) => model);

                    if (!compositeModel.ParentId.HasValue)
                    {
                        _topLevelIndigoCategories.AddOrUpdate(compositeModel.IndigoCategoryId, compositeModel, (i, category) => category);
                    }
                }

                // Now that the main Indigo categories dictionary is populated, now populate the supporting cast...
                _indigoCategoriesByBrowseCategoryId = new ConcurrentDictionary <int, List <IIndigoBreadcrumbCategory> >(_indigoCategoriesByIndigoCategoryId.Values.GroupBy(ic => ic.BrowseCategoryId).ToDictionary(kvp => kvp.Key, kvp => kvp.ToList()));
                //_entertainmentIndigoCategoriesByL2Name = new ConcurrentDictionary<string, List<FeedGeneratorIndigoCategory>>(entertainmentCategoryList.GroupBy(ic => ic.Crumbs[1]).ToDictionary(kvp => kvp.Key.ToLowerInvariant(), kvp => kvp.ToList()));
            }
Esempio n. 2
0
        private bool UpdateMapping(IGoogleCategory googleCategory, ProcessContext context)
        {
            bool isSuccess = true;

            try
            {
                this.Log.DebugFormat("Updating");

                this._indigoCategoryService.UpdateMapping(context.CurrentRecord.IndigoCategoryId,
                                                          googleCategory.GoogleCategoryId,
                                                          "NewGoogleCategoriesForIndigoCategoriesImporter");
            }
            catch (UpdateException ex)
            {
                this.Log.Error("UpdateException during UpdateMapping call.\n" + GetRecordErrorMessage(context), ex);
                isSuccess = false;
            }

            return(isSuccess);
        }
Esempio n. 3
0
        private IGoogleCategory UpdateOrInsertGoogleCategory(IGoogleCategory googleCategory)
        {
            GoogleCategoryWrapper googleCategoryWrapper;
            IGoogleCategory       result;

            // Works for Update or Insert mode. If there's nothing in the dictionary the insert branch is taken anyway.
            if (this.GoogleCategoryDictionary.TryGetValue(googleCategory.BreadcrumbPath.Trim(), out googleCategoryWrapper))
            {
                googleCategory.GoogleCategoryId = googleCategoryWrapper.GoogleCategoryId;

                result = _googleCategoryService.Update(googleCategory);

                googleCategoryWrapper.IsModified = true;
            }
            else
            {
                result = _googleCategoryService.Insert(googleCategory);
            }

            return(result);
        }
 public GoogleCategoryWrapper(IGoogleCategory googleCategory)
 {
     this.googleCategory = googleCategory;
     this.IsModified     = false;
 }
 public GoogleCategoryWrapper(IGoogleCategory googleCategory)
 {
     GoogleCategory = googleCategory;
     Status         = StatusEnum.NotProcessed;
 }