public ActionResult GetSourceFile(string file) { string path = this.HttpContext.Server.MapPath(file); string examplesRoot = this.HttpContext.Server.MapPath(ExamplesModel.ApplicationRoot + "/Areas/"); var fi = new FileInfo(path); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture)) { return(new HttpStatusCodeResult((int)HttpStatusCode.BadRequest)); } HighlighterBase hb = null; switch (fi.Extension.ToLowerInvariant()) { case ".aspx": case ".ascx": case ".cshtml": case ".master": hb = new ASPXHighlighter(); break; case ".cs": hb = new CSharpHighlighter(); break; case ".xml": case ".xsl": hb = new XMLHighlighter(); break; case ".js": hb = new JavaScriptHighlighter(); break; case ".css": hb = new CSSHighlighter(); break; default: return(Content(System.IO.File.ReadAllText(fi.FullName), "text/plain")); } HtmlParser parser = new HtmlParser(); hb.Parser = parser; string source = Regex.Replace(System.IO.File.ReadAllText(fi.FullName), "<%--Start exclude--%>.*?<%--End exclude--%>", "", RegexOptions.Singleline); source = hb.Parse(source); return(this.Content(string.Concat("<pre style='margin: 0px;font-size:14px;'>", source, "</pre>"), "text/html")); }
public ActionResult GetSourceFile(string file) { string path = this.HttpContext.Server.MapPath(file); string examplesRoot = this.HttpContext.Server.MapPath(ExamplesModel.ApplicationRoot + "/Areas/"); var fi = new FileInfo(path); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture)) { return new HttpStatusCodeResult((int)HttpStatusCode.BadRequest); } HighlighterBase hb = null; switch (fi.Extension.ToLowerInvariant()) { case ".aspx": case ".ascx": case ".cshtml": case ".master": hb = new ASPXHighlighter(); break; case ".cs": hb = new CSharpHighlighter(); break; case ".xml": case ".xsl": hb = new XMLHighlighter(); break; case ".js": hb = new JavaScriptHighlighter(); break; case ".css": hb = new CSSHighlighter(); break; default: return Content(System.IO.File.ReadAllText(fi.FullName), "text/plain"); } HtmlParser parser = new HtmlParser(); hb.Parser = parser; string source = Regex.Replace(System.IO.File.ReadAllText(fi.FullName), "<%--Start exclude--%>.*?<%--End exclude--%>", "", RegexOptions.Singleline); source = hb.Parse(source); return this.Content(string.Concat("<pre style='margin: 0px;font-size:14px;'>", source, "</pre>"), "text/html"); }
public static string JsToHtml(Uri url) { HighlighterBase hl = new JavaScriptHighlighter(); return SourceToHtml(url, hl); }
public static string JsToHtml(string source) { HighlighterBase hl = new JavaScriptHighlighter(); return SourceToHtml(source, hl); }
public void ProcessRequest(HttpContext context) { string examplesRoot = context.Server.MapPath(UIHelpers.ApplicationRoot + "/Examples/"); string codeRoot = context.Server.MapPath(UIHelpers.ApplicationRoot + "/Code/"); string path; string url; string transmit = context.Request["t"]; if (!string.IsNullOrEmpty(transmit)) { url = context.Request["e"]; if (string.IsNullOrEmpty(url)) { return; } url = "/Examples" + url; path = context.Server.MapPath(url); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture) && !path.StartsWith(codeRoot, true, CultureInfo.CurrentCulture)) { return; } context.Response.ContentType = "application/octet-stream"; context.Response.AppendHeader("Connection", "keep-alive"); context.Response.AppendHeader("Content-Disposition", string.Concat(" attachment; filename = ", new DirectoryInfo(path).Name, ".zip")); ZipFiles(path); context.Response.End(); return; } context.Response.ContentType = "text/html"; url = context.Request["f"]; path = context.Server.MapPath(url); FileInfo fi = new FileInfo(path); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture) && !path.StartsWith(codeRoot, true, CultureInfo.CurrentCulture)) { return; } HighlighterBase hb = null; switch (fi.Extension.ToLowerInvariant()) { case ".aspx": case ".ascx": case ".master": hb = new ASPXHighlighter(); break; case ".cs": hb = new CSharpHighlighter(); break; case ".xml": case ".xsl": hb = new XMLHighlighter(); break; case ".js": hb = new JavaScriptHighlighter(); break; case ".css": hb = new CSSHighlighter(); break; default: context.Response.ContentType = "text/plain"; context.Response.Write(File.ReadAllText(fi.FullName)); return; } context.Response.Write(HighLighterUtils.SourceToHtml(File.ReadAllText(fi.FullName), hb)); }
public static string JsToHtml(Uri url) { HighlighterBase hl = new JavaScriptHighlighter(); return(SourceToHtml(url, hl)); }
public static string JsToHtml(string source) { HighlighterBase hl = new JavaScriptHighlighter(); return(SourceToHtml(source, hl)); }
public ActionResult GetSourceFile(string file) { string path = this.HttpContext.Server.MapPath(file); string examplesRoot = this.HttpContext.Server.MapPath(ExamplesModel.ApplicationRoot + "/Areas/"); var fi = new FileInfo(path); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture)) { return(new HttpStatusCodeResult((int)HttpStatusCode.BadRequest)); } HighlighterBase hb = null; bool markup = false; switch (fi.Extension.ToLowerInvariant()) { case ".aspx": case ".ascx": case ".cshtml": case ".master": hb = new ASPXHighlighter(); markup = true; break; case ".cs": hb = new CSharpHighlighter(); break; case ".xml": case ".xsl": hb = new XMLHighlighter(); break; case ".js": hb = new JavaScriptHighlighter(); break; case ".css": hb = new CSSHighlighter(); break; default: return(Content(System.IO.File.ReadAllText(fi.FullName), "text/plain")); } string source = System.IO.File.ReadAllText(fi.FullName); if (markup) { string origCSScriptStart = @"<script runat=""server"">"; string origCSScriptEnd = @"</script>"; string origJSScriptStart = @"<script>"; string origJSScriptEnd = @"</script>"; string origCSScriptText = CutFromTo(source, origCSScriptStart, origCSScriptEnd); string origJSScriptText = CutFromTo(source, origJSScriptStart, origJSScriptEnd); source = HighLighterUtils.SourceToHtml(source, hb); if (!string.IsNullOrEmpty(origCSScriptText)) { string strCSScriptStart = CutFromTo(HighLighterUtils.SourceToHtml(origCSScriptStart, hb), ">", "</pre>"); string strCSScriptEnd = CutFromTo(HighLighterUtils.SourceToHtml(origCSScriptEnd, hb), ">", "</pre>"); string csText = CutFromTo(source, strCSScriptStart, strCSScriptEnd); source = source.Replace(csText, CutFromTo(HighLighterUtils.CSharpToHtml(origCSScriptText), ">", "</pre>")); } if (!string.IsNullOrEmpty(origJSScriptText)) { string strJSScriptStart = CutFromTo(HighLighterUtils.SourceToHtml(origJSScriptStart, hb), ">", "</pre>"); string strJSScriptEnd = CutFromTo(HighLighterUtils.SourceToHtml(origJSScriptEnd, hb), ">", "</pre>"); string jsText = CutFromTo(source, strJSScriptStart, strJSScriptEnd); source = source.Replace(jsText, CutFromTo(HighLighterUtils.JsToHtml(origJSScriptText), ">", "</pre>")); } } else { source = HighLighterUtils.SourceToHtml(source, hb); } return(this.Content(source, "text/html")); }
public void ProcessRequest(HttpContext context) { string examplesRoot = context.Server.MapPath(UIHelpers.ApplicationRoot+"/Examples/"); string codeRoot = context.Server.MapPath(UIHelpers.ApplicationRoot+"/Code/"); string path; string url; string transmit = context.Request["t"]; if (!string.IsNullOrEmpty(transmit)) { url = context.Request["e"]; if (string.IsNullOrEmpty(url)) { return; } url = "/Examples"+url; path = context.Server.MapPath(url); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture) && !path.StartsWith(codeRoot, true, CultureInfo.CurrentCulture)) { return; } context.Response.ContentType = "application/octet-stream"; context.Response.AppendHeader("Connection", "keep-alive"); context.Response.AppendHeader("Content-Disposition", string.Concat(" attachment; filename = ", new DirectoryInfo(path).Name, ".zip")); ZipFiles(path); context.Response.End(); return; } context.Response.ContentType = "text/html"; url = context.Request["f"]; path = context.Server.MapPath(url); FileInfo fi = new FileInfo(path); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture) && !path.StartsWith(codeRoot, true, CultureInfo.CurrentCulture)) { return; } HighlighterBase hb = null; switch (fi.Extension.ToLowerInvariant()) { case ".aspx": case ".ascx": case ".master": hb = new ASPXHighlighter(); break; case ".cs": hb = new CSharpHighlighter(); break; case ".xml": case ".xsl": hb = new XMLHighlighter(); break; case ".js": hb = new JavaScriptHighlighter(); break; case ".css": hb = new CSSHighlighter(); break; default: context.Response.ContentType = "text/plain"; context.Response.Write(File.ReadAllText(fi.FullName)); return; } context.Response.Write(HighLighterUtils.SourceToHtml(File.ReadAllText(fi.FullName), hb)); }
public void ProcessRequest(HttpContext context) { string examplesRoot = context.Server.MapPath(UIHelpers.ApplicationRoot + "/Moduls/"); string codeRoot = context.Server.MapPath(UIHelpers.ApplicationRoot + "/Code/"); string path; string url; string transmit = context.Request["t"]; if (!string.IsNullOrEmpty(transmit)) { url = context.Request["e"]; if (string.IsNullOrEmpty(url)) { return; } url = "/Moduls" + url; path = context.Server.MapPath(url); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture) && !path.StartsWith(codeRoot, true, CultureInfo.CurrentCulture)) { return; } context.Response.ContentType = "application/octet-stream"; context.Response.AppendHeader("Connection", "keep-alive"); context.Response.AppendHeader("Content-Disposition", string.Concat(" attachment; filename = ", new DirectoryInfo(path).Name, ".zip")); ZipFiles(path); context.Response.End(); return; } context.Response.ContentType = "text/html"; url = context.Request["f"]; path = context.Server.MapPath(url); FileInfo fi = new FileInfo(path); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture) && !path.StartsWith(codeRoot, true, CultureInfo.CurrentCulture)) { return; } HighlighterBase hb = null; bool markup = false; switch (fi.Extension.ToLowerInvariant()) { case ".aspx": case ".ascx": case ".master": hb = new ASPXHighlighter(); markup = true; break; case ".cs": hb = new CSharpHighlighter(); break; case ".xml": case ".xsl": hb = new XMLHighlighter(); break; case ".js": hb = new JavaScriptHighlighter(); break; case ".css": hb = new CSSHighlighter(); break; default: context.Response.ContentType = "text/plain"; context.Response.Write(File.ReadAllText(fi.FullName)); return; } string fileText = File.ReadAllText(fi.FullName); if (markup) { string origCSScriptStart = @"<script runat=""server"">"; string origCSScriptEnd = @"</script>"; string origJSScriptStart = @"<script>"; string origJSScriptEnd = @"</script>"; string origCSScriptText = CutFromTo(fileText, origCSScriptStart, origCSScriptEnd); string origJSScriptText = CutFromTo(fileText, origJSScriptStart, origJSScriptEnd); fileText = HighLighterUtils.SourceToHtml(fileText, hb); if (!string.IsNullOrEmpty(origCSScriptText)) { string strCSScriptStart = CutFromTo(HighLighterUtils.SourceToHtml(origCSScriptStart, hb), ">", "</pre>"); string strCSScriptEnd = CutFromTo(HighLighterUtils.SourceToHtml(origCSScriptEnd, hb), ">", "</pre>"); string csText = CutFromTo(fileText, strCSScriptStart, strCSScriptEnd); fileText = fileText.Replace(csText, CutFromTo(HighLighterUtils.CSharpToHtml(origCSScriptText), ">", "</pre>")); } if (!string.IsNullOrEmpty(origJSScriptText)) { string strJSScriptStart = CutFromTo(HighLighterUtils.SourceToHtml(origJSScriptStart, hb), ">", "</pre>"); string strJSScriptEnd = CutFromTo(HighLighterUtils.SourceToHtml(origJSScriptEnd, hb), ">", "</pre>"); string jsText = CutFromTo(fileText, strJSScriptStart, strJSScriptEnd); fileText = fileText.Replace(jsText, CutFromTo(HighLighterUtils.JsToHtml(origJSScriptText), ">", "</pre>")); } context.Response.Write(fileText); } else { context.Response.Write(HighLighterUtils.SourceToHtml(fileText, hb)); } }
public void ProcessRequest(HttpContext context) { string examplesRoot = context.Server.MapPath(UIHelpers.ApplicationRoot + "/Examples/"); string codeRoot = context.Server.MapPath(UIHelpers.ApplicationRoot + "/Code/"); string path; string url; string transmit = context.Request["t"]; if (!string.IsNullOrEmpty(transmit)) { url = context.Request["e"]; if (string.IsNullOrEmpty(url)) { return; } url = "/Examples" + url; path = context.Server.MapPath(url); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture) && !path.StartsWith(codeRoot, true, CultureInfo.CurrentCulture)) { return; } context.Response.ContentType = "application/octet-stream"; context.Response.AppendHeader("Connection", "keep-alive"); context.Response.AppendHeader("Content-Disposition", string.Concat(" attachment; filename = ", new DirectoryInfo(path).Name, ".zip")); ZipFiles(path); context.Response.End(); return; } context.Response.ContentType = "text/html"; url = context.Request["f"]; path = context.Server.MapPath(url); FileInfo fi = new FileInfo(path); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture) && !path.StartsWith(codeRoot, true, CultureInfo.CurrentCulture)) { return; } HighlighterBase hb = null; bool markup = false; switch (fi.Extension.ToLowerInvariant()) { case ".aspx": case ".ascx": case ".master": hb = new ASPXHighlighter(); markup = true; break; case ".cs": hb = new CSharpHighlighter(); break; case ".xml": case ".xsl": hb = new XMLHighlighter(); break; case ".js": hb = new JavaScriptHighlighter(); break; case ".css": hb = new CSSHighlighter(); break; default: context.Response.ContentType = "text/plain"; context.Response.Write(File.ReadAllText(fi.FullName)); return; } string fileText = File.ReadAllText(fi.FullName); if (markup) { string origCSScriptStart = @"<script runat=""server"">"; string origCSScriptEnd = @"</script>"; string origJSScriptStart = @"<script>"; string origJSScriptEnd = @"</script>"; string origCSScriptText = CutFromTo(fileText, origCSScriptStart, origCSScriptEnd); string origJSScriptText = CutFromTo(fileText, origJSScriptStart, origJSScriptEnd); fileText = HighLighterUtils.SourceToHtml(fileText, hb); if (!string.IsNullOrEmpty(origCSScriptText)) { string strCSScriptStart = CutFromTo(HighLighterUtils.SourceToHtml(origCSScriptStart, hb), ">", "</pre>"); string strCSScriptEnd = CutFromTo(HighLighterUtils.SourceToHtml(origCSScriptEnd, hb), ">", "</pre>"); string csText = CutFromTo(fileText, strCSScriptStart, strCSScriptEnd); fileText = fileText.Replace(csText, CutFromTo(HighLighterUtils.CSharpToHtml(origCSScriptText), ">", "</pre>")); } if (!string.IsNullOrEmpty(origJSScriptText)) { string strJSScriptStart = CutFromTo(HighLighterUtils.SourceToHtml(origJSScriptStart, hb), ">", "</pre>"); string strJSScriptEnd = CutFromTo(HighLighterUtils.SourceToHtml(origJSScriptEnd, hb), ">", "</pre>"); string jsText = CutFromTo(fileText, strJSScriptStart, strJSScriptEnd); fileText = fileText.Replace(jsText, CutFromTo(HighLighterUtils.JsToHtml(origJSScriptText), ">", "</pre>")); } context.Response.Write(fileText); } else { context.Response.Write(HighLighterUtils.SourceToHtml(fileText, hb)); } }
public ActionResult GetSourceFile(string file) { string path = this.HttpContext.Server.MapPath(file); string examplesRoot = this.HttpContext.Server.MapPath(ExamplesModel.ApplicationRoot + "/Areas/"); var fi = new FileInfo(path); if (!path.StartsWith(examplesRoot, true, CultureInfo.CurrentCulture)) { return new HttpStatusCodeResult((int)HttpStatusCode.BadRequest); } HighlighterBase hb = null; bool markup = false; switch (fi.Extension.ToLowerInvariant()) { case ".aspx": case ".ascx": case ".cshtml": case ".master": hb = new ASPXHighlighter(); markup = true; break; case ".cs": hb = new CSharpHighlighter(); break; case ".xml": case ".xsl": hb = new XMLHighlighter(); break; case ".js": hb = new JavaScriptHighlighter(); break; case ".css": hb = new CSSHighlighter(); break; default: return Content(System.IO.File.ReadAllText(fi.FullName), "text/plain"); } string source = System.IO.File.ReadAllText(fi.FullName); if (markup) { string origCSScriptStart = @"<script runat=""server"">"; string origCSScriptEnd = @"</script>"; string origJSScriptStart = @"<script>"; string origJSScriptEnd = @"</script>"; string origCSScriptText = CutFromTo(source, origCSScriptStart, origCSScriptEnd); string origJSScriptText = CutFromTo(source, origJSScriptStart, origJSScriptEnd); source = HighLighterUtils.SourceToHtml(source, hb); if (!string.IsNullOrEmpty(origCSScriptText)) { string strCSScriptStart = CutFromTo(HighLighterUtils.SourceToHtml(origCSScriptStart, hb), ">", "</pre>"); string strCSScriptEnd = CutFromTo(HighLighterUtils.SourceToHtml(origCSScriptEnd, hb), ">", "</pre>"); string csText = CutFromTo(source, strCSScriptStart, strCSScriptEnd); source = source.Replace(csText, CutFromTo(HighLighterUtils.CSharpToHtml(origCSScriptText), ">", "</pre>")); } if (!string.IsNullOrEmpty(origJSScriptText)) { string strJSScriptStart = CutFromTo(HighLighterUtils.SourceToHtml(origJSScriptStart, hb), ">", "</pre>"); string strJSScriptEnd = CutFromTo(HighLighterUtils.SourceToHtml(origJSScriptEnd, hb), ">", "</pre>"); string jsText = CutFromTo(source, strJSScriptStart, strJSScriptEnd); source = source.Replace(jsText, CutFromTo(HighLighterUtils.JsToHtml(origJSScriptText), ">", "</pre>")); } } else { source = HighLighterUtils.SourceToHtml(source, hb); } return this.Content(source, "text/html"); }