private void Button_Add_Click(object sender, RoutedEventArgs e) { string ChapterIndex = InputBox_ChapterIndex.ValueStr.ToString(); string ChapterName = InputBox_ChapterName.ValueStr.ToString(); if (!string.IsNullOrEmpty(ChapterIndex) && !string.IsNullOrEmpty(ChapterName)) { try { if (GVL.Instance.CurNovelTree.Count > 0) { NovelChapter chapter = new NovelChapter(); chapter.ChapterIndex = Convert.ToInt32(ChapterIndex); chapter.Name = ChapterName; GVL.Instance.CurNovel.Chapters.Add(chapter); GVL.Instance.UpdateTreeView(); } }catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.Close(); } else { MessageBox.Show("index or name is null"); } }
private void AddNovelChapter(HtmlNodeCollection chapters, int nId) { NovelBLL nBill = new NovelBLL(); int sort = 0; foreach (var chapter in chapters) { NovelChapter chapterInfo = new NovelChapter(); chapterInfo.NId = nId; chapterInfo.Sort = sort; chapterInfo.ChapterName = chapter.InnerText; var cHref = chapter.Attributes["href"].Value.ToString(); var chapterDoc = new HtmlDocument(); chapterDoc.LoadHtml(HttpHelper.GetHtml(cHref)); chapterInfo.Content = chapterDoc.DocumentNode.SelectSingleNode("//*[@id=\"content\"]")?.InnerText; nBill.AddNovelChapter(chapterInfo); sort++; if (this.txtContent.InvokeRequired) { Action <string, string> actionDelegate = (x, y) => { this.txtContent.Text = string.Format("小说[{0}]--[{1}]采集成功;\r\n", x, y); }; this.txtContent.Invoke(actionDelegate, nId.ToString(), chapterInfo.ChapterName); } else { txtContent.Text += string.Format("小说[{0}]--[{1}]采集成功;\r\n", nId.ToString(), chapterInfo.ChapterName); } } }
public int AddNovelChapter(NovelChapter chapter) { string cmdText = @"INSERT dbo.NovelChapters ( ChapterName, Content, NId,Sort ) VALUES ( @ChapterName, -- ChapterName - nvarchar(50) @Content, -- Content - nvarchar(max) @NId, -- NId - int @Sort );"; int num = 0; try { if (!CheckNovelChapterExists(chapter.NId, chapter.ChapterName)) { SqlParameter[] param = new SqlParameter[] { new SqlParameter("ChapterName", chapter.ChapterName), new SqlParameter("NId", chapter.NId), new SqlParameter("Content", chapter.Content), new SqlParameter("Sort", chapter.Sort) }; var obj = SqlHelper.ExecuteScalar(CommandType.Text, cmdText, param); if (obj != null) { num = Convert.ToInt32(obj); } } } catch (Exception ex) { throw ex; } return(num); }
private void TreeView_Novel_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { INode item = e.NewValue as INode; if (item != null) { GVL.Instance.CurNode = new INode(item.GID, item.Name); if (GVL.Instance.CurNovel.IsNovelGUID(item.GID)) { //GVL.Instance.Panel_Cpation = GVL.Instance.CurNovel.Name; TextBox_Panel_Cpation.Text = GVL.Instance.CurNovel.Name; TextBox_BeiZhu.Text = ""; GVL.Instance.ChapterLabelList.Clear(); try { if (!string.IsNullOrEmpty(GVL.Instance.CurNovel.DocumentStr)) { FlowDocument doc = XamlReader.Parse(GVL.Instance.CurNovel.DocumentStr) as FlowDocument; RichTextBox_MainDoc.Document = doc; } else { RichTextBox_MainDoc.Document = new FlowDocument(); } } catch (Exception ex) { } } else { NovelChapter chapter = GVL.Instance.CurNovel.FindChapterByGUID(item.GID); if (chapter != null) { //GVL.Instance.Panel_Cpation = chapter.Name; TextBox_Panel_Cpation.Text = chapter.Name; TextBox_BeiZhu.Text = chapter.Instraction; GVL.Instance.ChapterLabelList.Clear(); try { if (!string.IsNullOrEmpty(chapter.DocumentStr)) { FlowDocument doc = XamlReader.Parse(chapter.DocumentStr) as FlowDocument; RichTextBox_MainDoc.Document = doc; } else { RichTextBox_MainDoc.Document = new FlowDocument(); } } catch (Exception ex) { } } } } }
public async Task <IActionResult> Content(Guid chapterId) { if (await _chapterManager.GetById(chapterId) is var chapter && chapter == null) { return(NotFound()); } if (await _titlesManager.GetById(chapter.TitleId) is var title && title == null) { return(NotFound()); } if (!title.Visible || !chapter.Visible) { return(NotFound()); } object result = chapter switch { ComicChapter comicChapter => new { chapter.Id, chapter.Volume, chapter.Number, chapter.Name, chapter.ReleaseDate, chapter.TitleId, Pages = (await _pagesManager.GetAll(comicChapter)).Select(page => (ComicPage)page).OrderBy(page => page.Number).Select(page => new { page.Id, page.Number, pageUrl = $"/content/{comicChapter.TitleId}/{comicChapter.Id}/{page.Id}{(page.Animated ? ".gif" : ".png")}" }).ToArray() }, NovelChapter novelChapter => new { chapter.Id, chapter.Volume, chapter.Number, chapter.Name, chapter.ReleaseDate, chapter.TitleId, novelChapter.Content, Pages = (await _pagesManager.GetAll(novelChapter)).Select(page => new { page.Id, pageUrl = $"/content/{novelChapter.TitleId}/{novelChapter.Id}/{page.Id}{(page.Animated ? ".gif" : ".png")}" }).ToArray() }, _ => throw new ArgumentException($"{chapter.GetType().Name} is not a supported type.") }; return(Json(result)); }
public async Task <IActionResult> ChapterJson(Guid chapterId) { if (await _chapterManager.GetById(chapterId) is var chapter && chapter == null) { return(Json(new { success = false, messages = new[] { ValidationMessages.ChapterNotFound } })); } var title = await _titlesManager.GetById(chapter.TitleId); if (!_signInManager.IsSignedIn(User) && (!title !.Visible || !chapter.Visible)) { return(Json(new { success = false, messages = new[] { ValidationMessages.ContentNotAvailable } })); } object result = chapter switch { ComicChapter comicChapter => new { success = true, Pages = (await _pagesManager.GetAll(comicChapter)).Select(page => (ComicPage)page).OrderBy(page => page.Number).Select(page => new { number = page.Number, address = $"/content/{comicChapter.TitleId}/{comicChapter.Id}/{page.Id}{(page.Animated ? ".gif" : ".png")}" }).ToArray() }, NovelChapter novelChapter => new { success = true, content = novelChapter.Content.AddImgLazyLoading("/assets/placeholder_page.png") }, _ => new { success = false } }; return(Json(result)); }
private void TreeView_MenuItem_AddChapter_Click(object sender, RoutedEventArgs e) { try { if (GVL.Instance.CurNovelTree.Count > 0) { NovelChapter chapter = new NovelChapter(); chapter.ChapterIndex = Convert.ToInt32(GVL.Instance.CurNovel.Chapters.Count + 1); chapter.Name = "新的一章"; GVL.Instance.CurNovel.Chapters.Add(chapter); GVL.Instance.UpdateTreeView(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void TextBox_BeiZhu_TextChanged(object sender, TextChangedEventArgs e) { TextBox box = sender as TextBox; if (GVL.Instance.CurNode != null) { if (GVL.Instance.CurNovel.IsNovelGUID(GVL.Instance.CurNode.GID)) { } else { NovelChapter chapter = GVL.Instance.CurNovel.FindChapterByGUID(GVL.Instance.CurNode.GID); if (chapter != null) { chapter.Instraction = box.Text; } } } }
private void TreeView_MenuItem_DelChapter_Click(object sender, RoutedEventArgs e) { if (GVL.Instance.CurNode != null) { if (!GVL.Instance.CurNovel.IsNovelGUID(GVL.Instance.CurNode.GID)) { NovelChapter item = GVL.Instance.CurNovel.FindChapterByGUID(GVL.Instance.CurNode.GID); if (MessageBox.Show("确定删除++" + item.Name + "++吗?", "温馨提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { GVL.Instance.CurNovel.Chapters.Remove(item); GVL.Instance.CurNode.Children.Remove(GVL.Instance.CurNode); GVL.Instance.CurNode = null; GVL.Instance.UpdateTreeView(); } } else { MessageBox.Show("不能删除根节点"); } } }
private void TextBox_Panel_Cpation_TextChanged(object sender, TextChangedEventArgs e) { TextBox box = sender as TextBox; if (GVL.Instance.CurNode != null) { if (GVL.Instance.CurNovel.IsNovelGUID(GVL.Instance.CurNode.GID)) { //FIXME:TextBox仅在失去焦点时才进行twoway的更新 GVL.Instance.CurNovel.Name = box.Text; } else { NovelChapter chapter = GVL.Instance.CurNovel.FindChapterByGUID(GVL.Instance.CurNode.GID); if (chapter != null) { chapter.Name = box.Text; } } GVL.Instance.UpdateTreeView(); } }
private void RichTextBox_MainDoc_TextChanged(object sender, TextChangedEventArgs e) { RichTextBox rbox = sender as RichTextBox; if (GVL.Instance.CurNode != null) { if (GVL.Instance.CurNovel.IsNovelGUID(GVL.Instance.CurNode.GID)) { GVL.Instance.CurNovel.DocumentStr = XamlWriter.Save(RichTextBox_MainDoc.Document); } else { NovelChapter chapter = GVL.Instance.CurNovel.FindChapterByGUID(GVL.Instance.CurNode.GID); if (chapter != null) { chapter.DocumentStr = XamlWriter.Save(RichTextBox_MainDoc.Document); TextRange range = new TextRange(RichTextBox_MainDoc.Document.ContentStart, RichTextBox_MainDoc.Document.ContentEnd); chapter.MainText = range.Text; } } GVL.Instance.UpdateTreeView(); } }
public bool Update(string id, Expression <Func <NovelChapter, bool> > expression, NovelChapter data) { var collection = GetCollection(id); var filter = Builders <NovelChapter> .Filter.Where(expression); return(collection.FindOneAndReplace(filter, data) != null); }
public void Insert(string id, NovelChapter entity) { var collection = GetCollection(id); collection.InsertOne(entity); }
public int AddNovelChapter(NovelChapter chapter) { return(_dal.AddNovelChapter(chapter)); }
private async Task ProcessUpdate(Spider spider, string novelKey, NovelDetails info, NovelInfo model) { var chapterIndex = info.ChapterIndex; var novelInfo = _novelInfoRepository.FindOrDefault(x => x.Name == info.Name && x.Author == info.Author); if (novelInfo == null) { return; } //对比章节,判断是否需要新增 var oldIndexes = _novelIndexRepository.FindOrDefault(x => x.Id == novelInfo.IndexId); //老索引 var oldChapterList = oldIndexes?.Indexex.Select(x => x.ChapterName).ToList(); //老的章节列表 var chapterList = await spider.GetNovelChapterList(novelKey, chapterIndex); //抓取最新章节 var newChapterList = chapterList.Select(x => x.Key).ToList(); //新的章节列表 int updateIndex = 0; if (ChapterListNeedUpdate(oldChapterList, newChapterList, out updateIndex)) { var indexes = new List <Index>();//更新的列表 //更新章节 for (int i = updateIndex; i < chapterList.Count; i++) { if (!_isWorking) { break; } var chapter = chapterList[i]; try { var content = await spider.GetContent(novelKey, chapterIndex, chapter.Value); var chapterId = ObjectId.NextId(); var chapterEntity = new NovelChapter() { Id = chapterId, NovelId = novelInfo.Id, ChapterName = chapter.Key, UpdateTime = DateTime.Now, WordCount = Utils.GetWordCount(content), Content = content }; _novelChapterRepository.Insert(novelInfo.Id, chapterEntity); indexes.Add(new Index() { ChapterId = chapterId, ChapterName = chapter.Key }); //索引目录 Thread.Sleep(500); } catch (SpiderException ex) { Logger.Error("{0}-{1} 小说章节抓取失败:{2}", chapter.Key, chapter.Value, ex.Message); if (_options.SpiderOptions.错误章节处理 == 错误章节处理.停止本书_继续采集下一本) { Logger.ColorConsole2(string.Format("{0}-{1} 错误章节处理.停止本书_继续采集下一本", chapter.Key, chapter.Value, ex.Message), ConsoleColor.Red); break; } else if (_options.SpiderOptions.错误章节处理 == 错误章节处理.入库章节名_继续采集下一章) { Logger.ColorConsole2(string.Format("{0}-{1} 错误章节处理.入库章节名_继续采集下一章", chapter.Key, chapter.Value, ex.Message), ConsoleColor.Red); var chapterId = ObjectId.NextId(); var chapterEntity = new NovelChapter() { Id = chapterId, NovelId = novelInfo.Id, ChapterName = chapter.Key, UpdateTime = DateTime.Now, WordCount = 0, Content = "" }; _novelChapterRepository.Insert(novelInfo.Id, chapterEntity); indexes.Add(new Index() { ChapterId = chapterId, ChapterName = chapter.Key }); } } catch (Exception ex) { Logger.Fatal(ex, "ProcessEngine.ProcessUpdate"); break; } } //更新索引目录 oldIndexes.Indexex.AddRange(indexes); _novelIndexRepository.Update(x => x.Id == oldIndexes.Id, oldIndexes); //更新小说详情 novelInfo.State = info.State; novelInfo.UpdateTime = DateTime.Now; novelInfo.LatestChapter = oldIndexes.Indexex.LastOrDefault()?.ChapterName; novelInfo.LatestChapterId = oldIndexes.Indexex.LastOrDefault()?.ChapterId; if (_options.SpiderOptions.自动更新分类) { novelInfo.Sort = spider.MatchSort(info.Sort); } if (_options.SpiderOptions.自动更新封面) { novelInfo.Cover = spider.DownLoadImageToBase64(info.ImageUrl); } if (_options.SpiderOptions.自动更新简介) { novelInfo.Des = info.Des; } _novelInfoRepository.Update(x => x.Id == novelInfo.Id, novelInfo); } }
private async Task ProcessAdd(Spider spider, string novelKey, NovelDetails info) { var chapterIndex = info.ChapterIndex; //小说id var novelId = ObjectId.NextId(); //目录索引id var novelIndexId = ObjectId.NextId(); //小说封面 var novelCover = spider.DownLoadImageToBase64(info.ImageUrl); /* * 1 >>> 获取章节列表 */ var chapterList = await spider.GetNovelChapterList(novelKey, chapterIndex); var indexes = new List <Index>(); //抓取章节 单个抓取 需要延迟 不然容易被封 for (int i = 0; i < chapterList.Count; i++) { if (!_isWorking) { break; } var chapter = chapterList[i]; try { var content = await spider.GetContent(novelKey, chapterIndex, chapter.Value); var chapterId = ObjectId.NextId(); var chapterEntity = new NovelChapter() { Id = chapterId, NovelId = novelId, ChapterName = chapter.Key, UpdateTime = DateTime.Now, WordCount = Utils.GetWordCount(content), Content = content }; _novelChapterRepository.Insert(novelId, chapterEntity); indexes.Add(new Index() { ChapterId = chapterId, ChapterName = chapter.Key }); //索引目录 Thread.Sleep(500); } catch (SpiderException ex) { Logger.Error("{0}-{1} 小说章节抓取失败:{2}", chapter.Key, chapter.Value, ex.Message); if (_options.SpiderOptions.错误章节处理 == 错误章节处理.停止本书_继续采集下一本) { Logger.ColorConsole2(string.Format("{0}-{1} 错误章节处理.停止本书_继续采集下一本", chapter.Key, chapter.Value, ex.Message), ConsoleColor.Red); break; } else if (_options.SpiderOptions.错误章节处理 == 错误章节处理.入库章节名_继续采集下一章) { Logger.ColorConsole2(string.Format("{0}-{1} 错误章节处理.入库章节名_继续采集下一章", chapter.Key, chapter.Value, ex.Message), ConsoleColor.Red); var chapterId = ObjectId.NextId(); var chapterEntity = new NovelChapter() { Id = chapterId, NovelId = novelId, ChapterName = chapter.Key, UpdateTime = DateTime.Now, WordCount = 0, Content = "" }; _novelChapterRepository.Insert(novelId, chapterEntity); indexes.Add(new Index() { ChapterId = chapterId, ChapterName = chapter.Key }); } } catch (Exception ex) { Logger.Fatal(ex, "ProcessEngine.ProcessAdd"); break; } } /* * 2 >>> 写入索引目录 */ var novelIndex = new NovelIndex() { Id = novelIndexId, NovelId = novelId, UpdateTime = DateTime.Now, Indexex = indexes }; _novelIndexRepository.Insert(novelIndex); /* * 3 >>> 写入小说详情 */ var novelInfo = new NovelInfo() { Id = novelId, Name = info.Name, Author = info.Author, Sort = spider.MatchSort(info.Sort), State = info.State, Des = info.Des, Cover = novelCover, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, LatestChapter = indexes.LastOrDefault()?.ChapterName, LatestChapterId = indexes.LastOrDefault()?.ChapterId, IndexId = novelIndexId }; _novelInfoRepository.Insert(novelInfo); }