Exemplo n.º 1
0
        public void CloseBySelector(Selector selector, TimeSpan timeout, bool Force)
        {
            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 = first.Properties.Where(x => x.Name == "url").FirstOrDefault();
            string url = "";

            if (p != null)
            {
                url = p.Value;
            }
            NMHook.enumtabs();
            var tabs = NMHook.tabs.Where(x => x.browser == browser && x.url == url).ToList();

            if (string.IsNullOrEmpty(url))
            {
                tabs = NMHook.tabs.Where(x => x.browser == browser).ToList();
            }
            foreach (var tab in tabs)
            {
                NMHook.CloseTab(tab);
            }
        }
Exemplo n.º 2
0
        protected override void Execute(NativeActivityContext context)
        {
            var url     = Url.Get(context);
            var browser = Browser.Get(context);
            var timeout = TimeSpan.FromSeconds(3);
            var newtab  = NewTab.Get(context);

            if (browser != "chrome" && browser != "ff" && browser != "edge")
            {
                browser = "chrome";
            }
            if (!string.IsNullOrEmpty(url))
            {
                NMHook.enumtabs();
                var tab = NMHook.tabs.Where(x => x.browser == browser && x.url.ToLower().StartsWith(url.ToLower())).FirstOrDefault();
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }
            NMHook.openurl(browser, url, newtab);
        }
Exemplo n.º 3
0
        protected override void Execute(NativeActivityContext context)
        {
            var url     = Url.Get(context);
            var browser = Browser.Get(context);
            var timeout = TimeSpan.FromSeconds(3);
            var newtab  = NewTab.Get(context);

            if (browser != "chrome" && browser != "ff" && browser != "edge")
            {
                browser = "chrome";
            }
            if (!string.IsNullOrEmpty(url))
            {
                NMHook.enumtabs();
                var tab = NMHook.FindTabByURL(browser, url);
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }
            NMHook.openurl(browser, url, newtab);
        }
Exemplo n.º 4
0
        protected override void Execute(NativeActivityContext context)
        {
            var closeall = CloseAll.Get(context);
            var browser  = Browser.Get(context);
            var timeout  = TimeSpan.FromSeconds(3);

            if (browser != "chrome" && browser != "ff" && browser != "edge")
            {
                browser = "chrome";
            }
            NMHook.enumtabs();
            if (closeall)
            {
                foreach (var tab in NMHook.tabs.Where(x => x.browser == browser).ToList())
                {
                    NMHook.closetab(browser, tab.id);
                }
            }
            else
            {
                if (browser == "chrome")
                {
                    if (NMHook.CurrentChromeTab != null)
                    {
                        NMHook.closetab(browser, NMHook.CurrentChromeTab.id);
                    }
                    else
                    {
                        Log.Warning("No active tab found for " + browser);
                    }
                }
                if (browser == "ff")
                {
                    if (NMHook.CurrentFFTab != null)
                    {
                        NMHook.closetab(browser, NMHook.CurrentFFTab.id);
                    }
                    else
                    {
                        Log.Warning("No active tab found for " + browser);
                    }
                }
                if (browser == "edge")
                {
                    if (NMHook.CurrentEdgeTab != null)
                    {
                        NMHook.closetab(browser, NMHook.CurrentEdgeTab.id);
                    }
                    else
                    {
                        Log.Warning("No active tab found for " + browser);
                    }
                }
            }
        }
Exemplo n.º 5
0
 private void DoWaitForReady(string browser)
 {
     if (!string.IsNullOrEmpty(browser))
     {
         NMHook.enumtabs();
         if (browser == "chrome" && NMHook.CurrentChromeTab != null)
         {
             NMHook.WaitForTab(NMHook.CurrentChromeTab.id, browser, TimeSpan.FromSeconds(10));
         }
         if (browser == "ff" && NMHook.CurrentFFTab != null)
         {
             NMHook.WaitForTab(NMHook.CurrentFFTab.id, browser, TimeSpan.FromSeconds(10));
         }
     }
 }
