日期:2014-05-18 浏览次数:20504 次
public class BuilderHtml { public string RootUrl = WebUnits.WebRootUrl; public static string Serverpath = HttpContext.Current.Server.MapPath("/"); public void StartAutoBuilder() { WriteLog(string.Format("StartAutoBuilder")); ThreadStart threadStart = new ThreadStart(AutoBuilder); Thread th = new Thread(threadStart); th.Start(); } /// < summary> ///10分钟生成一次 /// < /summary> public void AutoBuilder() { int fasterBuilderTime = Int32.Parse(ConfigurationSettings.AppSettings["FasterBuilderTime"]); Thread.Sleep(fasterBuilderTime); BuildMethod(); } private void BuildMethod() { int sleepTime = Int32.Parse(ConfigurationSettings.AppSettings["BuilderTime"]); while (true) { Thread.Sleep(sleepTime); BuildAllHtmlPage(); } } /// <summary> /// 生成模块首页静态页面 /// </summary> public void BuildAllHtmlPage() { ThreadStart threadStart = new ThreadStart(BuildHtmlPage); Thread th = new Thread(threadStart); th.Start(); } private void BuildHtmlPage() { string[] htmlPages = ConfigurationSettings.AppSettings["HomeHtml"].ToString().Split(';'); for (int i = 0; i < htmlPages.Length; i++) { string config = htmlPages[i]; string[] arr = config.Split(','); string url = RootUrl + arr[0]; string filePath = Serverpath + arr[1]; try { DBResult result = HtmlBuilder.CreateHtml(url, filePath); if (!result.Succeed) WriteLog(string.Format("生成失败:{0},{1},原因:{2}", url, filePath, result.Message)); } catch (Exception ex) { WriteLog(string.Format("生成失败:{0},{1},原因:{2}", url, filePath, ex.Message)); } } } public static void WriteLog(string log) { try { string fileName = Serverpath + "log.txt"; if (File.Exists(fileName)) { using (StreamWriter sw = new StreamWriter(fileName, true)) { sw.WriteLine( string.Format("\r\n==[{0}]==================