protected virtual void EnsureCategoryPages(TreeNode <Category> rootCategory, CategoryPageData pageData)
 {
     foreach (var childCategory in rootCategory.Children)
     {
         var category = childCategory;
         var data     = pageData;
         EnsureSubCategoryPages(category, data);
     }
 }
        public void Sync()
        {
            var categories = CategoryRepository
                             .GetCategoriesTreeAsync(new GetCategoriesParam {
                Scope = ScopeProvider.DefaultScope
            }).Result;

            CategoryPageData categoryPageData = GetCategoryPages();

            EnsureCategoryPages(categories["Root"], categoryPageData);
        }
        private async void TestFunc()
        {
            if (_channelContent != null)
            {
                if (_channelContent.Title != "番剧")
                {
                    _categoryPageData = new CategoryPageData();
                    await _categoryPageData.GetData(AcFunAPI.GetCategoryUrl("11", _channelContent.id));

                    RootCVS.Source = DataCategory();
                    AddRecommendData();
                    AddRankData();
                    AddCategoryButton();
                    AddBanner();
                }
                else
                {
                }
            }
        }
        protected virtual CategoryPageData GetCategoryPages()
        {
            var result = new CategoryPageData
            {
                Others = new List <CategoryLocalizedPageData>()
            };

            foreach (var culture in GetCultures())
            {
                var catInfo = GetCategoryLocalizedPageData(culture);

                if (IsDefaultLanguage(culture))
                {
                    result.Default = catInfo;
                }
                else
                {
                    result.Others.Add(catInfo);
                }
            }
            return(result);
        }
        protected virtual void EnsureSubCategoryPages(TreeNode <Category> subCategory, CategoryPageData pageData)
        {
            var isLandingPage = subCategory.GetLevel() <= CategoriesConfiguration.LandingPageMaxLevel;
            var pageTypeId    = isLandingPage ? CategoryPages.CategoryLandingPageTypeId : CategoryPages.CategoryPageTypeId;

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                IPage source = null;

                var sourceData = pageData.Default;
                if (!CategoryExist(subCategory.Value, sourceData))
                {
                    using (var connection = new DataConnection(PublicationScope.Unpublished, pageData.Default.Culture))
                    {
                        // Get default page content
                        // TODO: Do it only once

                        var pageTypeDefaultPageContents =
                            DataFacade.GetData <IPageTypeDefaultPageContent>().
                            Where(f => f.PageTypeId == pageTypeId).
                            Evaluate();

                        // Add page to parent
                        var catPage = connection.CreateNew <IPage>();
                        FillCategoryPage(catPage, pageTypeId, subCategory, connection.CurrentLocale);
                        var parentParentId = subCategory.GetLevel() == 1
                                                        ? RootPageId
                                                        : GenerateCategoryPageId(subCategory.Parent.Value.Id);

                        catPage.AddPageAtBottom(parentParentId);

                        // Add ComposerCategoryPage MetaData info
                        AddCategoryPageInfo(subCategory, connection, catPage, isLandingPage, false);

                        // Add default page content
                        foreach (IPageTypeDefaultPageContent pageTypeDefaultPageContent in pageTypeDefaultPageContents)
                        {
                            IPagePlaceholderContent pagePlaceholderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                            pagePlaceholderContent.PageId        = catPage.Id;
                            pagePlaceholderContent.PlaceHolderId = pageTypeDefaultPageContent.PlaceHolderId;
                            pagePlaceholderContent.Content       = pageTypeDefaultPageContent.Content;
                            DataFacade.AddNew <IPagePlaceholderContent>(pagePlaceholderContent);
                        }

                        // Update page again to force publish
                        var addedPage = DataFacade.GetData <IPage>(p => p.Id == catPage.Id);

                        DataFacade.Update(addedPage);
                    }
                }

                foreach (var localizedData in pageData.Others)
                {
                    if (!CategoryExist(subCategory.Value, localizedData))
                    {
                        using (var locConnection = new DataConnection(PublicationScope.Unpublished, localizedData.Culture))
                        {
                            if (source == null)
                            {
                                var sourceId = GenerateCategoryPageId(subCategory.Value.Id);
                                using (var connection = new DataConnection(PublicationScope.Unpublished, pageData.Default.Culture))
                                {
                                    source = connection.Get <IPage>().FirstOrDefault(p => p.Id == sourceId);
                                }
                                if (source == null)
                                {
                                    //TODO: Log
                                    continue;
                                }
                                var localizedPage = CompositeLanguageFacade.TranslatePage(source, pageData.Default.Culture, localizedData.Culture);
                                FillCategoryPage(localizedPage, pageTypeId, subCategory, localizedData.Culture);
                                AddCategoryPageInfo(subCategory, locConnection, localizedPage, isLandingPage, false);
                                locConnection.Update(localizedPage);
                            }
                        }
                    }
                }
                transaction.Complete();
            }

            if (subCategory.Children == null)
            {
                return;
            }

            if (isLandingPage)
            {
                CreateCategoryAllProductsPage(subCategory, pageData);
            }

            foreach (var child in subCategory.Children)
            {
                EnsureSubCategoryPages(child, pageData);
            }
        }