public DocumentationWriter( FileNameMode fileNameMode, NestedTypeVisibility nestedTypeVisibility, bool wikiLinks, IReadOnlyDictionary <string, DocItem> items, IReadOnlyDictionary <string, string> links, string folderPath, DocItem item) { if (!_builders.TryDequeue(out _builder)) { _builder = new StringBuilder(1024); } _fileNameMode = fileNameMode; _wikiLinks = wikiLinks; NestedTypeVisibility = nestedTypeVisibility; _items = items; _links = links; _mainItem = item; _filePath = Path.Combine(folderPath, $"{item.GetLink(_fileNameMode)}.md"); }
/// <summary> /// SINA融资融券 /// </summary> public void SyncTouTiao() { var startTime = DateTime.Now;///开始运行时间 Console.Title = "股票全网新闻 更新进程 启动时间:" + startTime; var exe = StockTaskExecutor.CreateInstance(); var mongo = DataStorage.GetInstance(DBType.MongoDB); var dbName = CONST.DB.DBName_StockService; var collectionNameRZRQ = CONST.DB.CollectionName_RZRQ; var methodName = "SyncTouTiao"; while (true) { var q = this.PrepareData(methodName); while (0 < q.Count) { var stockCode = q.Dequeue(); var stockName = this.stockCodeDict[stockCode]; var array = WebDataSource.GetInstance().GetTouTiaoSearch(stockName); foreach (Dictionary <string, object> arrayItem in array) { var doc = DocItem.Create(arrayItem); doc.Save(); LOGGER.Log(string.Format("股票全网新闻 {0} {1} 保存完毕", stockCode, stockName)); } ThreadManager.Pause(seconds: 1); TaskStatusManager.Set(methodName, new { ID = methodName, StockCode = stockCode, StockName = stockName, Status = "已下载", CreateTime = DateTime.Now }); LOGGER.Log(string.Format("股票全网新闻 {0} {1} 保存完毕", stockCode, stockName)); } LOGGER.Log(string.Format("股票全网新闻更新完毕,下一次一天以后更新 {0}", DateTime.Now)); TaskStatusManager.Set(methodName, new { ID = methodName, Status = "队列处理完毕", CreateTime = DateTime.Now }); ThreadManager.Pause(days: 1); } }
public DocItem Search(string name, int depth = 1, bool ignorecase = true, bool strict = false) { DocItem ret = null; foreach (var item in this) { if (item.Name.CompareComplex(name)) { ret = item; break; } else if (depth >= 1) { foreach (var sub in item.Children) { if (sub.Name.CompareComplex(name)) { ret = sub; break; } /*else if (depth >= 2 && sub.Parameters.Length > 0) * { * foreach (var param in sub.Parameters) * { * if (param.Name.CompareComplex(name)) * { * ret = param; * break; * } * } * }*/ } } } return(ret); }
private DocItem CheckValue(DocItem docItem, string searchText, string restofLine, List <string> evalWords, string line, List <string> textlines, int currentLine) { /* look for values as attributes of docItem Terms * * Search 1: * |---------------|---------------------------| | Search Term | Line Value | |---------------|---------------------------| | | Search 2: | |---------------|---------------| | Search Term | Word(Value) | |---------------|---------------| | | | Search 3: | |---------------| | Search Term | |---------------| |-------------------| | Length (Value) | |-------------------| | | Search 4: | |---------------| | Search Term | |---------------| |-------------------------------------------| | Line Pos (Value) | |-------------------------------------------| | */ // if there are only numbers in the rest of the line then high chance this is // the value we are looking for //Search 1 if (helpers.IsOnlyNumbers(restofLine)) { docItem.Result = restofLine; docItem.Score = (int)Scores.HIGH_SCORE; } // if there are somw numbers in the rest of the line then medium chance this is // the value we are looking for since it could be mixed with uom, method et al else if (helpers.IsSomeNumbers(restofLine)) { // get just the next word if it is numeric if (evalWords.Count > 1) { string nextWord = evalWords[evalWords.IndexOf(searchText) + searchText.Split(" ").Length + 1]; //Search 2 if (helpers.IsSomeNumbers(nextWord)) { docItem.Result = nextWord; docItem.Score = (int)Scores.MEDIUM_SCORE; } else { docItem.Result = string.Empty;; docItem.Score = (int)Scores.NO_SCORE; } } } else //look below the found search term in case it is a tabular layout { int positionInLine = line.IndexOf(searchText); if (currentLine == textlines.Count) { return(docItem); } string nextLineText = textlines[currentLine + 1]; //Search 3 if ((helpers.IsSomeNumbers(nextLineText)) && (nextLineText.Length < 20)) { docItem.Result = nextLineText; docItem.Score = (int)Scores.MEDIUM_SCORE; } //Search 4 else if (nextLineText.Length >= line.Length) { if (positionInLine != -1) { docItem.Result = nextLineText.Substring(positionInLine); docItem.Score = (int)Scores.LOW_SCORE; } } else { docItem.Result = string.Empty;; docItem.Score = (int)Scores.NO_SCORE; } } return(docItem); }
public DocItem SearchForItem(DocItem docItem, List <string> textlines, SearchableContent searchData) { foreach (string searchText in docItem.Terms) { int currentLine = 0; string termType = docItem.Hint.ToLower(); /* * if (helpers.IsOnlyNumbers(docItem.Section)) * { * int stopSecton = int.Parse(docItem.Section); * stopSecton = stopSecton++; * textlines = helpers.GetSection(textlines, docItem.Section, stopSecton.ToString(), searchData); * } */ foreach (string line in textlines) { string evalLine = line.ToLower(); if (evalLine.Contains(searchText.ToLower())) { string restofLine = evalLine.Substring(evalLine.IndexOf(searchText) + searchText.Length + 1).Trim(); if (termType == "number") { List <string> evalWords = evalLine.Split(" ").ToList(); evalWords.RemoveAll(x => x.Trim() == string.Empty); docItem = CheckValue(docItem, searchText, restofLine, evalWords, line.ToLower(), textlines, currentLine); } else if (termType == "text") { docItem = CheckText(docItem, restofLine); } else if (termType == "yesno") { docItem = CheckBool(docItem, restofLine); } else { docItem = CheckText(docItem, restofLine); } } if (!string.IsNullOrEmpty(docItem.Result)) { Log.Debug($"[Found DocItem Term]: {searchText} [Score]: {docItem.Score} [Result]: {docItem.Result} "); return(docItem); } else { Log.Debug($"[Missed DocItem Term]: {searchText} "); } currentLine++; } } return(docItem); }
/// <summary> /// Parse a MSDN documentation file /// </summary> /// <param name="documentationToParse"></param> /// <returns></returns> public static DocItem ParseDocumentation(string documentationToParse) { if (string.IsNullOrEmpty(documentationToParse)) { return(new DocItem()); } var htmlDocument = new HtmlDocument(); // htmlDocument.Load("Documentation\\d3d11-ID3D11Device-CheckCounter.html"); htmlDocument.LoadHtml(documentationToParse); var item = new DocItem { Id = htmlDocument.DocumentNode.ChildNodes.FindFirst("id").InnerText }; var element = htmlDocument.GetElementbyId("mainSection"); // Page not found? if (element == null) { return(item); } // Get description before h3/collasiblearea and table item.Description = GetTextUntilNextHeader(element.FirstChild, false, "table"); HtmlNode firstElement = element.ChildNodes.FindFirst("dl"); if (firstElement != null) { List <string> currentDoc = new List <string>(); var nodes = firstElement.ChildNodes; int ddCount = 0; foreach (HtmlNode htmlNode in nodes) { if (htmlNode.Name == "dt") { if (currentDoc.Count > 0) { item.Items.Add(currentDoc[currentDoc.Count - 1]); currentDoc.Clear(); } } else if (htmlNode.Name == "dd") { currentDoc.Add(ParseNode(htmlNode)); } } if (currentDoc.Count > 0) { item.Items.Add(currentDoc[currentDoc.Count - 1]); } } var headerCollection = element.SelectNodes("//h3"); if (headerCollection != null) { foreach (HtmlNode htmlNode in headerCollection) { string text = ParseNode(htmlNode); if (text.StartsWith("Remarks")) { item.Remarks = GetTextUntilNextHeader(htmlNode); } else if (text.StartsWith("Return")) { item.Return = GetTextUntilNextHeader(htmlNode); } } } else { var returnCollection = element.SelectNodes("//h4[contains(.,'Return')]"); if (returnCollection != null) { item.Return = ParseNextDiv(returnCollection[0].NextSibling); } var remarksCollection = element.SelectNodes("//a[@id='remarks']"); if (remarksCollection != null) { item.Remarks = ParseNextDiv(remarksCollection[0].NextSibling); } } return(item); }
public string GetInnerLink(DocItem item, string displayedName = null) { DocItem pagedDocItem = item.GetPagedDocItem(); return($"[{displayedName ?? item.Name}]({(_mainItem == pagedDocItem ? string.Empty : $"./{pagedDocItem.Link}.md")}#{item.Link} '{item.FullName}')");
public string GetLink(DocItem item, string displayedName = null) => item.GeneratePage ? $"[{displayedName ?? item.Name}](./{item.Link}.md '{item.FullName}')" : GetInnerLink(item, displayedName);
public DocumentationWriter(IReadOnlyDictionary <string, DocItem> items, IReadOnlyDictionary <string, string> links, string folderPath, DocItem item) { if (!_builders.TryDequeue(out _builder)) { _builder = new StringBuilder(1024); } _items = items; _links = links; _mainItem = item; _filePath = Path.Combine(folderPath, $"{item.Link}.md"); }
public string GetInnerLink(DocItem item, string displayedName = null) { DocItem pagedDocItem = item.GetPagedDocItem(); return($"[{displayedName ?? item.Name}]({(_mainItem == pagedDocItem ? string.Empty : $"{(_wikiLinks ? "" : "./")}{pagedDocItem.GetLink(_fileNameMode)}{(_wikiLinks ? "" : ".md")}")}#{item.GetLink(_fileNameMode)} '{item.FullName}')"); }
public string GetLink(DocItem item, string displayedName = null) => item.GeneratePage ? $"[{displayedName ?? item.Name}]({(_wikiLinks ? "" : "./")}{item.GetLink(_fileNameMode)}{(_wikiLinks ? "" : ".md")} '{item.FullName}')" : GetInnerLink(item, displayedName);