Exemplo n.º 1
0
        public bool ParseUserAction(ref IRecordEvent e)
        {
            if (e.UIElement == null)
            {
                return(false);
            }

            if (e.UIElement.ProcessId < 1)
            {
                return(false);
            }
            var p = System.Diagnostics.Process.GetProcessById(e.UIElement.ProcessId);

            if (p.ProcessName.ToLower() != "chrome" && p.ProcessName.ToLower() != "firefox" && p.ProcessName.ToLower() != "msedge")
            {
                return(false);
            }

            if (p.ProcessName.ToLower() == "chrome" && !NMHook.chromeconnected)
            {
                System.Windows.MessageBox.Show("You clicked inside Chrome, but it looks like you dont have the OpenRPA plugin installed");
                return(false);
            }
            if (p.ProcessName.ToLower() == "msedge" && !NMHook.edgeconnected)
            {
                System.Windows.MessageBox.Show("You clicked inside Edge, but it looks like you dont have the OpenRPA plugin installed");
                return(false);
            }
            if (p.ProcessName.ToLower() == "firefox" && !NMHook.ffconnected)
            {
                System.Windows.MessageBox.Show("You clicked inside Firefix, but it looks like you dont have the OpenRPA plugin installed");
                return(false);
            }
            if (LastElement == null)
            {
                return(false);
            }
            if (LastElement.message == null)
            {
                return(false);
            }
            if (LastElement.message.tab == null)
            {
                LastElement.message.tab = NMHook.FindTabById(LastElement.message.browser, LastElement.message.tabid);
            }
            if (p.ProcessName.ToLower() == "chrome" || p.ProcessName.ToLower() == "msedge")
            {
                // if (e.UIElement.FrameworkId != "chrome" && e.UIElement.FrameworkId != "Chrome") return false;
            }
            var selector = new NMSelector(LastElement, null, true, null);
            var a        = new GetElement {
                DisplayName = LastElement.id + " " + LastElement.type + " " + LastElement.Name
            };

            a.Selector   = selector.ToString();
            a.Image      = LastElement.ImageString();
            a.MaxResults = 1;

            e.Element       = LastElement;
            e.Selector      = selector;
            e.a             = new GetElementResult(a);
            e.SupportInput  = LastElement.SupportInput;
            e.SupportSelect = LastElement.tagname.ToLower() == "select";
            e.OffsetX       = e.X - LastElement.Rectangle.X;
            e.OffsetY       = e.Y - LastElement.Rectangle.Y;
            e.ClickHandled  = false;
            //e.ClickHandled = true;
            //LastElement.Click(true, e.Button, e.X, e.Y, false, false);
            return(true);
        }
Exemplo n.º 2
0
        public static treeelement[] _GetRootElements(Selector anchor)
        {
            var rootelements = new List <treeelement>();
            var browser      = "";

            if (NMHook.chromeconnected)
            {
                browser = "chrome";
            }
            if (NMHook.ffconnected)
            {
                browser = "ff";
            }
            if (NMHook.edgeconnected)
            {
                browser = "edge";
            }
            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, PluginConfig.unique_xpath_ids)
            {
                browser = browser,
                xPath   = "/html",
                frameId = -1
            };
            var tab = NMHook.GetCurrentTab(browser);

            if (tab == null)
            {
                NMHook.enumwindowandtabs();
            }
            if (tab != null)
            {
                getelement.tabid    = tab.id;
                getelement.windowId = tab.windowId;
            }

            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, PluginConfig.protocol_timeout);
            }
            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.FindTabById(res.browser, res.tabid);
                        }
                        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());
        }
Exemplo n.º 3
0
        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.FindTabById(message.browser, message.tabid);

                        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());
            }
        }