Description of SearcherTemplateData.
Esempio n. 1
0
 public List<IUiElement> GetElements(SearcherTemplateData data, int timeout)
 {
     Timeout = timeout;
     SearcherData = data;
     var startTime = DateTime.Now;
     Wait = true;
     
     OnStartHook();
     
     // 20140125
     // AutomationFactory.InitNewCustomScope();
     
     do {
         // 20140125
         // AutomationFactory.InitNewCustomScope();
         
         BeforeSearchHook();
         ResultCollection = SearchForElements(data);
         AfterSearchHook();
         if (null != ResultCollection && 0 < ResultCollection.Count) break;
         Wait = ContinueSearch(Timeout, startTime);
         OnSleepHook();
         
     } while (Wait);
     
     OnFailureHook();
     OnSuccessHook();
     return ResultCollection;
 }
Esempio n. 2
0
        public List <IUiElement> GetElements(SearcherTemplateData data, int timeout)
        {
            Timeout      = timeout;
            SearcherData = data;
            var startTime = DateTime.Now;

            Wait = true;

            OnStartHook();

            // 20140125
            // AutomationFactory.InitNewCustomScope();

            do
            {
                // 20140125
                // AutomationFactory.InitNewCustomScope();

                BeforeSearchHook();
                ResultCollection = SearchForElements(data);
                AfterSearchHook();
                if (null != ResultCollection && 0 < ResultCollection.Count)
                {
                    break;
                }
                Wait = ContinueSearch(Timeout, startTime);
                OnSleepHook();
            } while (Wait);

            OnFailureHook();
            OnSuccessHook();
            return(ResultCollection);
        }
Esempio n. 3
0
        public override List <IUiElement> SearchForElements(SearcherTemplateData searchData)
        {
            #region search from the root
            ResultCollection.AddRange(
                UiElement.RootElement.FindAll(
                    classic.TreeScope.Children,
                    conditionsForContextMenuSearch).ToArray().ToList());
            #endregion search from the root

            #region search from the input
            if (null == ResultCollection || 0 == ResultCollection.Count)
            {
                ResultCollection.AddRange(
                    (searchData as ContextMenuSearcherData).InputObject.FindAll(
                        classic.TreeScope.Children,
                        conditionsForContextMenuSearch).ToArray().ToList());
            }
            #endregion search from the input

            #region search from the window
            if (null == ResultCollection || 0 == ResultCollection.Count)
            {
                if (null != CurrentData.CurrentWindow)
                {
                    ResultCollection.AddRange(
                        CurrentData.CurrentWindow.FindAll(
                            classic.TreeScope.Children,
                            conditionsForContextMenuSearch).ToArray().ToList());
                }
            }
            #endregion search from the window

            return(ResultCollection);
        }
Esempio n. 4
0
     public override List<IUiElement> SearchForElements(SearcherTemplateData searchData)
     {
         #region search from the root
         ResultCollection.AddRange(
             UiElement.RootElement.FindAll(
                 classic.TreeScope.Children,
                 conditionsForContextMenuSearch).ToArray().ToList());
         #endregion search from the root
         
         #region search from the input
         if (null == ResultCollection || 0 == ResultCollection.Count) {
             
             ResultCollection.AddRange(
                 (searchData as ContextMenuSearcherData).InputObject.FindAll(
                     classic.TreeScope.Children,
                     conditionsForContextMenuSearch).ToArray().ToList());
         }
         #endregion search from the input
         
         #region search from the window
         if (null == ResultCollection || 0 == ResultCollection.Count) {
             if (null != CurrentData.CurrentWindow) {
 
                 ResultCollection.AddRange(
                     CurrentData.CurrentWindow.FindAll(
                         classic.TreeScope.Children,
                         conditionsForContextMenuSearch).ToArray().ToList());
             }
         }
         #endregion search from the window
         
         return ResultCollection;
     }
