protected override void StartLoop(NativeActivityContext context) { if (Image == null) { new ArgumentException("Image is null"); } //var timeout = TimeSpan.FromSeconds(3); var timeout = Timeout.Get(context); if (Timeout == null || Timeout.Expression == null) { timeout = TimeSpan.FromSeconds(3); } var maxresults = MaxResults.Get(context); var processname = Processname.Get(context); var comparegray = CompareGray.Get(context); var threshold = Threshold.Get(context); var minresults = MinResults.Get(context); var from = From.Get(context); var limit = Limit.Get(context); if (maxresults < 1) { maxresults = 1; } if (threshold < 0.1) { threshold = 0.1; } if (threshold > 1) { threshold = 1; } ImageElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); do { elements = getBatch(minresults, maxresults, threshold, processname, timeout, comparegray, limit).ToArray(); } while (elements.Count() == 0 && sw.Elapsed < timeout); // Log.Debug(string.Format("OpenRPA.Image::GetElement::found {1} elements in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count())); context.SetValue(Elements, elements); IEnumerator <ImageElement> _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); } else if (elements.Count() < minresults) { throw new Interfaces.ElementNotFoundException("Failed locating item"); } }
private void RaiseDetector() { if (!string.IsNullOrEmpty(Processname)) { using (var automation = AutomationUtil.getAutomation()) { var current = automation.FocusedElement(); if (current.Properties.ProcessId.IsSupported) { var ProcessId = automation.FocusedElement().Properties.ProcessId.Value; using (var p = System.Diagnostics.Process.GetProcessById(automation.FocusedElement().Properties.ProcessId.Value)) { if (!PatternMatcher.FitsMask(p.ProcessName.ToLower(), Processname.ToLower())) { Log.Information("KeyboardDetector skipped, expected " + Processname + ", but got " + p.ProcessName); return; } } } } } OnDetector?.Invoke(this, new DetectorEvent(), EventArgs.Empty); }