Exemplo n.º 1
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.º 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.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.º 3
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();
            string browser = sel.browser;

            if (WaitForReady.Get(context))
            {
                if (from != null)
                {
                    browser = from.browser;
                }
                DoWaitForReady(browser);
            }
            var allelements = context.GetValue(_allelements);

            if (allelements == null)
            {
                allelements = new NMElement[] { }
            }
            ;

            var s = new NMSelectorItem(sel[0]);

            if (!string.IsNullOrEmpty(s.url))
            {
                var tab = NMHook.FindTabByURL(browser, s.url);
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }

            do
            {
                elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults);
                Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements");

                // allelements = allelements.Concat(elements).ToArray();
                if (allelements.Length > 0)
                {
                    var newelements = new List <NMElement>();
                    for (var i = elements.Length - 1; i >= 0; i--)
                    {
                        var element = elements[i];
                        if (!allelements.Contains(element))
                        {
                            newelements.Insert(0, element);
                        }
                    }
                    elements = newelements.ToArray();
                    //if(elements.Count() > 20)
                    //{
                    //    for(var i=0; i < allelements.Length && i < elements.Length; i++)
                    //    {
                    //        if (!eq.Equals(allelements[i], elements[i]) || allelements[i].GetHashCode() != elements[i].GetHashCode())
                    //        {
                    //            Log.Output(allelements[i].GetHashCode() + " / " + elements[i].GetHashCode());
                    //        }

                    //    }

                    //}
                }
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }

            if ((elements.Length + allelements.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)
            {
                allelements = allelements.Concat(elements).ToArray();
                var eq = new Activities.NMEqualityComparer();
                allelements = allelements.Distinct(eq).ToArray();

                //var allelementslength = allelements.Length;
                //Array.Resize(ref allelements, allelements.Length + elements.Length);
                //Array.Copy(elements, 0, allelements, allelementslength, elements.Length);
            }

            context.SetValue(_allelements, allelements);
            context.SetValue(Elements, allelements);
            Log.Selector("END:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements");

            if (more)
            {
                context.SetValue(_elements, _enum);
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }
Exemplo n.º 4
0
        protected override async Task <object> ExecuteAsync(NativeActivityContext context)
        {
            IsCancel = false;
            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 = { };
            string      browser  = sel.browser;

            if (WaitForReady != null && WaitForReady.Get(context))
            {
                if (from != null)
                {
                    browser = from.browser;
                }
                DoWaitForReady(browser);
            }
            var allelements = context.GetValue(_allelements);

            if (allelements == null)
            {
                allelements = new NMElement[] { }
            }
            ;

            var s = new NMSelectorItem(sel[0]);

            if (!string.IsNullOrEmpty(s.url))
            {
                var tab = NMHook.FindTabByURL(browser, s.url);
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }
            await Task.Run(() =>
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                do
                {
                    elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults);
                    Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements");
                    if (allelements.Length > 0)
                    {
                        var newelements = new List <NMElement>();
                        for (var i = elements.Length - 1; i >= 0; i--)
                        {
                            var element = elements[i];
                            if (!allelements.Contains(element))
                            {
                                newelements.Insert(0, element);
                            }
                        }
                        elements = newelements.ToArray();
                    }
                } while (elements.Count() == 0 && sw.Elapsed < timeout && !IsCancel);
                if (IsCancel)
                {
                    Console.WriteLine("was Canceled: true! DisplayName" + DisplayName);
                }
                //if (sw.Elapsed >= timeout)
                //{
                //    Console.WriteLine("Timeout !");
                //}
            });

            return(elements);
        }
Exemplo n.º 5
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();
            string browser = sel.browser;

            if (WaitForReady.Get(context))
            {
                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));
                    }
                }
            }
            var s = new NMSelectorItem(sel[0]);

            if (!string.IsNullOrEmpty(s.url))
            {
                var tab = NMHook.tabs.Where(x => x.browser == browser && x.url.ToLower().StartsWith(s.url.ToLower())).FirstOrDefault();
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }

            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.º 6
