private int GetCacheBuster(DemoAttribute att) { DateTime lastWrite = DateTime.MinValue; foreach (var ext in new [] { "txt", "cs", "js", "html"}) { String vsource = String.Format("{0}/{1}.{2}", att.Path, att.Id, ext); var fileInfo = new FileInfo(DextopUtil.MapPath(vsource)); if (fileInfo.Exists) { var lw = fileInfo.LastWriteTime; if (lw > lastWrite) lastWrite = lw; } } return Math.Abs(lastWrite.GetHashCode()); }
private int GetCacheBuster(DemoAttribute att) { DateTime lastWrite = DateTime.MinValue; foreach (var ext in new [] { "txt", "cs", "js", "html" }) { String vsource = String.Format("{0}/{1}.{2}", att.Path, att.Id, ext); var fileInfo = new FileInfo(DextopUtil.MapPath(vsource)); if (fileInfo.Exists) { var lw = fileInfo.LastWriteTime; if (lw > lastWrite) { lastWrite = lw; } } } return(Math.Abs(lastWrite.GetHashCode())); }
void CreateSourceHtml(DemoAttribute att, string type) { bool plain = (type != "html"); String extension = plain ? String.Format("{0}.html", type) : type; String vsource = String.Format("{0}/{1}.{2}", att.Path, att.Id, type); String vmdsource = String.Format("{0}/{1}.txt", att.Path, att.Id); String vdest = String.Format("~/source/{0}.{1}", att.Id, extension); String source = DextopUtil.MapPath(vsource); String mdsource = DextopUtil.MapPath(vmdsource); String dest = DextopUtil.MapPath(vdest); String content = null; if (File.Exists(source)) { if (type == "cs") { content = StripDemoAttributes(File.ReadAllLines(source)); } else { content = File.ReadAllText(source); } } else if (!plain && File.Exists(mdsource)) { content = ReadAndTransformMarkdownFile(mdsource); } using (var writer = new StringWriter()) { writer.WriteLine("<html>"); if (content != null) { writer.WriteLine("<head>"); writer.WriteLine("<link href=\"../client/css/showcase.css\" type=\"text/css\" rel=\"stylesheet\" />"); writer.WriteLine("<link href=\"../client/lib/prettify/prettify.css\" type=\"text/css\" rel=\"stylesheet\" />"); writer.WriteLine("<meta name=\"robots\" content=\"noindex\">"); writer.WriteLine("</head>"); if (plain) { writer.WriteLine("<script type=\"text/javascript\" src=\"../client/lib/prettify/prettify.js\"></script>"); writer.WriteLine("<script type=\"text/javascript\">window['PR_TAB_WIDTH'] = 4;</script>"); writer.WriteLine("<body onload=\"prettyPrint()\">"); writer.WriteLine("<pre class=\"prettyprint\">"); writer.WriteLine(WebUtility.HtmlEncode(content)); writer.WriteLine("</pre>"); } else { writer.WriteLine("<body>"); writer.WriteLine(content); } writer.WriteLine("</body>"); } writer.WriteLine("</html>"); var newContent = writer.ToString(); if (!File.Exists(dest) || File.ReadAllText(dest) != newContent) { File.WriteAllText(dest, newContent); } } }
void CreateSourceHtml(DemoAttribute att, string type) { bool plain = (type != "html"); String extension = plain ? String.Format("{0}.html", type) : type; String vsource = String.Format("{0}/{1}.{2}", att.Path, att.Id, type); String vmdsource = String.Format("{0}/{1}.txt", att.Path, att.Id); String vdest = String.Format("~/source/{0}.{1}", att.Id, extension); String source = DextopUtil.MapPath(vsource); String mdsource = DextopUtil.MapPath(vmdsource); String dest = DextopUtil.MapPath(vdest); String content = null; if (File.Exists(source)) { if (type == "cs") content = StripDemoAttributes(File.ReadAllLines(source)); else content = File.ReadAllText(source); } else if (!plain && File.Exists(mdsource)) { content = ReadAndTransformMarkdownFile(mdsource); } using (var writer = new StringWriter()) { writer.WriteLine("<html>"); if (content != null) { writer.WriteLine("<head>"); writer.WriteLine("<link href=\"../client/css/showcase.css\" type=\"text/css\" rel=\"stylesheet\" />"); writer.WriteLine("<link href=\"../client/lib/prettify/prettify.css\" type=\"text/css\" rel=\"stylesheet\" />"); writer.WriteLine("<meta name=\"robots\" content=\"noindex\">"); writer.WriteLine("</head>"); if (plain) { writer.WriteLine("<script type=\"text/javascript\" src=\"../client/lib/prettify/prettify.js\"></script>"); writer.WriteLine("<script type=\"text/javascript\">window['PR_TAB_WIDTH'] = 4;</script>"); writer.WriteLine("<body onload=\"prettyPrint()\">"); writer.WriteLine("<pre class=\"prettyprint\">"); writer.WriteLine(WebUtility.HtmlEncode(content)); writer.WriteLine("</pre>"); } else { writer.WriteLine("<body>"); writer.WriteLine(content); } writer.WriteLine("</body>"); } writer.WriteLine("</html>"); var newContent = writer.ToString(); if (!File.Exists(dest) || File.ReadAllText(dest) != newContent) File.WriteAllText(dest, newContent); } }