Example #1
0
 protected virtual bool CreatePlaceholder(ControlCollection container, string placeholder, string defaultContent, AttributeDictionary attributes)
 {
     if (placeholder == "membership-bar")
     {
         MembershipBar mb = new MembershipBar();
         mb.ID = "mb";
         if (attributes["data-display-remember-me"] == "false")
         {
             mb.DisplayRememberMe = false;
         }
         if (attributes["data-remember-me-set"] == "true")
         {
             mb.RememberMeSet = true;
         }
         if (attributes["data-display-password-recovery"] == "false")
         {
             mb.DisplayPasswordRecovery = false;
         }
         if (attributes["data-display-sign-up"] == "false")
         {
             mb.DisplaySignUp = false;
         }
         if (attributes["data-display-my-account"] == "false")
         {
             mb.DisplayMyAccount = false;
         }
         if (attributes["data-display-help"] == "false")
         {
             mb.DisplayHelp = false;
         }
         if (attributes["data-display-login"] == "false")
         {
             mb.DisplayLogin = false;
         }
         if (!(String.IsNullOrEmpty(attributes["data-idle-user-timeout"])))
         {
             mb.IdleUserTimeout = Convert.ToInt32(attributes["data-idle-user-timeout"]);
         }
         if (attributes["data-enable-history"] == "true")
         {
             mb.EnableHistory = true;
         }
         if (attributes["data-enable-permalinks"] == "true")
         {
             mb.EnablePermalinks = true;
         }
         container.Add(mb);
         return(true);
     }
     if (placeholder == "menu-bar")
     {
         HtmlGenericControl menuDiv = new HtmlGenericControl();
         menuDiv.TagName             = "div";
         menuDiv.ID                  = "PageMenuBar";
         menuDiv.Attributes["class"] = "PageMenuBar";
         container.Add(menuDiv);
         MenuExtender menu = new MenuExtender();
         menu.ID                = "Menu1";
         menu.DataSourceID      = "SiteMapDataSource1";
         menu.TargetControlID   = menuDiv.ID;
         menu.HoverStyle        = ((MenuHoverStyle)(TypeDescriptor.GetConverter(typeof(MenuHoverStyle)).ConvertFromString(attributes.ValueOf("data-hover-style", "Auto"))));
         menu.PopupPosition     = ((MenuPopupPosition)(TypeDescriptor.GetConverter(typeof(MenuPopupPosition)).ConvertFromString(attributes.ValueOf("data-popup-position", "Left"))));
         menu.ShowSiteActions   = (attributes["data-show-site-actions"] == "true");
         menu.PresentationStyle = ((MenuPresentationStyle)(TypeDescriptor.GetConverter(typeof(MenuPresentationStyle)).ConvertFromString(attributes.ValueOf("data-presentation-style", "MultiLevel"))));
         container.Add(menu);
         return(true);
     }
     if (placeholder == "site-map-path")
     {
         SiteMapPath siteMapPath1 = new SiteMapPath();
         siteMapPath1.ID       = "SiteMapPath1";
         siteMapPath1.CssClass = "SiteMapPath";
         siteMapPath1.PathSeparatorStyle.CssClass = "PathSeparator";
         siteMapPath1.CurrentNodeStyle.CssClass   = "CurrentNode";
         siteMapPath1.NodeStyle.CssClass          = "Node";
         siteMapPath1.RootNodeStyle.CssClass      = "RootNode";
         container.Add(siteMapPath1);
         return(true);
     }
     return(false);
 }
Example #2
0
 public virtual string ReplaceStaticPlaceholder(string name, AttributeDictionary attributes, string defaultContent)
 {
     return(null);
 }
