示例#1
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public PageEngine()
        {
            _activeNode        = null;
            _activeSection     = null;
            _templateControl   = null;
            _shouldLoadContent = true;
            _stylesheets       = new Hashtable();
            _metaTags          = new Hashtable();
            _navigationPath    = new ArrayList();

            // Get services from the container. Ideally, it should be possible to register the aspx page in the container
            // to automatically resolve dependencies but there were memory issues with registering pages in the container.
            _moduleLoader   = Container.Resolve <ModuleLoader>();
            _nodeService    = Container.Resolve <INodeService>();
            _siteService    = Container.Resolve <ISiteService>();
            _sectionService = Container.Resolve <ISectionService>();

            _isRedirected = false;
        }
示例#2
0
        private void LoadContent()
        {
            // ===== Load templates  =====

            string appRoot = UrlHelper.GetApplicationPath();

            // We know the active node so the template can be loaded.
            if (_activeNode.Template != null)
            {
                string templatePath = appRoot + _activeNode.Template.Path;
                _templateControl = (BaseTemplate)LoadControl(templatePath);
                // Explicitly set the id to 'p' to save some bytes (otherwise _ctl0 would be added).
                _templateControl.ID    = "p";
                _templateControl.Title = _activeNode.Site.Name + " - " + _activeNode.Title;
                // Register stylesheet that belongs to the template.
                RegisterStylesheet("maincss",
                                   appRoot + _activeNode.Template.BasePath + "/Css/" + _activeNode.Template.Css);
                //Register the metatags
                if (ActiveNode.MetaKeywords != null)
                {
                    RegisterMetaTag("keywords", ActiveNode.MetaKeywords);
                }
                else
                {
                    RegisterMetaTag("keywords", ActiveNode.Site.MetaKeywords);
                }
                if (ActiveNode.MetaDescription != null)
                {
                    RegisterMetaTag("description", ActiveNode.MetaDescription);
                }
                else
                {
                    RegisterMetaTag("description", ActiveNode.Site.MetaDescription);
                }

                // Add node vào navigation path
                if (ActiveNode != null)
                {
                    foreach (Node node in ActiveNode.NodePath)
                    {
                        RegisterNavigationPath(node.Title, UrlHelper.GetUrlFromNode(node), node.Sections.Count > 0);
                    }
                }

                // Load sections that are related to the template
                foreach (DictionaryEntry sectionEntry in ActiveNode.Template.Sections)
                {
                    string  placeholder = sectionEntry.Key.ToString();
                    Section section     = sectionEntry.Value as Section;
                    if (section != null)
                    {
                        BaseModuleControl moduleControl = CreateModuleControlForSection(section);
                        if (moduleControl != null)
                        {
                            ((PlaceHolder)_templateControl.Containers[placeholder]).Controls.Add(moduleControl);
                        }
                    }
                }
            }
            else
            {
                throw new Exception("No template associated with the current Node.");
            }

            // ===== Load sections and modules =====
            foreach (Section section in _activeNode.Sections)
            {
                BaseModuleControl moduleControl = CreateModuleControlForSection(section);
                if (moduleControl != null)
                {
                    ((PlaceHolder)_templateControl.Containers[section.PlaceholderId]).Controls.Add(moduleControl);
                }
            }

            Controls.AddAt(0, _templateControl);
            // remove html that was in the original page (Default.aspx)
            for (int i = Controls.Count - 1; i < 0; i--)
            {
                Controls.RemoveAt(i);
            }
        }