/// <summary> /// 对书名表创建静态的HTML页面 /// </summary> /// <param name="book">书对像</param> /// <param name="html">要生成页面的HTML</param> /// <returns>页面路径</returns> public static string CreateStaticHTMLFile(this 书名表 book, string html) { //susucong //string path = AppDomain.CurrentDomain.BaseDirectory + virtualPath + "/" + "HTML/" + book.分类标识.Trim().ToPingYing() + "/" + book.书名.Trim().ToPingYing() + "/"; string path = AppDomain.CurrentDomain.BaseDirectory + "../" + "HTML/" + book.分类标识.Trim().ToPingYing() + "/" + book.书名.Trim().ToPingYing() + "/"; //创建目录 if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } path = path + "index.html"; //写入文件 try { System.IO.File.WriteAllText(path, html, System.Text.Encoding.UTF8); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message + (ex.StackTrace == null ? " " : ex.StackTrace)); } return(path); }
/// <summary> /// 检查文件是不是存在 /// </summary> /// <param name="url"></param> /// <returns></returns> public string ImgIsOK(string url, 书名表 Currentbook) { // return url; if (url.Contains("86zw")) { string filename = "/images/BookImgs/" + Guid.NewGuid() + System.IO.Path.GetExtension(url); WebClient wc = new WebClient(); try { wc.DownloadFile(url, Server.MapPath(filename)); Currentbook.配图 = filename; NeedUpdate = true; } catch { //修改配图 Currentbook.配图 = "/Images/Noimg.jpg"; NeedUpdate = true; return(Currentbook.配图); } wc.Dispose(); } return(url); }
protected void Page_Load(object sender, EventArgs e) { System.Collections.Generic.IEnumerable <文章表> list = new List <文章表>(); string guid = Request.QueryString["guid"]; bool.TryParse(Request.QueryString["html"], out IsCresteHTMLPage); if (!string.IsNullOrEmpty(guid)) { //susucong 生成静态页面 if (QliliHelper.BaseSite.Contains("qlili.com") && System.Configuration.ConfigurationManager.AppSettings["启用Qlili获取数据"] != "0") { //使用url string result = QliliHelper.IndexBook(); if (!string.IsNullOrEmpty(result)) { currentBook = Tygdb.书名表.Where(p => p.GUID == Guid.Parse(guid)).FirstOrDefault(); Response.Write(result); currentBook.CreateStaticHTMLFile(result); Response.End(); return; } } list = Tygdb.文章表.Where(p => p.GUID == Guid.Parse(guid)).OrderBy(p => p.创建时间); if (list.Count() > 0) { var item = list.First(); BookName = item.书名; Creater = item.书名表.作者名称; LastTime = item.书名表.最后更新时间.ToString(); currentBook = item.书名表; } else { currentBook = Tygdb.书名表.Where(p => p.GUID == Guid.Parse(guid)).FirstOrDefault(); } if (list.Count() > 2) { //循环数据 list.Aggregate((c, n) => { n.一章 = c.本记录GUID; c.一章 = n.本记录GUID; return(n); }); currentBook.包含有效章节 = list.Count(); } } docList.EnableViewState = false; //System.Threading.Tasks.Task.Factory.StartNew(delegate //{ // System.Net.WebClient wc = new System.Net.WebClient(); // foreach (var item in list) // { // string url = item.GetHTMLFilePath(); // if (!System.IO.File.Exists(System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + url))) // { // //生成静态页面 // string str = wc.DownloadString(new Uri(Request.Url, "BookIndex.aspx?guid=" + item.本记录GUID)); // item.CreateStaticHTMLFile(str); // } // // item.采集用的URL9 = url ? url : "BookIndex.aspx?guid=" + book.GUID; // } //}); docList.DataSource = list; docList.DataBind(); }
/// <summary> /// 返回书本文件的文件名 /// </summary> /// <param name="book"></param> /// <returns></returns> public static string GetHTMLFilePath(this 书名表 book) { string path = virtualPath + "/HTML/" + book.分类标识.Trim().ToPingYing() + "/" + book.书名.Trim().ToPingYing() + "/index.html"; return(path); }
protected void Page_Load(object sender, EventArgs e) { List <文章表> list = new List <文章表>(); string guid = Request.QueryString["guid"]; string idstr = guid; bool.TryParse(Request.QueryString["html"], out IsCresteHTMLPage); if (!string.IsNullOrEmpty(guid)) { decimal id = 0; if (decimal.TryParse(idstr, out id)) { list = Tygdb.文章表.Where(p => p.ID == id).ToList(); } else { Guid guidx = Guid.Parse(guid); list = Tygdb.文章表.Where(p => p.本记录GUID == guidx).ToList(); } if (list.Count > 0) { BookName = list[0].书名; Creater = list[0].书名表.作者名称; DocName = list[0].章节名; Content = list[0].内容; 书id = list[0].GUID.ToString(); //替换86zw url Content = Content.Replace("<img src=\"http://", "<img src=\"/Site/PicProxy.ashx?guid=" + list[0].本记录GUID + "&u=" + Server.UrlEncode(list[0].采集用的URL1) + "&url=http://"); //上一章节 var perRecords = GetDocByGuid(list[0].一章.Value); 一章 = list[0].一章.Value.ToString(); //下一章节 var nextRecords = GetDocByGuid(list[0].一章.Value); 一章 = list[0].一章.Value.ToString(); 一页 = perRecords.Count() == 0 ? "" : string.Format(href, list[0].一章, "上一章 " + perRecords.ElementAt(0).章节名); 一页 = nextRecords.Count() == 0 ? "" : string.Format(href, list[0].一章, "下一章 " + nextRecords.ElementAt(0).章节名); list[0].最后访问时间 = DateTime.Now; list[0].总访问次数++; currentDoc = list[0]; currentBook = currentDoc.书名表; //生成静态页面 if (IsCresteHTMLPage) { href = "<a href='{0}'>{1}</a>"; if (perRecords.Count() > 0) { var per = perRecords.ElementAt(0); 一页 = perRecords.Count() == 0 ? "" : string.Format(href, per.GetHTMLFilePath(), "上一章 " + per.章节名); 一章 = per.ID + ".html"; } else { 一章 = "?"; 一页 = string.Empty; } if (nextRecords.Count() > 0) { var next = nextRecords.ElementAt(0); 一页 = nextRecords.Count() == 0 ? "" : string.Format(href, next.GetHTMLFilePath(), "下一章 " + next.章节名); 一章 = next.ID + ".html"; } else { 一页 = "?"; 一章 = string.Empty; } } } } }