private void load() { //Child = screenStack = new ScreenStack { RelativeSizeAxes = Axes.Both }; NovelContent.AddRange(new Drawable[] { new SpriteText { Anchor = Anchor.Centre, Origin = Anchor.Centre, Text = "Hello World", Font = new FontUsage(size: 72) }, new Sprite { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Size = new osuTK.Vector2(450, 600), // example texture is not included, this will get removed soon anyway Texture = LargeTextureStore.Get("example"), Depth = float.MinValue, }, new Box { Colour = Colour4.DarkSlateBlue, RelativeSizeAxes = Axes.Both, Depth = float.MaxValue } }); }
/// <summary> /// 根据书籍ID查询目录 /// </summary> /// <returns></returns> public MDataTable GetNovelContents(string novelId) { var model = new NovelContent(); var dt = model.Select(string.Format("NovelID='{0}' order by Id", novelId)); return(dt); }
/// <summary> /// 保存目录内容为HTML文件 /// </summary> /// <param name="novel">书籍</param> /// <param name="menu">目录实体</param> /// <param name="modelContent">模板</param> /// <param name="priorMenu">上一目录实体</param> /// <param name="nextMenu">下一目录实体</param> /// <param name="skipExist">跳过已下载章节,默认true</param> /// <returns></returns> public string SaveNovelContentToHtml(Novel novel, ref NovelContent menu, string modelContent, NovelContent priorMenu, NovelContent nextMenu, bool skipExist = true) { string saveFileName = string.Format(FILE_PATH_CHAPTER_MODEL, menu.NovelID, menu.Id); //跳过已下载的章节 if (skipExist && File.Exists(saveFileName)) { return(string.Format("已跳过 《{0}》", menu.Title)); } string html = CommonHelper.GetHtml(menu.ComeFrom); string content = CommonHelper.GetValue(html, novel.ContentStart, novel.ContentEnd); if (html.Contains("操作超时") && content.Length == 0) { content = "操作超时"; Console.WriteLine(string.Format("操作超时 - > {0}-{1}", menu.Id, menu.Title)); } CommonHelper.SaveToFile( saveFileName, modelContent .Replace(@"[[title]]", menu.Title) .Replace(@"[[Content]]", Regex.Replace(content, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase)) .Replace(@"Prior.htm", string.Format("{0}.htm", priorMenu == null ? "List" : priorMenu.Id.ToString())) .Replace(@"Next.htm", string.Format("{0}.htm", nextMenu == null ? "List" : nextMenu.Id.ToString())) ); menu.DownDate = DateTime.Now; menu.DownTime = DateTime.Now; menu.WordNums = content.Length; return(Path.GetFullPath(saveFileName)); }
/// <summary> /// 查询目录信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public NovelContent GetNovelContent(string id) { var model = new NovelContent(); if (model.Fill(id)) { return(model); } return(null); }
/// <summary> /// 保存目录内容为HTML文件 /// </summary> /// <param name="novel">书籍</param> /// <param name="menu">目录实体</param> /// <param name="modelContent">模板</param> /// <param name="priorMenu">上一目录实体</param> /// <param name="nextMenu">下一目录实体</param> /// <param name="skipExist">跳过已下载章节,默认true</param> /// <returns></returns> public string SaveNovelContentToHtml(Novel novel, ref NovelContent menu, string modelContent, NovelContent priorMenu, NovelContent nextMenu, ref string downLoadMsg, bool skipExist = true) { //string saveFileName = string.Format(FILE_PATH_CHAPTER_MODEL, menu.NovelID, menu.Id); string saveFileName = GetChapterFileName(SAVE_TYPE, menu.NovelID, menu.Id); //跳过已下载的章节 if (skipExist && File.Exists(saveFileName)) { downLoadMsg = "已跳过"; return(string.Format("已跳过 《{0}》", menu.Title)); } string html = CommonHelper.GetHtml(menu.ComeFrom); string content = CommonHelper.GetValue(html, novel.ContentStart, novel.ContentEnd); content = Regex.Replace(content, novel.NeedDelStr, "", RegexOptions.IgnoreCase); content = Regex.Replace(content, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); if (html.Contains("操作超时") && content.Length == 0) { downLoadMsg = "操作超时"; content = "操作超时"; Console.WriteLine(string.Format("操作超时 - > {0}-{1}", menu.Id, menu.Title)); } menu.DownDate = DateTime.Now; menu.DownTime = DateTime.Now; menu.WordNums = content.Length; CommonHelper.SaveToFile( saveFileName, modelContent .Replace(@"[[title]]", menu.Title) .Replace(@"[[Content]]", content) .Replace(@"Prior.htm", string.Format("{0}.htm", priorMenu == null ? "List" : priorMenu.Id.ToString())) .Replace(@"Next.htm", string.Format("{0}.htm", nextMenu == null ? "List" : nextMenu.Id.ToString())) ); //保存为json文件 content = CommonHelper.HtmlToText(content); //content = Regex.Replace(content, @"<\s*/p>", "\r\n", RegexOptions.IgnoreCase); //content = Regex.Replace(content, @"<br\s*/>", "\r\n", RegexOptions.IgnoreCase); //content = Regex.Replace(content, @" ", " ", RegexOptions.IgnoreCase); //content = Regex.Replace(content, @"\t", "", RegexOptions.IgnoreCase); CommonHelper.SaveToFile(saveFileName, content, Encoding.UTF8); return(Path.GetFullPath(saveFileName)); }
public NovelExecuter(NovelContent data) { this.novelContentData = data; // Get all inner classes of NoveCommand var nestedType = typeof(NovelCommand).GetNestedTypes(System.Reflection.BindingFlags.Public); dicNovelCommandType = nestedType .Where(type => { return(0 < type.GetCustomAttributes(typeof(NovelCommandAttribute), false).Length); } ) .Select(type => type) .ToDictionary(type => ((NovelCommandAttribute)type.GetCustomAttributes(typeof(NovelCommandAttribute), false).First()).t); }
/// <summary> /// 从HTML中获取目录列表 /// </summary> /// <param name="html"></param> /// <param name="listUrl"></param> /// <returns></returns> public List <NovelContent> GetMenuList(string html, string novelId, string listUrl) { if (listUrl.Substring(listUrl.Length - 1, 1) != "/") { listUrl += "/"; } string rootUrl = listUrl.Substring(0, listUrl.IndexOf("/", 8)) + "/"; var list = new List <NovelContent>(); string prttern = "<a(\\s+(href\\s*=\"(?<url>([^\"])*)\"|'([^'])*'|\\w+=\"(([^\"])*)\"|'([^'])*'))+>(?<text>(.*?))</a>"; var maths = Regex.Matches(html, prttern); for (int i = 0; i < maths.Count; i++) { string url = maths[i].Groups["url"].Value; string text = maths[i].Groups["text"].Value; if (!url.Contains(".htm") && !url.Contains(".html")) { continue; } if (url.IndexOf("http") == -1) { if (url.StartsWith("/")) { url = rootUrl + url.Substring(1, url.Length - 1); } else { url = listUrl + url; } } var menu = new NovelContent() { NovelID = novelId, ComeFrom = url.Trim(), Title = text, DownDate = DateTime.Now, DownTime = DateTime.Now, bIsRead = 0, ChpType = 1 }; list.Add(menu); } return(list); }
/// <summary> /// 获取待下载章节 /// </summary> /// <returns></returns> private NovelContent GetDownLoadReady() { lock (lockObj) { NovelContent currMenu = null; if (waitingList.Count > 0) { currMenu = waitingList[0]; waitingList.RemoveAt(0); } else { //IsGetCompleted = true; currMenu = null; } Console.WriteLine(string.Format("取章节-> {0}-{1}", currMenu?.Id, currMenu?.Title)); return(currMenu); } }
public string SaveChartsContentToJson(ref NovelContent menu, ref string content, ref string downLoadMsg, bool skipExist = true) { //string saveFileName = string.Format(FILE_PATH_CHAPTER_MODEL, menu.NovelID, menu.Id); string saveFileName = GetChapterFileName(SAVE_TYPE, menu.NovelID, menu.Id, true); saveFileName = saveFileName + " " + menu.Title; //跳过已下载的章节 if (skipExist && File.Exists(saveFileName)) { downLoadMsg = "已跳过"; return(string.Format("已跳过 《{0}》", menu.Title)); } string html = CommonHelper.GetHtml(menu.ComeFrom); var sign = GetSiteSign(menu.ComeFrom); if (sign == null) { downLoadMsg = string.Format("未维护章节标志 《{0}》", menu.Title); return(string.Format("未维护章节标志 《{0}》", menu.Title)); } content = CommonHelper.GetValue(html, sign.ContentStart, sign.ContentEnd); content = Regex.Replace(content, sign.NeedDelStr, "", RegexOptions.IgnoreCase); content = Regex.Replace(content, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); if (html.Contains("操作超时") && content.Length == 0) { downLoadMsg = "操作超时"; content = "操作超时"; Console.WriteLine(string.Format("操作超时 - > {0}-{1}", menu.Id, menu.Title)); } menu.DownDate = DateTime.Now; menu.DownTime = DateTime.Now; menu.WordNums = content.Length; //保存为json文件 content = CommonHelper.HtmlToText(content); content = "\r\n\r\n" + menu.Title + "\r\n\r\n" + content; CommonHelper.SaveToFile(saveFileName, content, Encoding.UTF8); return(Path.GetFullPath(saveFileName)); }
/// <summary> /// 下载完成事件 /// </summary> /// <param name="menu"></param> private void CompleteEvent(NovelContent menu) { if (!IsDownCompleted && (waitingList.Count == CompletedCount)) { IsDownCompleted = true; Console.WriteLine(string.Format("下载完成-> {0}//{1}", waitingList.Count, CompletedCount)); if (successList.Count > 0) { //更新已下载的章节 var dt = MDataTable.CreateFrom(successList); dt.TableName = successList[0].TableName; dt.AcceptChanges(AcceptOp.Update); Console.WriteLine(string.Format("更新保存-> {0}//{1}", successList.Count, CompletedCount)); this.Invoke(new EventHandler(delegate { UpdateResult(menu.Id, string.Format("更新保存 {0}", menu.Title, Thread.CurrentThread.Name)); })); //this.Invoke(new Action<int, string>(UpdateResult), menu.Id, string.Format("更新保存 {0}", menu.Title, Thread.CurrentThread.Name)); //eventX.Set(); } //MessageBox.Show(arg2, "提示"); } }