public void DetectorCheck(AutomationElement element, FlaUI.Core.Definitions.StructureChangeType e, int[] arg3)
 {
     try
     {
         if (Entity == null || string.IsNullOrEmpty(Selector))
         {
             return;
         }
         TimeSpan timepassed = DateTime.Now - lastTriggered;
         if (timepassed.Milliseconds < 100)
         {
             return;
         }
         lastTriggered = DateTime.Now;
         // if (e != FlaUI.Core.Definitions.StructureChangeType.ChildAdded) return;
         var pathToRoot = new List <AutomationElement>();
         while (element != null)
         {
             if (pathToRoot.Contains(element))
             {
                 break;
             }
             try
             {
                 if (element.Parent != null)
                 {
                     pathToRoot.Add(element);
                 }
             }
             catch (Exception)
             {
             }
             try
             {
                 element = element.Parent;
             }
             catch (Exception ex)
             {
                 Log.Error(ex, "");
                 return;
             }
         }
         WindowsSelector selector = new WindowsSelector(Selector);
         if (pathToRoot.Count < (selector.Count - 1))
         {
             return;
         }
         if (pathToRoot.Count > (selector.Count - 1))
         {
             return;
         }
         pathToRoot.Reverse();
         for (var i = 0; i < pathToRoot.Count; i++)
         {
             element = pathToRoot[i];
             if (selector.Count > (i + 1))
             {
                 WindowsSelectorItem s = new WindowsSelectorItem(selector[(i + 1)]);
                 if (!s.Match(element))
                 {
                     return;
                 }
             }
             else
             {
                 return;
             }
         }
         var _e = new DetectorEvent(new UIElement(element));
         OnDetector?.Invoke(this, _e, EventArgs.Empty);
     }
     catch (Exception ex)
     {
         Log.Error(ex.ToString());
     }
 }
Ejemplo n.º 2
0
 private void OnMouseUp(InputEventArgs e)
 {
     try
     {
         if (e.Element == null)
         {
             return;
         }
         if (Entity == null || string.IsNullOrEmpty(Selector))
         {
             return;
         }
         var pathToRoot            = new List <AutomationElement>();
         AutomationElement element = e.Element.RawElement;
         while (element != null)
         {
             if (pathToRoot.Contains(element))
             {
                 break;
             }
             try
             {
                 if (element.Parent != null)
                 {
                     pathToRoot.Add(element);
                 }
             }
             catch (Exception)
             {
             }
             try
             {
                 element = element.Parent;
             }
             catch (Exception ex)
             {
                 element = null;
                 Log.Error(ex, "");
                 // return;
             }
         }
         WindowsSelector selector = new WindowsSelector(Selector);
         if (pathToRoot.Count < (selector.Count - 1))
         {
             return;
         }
         if (pathToRoot.Count > (selector.Count - 1))
         {
             return;
         }
         pathToRoot.Reverse();
         for (var i = 0; i < pathToRoot.Count; i++)
         {
             element = pathToRoot[i];
             WindowsSelectorItem s = new WindowsSelectorItem(selector[(i + 1)]);
             if (!s.Match(element))
             {
                 Log.Verbose("WindowsClickDetectorPlugin: Element " + i + " does not match with selector");
                 return;
             }
         }
         var _e = new DetectorEvent(e.Element);
         OnDetector?.Invoke(this, _e, EventArgs.Empty);
     }
     catch (Exception ex)
     {
         Log.Error(ex.ToString());
     }
 }