Ejemplo n.º 1
0
        public override List <IUiElement> SearchForElements(SearcherTemplateData searchData)
        {
            // 20140208
            if (Preferences.CacheRequestCalled && null != CurrentData.CacheRequest)
            {
                try {
                    Preferences.FromCache = false;
                    // CurrentData.CacheRequest.Pop();
                    ClonedCacheRequest = null;
                }
                catch (Exception) {
//Console.WriteLine("failed to stop the cache request");
//Console.WriteLine(eeeee.Message);
                }
            }
            else
            {
                if (null == CurrentData.CacheRequest)
                {
//Console.WriteLine("cache request is null");
                }
            }

            try {
                var data = searchData as WindowSearcherData;
                // WindowSearcherData data = searchData as WindowSearcherData;

                AutomationFactory.InitializeChildKernel();

                if (data.Win32)
                {
                    if (null == ResultCollection || 0 == ResultCollection.Count)
                    {
                        ResultCollection = GetWindowCollectionViaWin32(data);
                    }
                }
                else if (null != data.InputObject && data.InputObject.Length > 0)
                {
                    if (null == ResultCollection || 0 == ResultCollection.Count)
                    {
                        ResultCollection = GetWindowCollectionFromProcess(data);
                    }
                }
                else if (null != data.ProcessIds && data.ProcessIds.Length > 0)
                {
                    if (null == ResultCollection || 0 == ResultCollection.Count)
                    {
                        ResultCollection = GetWindowCollectionByPid(UiElement.RootElement, data);
                    }
                }
                else if (null != data.ProcessNames && data.ProcessNames.Length > 0)
                {
                    if (null == ResultCollection || 0 == ResultCollection.Count)
                    {
                        // 20141001
                        // ResultCollection = GetWindowCollectionByProcessName(UiElement.RootElement, data);
                        ResultCollection = GetWindowCollectionByProcessName(data);
                    }
                }
                else if ((null != data.Name && data.Name.Length > 0) ||
                         !string.IsNullOrEmpty(data.AutomationId) ||
                         !string.IsNullOrEmpty(data.Class))
                {
                    if (null == ResultCollection || 0 == ResultCollection.Count)
                    {
                        ResultCollection = GetWindowCollectionByName(UiElement.RootElement, data);
                    }
                }

                if (null == ResultCollection || 0 == ResultCollection.Count)
                {
                    AutomationFactory.ChildKernel.Release(ResultCollection);
                }
            } catch (Exception) {
                //
                // throw;
            }

            return(ResultCollection);
        }