Esempio n. 5
0
 public abstract List<IUiElement> SearchForElements(SearcherTemplateData data);
Esempio n. 6
0
 public override List<IUiElement> SearchForElements(SearcherTemplateData searchData)
 {
     if (null == ResultCollection) return new List<IUiElement>();
     if (null == searchData) return ResultCollection;
     
     var data = searchData as ControlSearcherData;
     
     if (null == data) return ResultCollection;
     if (null == data.InputObject) return ResultCollection;
     
     foreach (IUiElement inputObject in data.InputObject) {
         
         int processId = 0;
         
         #region checking processId
         if (inputObject != null &&
             // 20140312
             // (int)inputObject.Current.ProcessId > 0) {
             (int)inputObject.GetCurrent().ProcessId > 0) {
             
             // 20140312
             // processId = inputObject.Current.ProcessId;
             processId = inputObject.GetCurrent().ProcessId;
         }
         #endregion checking processId
         
         // 20130204
         // don't change the order! (text->exact->wildcard->win32 to win32->text->exact->wildcard)
         #region text search
         if (0 == ResultCollection.Count) {
             if (!notTextSearch && !data.Win32) {
                 
                 UsedSearchType = UsedSearchType.Control_TextSearch;
                 ResultCollection.AddRange(
                     SearchByContainsTextViaUia(
                         inputObject,
                         conditionsForTextSearch));
             }
         }
         #endregion text search
         
         #region text search Win32
         if (0 == ResultCollection.Count) {
             if (!notTextSearch && data.Win32) {
                 
                 UsedSearchType = UsedSearchType.Control_TextSearchWin32;
                 var controlFromWin32Provider = AutomationFactory.GetObject<ControlFromWin32Provider>();
                 controlFromWin32Provider.SearchData = data;
                 controlFromWin32Provider.HandleCollector = AutomationFactory.GetObject<HandleCollector>();
                 
                 ResultCollection.AddRange(
                     SearchByContainsTextViaWin32(
                         inputObject,
                         controlFromWin32Provider));
             }
         }
         #endregion text search Win32
         
         #region exact search
         if (0 == ResultCollection.Count && notTextSearch && !data.Regex) {
             if (!Preferences.DisableExactSearch && !data.Win32 ) {
                     
                     UsedSearchType = UsedSearchType.Control_ExactSearch;
                     ResultCollection.AddRange(
                         SearchByExactConditionsViaUia(
                             inputObject,
                             data.SearchCriteria,
                             conditionsForExactSearch));
             }
         }
         #endregion exact search
         
         #region wildcard search
         if (0 == ResultCollection.Count && notTextSearch && !data.Regex) {
             if (!Preferences.DisableWildCardSearch && !data.Win32) {
                     
                     UsedSearchType = UsedSearchType.Control_WildcardSearch;
                     ResultCollection.AddRange(
                         SearchByWildcardOrRegexViaUia(
                             inputObject,
                             data,
                             // 20140206
                             // UiElement.RootElement,
                             conditionsForWildCards,
                             true));
             }
         }
         #endregion wildcard search
         
         #region Regex search
         if (0 == ResultCollection.Count && notTextSearch && data.Regex) {
             if (!Preferences.DisableWildCardSearch && !data.Win32) {
                 
                 UsedSearchType = UsedSearchType.Control_RegexSearch;
                 ResultCollection.AddRange(
                     SearchByWildcardOrRegexViaUia(
                         inputObject,
                         data,
                         conditionsForWildCards,
                         false));
             }
         }
         #endregion Regex search
         
         #region Win32 search
         if (0 == ResultCollection.Count && notTextSearch && !data.Regex) {
             if (!Preferences.DisableWin32Search && data.Win32) {
                 
                 UsedSearchType = UsedSearchType.Control_Win32Search;
                 var handleCollector = AutomationFactory.GetObject<HandleCollector>();
                 
                 ResultCollection.AddRange(
                     SearchByWildcardViaWin32(
                         inputObject,
                         data,
                         handleCollector));
                 
             }
         } // FindWindowEx
         #endregion Win32 search                
     }
     
     return ResultCollection;
 }
