public void ProcessRequest(HttpRequest request, Org.Reddragonit.EmbeddedWebServer.Interfaces.Site site) { request.ResponseHeaders["Cache-Control"] = "max-age = " + (60 * 60).ToString(); List <string> paths = new List <string>(); string ext = request.URL.AbsolutePath.Substring(request.URL.AbsolutePath.LastIndexOf(".")); string bPath = "scripts"; if (ext == ".css") { bPath = "styles"; } switch (request.URL.AbsolutePath) { case "/resources/scripts/core.js": case "/resources/styles/core.css": paths.AddRange(_CORE_PATHS); break; case "/resources/scripts/setup.js": case "/resources/styles/setup.css": paths.AddRange(_SETUP_PATHS); break; case "/resources/scripts/user.js": paths.AddRange(_USER_PATHS); foreach (MainMenuItem mmi in MainMenuItem.LoadAll()) { if (mmi.JavascriptURLs != null) { paths.AddRange(mmi.JavascriptURLs); } if (mmi.CombinedURLs != null) { paths.AddRange(mmi.CombinedURLs); } if (mmi.SubMenuItems != null) { foreach (SubMenuItem smi in mmi.SubMenuItems) { if (smi.JavascriptURLs != null) { paths.AddRange(smi.JavascriptURLs); } if (smi.CombinedURLs != null) { paths.AddRange(smi.CombinedURLs); } } } foreach (IHomePageComponent ihp in parts) { if (ihp.JSUrls != null) { paths.AddRange(ihp.JSUrls); } } } break; case "/resources/styles/user.css": paths.AddRange(_USER_PATHS); foreach (MainMenuItem mmi in MainMenuItem.LoadAll()) { if (mmi.CssURLs != null) { paths.AddRange(mmi.CssURLs); } if (mmi.CombinedURLs != null) { paths.AddRange(mmi.CombinedURLs); } if (mmi.SubMenuItems != null) { foreach (SubMenuItem smi in mmi.SubMenuItems) { if (smi.CssURLs != null) { paths.AddRange(smi.CssURLs); } if (smi.CombinedURLs != null) { paths.AddRange(smi.CombinedURLs); } } } foreach (IHomePageComponent ihp in parts) { if (ihp.CSSUrls != null) { paths.AddRange(ihp.CSSUrls); } } } break; } request.ResponseHeaders.ContentType = HttpUtility.GetContentTypeForExtension(request.URL.AbsolutePath.Substring(request.URL.AbsolutePath.LastIndexOf("."))); foreach (string str in paths) { if (str.StartsWith("TYPE=") || str.StartsWith("/EmbeddedJSGenerator.js?TYPE=")) { if (ext != ".css") { request.ResponseWriter.WriteLine("/* " + str + " */"); foreach (IRequestHandler irh in site.Handlers) { if (irh is EmbeddedServiceHandler) { request.ResponseWriter.WriteLine(((EmbeddedServiceHandler)irh).GenerateJSForServiceType(str.Substring(str.IndexOf("=") + 1))); } } } } else { List <string> tpaths = new List <string>(); if (str.StartsWith("/")) { if (str.EndsWith(".min" + ext)) { tpaths.Add(str); tpaths.Add(str.Substring(0, str.LastIndexOf(".min")) + ext); } else { tpaths.Add(str); tpaths.Add(str.Substring(0, str.LastIndexOf(ext)) + ".min" + ext); } } else { tpaths.AddRange(new string[] { "/resources/" + bPath + "/" + str.Replace(".", "/") + ext, "/resources/" + bPath + "/base/" + str.Replace(".", "/") + ext, "/resources/" + bPath + "/" + (request.IsMobile ? "mobile" : "desktop") + "/" + str.Replace(".", "/") + ext, "Org.Reddragonit.FreeSwitchConfig.Site." + bPath + ".base." + str + ext, "Org.Reddragonit.FreeSwitchConfig.Site." + bPath + "." + (request.IsMobile ? "mobile" : "desktop") + "." + str + ext, "/resources/" + bPath + "/" + str.Replace(".", "/") + ".min" + ext, "/resources/" + bPath + "/base/" + str.Replace(".", "/") + ".min" + ext, "/resources/" + bPath + "/" + (request.IsMobile ? "mobile" : "desktop") + "/" + str.Replace(".", "/") + ".min" + ext, "Org.Reddragonit.FreeSwitchConfig.Site." + bPath + ".base." + str + ".min" + ext, "Org.Reddragonit.FreeSwitchConfig.Site." + bPath + "." + (request.IsMobile ? "mobile" : "desktop") + "." + str + ".min" + ext }); } foreach (string path in tpaths) { if (path.StartsWith("/")) { request.ResponseWriter.WriteLine("/* " + path + " */"); VirtualMappedRequest vmp = new VirtualMappedRequest(new Uri("http://" + request.URL.Host + ":" + request.URL.Port.ToString() + path), request.Headers["Accept-Language"]); Org.Reddragonit.BackBoneDotNet.RequestHandler.HandleRequest(vmp); request.ResponseWriter.WriteLine(vmp.ToString()); if (site.EmbeddedFiles != null) { if (site.EmbeddedFiles.ContainsKey(path)) { if (ModelHandler.CompressJS) { request.ResponseWriter.WriteLine((request.URL.AbsolutePath.EndsWith(".js") ? JSMinifier.Minify(Utility.ReadEmbeddedResource(site.EmbeddedFiles[path].DLLPath)) : CSSMinifier.Minify(Utility.ReadEmbeddedResource(site.EmbeddedFiles[path].DLLPath)))); } else { request.ResponseWriter.WriteLine(Utility.ReadEmbeddedResource(site.EmbeddedFiles[path].DLLPath)); } } } string tmpStr = Utility.ReadEmbeddedResource(_ReverseURL(path)); if (tmpStr != null) { if (ModelHandler.CompressJS) { request.ResponseWriter.WriteLine((request.URL.AbsolutePath.EndsWith(".js") ? JSMinifier.Minify(tmpStr) : CSSMinifier.Minify(tmpStr))); } else { request.ResponseWriter.WriteLine(tmpStr); } } } else { request.ResponseWriter.WriteLine("/* " + _ExtractURL(path) + " */"); request.ResponseWriter.WriteLine(Utility.ReadEmbeddedResource(path)); } } } } if (request.URL.AbsolutePath == "/resources/scripts/core.js") { _WriteConstants(request); } else if (request.URL.AbsolutePath == "/resources/scripts/setup.js") { } else if (request.URL.AbsolutePath == "/resources/scripts/user.js") { Template st = new Template(Utility.ReadEmbeddedResource("Org.Reddragonit.FreeSwitchConfig.Site.Deployments.home.js")); st.SetAttribute("components", parts); request.ResponseWriter.WriteLine(st.ToString()); } }
/// <summary> /// Minifies the provided CSS /// </summary> /// <param name="css">CSS to minify</param> /// <returns>Minified CSS</returns> private static string RunCSSMin(string css) { return(CSSMinifier.Minify(css)); }