示例#1
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);
            }

            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);
        }
示例#2
0
文件: Element.cs 项目: zergmk2/Roro
        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);
        }
示例#3
0
        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());
        }
示例#4
0
文件: Element.cs 项目: zergmk2/Roro
 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);
 }
示例#5
0
 public abstract IEnumerable <Element> GetElementsFromQuery(ElementQuery query);