Esempio n. 7
0
 public abstract List <IUiElement> SearchForElements(SearcherTemplateData data);
Esempio n. 8
0
        internal static List <IUiElement> ReturnOnlyRightElements(
            IEnumerable inputCollection,
            SearcherTemplateData searcherData,
            bool caseSensitive,
            bool viaWildcardOrRegex)
        {
            // ControlSearcherData data = searcherData as ControlSearcherData;
            var data = searcherData as ControlSearcherData;

            var  resultCollection          = new List <IUiElement>();
            bool requiresValuePatternCheck =
                !string.IsNullOrEmpty(data.Value);

            if (null == inputCollection)
            {
                return(resultCollection);
            }

            WildcardOptions options;

            if (caseSensitive)
            {
                options =
                    WildcardOptions.Compiled;
            }
            else
            {
                options =
                    WildcardOptions.IgnoreCase |
                    WildcardOptions.Compiled;
            }

            RegexOptions regexOptions = RegexOptions.Compiled;

            if (!caseSensitive)
            {
                regexOptions |= RegexOptions.IgnoreCase;
            }

            if (viaWildcardOrRegex)
            {
                data.Name         = string.IsNullOrEmpty(data.Name) ? "*" : data.Name;
                data.AutomationId = string.IsNullOrEmpty(data.AutomationId) ? "*" : data.AutomationId;
                data.Class        = string.IsNullOrEmpty(data.Class) ? "*" : data.Class;
                data.Value        = string.IsNullOrEmpty(data.Value) ? "*" : data.Value;
            }
            else
            {
                data.Name         = string.IsNullOrEmpty(data.Name) ? ".*" : data.Name;
                data.AutomationId = string.IsNullOrEmpty(data.AutomationId) ? ".*" : data.AutomationId;
                data.Class        = string.IsNullOrEmpty(data.Class) ? ".*" : data.Class;
                data.Value        = string.IsNullOrEmpty(data.Value) ? ".*" : data.Value;
            }

            var wildcardName =
                new WildcardPattern(data.Name, options);
            var wildcardAutomationId =
                new WildcardPattern(data.AutomationId, options);
            var wildcardClass =
                new WildcardPattern(data.Class, options);
            var wildcardValue =
                new WildcardPattern(data.Value, options);

            var inputList = inputCollection.Cast <IUiElement>().ToList();

            try {
                List <IUiElement> query;

                if (requiresValuePatternCheck)
                {
                    if (viaWildcardOrRegex)
                    {
                        query = inputList
                                .Where <IUiElement>(
                            item => (wildcardName.IsMatch(item.GetCurrent().Name) &&
                                     wildcardAutomationId.IsMatch(item.GetCurrent().AutomationId) &&
                                     wildcardClass.IsMatch(item.GetCurrent().ClassName) &&
                                     // check whether a control has or hasn't ValuePattern
                                     (item.GetSupportedPatterns().AsQueryable <IBasePattern>().Any(pattern => null != pattern && null != (pattern as IValuePattern)) ?
                                      item.CompareElementValueAndValueParameter(data.Value, true, wildcardValue, regexOptions) :
                                      // check whether the -Value parameter has or hasn't value
                                      ("*" == data.Value ? true : false)
                                     )
                                     )
                            )
                                .ToList <IUiElement>();
                    }
                    else
                    {
                        query = inputList
                                .Where <IUiElement>(
                            item => (Regex.IsMatch(item.GetCurrent().Name, data.Name, regexOptions) &&
                                     Regex.IsMatch(item.GetCurrent().AutomationId, data.AutomationId, regexOptions) &&
                                     Regex.IsMatch(item.GetCurrent().ClassName, data.Class, regexOptions) &&
                                     // check whether a control has or hasn't ValuePattern
                                     (item.GetSupportedPatterns().AsQueryable <IBasePattern>().Any(p => null != p && null != (p as IValuePattern)) ?
                                      item.CompareElementValueAndValueParameter(data.Value, false, null, regexOptions) :
                                      // check whether the -Value parameter has or hasn't value
                                      (".*" == data.Value ? true : false)
                                     )
                                     )
                            )
                                .ToList <IUiElement>();
                    }
                }
                else
                {
                    if (viaWildcardOrRegex)
                    {
                        query = inputList
                                .Where <IUiElement>(
                            item => (wildcardName.IsMatch(item.GetCurrent().Name) &&
                                     wildcardAutomationId.IsMatch(item.GetCurrent().AutomationId) &&
                                     wildcardClass.IsMatch(item.GetCurrent().ClassName)
                                     )
                            )
                                .ToList <IUiElement>();
                    }
                    else
                    {
                        query = inputList
                                .Where <IUiElement>(
                            item => (Regex.IsMatch(item.GetCurrent().Name, data.Name, regexOptions) &&
                                     Regex.IsMatch(item.GetCurrent().AutomationId, data.AutomationId, regexOptions) &&
                                     Regex.IsMatch(item.GetCurrent().ClassName, data.Class, regexOptions)
                                     )
                            )
                                .ToList <IUiElement>();
                    }
                }

                resultCollection.AddRange(query);
            }
            catch (Exception) {
                //                cmdlet.WriteVerbose(eProcessing.Message);
            }

            // 20140121
            //            if (null != inputList) {
            //                inputList.Clear();
            //                inputList = null;
            //            }

            // 20140131
//            foreach (IUiElement element in inputList) {
//                element.Dispose();
//            }

            // 20140121
            // inputCollection ??

            // 20140121
            wildcardName = wildcardAutomationId = wildcardClass = wildcardValue = null;

            return(resultCollection);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        public override List <IUiElement> SearchForElements(SearcherTemplateData searchData)
        {
            if (null == ResultCollection)
            {
                return(new List <IUiElement>());
            }
            if (null == searchData)
            {
                return(ResultCollection);
            }

            var data = searchData as ControlSearcherData;

            if (null == data)
            {
                return(ResultCollection);
            }
            if (null == data.InputObject)
            {
                return(ResultCollection);
            }

            foreach (IUiElement inputObject in data.InputObject)
            {
                int processId = 0;

                #region checking processId
                if (inputObject != null &&
                    // 20140312
                    // (int)inputObject.Current.ProcessId > 0) {
                    (int)inputObject.GetCurrent().ProcessId > 0)
                {
                    // 20140312
                    // processId = inputObject.Current.ProcessId;
                    processId = inputObject.GetCurrent().ProcessId;
                }
                #endregion checking processId

                // 20130204
                // don't change the order! (text->exact->wildcard->win32 to win32->text->exact->wildcard)
                #region text search
                if (0 == ResultCollection.Count)
                {
                    if (!notTextSearch && !data.Win32)
                    {
                        UsedSearchType = UsedSearchType.Control_TextSearch;
                        ResultCollection.AddRange(
                            SearchByContainsTextViaUia(
                                inputObject,
                                conditionsForTextSearch));
                    }
                }
                #endregion text search

                #region text search Win32
                if (0 == ResultCollection.Count)
                {
                    if (!notTextSearch && data.Win32)
                    {
                        UsedSearchType = UsedSearchType.Control_TextSearchWin32;
                        var controlFromWin32Provider = AutomationFactory.GetObject <ControlFromWin32Provider>();
                        controlFromWin32Provider.SearchData      = data;
                        controlFromWin32Provider.HandleCollector = AutomationFactory.GetObject <HandleCollector>();

                        ResultCollection.AddRange(
                            SearchByContainsTextViaWin32(
                                inputObject,
                                controlFromWin32Provider));
                    }
                }
                #endregion text search Win32

                #region exact search
                if (0 == ResultCollection.Count && notTextSearch && !data.Regex)
                {
                    if (!Preferences.DisableExactSearch && !data.Win32)
                    {
                        UsedSearchType = UsedSearchType.Control_ExactSearch;
                        ResultCollection.AddRange(
                            SearchByExactConditionsViaUia(
                                inputObject,
                                data.SearchCriteria,
                                conditionsForExactSearch));
                    }
                }
                #endregion exact search

                #region wildcard search
                if (0 == ResultCollection.Count && notTextSearch && !data.Regex)
                {
                    if (!Preferences.DisableWildCardSearch && !data.Win32)
                    {
                        UsedSearchType = UsedSearchType.Control_WildcardSearch;
                        ResultCollection.AddRange(
                            SearchByWildcardOrRegexViaUia(
                                inputObject,
                                data,
                                // 20140206
                                // UiElement.RootElement,
                                conditionsForWildCards,
                                true));
                    }
                }
                #endregion wildcard search

                #region Regex search
                if (0 == ResultCollection.Count && notTextSearch && data.Regex)
                {
                    if (!Preferences.DisableWildCardSearch && !data.Win32)
                    {
                        UsedSearchType = UsedSearchType.Control_RegexSearch;
                        ResultCollection.AddRange(
                            SearchByWildcardOrRegexViaUia(
                                inputObject,
                                data,
                                conditionsForWildCards,
                                false));
                    }
                }
                #endregion Regex search

                #region Win32 search
                if (0 == ResultCollection.Count && notTextSearch && !data.Regex)
                {
                    if (!Preferences.DisableWin32Search && data.Win32)
                    {
                        UsedSearchType = UsedSearchType.Control_Win32Search;
                        var handleCollector = AutomationFactory.GetObject <HandleCollector>();

                        ResultCollection.AddRange(
                            SearchByWildcardViaWin32(
                                inputObject,
                                data,
                                handleCollector));
                    }
                } // FindWindowEx
                #endregion Win32 search
            }

            return(ResultCollection);
        }
Esempio n. 11
0
        internal static List<IUiElement> ReturnOnlyRightElements(
            IEnumerable inputCollection,
            SearcherTemplateData searcherData,
            bool caseSensitive,
            bool viaWildcardOrRegex)
        {
            // ControlSearcherData data = searcherData as ControlSearcherData;
            var data = searcherData as ControlSearcherData;
            
            var resultCollection = new List<IUiElement>();
            bool requiresValuePatternCheck =
                !string.IsNullOrEmpty(data.Value);
            
            if (null == inputCollection) { return resultCollection; }
            
            WildcardOptions options;
            if (caseSensitive) {
                options =
                    WildcardOptions.Compiled;
            } else {
                options =
                    WildcardOptions.IgnoreCase |
                    WildcardOptions.Compiled;
            }
            
            RegexOptions regexOptions = RegexOptions.Compiled;
            if (!caseSensitive) {
                regexOptions |= RegexOptions.IgnoreCase;
            }
            
            if (viaWildcardOrRegex) {
                data.Name = string.IsNullOrEmpty(data.Name) ? "*" : data.Name;
                data.AutomationId = string.IsNullOrEmpty(data.AutomationId) ? "*" : data.AutomationId;
                data.Class = string.IsNullOrEmpty(data.Class) ? "*" : data.Class;
                data.Value = string.IsNullOrEmpty(data.Value) ? "*" : data.Value;
            } else {
                data.Name = string.IsNullOrEmpty(data.Name) ? ".*" : data.Name;
                data.AutomationId = string.IsNullOrEmpty(data.AutomationId) ? ".*" : data.AutomationId;
                data.Class = string.IsNullOrEmpty(data.Class) ? ".*" : data.Class;
                data.Value = string.IsNullOrEmpty(data.Value) ? ".*" : data.Value;
            }
            
            var wildcardName =
                new WildcardPattern(data.Name, options);
            var wildcardAutomationId =
                new WildcardPattern(data.AutomationId, options);
            var wildcardClass =
                new WildcardPattern(data.Class, options);
            var wildcardValue =
                new WildcardPattern(data.Value, options);
            
            var inputList = inputCollection.Cast<IUiElement>().ToList();
            
            try {
                
                List<IUiElement> query;
                
                if (requiresValuePatternCheck) {
                    
                    if (viaWildcardOrRegex) {
                        
                        query = inputList
                            .Where<IUiElement>(
                                item => (wildcardName.IsMatch(item.GetCurrent().Name) &&
                                         wildcardAutomationId.IsMatch(item.GetCurrent().AutomationId) &&
                                         wildcardClass.IsMatch(item.GetCurrent().ClassName) &&
                                         // check whether a control has or hasn't ValuePattern
                                         (item.GetSupportedPatterns().AsQueryable<IBasePattern>().Any(pattern => null != pattern && null != (pattern as IValuePattern)) ?
                                          item.CompareElementValueAndValueParameter(data.Value, true, wildcardValue, regexOptions) :
                                          // check whether the -Value parameter has or hasn't value
                                          ("*" == data.Value ? true : false)
                                         )
                                        )
                               )
                            .ToList<IUiElement>();
                    } else {
                        
                        query = inputList
                            .Where<IUiElement>(
                                item => (Regex.IsMatch(item.GetCurrent().Name, data.Name, regexOptions) &&
                                         Regex.IsMatch(item.GetCurrent().AutomationId, data.AutomationId, regexOptions) &&
                                         Regex.IsMatch(item.GetCurrent().ClassName, data.Class, regexOptions) &&
                                         // check whether a control has or hasn't ValuePattern
                                         (item.GetSupportedPatterns().AsQueryable<IBasePattern>().Any(p => null != p && null != (p as IValuePattern)) ?
                                          item.CompareElementValueAndValueParameter(data.Value, false, null, regexOptions) :
                                          // check whether the -Value parameter has or hasn't value
                                          (".*" == data.Value ? true : false)
                                         )
                                        )
                               )
                            .ToList<IUiElement>();
                    }
                    
                } else {
                    
                    if (viaWildcardOrRegex) {
                            
                        query = inputList
                            .Where<IUiElement>(
                                item => (wildcardName.IsMatch(item.GetCurrent().Name) &&
                                         wildcardAutomationId.IsMatch(item.GetCurrent().AutomationId) &&
                                         wildcardClass.IsMatch(item.GetCurrent().ClassName)
                                        )
                               )
                            .ToList<IUiElement>();
                    } else {
                        query = inputList
                            .Where<IUiElement>(
                                item => (Regex.IsMatch(item.GetCurrent().Name, data.Name, regexOptions) &&
                                         Regex.IsMatch(item.GetCurrent().AutomationId, data.AutomationId, regexOptions) &&
                                         Regex.IsMatch(item.GetCurrent().ClassName, data.Class, regexOptions)
                                        )
                               )
                            .ToList<IUiElement>();
                    }
                    
                }
                
                resultCollection.AddRange(query);
            }
            catch (Exception) {
                //                cmdlet.WriteVerbose(eProcessing.Message);
            }
            
            // 20140121
            //            if (null != inputList) {
            //                inputList.Clear();
            //                inputList = null;
            //            }
            
            // 20140131
//            foreach (IUiElement element in inputList) {
//                element.Dispose();
//            }
            
            // 20140121
            // inputCollection ??
            
            // 20140121
            wildcardName = wildcardAutomationId = wildcardClass = wildcardValue = null;
            
            return resultCollection;
        }
Esempio n. 12
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;
        }