Пример #1
0
        public void Execute()
        {
            var startTime = DateTime.Now;

            Log.Info("Execution started.");
            // Start

            try
            {
                // Get a dictionary of Indigo categories keyed on the EndecaBreadcrumbId from the database.
                Dictionary <string, IndigoCategoryWrapper> indigoCategoryDictionary =
                    _indigoCategoryServiceProxy.GetAllIndigoCategories()
                    .Select(indigoCategory => new IndigoCategoryWrapper(indigoCategory))
                    .ToDictionary(p => p.IndigoCategory.EndecaBreadcrumbId.Trim());

                // Get a dictionary of Google categories keyed on the Breadcrumb path from the database.
                Dictionary <string, GoogleCategoryWrapper> googleCategoryDictionary =
                    _googleCategoryService.GetAllGoogleCategories()
                    .Select(googleCategory => new GoogleCategoryWrapper(googleCategory))
                    .ToDictionary(p => p.GoogleCategory.BreadcrumbPath.Trim());

                MapCategoryIds(indigoCategoryDictionary, googleCategoryDictionary);
                UpdateDatabase(indigoCategoryDictionary);
                Statistics.Output(indigoCategoryDictionary, googleCategoryDictionary, Log);
            }
            catch (Exception ex)
            {
                Log.Error("An error occurred during execution. Terminating...", ex);
            }

            // End
            var elapsedTime = DateTime.Now - startTime;

            Log.InfoFormat("Execution completed. Elapsed time: {0}", elapsedTime.ToString(@"dd\.hh\:mm\:ss"));
        }
            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()));
            }