コード例 #1
0
        public DemoConfiguration(IConfiguration configuration)
        {
            Configuration = configuration;

            var jsonContent = GetDemoFileContent(ConfigJsonPath);

            Data = JsonConvert.DeserializeObject <DemoConfigurationData>(jsonContent);
            if (Data == null)
            {
                return;
            }

            Products  = Data.Products ?? new DemoProductInfo[0];
            RootPages = Data.RootPages ?? new DemoRootPage[0];
            Redirect  = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);
            foreach (var rootPage in RootPages)
            {
                rootPage.Pages = rootPage.Pages ?? new DemoPage[0];
                foreach (var page in rootPage.Pages)
                {
                    page.PageSections = page.PageSections ?? new DemoPageSection[0];
                    foreach (var pageSection in page.PageSections)
                    {
                        pageSection.ParentPage = page;
                        AddRedirect(pageSection);
                    }
                    page.ParentPage = rootPage;
                    AddRedirect(page);
                }
                AddRedirect(rootPage);
            }
            Search = new DemoSearchHelper(Data.Search, RootPages);
            void AddRedirect(DemoPageSection section)
            {
                if (section.RedirectFrom?.Length > 0)
                {
                    foreach (var redirect in section.RedirectFrom)
                    {
                        Redirect.Add(redirect, section.Uri);
                    }
                }
            }
        }
コード例 #2
0
        public DemoConfiguration(IConfiguration configuration)
        {
            Configuration = configuration;

            var jsonContent = GetDemoFileContent(ConfigJsonPath);

            Data = JsonConvert.DeserializeObject <DemoConfigurationData>(jsonContent);
            if (Data == null)
            {
                return;
            }

            Products  = Data.Products ?? new DemoProductInfo[0];
            RootPages = Data.RootPages ?? new DemoRootPage[0];
            Redirect  = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);
            ConnectRecursive(RootPages, null);
            Search = new DemoSearchHelper(Data.Search, RootPages);

            void ConnectRecursive(IEnumerable <DemoPageSection> childSections, DemoPageBase parent)
            {
                foreach (var section in childSections)
                {
                    if (section is DemoPageBase pageBase)
                    {
                        pageBase.Pages ??= Array.Empty <DemoPage>();
                        ConnectRecursive(pageBase.Pages, pageBase);
                    }
                    if (section is DemoPage page)
                    {
                        page.PageSections ??= Array.Empty <DemoPageSection>();
                        ConnectRecursive(page.PageSections, page);
                    }
                    section.ParentPage = parent;
                    if (section.RedirectFrom?.Length > 0)
                    {
                        foreach (var redirect in section.RedirectFrom)
                        {
                            Redirect.Add(redirect, section.Uri);
                        }
                    }
                }
            }
        }