/// <summary> /// 初始化。 /// </summary> public ItemChapter(Models.Domains.Entities.Chapter target) { this.ChapterId = target.ChapterId; this.ChapterName = target.ChapterName; this.Priority = target.Priority; }
/// <summary> /// 获取域对象。 /// </summary> /// <returns>域对象。</returns> public Models.Domains.Entities.Chapter GetReturn() { var target = new Models.Domains.Entities.Chapter(); target.ChapterId = Guid.NewGuid(); target.DocumentId = this.DocumentId; target.ChapterName = this.ChapterName.Trim(); target.Priority = this.Priority; target.UpdateTime = DateTime.Now; return(target); }
public override bool ParsePage() { this.Document = new Models.Domains.Entities.Document(); var DOM = new HtmlAgilityPack.HtmlDocument(); DOM.LoadHtml(this.SourceText); try { var div = DOM.GetElementbyId("main"); var h2s = div.MyChildNodeFilter("h2"); var i = 1; foreach (var h2 in h2s) { if (h2.Attributes["class"].Value == "hiddenAnchor") { continue; } var name = h2.InnerText; if (string.IsNullOrEmpty(name)) { continue; } var chapter = new Models.Domains.Entities.Chapter(); chapter.ChapterId = Guid.NewGuid(); chapter.DocumentId = this.DocumentId; chapter.ChapterName = name; chapter.Priority = i++; chapter.UpdateTime = DateTime.Now; this.Document.Chapters.Add(chapter); } } catch { return(false); } return(true); }
public List <Models.Domains.Entities.Chapter> GetReturnList() { var db = new Models.Domains.Entities.DMsDbContext(); var document = db.Documents.Find(this.DocumentId); int maxPriority; if (document.Chapters.Count() == 0) { maxPriority = 0; } else { maxPriority = document.Chapters.Max(c => c.Priority); } var listInput = new List <string>(this.Input.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries)); var listChapter = new List <Models.Domains.Entities.Chapter>(); foreach (var itemInput in listInput) { if (string.IsNullOrEmpty(itemInput)) { continue; } var itemChapter = new Models.Domains.Entities.Chapter(); itemChapter.ChapterId = Guid.NewGuid(); itemChapter.DocumentId = this.DocumentId; itemChapter.ChapterName = itemInput.Trim(); itemChapter.Priority = ++maxPriority; itemChapter.UpdateTime = DateTime.Now; listChapter.Add(itemChapter); } return(listChapter); }
public override bool ParsePage() { this.Document = new Models.Domains.Entities.Document(); var DOM = new HtmlAgilityPack.HtmlDocument(); DOM.LoadHtml(this.SourceText); try { //var meta = DOM.DocumentNode.MyGetNode("html",1).MyGetNode("head", 1).MyGetNode("meta", "name", "APIName", 1); var div_main = DOM.GetElementbyId("main"); var div_main_h1 = div_main.MyGetNode("h1", 1); this.Document.DocumentId = Guid.NewGuid(); //this.Document.ParentDocumentId this.Document.Title = div_main_h1.InnerText; this.Document.Title = System.Web.HttpUtility.HtmlDecode(this.Document.Title); this.Document.Title = System.Text.RegularExpressions.Regex.Replace(this.Document.Title, @"\s+", " ").Trim(); //this.Document.NodeName = meta.Attributes["content"].Value; //this.Document.NodeName = System.Web.HttpUtility.HtmlDecode(this.Document.NodeName); { switch (this.NodeNameParsingMode) { case "MicrosoftDocsApiType": this.Document.NodeName = this.Document.Title.Split(new string[] { " " }, StringSplitOptions.None)[0]; break; case "MicrosoftDocsApiMember": this.Document.NodeName = this.Document.Title.Split(new string[] { " ", "." }, StringSplitOptions.None)[1]; break; default: break; } } //this.Document.Priority this.Document.UpdateTimeForHTTPGet = DateTime.Now; this.Document.Url = this.Url; this.Document.UpdateTime = DateTime.Now; //处理Chapters var h2s = div_main.Descendants("h2"); var i = 1; foreach (var h2 in h2s) { if (h2.Attributes["class"].Value == "hiddenAnchor") { continue; } var name = h2.InnerText; if (string.IsNullOrEmpty(name)) { continue; } var chapter = new Models.Domains.Entities.Chapter(); chapter.ChapterId = Guid.NewGuid(); chapter.DocumentId = this.Document.DocumentId; chapter.ChapterName = name; chapter.Priority = i++; chapter.UpdateTime = DateTime.Now; this.Document.Chapters.Add(chapter); } this.Document.IsGetAllChapters = true; } catch { return(false); } return(true); }