Esempio n. 1
0
        internal string ParseTemplate(string template, Contract.Page page, dynamic instance, ModuleSession moduleSession)
        {
            Debug.StartTimer("ThemeManager:ParseTemplate()");
            template = ParseBlocks(template, page, instance, moduleSession);
            Debug.StopTimer("ThemeManager:ParseTemplate()");

            return(template);
        }
Esempio n. 2
0
        private void Page_Load(object sender, EventArgs e)
        {
            try
            {
                #region Signing stuff
                //string CompiledKeySignature = "ACQAAASAAACUAAAABgIAAAAkAABSU0ExAAQAAAEAAQDdmZjq3STJVDfs8UsPnWlObTAO3q2S6ksjcEcNZyjndUVSBsg7Taeyl13TQIZvdcs7JotZxqFN/6Ix+A5D3luYGwfalRsPUm4MSo8tHgVg2frb8KkgxJnb8ma7d+KWdliykrAFfaCamF9xDAUxNPapzO4u2ip1m0IiL9Y9JCGFnw==";
                //string AssemblyKeySignature = Convert.ToBase64String(Assembly.GetExecutingAssembly().GetName().GetPublicKey());

                //if (CompiledKeySignature != AssemblyKeySignature)
                //throw new Exception("WebCore modification has been detected. This is a voilation of the BlazeSoft terms of service and has been reported to BlazeSoft.");
                #endregion

                Debug.StartTimer("PageLoad");
                Debug.WriteLine("Page Access Count: {0}", ++PageAccessCount);

                string httpProtocol = (Request.IsSecureConnection) ? "https://" : "http://";
                this.pageUri = new Uri(httpProtocol + Request.Url.Host + Request.RawUrl);

                #if !DEBUG
                if (SettingsManager.Session.GetSystemSetting("IsSetup", false) == false)
                {
                    if (Request.UserHostAddress != "::1")
                    {
                        Response.Write("We're sorry. This web site has not been set up yet.");
                        return;
                    }
                    else
                    {
                        pageUri = pageUri.ChangePageUriPath("/administration/setup");
                    }
                }
                #endif

                if (pageUri.AbsolutePath.ToLower().StartsWith("/themes"))
                {
                    string[] urlParts = pageUri.AbsolutePath.ToLower().Split('/');

                    if (urlParts.Length >= 4)
                    {
                        string themeKey = urlParts[2];
                        string assetKey = string.Join("/", urlParts, 3, urlParts.Length - 3);

                        Theme theme = ThemeManager.Session.GetTheme(themeKey);

                        if (theme == null)
                        {
                            throw new Exceptions.PageNotFoundException();
                        }

                        Asset asset = theme.GetAsset(assetKey);

                        if (asset == null)
                        {
                            throw new Exceptions.PageNotFoundException();
                        }

                        Response.ContentType = asset.MimeType;
                        Response.BinaryWrite(asset.Data);

                        Response.End();
                    }
                    else
                    {
                        throw new Exceptions.PageNotFoundException();
                    }
                }
                else
                {
                    moduleSession = new ModuleSession(HttpContext.Current);

                    foreach (Contract.Module module in moduleSession.GetLoadedModules())
                    {
                        if (moduleSession.GetInstance(module) != null)
                        {
                            pageUri = moduleSession.GetInstance(module).GetPageUri(pageUri);
                        }
                    }

                    Uri newPageUri = pageUri;

                    foreach (Contract.Module module in moduleSession.GetLoadedModules())
                    {
                        if (moduleSession.GetInstance(module) != null)
                        {
                            newPageUri = moduleSession.GetInstance(module).GetPageRedirect(newPageUri);
                        }
                    }

                    if (newPageUri.ToString() != pageUri.ToString())
                    {
                        Response.Redirect(newPageUri.ToString());
                    }

                    Contract.Page page = PageManager.Session.GetPageByUri(pageUri);

                    if (page == null)
                    {
                        throw new Exceptions.PageNotFoundException();
                    }

                    if (page.CompilerLanguage == "Html")
                    {
                        var htmlPageInstance = new Page();
                        htmlPageInstance.CorePage      = page;
                        htmlPageInstance.ModuleSession = moduleSession;

                        Response.Write(ThemeManager.Session.ParseTemplate(string.Join("\r\n", page.LatestReversion.Classes.Select(c => c.Data)), page, htmlPageInstance, moduleSession));
                    }
                    else
                    {
                        //PageManager.Session.CompilePages();

                        Page PageInstance = page.Instance;

                        if (PageInstance != null)
                        {
                            PageInstance.CorePage      = page;
                            PageInstance.ModuleSession = moduleSession;

                            Debug.StartTimer("Page:" + page.ID + ":Initialize()");
                            PageInstance.Initialize();
                            Debug.StopTimer("Page:" + page.ID + ":Initialize()");
                            string Output = PageInstance.Themes.GetHtmlOutput(page, PageInstance, moduleSession);
                            Debug.StartTimer("Page:" + page.ID + ":Deinitialize()");
                            PageInstance.Deinitialize();
                            Debug.StopTimer("Page:" + page.ID + ":Deinitialize()");

                            Response.Write(Output);
                        }
                    }
                }

                Debug.StopTimer("PageLoad");

                #if DEBUG
                Response.Write(Debug.Output);
                #else
                //if(SettingsCore.Instance.GetSystemSetting("InDev", false))
                Response.Write(Debug.Output);
                #endif
            }
            catch (ThreadAbortException) { this.Page_Unload(sender, e); }
        }
