Esempio n. 1
0
        protected override void OnInit(EventArgs e)
        {
            if (Request.Path.StartsWith((ResolveUrl(AquariumExtenderBase.DefaultServicePath) + "/"), StringComparison.CurrentCultureIgnoreCase) || Request.Path.StartsWith((ResolveUrl(AquariumExtenderBase.AppServicePath) + "/"), StringComparison.CurrentCultureIgnoreCase))
            {
                ApplicationServices.HandleServiceRequest(Context);
            }
            if (Request.Params["_page"] == "_blank")
            {
                return;
            }
            var link = Request.Params["_link"];

            if (!(string.IsNullOrEmpty(link)))
            {
                var permalink = StringEncryptor.FromString(link.Replace(" ", "+").Split(',')[0]).Split('?');
                if (permalink.Length == 2)
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "Redirect", string.Format("window.location.replace(\'{0}?_link={1}\');", permalink[0], HttpUtility.UrlEncode(link)), true);
                }
            }
            else
            {
                var requestUrl = Request.RawUrl;
                if ((requestUrl.Length > 1) && requestUrl.EndsWith("/"))
                {
                    requestUrl = requestUrl.Substring(0, (requestUrl.Length - 1));
                }
                if (Request.ApplicationPath.Equals(requestUrl, StringComparison.CurrentCultureIgnoreCase))
                {
                    var homePageUrl = ApplicationServices.HomePageUrl;
                    if (!(Request.ApplicationPath.Equals(homePageUrl)))
                    {
                        Response.Redirect(homePageUrl);
                    }
                }
            }
            var contentInfo = ApplicationServices.LoadContent();

            InitializeSiteMaster();
            string s = null;

            if (!(contentInfo.TryGetValue("PageTitle", out s)))
            {
                s = ApplicationServicesBase.Current.DisplayName;
            }
            this.Title = s;
            if (_pageTitleContent != null)
            {
                if (_isTouchUI)
                {
                    _pageTitleContent.Text = string.Empty;
                }
                else
                {
                    _pageTitleContent.Text = s;
                }
            }
            var appName = new HtmlMeta();

            appName.Name    = "application-name";
            appName.Content = ApplicationServicesBase.Current.DisplayName;
            Header.Controls.Add(appName);
            if (contentInfo.TryGetValue("Head", out s) && (_headContent != null))
            {
                _headContent.Text = s;
            }
            if (contentInfo.TryGetValue("PageContent", out s) && (_pageContent != null))
            {
                if (_isTouchUI)
                {
                    s = string.Format("<div id=\"PageContent\" style=\"display:none\">{0}</div>", s);
                }
                var userControl = Regex.Match(s, "<div\\s+data-user-control\\s*=s*\"([\\s\\S]+?)\".*?>\\s*</div>");
                if (userControl.Success)
                {
                    var startPos = 0;
                    while (userControl.Success)
                    {
                        _pageContent.Controls.Add(new LiteralControl(s.Substring(startPos, (userControl.Index - startPos))));
                        startPos = (userControl.Index + userControl.Length);
                        var    controlFileName  = userControl.Groups[1].Value;
                        var    controlExtension = Path.GetExtension(controlFileName);
                        string siteControlText  = null;
                        if (!(controlFileName.StartsWith("~")))
                        {
                            controlFileName = (controlFileName + "~");
                        }
                        if (string.IsNullOrEmpty(controlExtension))
                        {
                            var testFileName = (controlFileName + ".ascx");
                            if (File.Exists(Server.MapPath(testFileName)))
                            {
                                controlFileName  = testFileName;
                                controlExtension = ".ascx";
                            }
                            else
                            {
                                if (ApplicationServices.IsSiteContentEnabled)
                                {
                                    var relativeControlPath = controlFileName.Substring(1);
                                    if (relativeControlPath.StartsWith("/"))
                                    {
                                        relativeControlPath = relativeControlPath.Substring(1);
                                    }
                                    siteControlText = ApplicationServices.Current.ReadSiteContentString(("sys/" + relativeControlPath));
                                }
                                if (siteControlText == null)
                                {
                                    testFileName = (controlFileName + ".html");
                                    if (File.Exists(Server.MapPath(testFileName)))
                                    {
                                        controlFileName  = testFileName;
                                        controlExtension = ".html";
                                    }
                                }
                            }
                        }
                        var userControlAuthorizeRoles = Regex.Match(userControl.Value, "data-authorize-roles\\s*=\\s*\"(.+?)\"");
                        var allowUserControl          = !userControlAuthorizeRoles.Success;
                        if (!allowUserControl)
                        {
                            var authorizeRoles = userControlAuthorizeRoles.Groups[1].Value;
                            if (authorizeRoles == "?")
                            {
                                if (!Context.User.Identity.IsAuthenticated)
                                {
                                    allowUserControl = true;
                                }
                            }
                            else
                            {
                                allowUserControl = ApplicationServices.UserIsAuthorizedToAccessResource(controlFileName, authorizeRoles);
                            }
                        }
                        if (allowUserControl)
                        {
                            try
                            {
                                if (controlExtension == ".ascx")
                                {
                                    _pageContent.Controls.Add(LoadControl(controlFileName));
                                }
                                else
                                {
                                    var controlText = siteControlText;
                                    if (controlText == null)
                                    {
                                        controlText = File.ReadAllText(Server.MapPath(controlFileName));
                                    }
                                    var bodyMatch = Regex.Match(controlText, "<body[\\s\\S]*?>([\\s\\S]+?)</body>");
                                    if (bodyMatch.Success)
                                    {
                                        controlText = bodyMatch.Groups[1].Value;
                                    }
                                    controlText = ApplicationServices.EnrichData(Localizer.Replace("Controls", Path.GetFileName(Server.MapPath(controlFileName)), controlText));
                                    _pageContent.Controls.Add(new LiteralControl(InjectPrefetch(controlText)));
                                }
                            }
                            catch (Exception ex)
                            {
                                _pageContent.Controls.Add(new LiteralControl(string.Format("Error loading \'{0}\': {1}", controlFileName, ex.Message)));
                            }
                        }
                        userControl = userControl.NextMatch();
                    }
                    if (startPos < s.Length)
                    {
                        _pageContent.Controls.Add(new LiteralControl(s.Substring(startPos)));
                    }
                }
                else
                {
                    _pageContent.Text = InjectPrefetch(s);
                }
            }
            else
            if (_isTouchUI)
            {
                _pageContent.Text = "<div id=\"PageContent\" style=\"display:none\"><div data-app-role=\"page\">404 Not Foun" +
                                    "d</div></div>";
                this.Title = ApplicationServicesBase.Current.DisplayName;
            }
            else
            {
                _pageContent.Text = "404 Not Found";
            }
            if (_isTouchUI)
            {
                if (_pageFooterContent != null)
                {
                    _pageFooterContent.Text = (("<footer style=\"display:none\"><small>" + Copyright)
                                               + "</small></footer>");
                }
            }
            else
            if (contentInfo.TryGetValue("About", out s))
            {
                if (_pageSideBarContent != null)
                {
                    _pageSideBarContent.Text = string.Format("<div class=\"TaskBox About\"><div class=\"Inner\"><div class=\"Header\">About</div><div" +
                                                             " class=\"Value\">{0}</div></div></div>", s);
                }
            }
            string bodyAttributes = null;

            if (contentInfo.TryGetValue("BodyAttributes", out bodyAttributes))
            {
                _bodyAttributes.Parse(bodyAttributes);
            }
            var classAttr = _bodyAttributes["class"];

            if (string.IsNullOrEmpty(classAttr))
            {
                classAttr = string.Empty;
            }
            if (!_isTouchUI)
            {
                if (!(classAttr.Contains("Wide")))
                {
                    classAttr = (classAttr + " Standard");
                }
                classAttr = ((classAttr + " ")
                             + (Regex.Replace(Request.Path.ToLower(), "\\W", "_").Substring(1) + "_html"));
            }
            else
            if (_summaryDisabled)
            {
                classAttr = (classAttr + " see-all-always");
            }
            if (!(string.IsNullOrEmpty(classAttr)))
            {
                _bodyAttributes["class"] = classAttr.Trim();
            }
            _bodyTag.Text = string.Format("\r\n<body{0}>\r\n", _bodyAttributes.ToString());
            base.OnInit(e);
        }
