protected void Page_Load(object sender, EventArgs e) { // Check the templates are loaded, else load them #if !DEBUG if (templates == null) { templates = new UberCMS.Misc.HtmlTemplates(); templates.reloadFromDisk(AppDomain.CurrentDomain.BaseDirectory + "\\Installer\\Templates"); } #else if (templates == null) { templates = new UberCMS.Misc.HtmlTemplates(); } templates.reloadFromDisk(AppDomain.CurrentDomain.BaseDirectory + "\\Installer\\Templates"); #endif // Check if any DB settings have been loaded, else load them if (dbSettings == null && File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\CMS.config")) { XmlDocument settings = new XmlDocument(); settings.LoadXml(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "\\CMS.config")); dbSettings = new DbSettings( settings["settings"]["db"]["host"].InnerText, settings["settings"]["db"]["database"].InnerText, settings["settings"]["db"]["username"].InnerText, settings["settings"]["db"]["password"].InnerText, int.Parse(settings["settings"]["db"]["port"].InnerText) ); settings = null; } // Invoke the correct page to handle the request UberCMS.Misc.PageElements pageElements = new UberCMS.Misc.PageElements(); pageElements["URL"] = ResolveUrl("/install"); pageElements["BASE_URL"] = ResolveUrl("/"); StringBuilder content = new StringBuilder(); #if !INSTALLED switch (Request.QueryString["1"]) { case "home": case null: pageHome(ref pageElements, Request, Response, ref content); break; case "setup": pageSetup(ref pageElements, Request, Response, ref content); break; case "install": pageInstall(ref pageElements, Request, Response, ref content); break; } #else Response.Redirect(ResolveUrl("")); #endif // Build and display the final output pageElements["CONTENT"] = content.ToString(); StringBuilder template = new StringBuilder(templates[TEMPLATES_KEY]["template"]); pageElements.replaceElements(ref template, 0, 5); Response.Write(template.ToString()); }
protected void Page_Load(object sender, EventArgs e) { // Check the templates are loaded, else load them #if !DEBUG if (templates == null) { templates = new UberCMS.Misc.HtmlTemplates(); templates.reloadFromDisk(AppDomain.CurrentDomain.BaseDirectory + "\\Installer\\Templates"); } #else if (templates == null) templates = new UberCMS.Misc.HtmlTemplates(); templates.reloadFromDisk(AppDomain.CurrentDomain.BaseDirectory + "\\Installer\\Templates"); #endif // Check if any DB settings have been loaded, else load them if (dbSettings == null && File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\CMS.config")) { XmlDocument settings = new XmlDocument(); settings.LoadXml(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "\\CMS.config")); dbSettings = new DbSettings( settings["settings"]["db"]["host"].InnerText, settings["settings"]["db"]["database"].InnerText, settings["settings"]["db"]["username"].InnerText, settings["settings"]["db"]["password"].InnerText, int.Parse(settings["settings"]["db"]["port"].InnerText) ); settings = null; } // Invoke the correct page to handle the request UberCMS.Misc.PageElements pageElements = new UberCMS.Misc.PageElements(); pageElements["URL"] = ResolveUrl("/install"); pageElements["BASE_URL"] = ResolveUrl("/"); StringBuilder content = new StringBuilder(); #if !INSTALLED switch (Request.QueryString["1"]) { case "home": case null: pageHome(ref pageElements, Request, Response, ref content); break; case "setup": pageSetup(ref pageElements, Request, Response, ref content); break; case "install": pageInstall(ref pageElements, Request, Response, ref content); break; } #else Response.Redirect(ResolveUrl("")); #endif // Build and display the final output pageElements["CONTENT"] = content.ToString(); StringBuilder template = new StringBuilder(templates[TEMPLATES_KEY]["template"]); pageElements.replaceElements(ref template, 0, 5); Response.Write(template.ToString()); }
protected void Page_Load(object sender, EventArgs e) { // Begin recording the time for the request to be processed Stopwatch timer = new Stopwatch(); timer.Start(); // Check the core is operational switch (Core.state) { case Core.State.NotInstalled: Response.Redirect("/install", true); break; case Core.State.CriticalFailure: Response.Write("<html><head><title>Uber CMS - Critical Failure</title></head><body>"); Response.Write("<h1>Core Failure - Critical Error</h1>"); Response.Write("<h2>Error</h2><p>" + Core.criticalFailureError.Message + "</p><h2>Stack-trace</h2><p>" + Core.criticalFailureError.StackTrace + "</p>"); Response.Write("<h2>Base Error</h2><p>" + Core.criticalFailureError.GetBaseException().Message + "</p><h2>Base Stack-trace</h2><p>" + Core.criticalFailureError.GetBaseException().StackTrace + "</p>"); Response.Write("</body></html>"); Response.End(); break; case Core.State.Stopped: Core.cmsStart(); break; } // Setup the request conn = Core.connectorCreate(true); elements = new PageElements(); elements["URL"] = ResolveUrl(""); // If debugging, reload cached templates #if DEBUG Core.templates.reloadDb(conn); #endif // Invoke the pre-handler methods Result plugins = conn.Query_Read("SELECT pluginid, classpath FROM plugins WHERE state='" + (int)UberCMS.Plugins.Base.State.Enabled + "' AND handles_request_start='1' ORDER BY invoke_order ASC"); foreach (ResultRow plugin in plugins) Plugins.invokeMethod(plugin["classpath"], "requestStart", new object[] { plugin["pluginid"], conn, elements, Request, Response }); // Invoke the plugin responsible for handling the request int i; Plugins.Request.RequestHandler handler; Plugins.Request.RequestHandlers handlers = Plugins.Request.getRequestPlugin(conn, Request); for (i = 0; i < handlers.count() && elements["CONTENT"] == null; i++) { handler = handlers[i]; Plugins.invokeMethod(handler.ClassPath, "handleRequest", new object[] { handler.Pluginid, conn, elements, Request, Response }); } // If no content has been set, a 404 has occurred - hence find a plugin to handle this issue if (elements["CONTENT"] == null) { handlers = Plugins.Request.getRequest404s(conn); for (i = 0; i < handlers.count() && elements["CONTENT"] == null; i++) { handler = handlers[i]; Plugins.invokeMethod(handler.ClassPath, "handleRequestNotFound", new object[] { handler.Pluginid, conn, elements, Request, Response }); } } // Check if any content has still not been set - if so we'll display a manual error to inform the user/developer/administrator/operator if(elements["CONTENT"] == null) { // 404 not found... elements["TITLE"] = "Page Not Found"; elements["CONTENT"] = "<p>The requested page could not be found and a 404 page could not be served...</p>"; } // Invoke the post-handler methods plugins = conn.Query_Read("SELECT pluginid, classpath FROM plugins WHERE state='" + (int)UberCMS.Plugins.Base.State.Enabled + "' AND handles_request_end='1' ORDER BY invoke_order ASC"); foreach (ResultRow plugin in plugins) try { Plugins.invokeMethod(plugin["classpath"], "requestEnd", new object[] { plugin["pluginid"], conn, elements, Request, Response }); } catch { } // Format the site template StringBuilder content = new StringBuilder(Core.templates.get(elements["TEMPLATE"], "base", null) ?? string.Empty); // Stop the timer and set element timer.Stop(); elements["BENCH_MARK"] = "Generated in " + timer.ElapsedMilliseconds + " m/s (" + ((float)timer.ElapsedMilliseconds / 1000) + " secs)"; // Replace elements within template elements.replaceElements(ref content, 0, 3); // Output the built page to the user Response.Write(content.ToString()); // Dispose connector conn.Disconnect(); }