public override IEnumerable <Element> GetElementsFromQuery(ElementQuery query) { var result = new List <WinElement>(); var candidates = new Queue <WinElement>(); var targetPath = query.FirstOrDefault(x => x.Name == "Path")?.Value.ToString(); if (targetPath == null) { return(result); } var targetMainWindowName = query.FirstOrDefault(x => x.Name == "MainWindowName").Value.ToString(); var targetWindowName = query.FirstOrDefault(x => x.Name == "WindowName").Value.ToString(); var targetWindowCount = targetPath.Split('/').Count(); candidates.Enqueue(WinElement.GetRoot()); while (candidates.Count > 0) { var candidate = candidates.Dequeue(); var candidatePath = candidate.Path; var candidateWindowCount = candidatePath.Split('/').Count(x => x == "window"); if (targetPath.StartsWith(candidatePath)) { if (candidateWindowCount > 0) { if (candidate.MainWindowName != targetMainWindowName) { continue; } } if (candidateWindowCount == targetWindowCount) { if (candidate.WindowName != targetWindowName) { continue; } } if (targetPath.Equals(candidatePath)) { if (candidate.TryQuery(query)) { result.Add(candidate); } } else { foreach (var child in candidate.Children) { candidates.Enqueue(child); } } } } return(result); }
public ElementQuery GetQuery() { var query = new ElementQuery(); var props = this.GetType().GetProperties().Where(attr => Attribute.IsDefined(attr, typeof(Property))); foreach (var prop in props) { var attr = Attribute.GetCustomAttribute(prop, typeof(Property), true) as Property; var condition = new Condition(prop.Name, prop.GetValue(this), attr.Enabled, attr.Required); query.Add(condition); } return(query); }
public static int CountElements(this ActivityContext context, Input <ElementQuery> input) { var query = new ElementQuery(XmlSerializerHelper.ToObject <List <Condition> >(input.Value)); if (query == null) { throw new Exception("Input 'Element' is required."); } var elements = WinContext.Shared.GetElementsFromQuery(query); return(elements.Count()); }
public bool TryQuery(ElementQuery query) { foreach (var condition in query) { if (condition.Required || condition.Enabled) { var prop = this.GetType().GetProperty(condition.Name); if (condition.Compare(prop.GetValue(this), prop.PropertyType)) { continue; } return(false); } } return(true); }
public abstract IEnumerable <Element> GetElementsFromQuery(ElementQuery query);