public override IEnumerable GetAllResults(Query query, TimeSpan timeout)
{
Debug.WriteLine("AllResults - " + query, "UIAutomation-SearchEngine-TreeWalker");
var root = query.Root;
var scope = query.Scope;
var conditions = query.Conditions;
var results = new ArrayList();
// The callback for saving all matched elements.
var saveMatchingChildren = new WithElementCallback(child => {
Trace.WriteLine("Checking " + AutomationElementHelper.ToString(child) + "...", "UIAutomation-SearchEngine-TreeWalker");
if (ConditionHelper.IsMeetsRequirements(conditions, child))
results.Add(child);
return null;
});
// Execute based on scope.
switch (scope) {
case TreeScope.Children:
ExecuteWithChildren(root, saveMatchingChildren);
return results;
case TreeScope.Descendants:
ExecuteWithDescendants(root, saveMatchingChildren);
return results;
default:
throw new NotSupportedException("Scope '" + scope + "' is not supported for TreeWalker search engines");
}
}