public messagehandler() { Task.Run(async() => { //var decoder = new TextDecoder("utf-8"); while (true) // Loop runs only once per line received { using (var stdin = Console.OpenStandardInput()) { string input = ""; try { int length = 0; byte[] bytes = new byte[4]; await stdin.ReadAsync(bytes, 0, 4); length = BitConverter.ToInt32(bytes, 0); //for (int i = 0; i < length; i++) //{ // input += (char)stdin.ReadByte(); //} byte[] buff = new byte[length]; stdin.Read(buff, 0, buff.Length); input += Encoding.UTF8.GetString(buff); // input += Encoding.Default.GetString(buff); // make sure to get message as UTF-8 format //String msgStr = new String(msg, "UTF-8"); if (string.IsNullOrEmpty(input)) { if (autoReset != null) { autoReset.Set(); } return; } //sstring msgStr = new string(input, "UTF-8"); var msg = JsonConvert.DeserializeObject <NativeMessagingMessage>(input); if (msg.functionName == "openrpautilscript") { var r2 = new NativeMessagingMessage(msg.functionName, msg.debug); loadscript(ref r2, "openrpautil"); sendMessage(r2); } if (msg.functionName == "contentscript") { var r2 = new NativeMessagingMessage(msg.functionName, msg.debug); loadscript(ref r2, "content"); sendMessage(r2); } if (msg.functionName == "backgroundscript") { var r2 = new NativeMessagingMessage(msg.functionName, msg.debug); loadscript(ref r2, "background"); sendMessage(r2); } #pragma warning disable 4014 Task.Run(() => { onMessage?.Invoke(msg); }); #pragma warning restore 4014 } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); System.Diagnostics.Trace.WriteLine(input); } } } }); }
public NMElement(NativeMessagingMessage message, string _chromeelement) { this.message = message; _browser = message.browser; parseChromeString(_chromeelement); }
public static void loadscript(ref NativeMessagingMessage msg, string name) { msg.script = GetStringFromResource(name + ".js"); }
public static treeelement[] _GetRootElements(Selector anchor) { var rootelements = new List <treeelement>(); NMHook.reloadtabs(); // var tab = NMHook.tabs.Where(x => x.highlighted == true && x.browser == "chrome").FirstOrDefault(); var tab = NMHook.tabs.Where(x => x.highlighted == true).FirstOrDefault(); if (tab == null) { // tab = NMHook.tabs.Where(x => x.browser == "chrome").FirstOrDefault(); tab = NMHook.tabs.FirstOrDefault(); } if (NMHook.tabs.Count == 0) { return(rootelements.ToArray()); } // getelement.data = "getdom"; var getelement = new NativeMessagingMessage("getelement") { browser = tab.browser, tabid = tab.id, xPath = "/html" }; if (anchor != null && anchor.Count > 1) { var s = anchor[1]; var p = s.Properties.Where(x => x.Name == "xpath").FirstOrDefault(); if (p != null) { getelement.xPath = p.Value; } } NativeMessagingMessage result = null; try { result = NMHook.sendMessageResult(getelement, true, TimeSpan.FromSeconds(2)); } catch (Exception) { } if (result != null && result.result != null && result.results == null) { result.results = new NativeMessagingMessage[] { result }; } if (result != null && result.results != null && result.results.Count() > 0) { foreach (var res in result.results) { if (res.result != null) { //var html = new HtmlElement(getelement.xPath, getelement.cssPath, res.tabid, res.frameId, res.result); var html = new NMElement(res); rootelements.Add(new NMTreeElement(null, true, html)); } } //result = result.results[0]; } return(rootelements.ToArray()); }
private static void tabupdated(NativeMessagingMessage msg) { tabremoved(msg); msg.tab.browser = msg.browser; tabs.Add(msg.tab); }
private static void Client_OnReceivedMessage(NativeMessagingMessage message) { try { NativeMessagingMessage msg; try { msg = message; //msg = JsonConvert.DeserializeObject<NativeMessagingMessage>(e.Message); if (string.IsNullOrEmpty(message.functionName) || message.functionName == "ping") { return; } } catch (Exception) { return; } if (msg.functionName == "windowcreated" && !windows.Contains(msg.windowId)) { windows.Add(msg.windowId); } if (msg.functionName == "windowremoved" && windows.Contains(msg.windowId)) { windows.Remove(msg.windowId); } if (msg.tab != null) { if (msg.functionName == "tabcreated") { var tab = tabs.Where(x => x.id == msg.tab.id && x.browser == msg.browser).FirstOrDefault(); if (tab != null) { tabs.Remove(tab); } msg.tab.browser = msg.browser; Log.Debug(msg.browser + " " + msg.functionName + " " + msg.tab.id + " " + msg.tab.status); tabs.Add(msg.tab); } if (msg.functionName == "tabremoved" || msg.functionName == "tabupdated") { var tab = tabs.Where(x => x.id == msg.tab.id && x.browser == msg.browser).FirstOrDefault(); if (tab != null) { tabs.Remove(tab); } if (msg.functionName == "tabupdated") { msg.tab.browser = msg.browser; tabs.Add(msg.tab); Log.Debug(msg.browser + " " + msg.functionName + " " + msg.tab.id + " " + msg.tab.status); } else { Log.Debug(msg.browser + " " + msg.functionName + " " + msg.tab.id); } } } else { msg.tab = tabs.Where(x => x.id == msg.tabid && x.browser == msg.browser).FirstOrDefault(); } if (msg.functionName == "tabactivated") { foreach (var tab in tabs.Where(x => x.browser == msg.browser && x.windowId == msg.windowId)) { tab.highlighted = (tab.id == msg.tabid); } } Task.Run(() => { onMessage?.Invoke(msg); }); } catch (Exception ex) { Log.Error(ex.ToString()); } }
//private static NMElement[] GetElementsWithuiSelector(WindowsAccessBridgeInterop.AccessibleJvm jvm, NMSelector selector, IElement fromElement, int maxresults) //{ // NMElement[] result = null; // NMElement _fromElement = fromElement as NMElement; // var selectors = selector.Where(x => x.Enabled == true && x.Selector == null).ToList(); // var current = new List<NMElement>(); // NMElement startfrom = null; // if (_fromElement != null) startfrom = _fromElement; // if (startfrom == null) startfrom = new NMElement(jvm); // current.Add(startfrom); // for (var i = 0; i < selectors.Count; i++) // { // var sw = new System.Diagnostics.Stopwatch(); // sw.Start(); // var s = new NMSelectorItem(selectors[i]); // Log.Selector(string.Format("OpenRPA.NM::GetElementsWithuiSelector::Find for selector {0} {1}", i, s.ToString())); // var elements = new List<NMElement>(); // elements.AddRange(current); // current.Clear(); // foreach (var _element in elements) // { // result = ((NMSelectorItem)s).matches(_element); // current.AddRange(result); // } // if (i == (selectors.Count - 1)) result = current.ToArray(); // if (current.Count == 0) // { // var _c = new NMSelectorItem(selectors[i]); // var message = "needed to find " + Environment.NewLine + _c.ToString() + Environment.NewLine + "but found only: " + Environment.NewLine; // foreach (var element in elements) // { // var children = element.Children; // foreach (var c in children) // { // try // { // message += c.ToString() + Environment.NewLine; // } // catch (Exception) // { // } // } // } // Log.Selector(message); // return new NMElement[] { }; // } // Log.Selector(string.Format("OpenRPA.NM::GetElement::found {1} for selector {2} in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count(), i)); // } // if (result == null) return new NMElement[] { }; // return result; //} public static NMElement[] GetElementsWithuiSelector(NMSelector selector, IElement fromElement = null, int maxresults = 1) { var results = new List <NMElement>(); var first = selector[0]; var second = selector[1]; var p = first.Properties.Where(x => x.Name == "browser").FirstOrDefault(); string browser = ""; if (p != null) { browser = p.Value; } p = second.Properties.Where(x => x.Name == "xpath").FirstOrDefault(); string xpath = ""; if (p != null) { xpath = p.Value; } p = second.Properties.Where(x => x.Name == "cssselector").FirstOrDefault(); string cssselector = ""; if (p != null) { cssselector = p.Value; } NMHook.checkForPipes(true, true); NMHook.reloadtabs(); var tabs = NMHook.tabs; if (!string.IsNullOrEmpty(browser)) { tabs = NMHook.tabs.Where(x => x.browser == browser).ToList(); } foreach (var tab in tabs) { NativeMessagingMessage subresult = null; var getelement = new NativeMessagingMessage("getelements"); getelement.browser = browser; getelement.xPath = xpath; getelement.cssPath = cssselector; subresult = NMHook.sendMessageResult(getelement, false, TimeSpan.FromSeconds(2)); if (subresult != null) { foreach (var b in subresult.results) { if (b.cssPath == "true" || b.xPath == "true") { var data = b.result; var arr = JArray.Parse(data); foreach (var _e in arr) { var json = _e.ToString(); var subsubresult = Newtonsoft.Json.JsonConvert.DeserializeObject <NativeMessagingMessage>(json); subsubresult.browser = browser; subsubresult.result = json; subsubresult.tabid = b.tabid; subsubresult.tab = b.tab; results.Add(new NMElement(subsubresult)); } } } } } return(results.ToArray()); //NMHook.Instance.refreshJvms(); //NMElement[] result = null; //foreach (var jvm in NMHook.Instance.jvms) //{ // result = GetElementsWithuiSelector(jvm, selector, fromElement, maxresults); // if (result.Count() > 0) return result; //} //if (result == null) return new NMElement[] { }; //return result; //return new NMElement[] { }; }
private void OnMessage(NativeMessagingMessage message) { try { //lock(_lock) //{ // //if (dpiscale == 0) // //{ // // dpiscale = NativeMethods.getScalingFactor(); // //} else // //{ // // dpiscale = NativeMethods.getScalingFactor(); // //} // var dpi = NativeMethods.GetDpiForSystem(); // dpiscale = 1; // if (dpi == 96) dpiscale = 1; // if (dpi == 120) dpiscale = 1.25f; // if (dpi == 144) dpiscale = 1.5f; // if (dpi == 192) dpiscale = 2; //} if (message.uiy > 0 && message.uix > 0 && message.uiwidth > 0 && message.uiheight > 0) { //message.uiy = (int)(message.uiy * dpiscale); //message.uix = (int)(message.uix * dpiscale); //message.uiwidth = (int)(message.uiwidth * dpiscale); //message.uiheight = (int)(message.uiheight * dpiscale); if (dpiscale == 1.25) { message.uiy += 158; } LastElement = new NMElement(message); } if (message.functionName == "click") { if (IsRecording) { if (LastElement == null) { return; } var re = new RecordEvent { Button = Input.MouseButton.Left }; var a = new GetElement { DisplayName = LastElement.ToString() }; message.tab = NMHook.tabs.Where(x => x.id == message.tabid && x.windowId == message.windowId).FirstOrDefault(); var selector = new NMSelector(LastElement, null, true, null); a.Selector = selector.ToString(); a.Image = LastElement.ImageString(); a.MaxResults = 1; re.Selector = selector; re.a = new GetElementResult(a); re.SupportInput = LastElement.SupportInput; re.SupportSelect = false; re.ClickHandled = true; OnUserAction?.Invoke(this, re); return; } } } catch (Exception ex) { Log.Error(ex.ToString()); } }
public static treeelement[] _GetRootElements(Selector anchor) { var rootelements = new List <treeelement>(); var browser = ""; if (NMHook.chromeconnected) { browser = "chrome"; } if (NMHook.ffconnected) { browser = "ff"; } if (string.IsNullOrEmpty(browser)) { return(rootelements.ToArray()); } //NMHook.enumtabs(); //// var tab = NMHook.tabs.Where(x => x.highlighted == true && x.browser == "chrome").FirstOrDefault(); //var tab = NMHook.tabs.Where(x => x.highlighted == true).FirstOrDefault(); //if (tab == null) //{ // // tab = NMHook.tabs.Where(x => x.browser == "chrome").FirstOrDefault(); // tab = NMHook.tabs.FirstOrDefault(); //} //if (NMHook.tabs.Count == 0) { return rootelements.ToArray(); } //// getelement.data = "getdom"; var getelement = new NativeMessagingMessage("getelements", PluginConfig.debug_console_output) { browser = browser, xPath = "/html", frameId = -1 }; if (anchor != null && anchor.Count > 1) { var s = anchor[1]; var p = s.Properties.Where(x => x.Name == "xpath").FirstOrDefault(); if (p != null) { getelement.xPath = p.Value; } } NativeMessagingMessage result = null; try { result = NMHook.sendMessageResult(getelement, true, TimeSpan.FromSeconds(3)); } catch (Exception) { } if (result != null && result.result != null && result.results == null) { // result.results = new NativeMessagingMessage[] { result }; var html = new NMElement(result); rootelements.Add(new NMTreeElement(null, true, html)); return(rootelements.ToArray()); } if (result != null && result.results != null && result.results.Count() > 0) { foreach (var res in result.results) { if (res.result != null) { if (res.tab == null) { res.tab = NMHook.tabs.Where(x => x.browser == res.browser && x.id == res.tabid).FirstOrDefault(); } var html = new NMElement(res); rootelements.Add(new NMTreeElement(null, true, html)); //var html = new HtmlElement(getelement.xPath, getelement.cssPath, res.tabid, res.frameId, res.result); } } //result = result.results[0]; } return(rootelements.ToArray()); }
private static void Client_OnReceivedMessage(NativeMessagingMessage message) { try { NativeMessagingMessage msg; try { msg = message; //msg = JsonConvert.DeserializeObject<NativeMessagingMessage>(e.Message); if (string.IsNullOrEmpty(message.functionName) || message.functionName == "ping") { return; } } catch (Exception) { return; } if (msg.functionName != "mousemove") { Log.Verbose("[nmhook][resc][" + msg.browser + "]" + msg.functionName + " for tab " + msg.tabid + " - " + msg.messageid); //Log.Output("[nmhook][resc][" + msg.browser + "]" + msg.functionName + " for tab " + msg.tabid + " - " + msg.messageid + " (" + msg.uix + "," + msg.uiy + "," + msg.uiwidth + "," + msg.uiheight + ")"); } if (PluginConfig.compensate_for_old_addon) { msg.uix -= 7; msg.uiy += 7; } if (msg.functionName == "windowcreated") { windowcreated(msg); } if (msg.functionName == "windowremoved") { windowremoved(msg); } if (msg.functionName == "windowfocus") { windowfocus(msg); } if (msg.functionName == "tabcreated") { tabcreated(msg); } if (msg.functionName == "tabremoved") { tabremoved(msg); } if (msg.functionName == "tabupdated") { tabupdated(msg); } if (msg.functionName == "tabactivated") { tabactivated(msg); } if (msg.functionName == "downloadcomplete") { downloadcomplete(msg); } Task.Run(() => { onMessage?.Invoke(msg); }); } catch (Exception ex) { Log.Error(ex.ToString()); } }
//private static NMElement[] GetElementsWithuiSelector(WindowsAccessBridgeInterop.AccessibleJvm jvm, NMSelector selector, IElement fromElement, int maxresults) //{ // NMElement[] result = null; // NMElement _fromElement = fromElement as NMElement; // var selectors = selector.Where(x => x.Enabled == true && x.Selector == null).ToList(); // var current = new List<NMElement>(); // NMElement startfrom = null; // if (_fromElement != null) startfrom = _fromElement; // if (startfrom == null) startfrom = new NMElement(jvm); // current.Add(startfrom); // for (var i = 0; i < selectors.Count; i++) // { // var sw = new System.Diagnostics.Stopwatch(); // sw.Start(); // var s = new NMSelectorItem(selectors[i]); // Log.Selector(string.Format("OpenRPA.NM::GetElementsWithuiSelector::Find for selector {0} {1}", i, s.ToString())); // var elements = new List<NMElement>(); // elements.AddRange(current); // current.Clear(); // foreach (var _element in elements) // { // result = ((NMSelectorItem)s).matches(_element); // current.AddRange(result); // } // if (i == (selectors.Count - 1)) result = current.ToArray(); // if (current.Count == 0) // { // var _c = new NMSelectorItem(selectors[i]); // var message = "needed to find " + Environment.NewLine + _c.ToString() + Environment.NewLine + "but found only: " + Environment.NewLine; // foreach (var element in elements) // { // var children = element.Children; // foreach (var c in children) // { // try // { // message += c.ToString() + Environment.NewLine; // } // catch (Exception) // { // } // } // } // Log.Selector(message); // return new NMElement[] { }; // } // Log.Selector(string.Format("OpenRPA.NM::GetElement::found {1} for selector {2} in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count(), i)); // } // if (result == null) return new NMElement[] { }; // return result; //} public static NMElement[] GetElementsWithuiSelector(NMSelector selector, IElement fromElement = null, int maxresults = 1) { var results = new List <NMElement>(); SelectorItem first = null; SelectorItem second = null; string browser = ""; SelectorItemProperty p = null; if (selector.Count > 1) { first = selector[0]; second = selector[1]; p = first.Properties.Where(x => x.Name == "browser").FirstOrDefault(); if (p != null) { browser = p.Value; } } else if (fromElement == null) { throw new ArgumentException("Invalid select with onlu 1 child and no anchor"); } else { second = selector[0]; } p = second.Properties.Where(x => x.Name == "xpath").FirstOrDefault(); string xpath = ""; if (p != null) { xpath = p.Value; } p = second.Properties.Where(x => x.Name == "cssselector").FirstOrDefault(); string cssselector = ""; if (p != null) { cssselector = p.Value; } NMElement fromNMElement = fromElement as NMElement; if (fromElement != null) { browser = fromNMElement.browser; //if (browser != fromNMElement.browser) throw new ArgumentException("browser mismatch " + browser + "/" + fromNMElement.browser); p = second.Properties.Where(x => x.Name == "cssselector").FirstOrDefault(); if (p == null) { throw new ArgumentException("fromElement missing cssselector"); } // xpath += p.Value.Substring(1); xpath = ""; cssselector = fromNMElement.cssselector + " > " + p.Value; } NMHook.checkForPipes(true, true); NMHook.reloadtabs(); var tabs = NMHook.tabs; if (!string.IsNullOrEmpty(browser)) { lock (NMHook.tabs) { tabs = NMHook.tabs.Where(x => x.browser == browser).ToList(); } } foreach (var tab in tabs) { NativeMessagingMessage subresult = null; var getelement = new NativeMessagingMessage("getelements"); getelement.browser = browser; getelement.xPath = xpath; getelement.cssPath = cssselector; subresult = NMHook.sendMessageResult(getelement, false, TimeSpan.FromSeconds(2)); if (subresult != null) { if (subresult.results != null) { foreach (var b in subresult.results) { if (b.cssPath == "true" || b.xPath == "true") { var data = b.result; var arr = JArray.Parse(data); foreach (var _e in arr) { if (results.Count > maxresults) { continue; } var json = _e.ToString(); var subsubresult = Newtonsoft.Json.JsonConvert.DeserializeObject <NativeMessagingMessage>(json); subsubresult.browser = browser; subsubresult.result = json; subsubresult.tabid = b.tabid; subsubresult.tab = b.tab; results.Add(new NMElement(subsubresult)); } } } } } } return(results.ToArray()); //NMHook.Instance.refreshJvms(); //NMElement[] result = null; //foreach (var jvm in NMHook.Instance.jvms) //{ // result = GetElementsWithuiSelector(jvm, selector, fromElement, maxresults); // if (result.Count() > 0) return result; //} //if (result == null) return new NMElement[] { }; //return result; //return new NMElement[] { }; }
private static void Server_OnReceivedMessage(NamedPipeConnection <NativeMessagingMessage, NativeMessagingMessage> connection, NativeMessagingMessage message) { try { //if (string.IsNullOrEmpty(e.Message)) return; //var msg = JsonConvert.DeserializeObject<NativeMessagingMessage>(e.Message); System.Diagnostics.Trace.WriteLine("[resv]" + message.functionName + " for tab " + message.tabid + " - " + message.messageid); handler.sendMessage(message); //e.replyhandled = true; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } }
public static NMElement[] GetElementsWithuiSelector(NMSelector selector, IElement fromElement = null, int maxresults = 1) { var results = new List <NMElement>(); SelectorItem first = null; SelectorItem second = null; string browser = ""; SelectorItemProperty p = null; if (selector.Count > 1) { first = selector[0]; second = selector[1]; p = first.Properties.Where(x => x.Name == "browser").FirstOrDefault(); if (p != null) { browser = p.Value; } } else if (fromElement == null) { throw new ArgumentException("Invalid select with only 1 child and no anchor"); } else { second = selector[0]; } p = second.Properties.Where(x => x.Name == "xpath").FirstOrDefault(); string xpath = ""; if (p != null) { xpath = p.Value; } p = second.Properties.Where(x => x.Name == "cssselector").FirstOrDefault(); string cssselector = ""; if (p != null) { cssselector = p.Value; } NMElement fromNMElement = fromElement as NMElement; string fromcssPath = ""; string fromxPath = ""; if (fromElement != null) { fromcssPath = fromNMElement.cssselector; fromxPath = fromNMElement.xpath; } //NMHook.checkForPipes(true, true); //NMHook.reloadtabs(); //var tabs = NMHook.tabs.ToList(); //if (!string.IsNullOrEmpty(browser)) { // lock(NMHook.tabs) // { // tabs = NMHook.tabs.Where(x => x.browser == browser).ToList(); // } //} //foreach (var tab in tabs) //{ //} NativeMessagingMessage subresult = null; var getelement = new NativeMessagingMessage("getelements", PluginConfig.debug_console_output, PluginConfig.unique_xpath_ids); getelement.browser = browser; getelement.xPath = xpath; getelement.cssPath = cssselector; getelement.fromxPath = fromxPath; getelement.fromcssPath = fromcssPath; if (fromElement != null && fromElement is NMElement) { getelement.windowId = ((NMElement)fromElement).message.windowId; getelement.tabid = ((NMElement)fromElement).message.tabid; getelement.frameId = ((NMElement)fromElement).message.frameId; } subresult = NMHook.sendMessageResult(getelement, false, TimeSpan.FromSeconds(2)); if (subresult != null) { if (subresult.results != null) { foreach (var b in subresult.results) { if (b.cssPath == "true" || b.xPath == "true") { if (results.Count > maxresults) { continue; } results.Add(new NMElement(b)); //var data = b.result; //var arr = JArray.Parse(data.ToString()); //foreach (var _e in arr) //{ // if (results.Count > maxresults) continue; // var json = _e.ToString(); // var subsubresult = Newtonsoft.Json.JsonConvert.DeserializeObject<NativeMessagingMessage>(json); // subsubresult.browser = browser; // subsubresult.result = json; // subsubresult.tabid = b.tabid; // subsubresult.tab = b.tab; // results.Add(new NMElement(subsubresult)); //} } } } } return(results.ToArray()); }
public static NMElement[] GetElementsWithuiSelector(NMSelector selector, IElement fromElement = null, int maxresults = 1) { var results = new List <NMElement>(); SelectorItem first = null; SelectorItem second = null; string browser = ""; SelectorItemProperty p = null; if (selector.Count > 1) { first = selector[0]; second = selector[1]; p = first.Properties.Where(x => x.Name == "browser").FirstOrDefault(); if (p != null) { browser = p.Value; } } else if (fromElement == null) { throw new ArgumentException("Invalid select with only 1 child and no anchor"); } else { second = selector[0]; } p = second.Properties.Where(x => x.Name == "xpath").FirstOrDefault(); string xpath = ""; if (p != null) { xpath = p.Value; } p = second.Properties.Where(x => x.Name == "cssselector").FirstOrDefault(); string cssselector = ""; if (p != null) { cssselector = p.Value; } NMElement fromNMElement = fromElement as NMElement; string fromcssPath = ""; string fromxPath = ""; if (fromElement != null) { fromcssPath = fromNMElement.cssselector; fromxPath = fromNMElement.xpath; } NativeMessagingMessage subresult = null; var getelement = new NativeMessagingMessage("getelements", PluginConfig.debug_console_output, PluginConfig.unique_xpath_ids); getelement.browser = browser; getelement.xPath = xpath; getelement.cssPath = cssselector; getelement.fromxPath = fromxPath; getelement.fromcssPath = fromcssPath; if (fromElement != null && fromElement is NMElement) { getelement.windowId = ((NMElement)fromElement).message.windowId; getelement.tabid = ((NMElement)fromElement).message.tabid; getelement.frameId = ((NMElement)fromElement).message.frameId; } subresult = NMHook.sendMessageResult(getelement, PluginConfig.protocol_timeout); if (subresult != null) { if (subresult.results != null) { foreach (var b in subresult.results) { if (b.cssPath == "true" || b.xPath == "true") { if (results.Count > maxresults) { continue; } var nme = new NMElement(b); results.Add(nme); } } } } return(results.ToArray()); }