Esempio n. 2
0
        protected override void OnInit(EventArgs e)
        {
            if (Request.Path.StartsWith((ResolveUrl(AquariumExtenderBase.DefaultServicePath) + "/"), StringComparison.CurrentCultureIgnoreCase))
            {
                ApplicationServices.HandleServiceRequest(Context);
            }
            if (Request.Params["_page"] == "_blank")
            {
                return;
            }
            string link = Request.Params["_link"];

            if (!(String.IsNullOrEmpty(link)))
            {
                StringEncryptor enc       = new StringEncryptor();
                string[]        permalink = enc.Decrypt(link.Split(',')[0]).Split('?');
                Page.ClientScript.RegisterStartupScript(GetType(), "Redirect", String.Format("window.location.replace(\'0?_link=1\');", permalink[0], HttpUtility.UrlEncode(link)), true);
                return;
            }
            else
            {
                string requestUrl = Request.RawUrl;
                if ((requestUrl.Length > 1) && requestUrl.EndsWith("/"))
                {
                    requestUrl = requestUrl.Substring(0, (requestUrl.Length - 1));
                }
                if (Request.ApplicationPath.Equals(requestUrl, StringComparison.CurrentCultureIgnoreCase))
                {
                    string homePageUrl = ApplicationServices.HomePageUrl;
                    if (!(Request.ApplicationPath.Equals(homePageUrl)))
                    {
                        Response.Redirect(homePageUrl);
                    }
                }
            }
            SortedDictionary <string, string> contentInfo = ApplicationServices.LoadContent();

            InitializeSiteMaster();
            string s = null;

            if (!(contentInfo.TryGetValue("PageTitle", out s)))
            {
                s = ApplicationServices.Current.Name;
            }
            this.Title = s;
            if (_pageTitleContent != null)
            {
                if (_isTouchUI)
                {
                    _pageTitleContent.Text = String.Empty;
                }
                else
                {
                    _pageTitleContent.Text = s;
                }
            }
            HtmlMeta appName = new HtmlMeta();

            appName.Name    = "application-name";
            appName.Content = ApplicationServices.Current.Name;
            Header.Controls.Add(appName);
            if (contentInfo.TryGetValue("Head", out s) && (_headContent != null))
            {
                _headContent.Text = s;
            }
            if (contentInfo.TryGetValue("PageContent", out s) && (_pageContent != null))
            {
                if (_isTouchUI)
                {
                    s = String.Format("<div id=\"PageContent\" style=\"display:none\">{0}</div>", s);
                }
                Match userControl = Regex.Match(s, "<div\\s+data-user-control\\s*=s*\"([\\s\\S]+?)\"\\s*>\\s*</div>");
                if (userControl.Success)
                {
                    int startPos = 0;
                    while (userControl.Success)
                    {
                        _pageContent.Controls.Add(new LiteralControl(s.Substring(startPos, (userControl.Index - startPos))));
                        startPos = (userControl.Index + userControl.Length);
                        string controlFileName  = userControl.Groups[1].Value;
                        string controlExtension = Path.GetExtension(controlFileName);
                        string siteControlText  = null;
                        if (!(controlFileName.StartsWith("~")))
                        {
                            controlFileName = (controlFileName + "~");
                        }
                        if (String.IsNullOrEmpty(controlExtension))
                        {
                            string testFileName = (controlFileName + ".ascx");
                            if (File.Exists(Server.MapPath(testFileName)))
                            {
                                controlFileName  = testFileName;
                                controlExtension = ".ascx";
                            }
                            else
                            {
                                if (ApplicationServices.IsSiteContentEnabled)
                                {
                                    string relativeControlPath = controlFileName.Substring(1);
                                    if (relativeControlPath.StartsWith("/"))
                                    {
                                        relativeControlPath = relativeControlPath.Substring(1);
                                    }
                                    siteControlText = ApplicationServices.Current.ReadSiteContentString(("sys/" + relativeControlPath));
                                }
                                if (siteControlText == null)
                                {
                                    testFileName = (controlFileName + ".html");
                                    if (File.Exists(Server.MapPath(testFileName)))
                                    {
                                        controlFileName  = testFileName;
                                        controlExtension = ".html";
                                    }
                                }
                            }
                        }
                        try
                        {
                            if (controlExtension == ".ascx")
                            {
                                _pageContent.Controls.Add(LoadControl(controlFileName));
                            }
                            else
                            {
                                string controlText = siteControlText;
                                if (controlText == null)
                                {
                                    controlText = File.ReadAllText(Server.MapPath(controlFileName));
                                }
                                Match bodyMatch = Regex.Match(controlText, "<body[\\s\\S]*?>([\\s\\S]+?)</body>");
                                if (bodyMatch.Success)
                                {
                                    controlText = bodyMatch.Groups[1].Value;
                                }
                                controlText = Localizer.Replace("Controls", Path.GetFileName(Server.MapPath(controlFileName)), controlText);
                                _pageContent.Controls.Add(new LiteralControl(controlText));
                            }
                        }
                        catch (Exception ex)
                        {
                            _pageContent.Controls.Add(new LiteralControl(String.Format("Error loading \'{0}\': {1}", controlFileName, ex.Message)));
                        }
                        userControl = userControl.NextMatch();
                    }
                    if (startPos < s.Length)
                    {
                        _pageContent.Controls.Add(new LiteralControl(s.Substring(startPos)));
                    }
                }
                else
                {
                    _pageContent.Text = s;
                }
            }
            else
            if (_isTouchUI)
            {
                _pageContent.Text = "<div id=\"PageContent\" style=\"display:none\"><div data-app-role=\"page\">404 Not Foun" +
                                    "d</div></div>";
                this.Title = "Police-Training";
            }
            else
            {
                _pageContent.Text = "404 Not Found";
            }
            if (_isTouchUI)
            {
                if (_pageFooterContent != null)
                {
                    _pageFooterContent.Text = "<footer style=\"display:none\"><small>\t\r\n2017 &copy;<b> Beaver Borough Police Depar" +
                                              "tment</b> All rights reserved.</small></footer>";
                }
            }
            else
            if (contentInfo.TryGetValue("About", out s))
            {
                if (_pageSideBarContent != null)
                {
                    _pageSideBarContent.Text = String.Format("<div class=\"TaskBox About\"><div class=\"Inner\"><div class=\"Header\">About</div><div" +
                                                             " class=\"Value\">{0}</div></div></div>", s);
                }
            }
            string bodyAttributes = null;

            if (contentInfo.TryGetValue("BodyAttributes", out bodyAttributes))
            {
                _bodyAttributes.Parse(bodyAttributes);
            }
            if (!(_isTouchUI))
            {
                string classAttr = _bodyAttributes["class"];
                if (String.IsNullOrEmpty(classAttr))
                {
                    classAttr = String.Empty;
                }
                if (!(classAttr.Contains("Wide")))
                {
                    classAttr = (classAttr + " Standard");
                }
                classAttr = ((classAttr + " ")
                             + (Regex.Replace(Request.Path.ToLower(), "\\W", "_").Substring(1) + "_html"));
                _bodyAttributes["class"] = classAttr.Trim();
            }
            _bodyTag.Text = String.Format("\r\n<body{0}>\r\n", _bodyAttributes.ToString());
            base.OnInit(e);
        }