예제 #1
0
        private void Highlight_Click(object sender, RoutedEventArgs e)
        {
            ModelItem   loadFrom = ModelItem.Parent;
            string      loadFromSelectorString = "";
            SAPSelector anchor = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Selector").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    anchor = new SAPSelector(loadFromSelectorString);
                    break;
                }
                loadFrom = loadFrom.Parent;
            }

            HighlightImage = Interfaces.Extensions.GetImageSourceFromResource(".x.png");
            NotifyPropertyChanged("HighlightImage");
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresults     = ModelItem.GetValue <int>("MaxResults");

            if (maxresults < 1)
            {
                maxresults = 1;
            }
            var selector = new SAPSelector(SelectorString);

            var elements = new List <SAPElement>();

            if (anchor != null)
            {
                var _base = SAPSelector.GetElementsWithuiSelector(anchor, null, 10);
                foreach (var _e in _base)
                {
                    var res = SAPSelector.GetElementsWithuiSelector(selector, _e, maxresults);
                    elements.AddRange(res);
                }
            }
            else
            {
                var res = SAPSelector.GetElementsWithuiSelector(selector, null, maxresults);
                elements.AddRange(res);
            }
            if (elements.Count() > maxresults && maxresults > 0)
            {
                elements = elements.ToList().Take(maxresults).ToList();
            }
            if (elements.Count() > 0)
            {
                HighlightImage = Interfaces.Extensions.GetImageSourceFromResource("check.png");
                NotifyPropertyChanged("HighlightImage");
            }
            foreach (var ele in elements)
            {
                ele.Highlight(false, System.Drawing.Color.Red, TimeSpan.FromSeconds(1));
            }
        }
예제 #2
0
        protected override void Execute(NativeActivityContext context)
        {
            var SelectorString = Selector.Get(context);

            SelectorString = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(SelectorString, context.DataContext);
            var sel        = new SAPSelector(SelectorString);
            var timeout    = TimeSpan.FromSeconds(3);
            var maxresults = MaxResults.Get(context);
            var minresults = MinResults.Get(context);
            var from       = From.Get(context);

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

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

            sw.Start();
            do
            {
                var selector = new SAPSelector(SelectorString);
                elements = SAPSelector.GetElementsWithuiSelector(selector, from, maxresults);
            } 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)
            {
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
            else
            {
                throw new Interfaces.ElementNotFoundException("Failed locating item");
            }
        }
예제 #3
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);
            }
        }
예제 #4
0
 public override IElement[] GetElements(IElement fromElement = null, int maxresults = 1)
 {
     return(SAPSelector.GetElementsWithuiSelector(this, fromElement, maxresults));
 }