示例#1
0
        public virtual UiObjectBase FindFirst(string ui, TimeSpan timeout)
        {
            Console.WriteLine("Find: {0}.", ui);
            DateTime     start = DateTime.Now;
            UiObjectBase t     = null;

            while (DateTime.Now - start < timeout)
            {
                Queue <Expression> expressionQueue = new Queue <Expression>();
                Expression         expression      = ui;
                if (expression is MultipleExpression)
                {
                    var multipleExpr = expression as MultipleExpression;
                    expressionQueue.EnqueueRange(multipleExpr.Expressions);
                }
                else
                {
                    expressionQueue.Enqueue(expression);
                }
                t = FindFirst(this, expressionQueue);
                if (t != null)
                {
                    return(t);
                }
                Waiter.WaitOne(UITryInterval);
            }
            return(null);
        }
示例#2
0
        public virtual UiObjectBase Wait(string ui, TimeSpan timeout)
        {
            DateTime     start = DateTime.Now;
            UiObjectBase t     = null;

            while (true)
            {
                t = FindFirst(ui);
                if (t != null)
                {
                    return(t);
                }
                if (DateTime.Now - start < timeout)
                {
                    break;
                }
                Waiter.WaitOne(UITryInterval);
            }
            return(null);
        }
示例#3
0
        protected virtual UiObjectBase FindFirst(UiObjectBase uiParent, Queue <Expression> expressionQueue)
        {
            Queue <UiObjectBase> searchQueue = new Queue <UiObjectBase>();

            searchQueue.EnqueueRange(uiParent.Children);

            while (expressionQueue.Count > 0)
            {
                Expression expression = expressionQueue.Dequeue();
                while (searchQueue.Count > 0)
                {
                    UiObjectBase uiChild = searchQueue.Dequeue();
                    //Log.Default.Trace(uiChild.ToString());
                    bool isMatch = Expression.IsMatch(expression, (s) => uiChild.Properties.Contains(s), (s) => uiChild[s]);
                    if (isMatch)
                    {
                        if (expressionQueue.Count == 0)
                        {
                            return(uiChild);
                        }
                        else
                        {
                            //var result = FindFirst(uiChild, expressionQueue);
                            //if (result != null)
                            //{
                            //    return result;
                            //}
                            return(FindFirst(uiChild, expressionQueue));
                        }
                    }
                    else
                    {
                        searchQueue.EnqueueRange(uiChild.Children);
                    }
                }
            }
            return(null);
        }