Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
 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);
 }
Exemple #5
0
        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);
        }
Exemple #6
0
 public abstract IEnumerable <Element> GetElementsFromQuery(ElementQuery query);