0
        protected override void StartLoop(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;
            }
            if (timeout.Minutes > 5 || timeout.Hours > 1)
            {
                Activity _Activity = null;
                try
                {
                    var strProperty = context.GetType().GetProperty("Activity", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    var strGetter   = strProperty.GetGetMethod(nonPublic: true);
                    _Activity = (Activity)strGetter.Invoke(context, null);
                }
                catch (Exception)
                {
                }
                if (_Activity != null)
                {
                    Log.Warning("Timeout for Activity " + _Activity.Id + " is above 5 minutes, was this the intention ? calculated value " + timeout.ToString());
                }
                else
                {
                    Log.Warning("Timeout for on of your NM.GetElements is above 5 minutes, was this the intention ? calculated value " + timeout.ToString());
                }
            }
            NMElement[] elements = { };
            var         sw       = new Stopwatch();

            sw.Start();
            string browser = sel.browser;

            if (WaitForReady.Get(context))
            {
                if (from != null)
                {
                    browser = from.browser;
                }
                DoWaitForReady(browser);
            }
            var allelements = context.GetValue(_allelements);

            if (allelements == null)
            {
                allelements = new NMElement[] { }
            }
            ;

            var s = new NMSelectorItem(sel[0]);

            if (!string.IsNullOrEmpty(s.url))
            {
                var tab = NMHook.FindTabByURL(browser, s.url);
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }

            do
            {
                elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults);
                Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements");

                // allelements = allelements.Concat(elements).ToArray();
                if (allelements.Length > 0)
                {
                    var newelements = new List <NMElement>();
                    for (var i = elements.Length - 1; i >= 0; i--)
                    {
                        var element = elements[i];
                        if (!allelements.Contains(element))
                        {
                            newelements.Insert(0, element);
                        }
                    }
                    elements = newelements.ToArray();
                    //if(elements.Count() > 20)
                    //{
                    //    for(var i=0; i < allelements.Length && i < elements.Length; i++)
                    //    {
                    //        if (!eq.Equals(allelements[i], elements[i]) || allelements[i].GetHashCode() != elements[i].GetHashCode())
                    //        {
                    //            Log.Output(allelements[i].GetHashCode() + " / " + elements[i].GetHashCode());
                    //        }

                    //    }

                    //}
                }
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }

            if ((elements.Length + allelements.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)
            {
                allelements = allelements.Concat(elements).ToArray();
                var eq = new Activities.NMEqualityComparer();
                allelements = allelements.Distinct(eq).ToArray();

                //var allelementslength = allelements.Length;
                //Array.Resize(ref allelements, allelements.Length + elements.Length);
                //Array.Copy(elements, 0, allelements, allelementslength, elements.Length);
            }

            context.SetValue(_allelements, allelements);
            context.SetValue(Elements, allelements);
            Log.Selector("END:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements");

            if (more)
            {
                context.SetValue(_elements, _enum);
                IncIndex(context);
                SetTotal(context, allelements.Length);
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }
Exemplo n.º 7
0
        protected override void Execute(NativeActivityContext context)
        {
            var eq       = new Activities.NMEqualityComparer();
            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();
            string browser = sel.browser;

            if (WaitForReady.Get(context))
            {
                if (from != null)
                {
                    browser = from.browser;
                }
                DoWaitForReady(browser);
            }
            var s = new NMSelectorItem(sel[0]);

            if (!string.IsNullOrEmpty(s.url))
            {
                var tab = NMHook.tabs.Where(x => x.browser == browser && x.url.ToLower().StartsWith(s.url.ToLower())).FirstOrDefault();
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }

            do
            {
                elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults);
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }

            var lastelements = context.GetValue(_lastelements);

            if (lastelements == null)
            {
                lastelements = new NMElement[] { }
            }
            ;
            context.SetValue(_lastelements, elements);
            if (lastelements.Length > 0)
            {
                var newelements = new List <NMElement>();
                for (var i = elements.Length - 1; i >= 0; i--)
                {
                    var  element = elements[i];
                    bool exists  = false;
                    foreach (var ele in lastelements)
                    {
                        if (eq.Equals(ele, element))
                        {
                            exists = true;
                            break;
                        }
                        else if (element.ToString() == ele.ToString())
                        {
                            var b = eq.Equals(ele, element);
                        }
                    }
                    if (!exists)
                    {
                        newelements.Insert(0, element);
                    }
                }
                if (elements.Length > 0)
                {
                    elements = newelements.ToArray();

                    newelements = new List <NMElement>();
                    for (var i = elements.Length - 1; i >= 0; i--)
                    {
                        bool exists = false;
                        foreach (var ele in lastelements)
                        {
                            if (eq.Equals(ele, elements[i]))
                            {
                                exists = true;
                                break;
                            }
                        }
                        if (!exists)
                        {
                            newelements.Insert(0, elements[i]);
                        }
                    }
                    elements = newelements.ToArray();
                }
            }
            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);
            }

            var allelements = context.GetValue(_allelements);

            if (more)
            {
                if (allelements == null)
                {
                    allelements = new NMElement[] { }
                }
                ;
                var allelementslength = allelements.Length;
                Array.Resize(ref allelements, allelements.Length + elements.Length);
                Array.Copy(elements, 0, allelements, allelementslength, elements.Length);
            }
            context.SetValue(Elements, allelements);
            context.SetValue(_allelements, allelements);
        }