Exemplo n.º 6
0
        protected override void Execute(NativeActivityContext context)
        {
            var selector = Selector.Get(context);

            selector = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selector, context.DataContext);
            var sel        = new NMSelector(selector);
            var timeout    = Timeout.Get(context);
            var from       = From.Get(context);
            var maxresults = MaxResults.Get(context);
            var minresults = MinResults.Get(context);

            if (maxresults < 1)
            {
                maxresults = 1;
            }
            NMElement[] elements = { };
            var         sw       = new Stopwatch();

            sw.Start();
            if (WaitForReady.Get(context))
            {
                string browser = sel.browser;
                if (from != null)
                {
                    browser = from.browser;
                }
                if (!string.IsNullOrEmpty(browser))
                {
                    NMHook.enumtabs();
                    if (browser == "chrome" && NMHook.CurrentChromeTab != null)
                    {
                        NMHook.WaitForTab(NMHook.CurrentChromeTab.id, browser, TimeSpan.FromSeconds(10));
                    }
                    if (browser == "ff" && NMHook.CurrentFFTab != null)
                    {
                        NMHook.WaitForTab(NMHook.CurrentFFTab.id, browser, TimeSpan.FromSeconds(10));
                    }
                }
            }
            do
            {
                elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults);
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }
            context.SetValue(Elements, elements);

            var lastelements = context.GetValue(_lastelements);

            if (lastelements == null)
            {
                lastelements = new NMElement[] { }
            }
            ;
            context.SetValue(_lastelements, elements);
            if ((elements.Length + lastelements.Length) < minresults)
            {
                Log.Selector(string.Format("Windows.GetElement::Failed locating " + minresults + " item(s) {0:mm\\:ss\\.fff}", sw.Elapsed));
                throw new ElementNotFoundException("Failed locating " + minresults + " item(s)");
            }

            IEnumerator <NMElement> _enum = elements.ToList().GetEnumerator();
            bool more = _enum.MoveNext();

            if (lastelements.Length == elements.Length && lastelements.Length > 0)
            {
                var eq = new Activities.NMEqualityComparer();

                more = !System.Collections.StructuralComparisons.StructuralEqualityComparer.Equals(lastelements, elements);
            }
            if (more)
            {
                context.SetValue(_elements, _enum);
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }
Exemplo n.º 7
0
        protected override void Execute(NativeActivityContext context)
        {
            var url     = Url.Get(context);
            var browser = Browser.Get(context);
            var timeout = TimeSpan.FromSeconds(3);
            var newtab  = NewTab.Get(context);

            if (browser != "chrome" && browser != "ff" && browser != "edge")
            {
                browser = "chrome";
            }
            if (!string.IsNullOrEmpty(url))
            {
                NMHook.enumtabs();
                var tab = NMHook.FindTabByURL(browser, url);
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }
            var    userDataFolderMode = UserDataFolderMode.Get(context);
            var    userDataFolderPath = UserDataFolderPath.Get(context);
            string profilepath        = "";
            string profilename        = "";

            if (string.IsNullOrEmpty(userDataFolderMode))
            {
                userDataFolderMode = "automatic";
            }
            userDataFolderMode = userDataFolderMode.ToLower();
            if (userDataFolderMode == "automatic") // child session uses a different folder than the default mode, automatically generated if UserDataFolderPath is not set
            {
                if (Plugin.client.isRunningInChildSession)
                {
                    profilepath = userDataFolderPath;
                    if (string.IsNullOrEmpty(profilepath))
                    {
                        profilepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\openrpa\\ChildSession\\" + browser;
                        profilename = "ChildSession";
                    }
                }
            }
            else if (userDataFolderMode == "customfolder")
            {
                profilepath = userDataFolderPath;
                if (string.IsNullOrEmpty(profilepath))
                {
                    if (Plugin.client.isRunningInChildSession)
                    {
                        profilepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\openrpa\\ChildSession\\" + browser;
                        profilename = "ChildSession";
                    }
                    else
                    {
                        profilepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\openrpa\\" + browser;
                        profilename = "openrpa";
                    }
                }
            }
            else if (userDataFolderMode == "defaultfolder")
            {
                // Uses the default browser folder, no matter what
            }

            NMHook.openurl(browser, url, newtab, profilename, profilepath);
        }