Esempio n. 1
0
        protected override void StartLoop(NativeActivityContext context)
        {
            var SelectorString = Selector.Get(context);

            SelectorString = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(SelectorString, context.DataContext);
            var sel             = new SAPSelector(SelectorString);
            var timeout         = Timeout.Get(context);
            var maxresults      = MaxResults.Get(context);
            var minresults      = MinResults.Get(context);
            var flatternguitree = FlatternGuiTree.Get(context);
            //var from = From.Get(context);
            SAPElement from = null;

            if (maxresults < 1)
            {
                maxresults = 1;
            }

            SAPElement[] elements = { };
            var          sw       = new Stopwatch();

            sw.Start();
            do
            {
                var selector = new SAPSelector(SelectorString);
                elements = SAPSelector.GetElementsWithuiSelector(selector, from, 0, maxresults, flatternguitree);
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            Log.Debug(string.Format("OpenRPA.SAP::GetElement::found {1} elements in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count()));
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }
            if (elements.Count() < 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)");
            }
            context.SetValue(Elements, elements);
            IEnumerator <SAPElement> _enum = elements.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                IncIndex(context);
                SetTotal(context, elements.Length);
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }
Esempio n. 2
0
        protected override void StartLoop(NativeActivityContext context)
        {
            var SelectorString = Selector.Get(context);

            SelectorString = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(SelectorString, context.DataContext);
            var sel             = new SAPSelector(SelectorString);
            var timeout         = Timeout.Get(context);
            var maxresults      = MaxResults.Get(context);
            var minresults      = MinResults.Get(context);
            var flatternguitree = FlatternGuiTree.Get(context);
            //var from = From.Get(context);
            SAPElement from = null;

            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 SAP.GetElements is above 5 minutes, was this the intention ? calculated value " + timeout.ToString());
                }
            }
            SAPElement[] elements = { };
            var          sw       = new Stopwatch();

            sw.Start();
            do
            {
                var selector = new SAPSelector(SelectorString);
                elements = SAPSelector.GetElementsWithuiSelector(selector, from, 0, maxresults, flatternguitree);
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            Log.Debug(string.Format("OpenRPA.SAP::GetElement::found {1} elements in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count()));
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }
            if (elements.Count() < 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)");
            }
            context.SetValue(Elements, elements);
            IEnumerator <SAPElement> _enum = elements.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                IncIndex(context);
                SetTotal(context, elements.Length);
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }