public static ElementQuery Get(Input <ElementQuery> input) { var value = input.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(input).ToString(); if (value == string.Empty) { return(null); } var query = new ElementQuery(DataContractSerializerHelper.ToObject <List <Condition> >(value)); return(query); }
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 ElementQuery Get(Input <ElementQuery> input) { var value = input.Value; if (value == string.Empty) { return(null); } var query = new ElementQuery(XmlSerializerHelper.ToObject <List <Condition> >(value)); return(query); }
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 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); } candidates.Enqueue(WinElement.GetRoot()); while (candidates.Count > 0) { var candidate = candidates.Dequeue(); var candidatePath = candidate.Path; if (targetPath.StartsWith(candidatePath)) { if (targetPath.Equals(candidatePath)) { if (candidate.TryQuery(query)) { result.Add(candidate); } } else { foreach (var child in candidate.Children) { candidates.Enqueue(child); } } } } return(result); }
public abstract IEnumerable <Element> GetElementsFromQuery(ElementQuery query);