Example #3
0
        protected virtual void InitializeSiteMaster()
        {
            _isTouchUI = ApplicationServices.IsTouchClient;
            string html           = String.Empty;
            string siteMasterPath = "~/site.desktop.html";

            if (_isTouchUI)
            {
                siteMasterPath = "~/site.touch.html";
            }
            siteMasterPath = Server.MapPath(siteMasterPath);
            if (!(File.Exists(siteMasterPath)))
            {
                siteMasterPath = Server.MapPath("~/site.html");
            }
            if (File.Exists(siteMasterPath))
            {
                html = File.ReadAllText(siteMasterPath);
            }
            else
            {
                throw new Exception("File site.html has not been found.");
            }
            Match htmlMatch = Regex.Match(html, "<html(?\'HtmlAttr\'[\\S\\s]*?)>\\s*<head(?\'HeadAttr\'[\\S\\s]*?)>\\s*(?\'Head\'[\\S\\s]*?)\\s*<" +
                                          "/head>\\s*<body(?\'BodyAttr\'[\\S\\s]*?)>\\s*(?\'Body\'[\\S\\s]*?)\\s*</body>\\s*</html>\\s*");

            if (!(htmlMatch.Success))
            {
                throw new Exception("File site.html must contain \'head\' and \'body\' elements.");
            }
            // instructions
            Controls.Add(new LiteralControl(html.Substring(0, htmlMatch.Index)));
            // html
            Controls.Add(new LiteralControl(String.Format("<html{0} xml:lang={1} lang=\"{1}\">\r\n", htmlMatch.Groups["HtmlAttr"].Value, CultureInfo.CurrentUICulture.IetfLanguageTag)));
            // head
            Controls.Add(new HtmlHead());
            if (_isTouchUI)
            {
                Header.Controls.Add(new LiteralControl("<meta charset=\"utf-8\">\r\n"));
            }
            else
            {
                Header.Controls.Add(new LiteralControl("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n"));
            }
            string headHtml = Regex.Replace(htmlMatch.Groups["Head"].Value, "\\s*<title([\\s\\S+]*?title>)\\s*", String.Empty);

            Header.Controls.Add(new LiteralControl(headHtml));
            _headContent = new LiteralContainer();
            Header.Controls.Add(_headContent);
            // body
            _bodyTag        = new LiteralControl();
            _bodyAttributes = new AttributeDictionary(htmlMatch.Groups["BodyAttr"].Value);
            Controls.Add(_bodyTag);
            string themePath = Server.MapPath("~/App_Themes/VSM");

            if (Directory.Exists(themePath))
            {
                foreach (string stylesheetFileName in Directory.GetFiles(themePath, "*.css"))
                {
                    string fileName = Path.GetFileName(stylesheetFileName);
                    if (!(fileName.Equals("_Theme_Modern.css")))
                    {
                        HtmlLink link = new HtmlLink();
                        link.Href = ("~/App_Themes/VSM/" + fileName);
                        link.Attributes["type"] = "text/css";
                        link.Attributes["rel"]  = "stylesheet";
                        Header.Controls.Add(link);
                    }
                }
            }
            // form
            Controls.Add(new HtmlForm());
            Form.ID = "aspnetForm";
            // ScriptManager
            ScriptManager sm = new ScriptManager();

            sm.ID = "sm";
            sm.AjaxFrameworkMode = AjaxFrameworkMode.Disabled;
            if (AquariumExtenderBase.EnableCombinedScript)
            {
                sm.EnableScriptLocalization = false;
            }
            sm.ScriptMode = ScriptMode.Release;
            Form.Controls.Add(sm);
            // SiteMapDataSource
            SiteMapDataSource siteMapDataSource1 = new SiteMapDataSource();

            siteMapDataSource1.ID = "SiteMapDataSource1";
            siteMapDataSource1.ShowStartingNode = false;
            Form.Controls.Add(siteMapDataSource1);
            // parse and initialize placeholders
            string body             = htmlMatch.Groups["Body"].Value;
            Match  placeholderMatch = Regex.Match(body, "<div\\s+data-role\\s*=\\s*\"placeholder\"(?\'Attributes\'[\\s\\S]+?)>\\s*(?\'DefaultContent\'" +
                                                  "[\\s\\S]*?)\\s*</div>");
            int startPos = 0;

            while (placeholderMatch.Success)
            {
                AttributeDictionary attributes = new AttributeDictionary(placeholderMatch.Groups["Attributes"].Value);
                // create placeholder content
                Form.Controls.Add(new LiteralControl(body.Substring(startPos, (placeholderMatch.Index - startPos))));
                string placeholder    = attributes["data-placeholder"];
                string defaultContent = placeholderMatch.Groups["DefaultContent"].Value;
                if (!(CreatePlaceholder(Form.Controls, placeholder, defaultContent, attributes)))
                {
                    LiteralContainer placeholderControl = new LiteralContainer();
                    placeholderControl.Text = defaultContent;
                    Form.Controls.Add(placeholderControl);
                    if (placeholder == "page-header")
                    {
                        _pageHeaderContent = placeholderControl;
                    }
                    if (placeholder == "page-title")
                    {
                        _pageTitleContent = placeholderControl;
                    }
                    if (placeholder == "page-side-bar")
                    {
                        _pageSideBarContent = placeholderControl;
                    }
                    if (placeholder == "page-content")
                    {
                        _pageContent = placeholderControl;
                    }
                    if (placeholder == "page-footer")
                    {
                        _pageFooterContent = placeholderControl;
                    }
                }
                startPos         = (placeholderMatch.Index + placeholderMatch.Length);
                placeholderMatch = placeholderMatch.NextMatch();
            }
            if (startPos < body.Length)
            {
                Form.Controls.Add(new LiteralControl(body.Substring(startPos)));
            }
            // end body
            Controls.Add(new LiteralControl("\r\n</body>\r\n"));
            // end html
            Controls.Add(new LiteralControl("\r\n</html>\r\n"));
        }