internal static Root CollectHtmlNodes(ref SearchDescriptor searchData) { Root root = null; List<int> positions = null; List<Node> nodes = new List<Node>(); ModuleDescriptor moduleDesc = searchData.Modules[searchData.CurrentModuleIndex]; moduleDesc.Form = new HTMLForm(); try { if (moduleDesc.HTMLDoc != null) { moduleDesc.Form.Text = moduleDesc.HTMLDoc.title; mshtml.IHTMLElement documentElement = moduleDesc.HTMLDoc.documentElement; if (documentElement != null && !String.IsNullOrEmpty(documentElement.outerHTML)) { moduleDesc.Form.richHtmlText.Text = documentElement.outerHTML; int length = moduleDesc.Form.richHtmlText.Lines.Length; for (int line = 0; line < length; line++) { if (searchData.CheckCase) { if (searchData.CheckWholeWord) { if ((positions = VisibleContent.CaseSensitive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); } } } else { if ((positions = VisibleContent.CaseSensitive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); } } } } else { if (searchData.CheckWholeWord) { if ((positions = VisibleContent.CaseInsensetive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); } } } else { if ((positions = VisibleContent.CaseInsensetive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); } } } } } if (nodes.Count > Const.Ok) root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); Marshal.ReleaseComObject(documentElement); documentElement = null; } } } finally { if (moduleDesc.Form != null) { moduleDesc.Form.Dispose(); moduleDesc.Form = null; } } return root; }
private static void Search_Window_Tab_HTML(ref SearchDescriptor searchData) { ModuleDescriptor moduleDesc = searchData.Modules[searchData.CurrentModuleIndex]; if (moduleDesc.HTMLDoc != null) { moduleDesc.Form = new HTMLForm(); moduleDesc.Form.Text = moduleDesc.HTMLDoc.title; mshtml.IHTMLElement element = moduleDesc.HTMLDoc.documentElement; moduleDesc.Form.richHtmlText.Text = element.outerHTML; List<int> positions = null; List<Node> nodes = new List<Node>(); Marshal.ReleaseComObject(element); Root root = null; if (CancelOperationOrReportUI((int)SearchProgress.Initializing)) return; int length = moduleDesc.Form.richHtmlText.Lines.Length; if (searchData.CheckCase) { if (searchData.CheckWholeWord) { for (int line = 0; line < length; line++) { if ((positions = VisibleContent.CaseSensitive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); if (IsCancelled) return; } if (CancelOperationOrReportUI((int)SearchProgress.Searching, System.Convert.ToInt32((Convert.ToDouble(line) / length) * 100))) return; } } if (nodes.Count > Const.Ok) { root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); } } else { for (int line = 0; line < length; line++) { if ((positions = VisibleContent.CaseSensitive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); if (IsCancelled) return; } if (CancelOperationOrReportUI((int)SearchProgress.Searching, System.Convert.ToInt32((Convert.ToDouble(line) / length) * 100))) return; } } if (nodes.Count > Const.Ok) { root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); } } } else { if (searchData.CheckWholeWord) { for (int line = 0; line < length; line++) { if ((positions = VisibleContent.CaseInsensetive.WholeWord.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); if (IsCancelled) return; } if (CancelOperationOrReportUI((int)SearchProgress.Searching, System.Convert.ToInt32((Convert.ToDouble(line) / length) * 100))) return; } } if (nodes.Count > Const.Ok) { root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); } } else { for (int line = 0; line < length; line++) { if ((positions = VisibleContent.CaseInsensetive.WordAsPart.AdvancedSearchEngine.Contains(moduleDesc.Form.richHtmlText.Lines[line], searchData.Term)).Count > Const.Ok) { foreach (int pos in positions) { nodes.Add(new Node(moduleDesc.Form.richHtmlText.Lines[line], moduleDesc.Form.richHtmlText.Lines[line], 0, new HtmlInfoTag(line, pos))); if (IsCancelled) return; } if (CancelOperationOrReportUI((int)SearchProgress.Searching, System.Convert.ToInt32((Convert.ToDouble(line) / length) * 100))) return; } } if (nodes.Count > Const.Ok) { root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); } } } if (root != null) { TreeNode treeNode = new TreeNode(root.Title); treeNode.Tag = root.WindowInfo; List<TreeNode> treeNodes = new List<TreeNode>(root.Nodes.Count); foreach (Node nodeInTheList in root.Nodes) { TreeNode leaf = new TreeNode(nodeInTheList.InnerText); leaf.ToolTipText = nodeInTheList.ToolTipText; leaf.Tag = nodeInTheList.HtmlTag; treeNodes.Add(leaf); } treeNode.Nodes.AddRange(treeNodes.ToArray()); searchData.ResultNode.Nodes.Add(treeNode); } if (element != null) Marshal.ReleaseComObject(element); element = null; if (CancelOperationOrReportUI((int)SearchProgress.Done, SearchProgress.Done)) return; } }
private static Root CollectTextNodes(List<int> pos, ref SearchDescriptor searchData) { Root root = null; if (pos == null) return root; ModuleDescriptor moduleDesc = searchData.Modules[searchData.CurrentModuleIndex]; mshtml.IHTMLElement documentElement = moduleDesc.HTMLDoc.documentElement; if (documentElement != null && !String.IsNullOrEmpty(documentElement.outerHTML)) { List<Node> nodes = new List<Node>(); mshtml.IHTMLTxtRange range = null; for (int position = 0; position < pos.Count; position++) { mshtml.IHTMLSelectionObject sel = moduleDesc.HTMLDoc.selection; if (sel != null) { sel.empty(); Marshal.ReleaseComObject(sel); } mshtml.IHTMLSelectionObject selectionObject = moduleDesc.HTMLDoc.selection; mshtml.IHTMLElement bodyElement = moduleDesc.HTMLDoc.body; range = selectionObject.createRange() as mshtml.IHTMLTxtRange; range.moveToElementText(bodyElement); for (int i = 1; i <= position; i++) { range.findText(searchData.Term, bodyElement.innerText.Length, (int)searchData.Flags); range.moveStart("character", 1); } range.findText(searchData.Term, bodyElement.innerText.Length, (int)searchData.Flags); mshtml.IHTMLElement parentElement = range.parentElement(); Node node = new Node(parentElement.innerText, moduleDesc.HTMLDoc.title, position, null); nodes.Add(node); Marshal.ReleaseComObject(parentElement); parentElement = null; Marshal.ReleaseComObject(bodyElement); bodyElement = null; Marshal.ReleaseComObject(selectionObject); selectionObject = null; Marshal.ReleaseComObject(range); range = null; } if (nodes.Count > Const.Ok) root = new Root(moduleDesc.HTMLDoc.title, nodes, new WindowInfoTag(moduleDesc, searchData.Term, searchData.Flags)); Marshal.ReleaseComObject(documentElement); documentElement = null; } return root; }