Esempio n. 3
0
        public string ParseBlocks(string Template, Contract.Page Page, dynamic This, ModuleSession ModuleSession)
        {
            int OpenCodeTags        = 0;
            int StartingCodeTag     = 0;
            int StartCodeIndex      = 0;
            int OpenVariableTags    = 0;
            int StartingVariableTag = 0;
            int StartVariableIndex  = 0;

            for (int i = 0; i < Template.Length; i++)
            {
                if (Template[i] == '{' && (i > 0 && Template[i - 1] != '\\'))
                {
                    OpenCodeTags++;
                }
                else if (Template[i] == '}' && (i > 0 && Template[i - 1] != '\\') && OpenCodeTags > 0)
                {
                    OpenCodeTags--;
                }

                if (Template[i] == '[' && (i > 0 && Template[i - 1] != '\\'))
                {
                    OpenVariableTags++;
                }
                else if (Template[i] == ']' && (i > 0 && Template[i - 1] != '\\') && OpenVariableTags > 0)
                {
                    OpenVariableTags--;
                }

                if (Template[i] == '{' && (i > 0 && Template[i - 1] == '#') && StartingCodeTag == 0)
                {
                    StartCodeIndex  = i;
                    StartingCodeTag = OpenCodeTags;
                }
                if (OpenCodeTags == StartingCodeTag - 1 && Template[i] == '}')
                {
                    StartingCodeTag = 0;

                    string Code       = Template.Substring(StartCodeIndex + 1, i - StartCodeIndex - 1).Replace("\\}", "}").Replace("\\{", "{");
                    string EvaledCode = this.EvalCode(Code, Page, This);

                    string tmpTemplate = Template.Substring(0, StartCodeIndex - 1) + EvaledCode + Template.Substring(i + 1);

                    i += tmpTemplate.Length - Template.Length;

                    Template = tmpTemplate;
                }

                if (Template[i] == '[' && (i > 0 && Template[i - 1] == '#') && StartingVariableTag == 0)
                {
                    StartVariableIndex  = i;
                    StartingVariableTag = OpenVariableTags;
                }
                if (OpenVariableTags == StartingVariableTag - 1 && Template[i] == ']')
                {
                    StartingVariableTag = 0;

                    string Code       = "Write(" + Template.Substring(StartVariableIndex + 1, i - StartVariableIndex - 1).Replace("\\]", "]").Replace("\\[", "[") + ");";
                    string EvaledCode = this.EvalCode(Code, Page, This);

                    string tmpTemplate = Template.Substring(0, StartVariableIndex - 1) + EvaledCode + Template.Substring(i + 1);

                    i += tmpTemplate.Length - Template.Length;

                    Template = tmpTemplate;
                }
            }

            return(Template);
        }