Exemplo n.º 8
0
        protected override async Task <object> ExecuteAsync(NativeActivityContext context)
        {
            IsCancel = false;
            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 = { };

            sw.Start();
            string browser = sel.browser;

            if (WaitForReady != null && WaitForReady.Get(context))
            {
                if (from != null)
                {
                    browser = from.browser;
                }
                DoWaitForReady(browser);
            }
            var allelements = context.GetValue(_allelements);

            if (allelements == null)
            {
                allelements = new NMElement[] { }
            }
            ;

            var s = new NMSelectorItem(sel[0]);

            if (!string.IsNullOrEmpty(s.url))
            {
                var tab = NMHook.tabs.Where(x => x.browser == browser && x.url.ToLower().StartsWith(s.url.ToLower())).FirstOrDefault();
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }



            //var id = Guid.NewGuid().ToString();
            //context.CreateBookmark(id, (activityContext, bookmark, value) =>
            //{

            //});

            //Task.Factory.StartNew(() =>
            //{
            //    // context.RemoveBookmark(id);
            //});

            // await Task.Delay(100);
            await Task.Run(() =>
            {
                do
                {
                    elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults);
                    Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements");

                    // allelements = allelements.Concat(elements).ToArray();
                    if (allelements.Length > 0)
                    {
                        var newelements = new List <NMElement>();
                        for (var i = elements.Length - 1; i >= 0; i--)
                        {
                            var element = elements[i];
                            if (!allelements.Contains(element))
                            {
                                newelements.Insert(0, element);
                            }
                        }
                        elements = newelements.ToArray();
                        //if(elements.Count() > 20)
                        //{
                        //    for(var i=0; i < allelements.Length && i < elements.Length; i++)
                        //    {
                        //        if (!eq.Equals(allelements[i], elements[i]) || allelements[i].GetHashCode() != elements[i].GetHashCode())
                        //        {
                        //            Log.Output(allelements[i].GetHashCode() + " / " + elements[i].GetHashCode());
                        //        }

                        //    }

                        //}
                    }
                } while (elements.Count() == 0 && sw.Elapsed < timeout && !IsCancel);
                if (IsCancel)
                {
                    Console.WriteLine("was Canceled: true! DisplayName" + DisplayName);
                }
            });

            return(elements);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        protected override async Task <object> ExecuteAsync(NativeActivityContext context)
        {
            IsCancel = false;
            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 = { };
            string      browser  = sel.browser;

            if (WaitForReady != null && WaitForReady.Get(context))
            {
                if (from != null)
                {
                    browser = from.browser;
                }
                DoWaitForReady(browser);
            }
            var allelements = context.GetValue(_allelements);

            if (allelements == null)
            {
                allelements = new NMElement[] { }
            }
            ;
            if (timeout.Minutes > 5 || timeout.Hours > 1)
            {
                Activity _Activity = null;
                try
                {
                    var strProperty = context.GetType().GetProperty("Activity", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    var strGetter   = strProperty.GetGetMethod(nonPublic: true);
                    _Activity = (Activity)strGetter.Invoke(context, null);
                }
                catch (Exception)
                {
                }
                if (_Activity != null)
                {
                    Log.Warning("Timeout for Activity " + _Activity.Id + " is above 5 minutes, was this the intention ? calculated value " + timeout.ToString());
                }
                else
                {
                    Log.Warning("Timeout for on of your NM.GetElementAsync is above 5 minutes, was this the intention ? calculated value " + timeout.ToString());
                }
            }

            var s = new NMSelectorItem(sel[0]);

            if (!string.IsNullOrEmpty(s.url))
            {
                var tab = NMHook.FindTabByURL(browser, s.url);
                if (tab != null)
                {
                    if (!tab.highlighted || !tab.selected)
                    {
                        var _tab = NMHook.selecttab(browser, tab.id);
                    }
                }
            }
            await Task.Run(() =>
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                do
                {
                    elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults);
                    Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements");
                    if (allelements.Length > 0)
                    {
                        var newelements = new List <NMElement>();
                        for (var i = elements.Length - 1; i >= 0; i--)
                        {
                            var element = elements[i];
                            if (!allelements.Contains(element))
                            {
                                newelements.Insert(0, element);
                            }
                        }
                        elements = newelements.ToArray();
                    }
                } while (elements.Count() == 0 && sw.Elapsed < timeout && !IsCancel);
                if (IsCancel)
                {
                    Console.WriteLine("was Canceled: true! DisplayName" + DisplayName);
                }
                //if (sw.Elapsed >= timeout)
                //{
                //    Console.WriteLine("Timeout !");
                //}
            });

            return(elements);
        }