Esempio n. 1
0
        internal static classic.OrCondition GetOrCondition(List <classic.PropertyCondition> propertyCollection)
        {
            if (null == propertyCollection)
            {
                return(null);
            }
            var resultCondition = new UIANET::System.Windows.Automation.OrCondition(propertyCollection.ToArray());

            return(resultCondition);
        }
Esempio n. 2
0
        internal static classic.Condition GetTextSearchCondition(string searchString, string[] controlTypeNames, bool caseSensitive1)
        {
            if (string.IsNullOrEmpty(searchString))
            {
                return(null);
            }

            classic.PropertyConditionFlags flags =
                caseSensitive1 ? classic.PropertyConditionFlags.None : classic.PropertyConditionFlags.IgnoreCase;

            var searchStringOrCondition =
                new classic.OrCondition(
                    new classic.PropertyCondition(
                        classic.AutomationElement.AutomationIdProperty,
                        searchString,
                        flags),
                    new classic.PropertyCondition(
                        classic.AutomationElement.NameProperty,
                        searchString,
                        flags),
                    new classic.PropertyCondition(
                        classic.AutomationElement.ClassNameProperty,
                        searchString,
                        flags),
                    new classic.PropertyCondition(
                        classic.ValuePattern.ValueProperty,
                        searchString,
                        flags));

            if (null == controlTypeNames || 0 == controlTypeNames.Length)
            {
                return(searchStringOrCondition);
            }

            classic.Condition controlTypeCondition =
                GetControlTypeCondition(controlTypeNames);

            if (null == controlTypeCondition)
            {
                return(searchStringOrCondition);
            }

            var resultCondition =
                new classic.AndCondition(
                    new classic.Condition[] {
                searchStringOrCondition,
                controlTypeCondition
            });

            return(resultCondition);
        }
Esempio n. 3
0
 internal static classic.Condition GetTextSearchCondition(string searchString, string[] controlTypeNames, bool caseSensitive1)
 {
     if (string.IsNullOrEmpty(searchString)) return null;
     
     classic.PropertyConditionFlags flags =
         caseSensitive1 ? classic.PropertyConditionFlags.None : classic.PropertyConditionFlags.IgnoreCase;
     
     var searchStringOrCondition =
         new classic.OrCondition(
             new classic.PropertyCondition(
                 classic.AutomationElement.AutomationIdProperty,
                 searchString,
                 flags),
             new classic.PropertyCondition(
                 classic.AutomationElement.NameProperty,
                 searchString,
                 flags),
             new classic.PropertyCondition(
                 classic.AutomationElement.ClassNameProperty,
                 searchString,
                 flags),
             new classic.PropertyCondition(
                 classic.ValuePattern.ValueProperty,
                 searchString,
                 flags));
     
     if (null == controlTypeNames || 0 == controlTypeNames.Length) return searchStringOrCondition;
     
     classic.Condition controlTypeCondition =
         GetControlTypeCondition(controlTypeNames);
     
     if (null == controlTypeCondition) return searchStringOrCondition;
     
     var resultCondition =
         new classic.AndCondition(
             new classic.Condition[] {
                 searchStringOrCondition,
                 controlTypeCondition
             });
     
     return resultCondition;
 }
Esempio n. 4
0
 internal static classic.OrCondition GetOrCondition(List<classic.PropertyCondition> propertyCollection)
 {
     if (null == propertyCollection) return null;
     var resultCondition = new UIANET::System.Windows.Automation.OrCondition(propertyCollection.ToArray());
     return resultCondition;
 }
Esempio n. 5
0
        internal List <IUiElement> GetWindowCollectionByPid(
            IUiElement rootElement,
            WindowSearcherData data)
        {
            classic.AndCondition conditionsForRecurseSearch = null;

            var elementsByProcessId =
                new List <IUiElement>();

            // 20141001
            // if ((null != data.Name && 0 < data.Name.Count()) ||
            if ((null != data.Name && data.Name.Any()) ||
                !string.IsNullOrEmpty(data.AutomationId) ||
                !string.IsNullOrEmpty(data.Class))
            {
                data.Recurse = true;
            }

            var conditionWindowPaneMenu =
                new classic.OrCondition(
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Window),
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Pane),
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Menu));

            foreach (int processId in data.ProcessIds)
            {
                conditionsForRecurseSearch =
                    new classic.AndCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ProcessIdProperty,
                            processId),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window));

                var conditionsProcessId =
                    new classic.AndCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ProcessIdProperty,
                            processId),
                        conditionWindowPaneMenu);

                try {
                    if (data.Recurse)
                    {
                        if (data.First)
                        {
                            IUiElement rootWindowElement =
                                rootElement.FindFirst(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != rootWindowElement)
                            {
                                elementsByProcessId.Add(rootWindowElement);
                            }
                        }
                        else
                        {
                            IUiEltCollection rootCollection =
                                rootElement.FindAll(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != rootCollection && 0 < rootCollection.Count)
                            {
                                elementsByProcessId.AddRange(rootCollection.Cast <IUiElement>());
                            }
                        }
                    }
                    else
                    {
                        if (data.First)
                        {
                            IUiElement tempElement =
                                rootElement.FindFirst(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != tempElement)
                            {
                                elementsByProcessId.Add(tempElement);
                            }
                        }
                        else
                        {
                            IUiEltCollection tempCollection =
                                rootElement.FindAll(
                                    classic.TreeScope.Children,
                                    conditionsProcessId);

                            if (null != tempCollection && 0 < tempCollection.Count)
                            {
                                elementsByProcessId.AddRange(tempCollection.Cast <IUiElement>());
                            }
                        }
                    }
                } catch (Exception) {
                    // WriteVerbose(
                    //     this,
                    //     "exception: " +
                    //     eGetFirstChildOfRootByProcessId.Message);
                }
            }

            if (!data.Recurse ||
                // 20141001
                // ((null == data.Name || 0 == data.Name.Count()) && string.IsNullOrEmpty(data.AutomationId) &&
                ((null == data.Name || !data.Name.Any()) && string.IsNullOrEmpty(data.AutomationId) &&
                 string.IsNullOrEmpty(data.Class)))
            {
                return(elementsByProcessId);
            }

            var resultList =
                new List <IUiElement>();

            /*
             * List<IUiElement> resultList =
             *  new List<IUiElement>();
             */

            // 20141001
            // if (null != data.Name && 0 < data.Name.Count()) {
            if (null != data.Name && data.Name.Any())
            {
                foreach (string name in data.Name)
                {
                    var controlSearcherData =
                        new ControlSearcherData {
                        Name         = name,
                        AutomationId = data.AutomationId,
                        Class        = data.Class,
                        Value        = string.Empty,
                        ControlType  = new string[] { "Window" }
                    };

                    resultList.AddRange(
                        ReturnOnlyRightElements(
                            elementsByProcessId,
                            controlSearcherData,
                            false,
                            true));
                }
            }
            else
            {
                var controlSearcherData =
                    new ControlSearcherData {
                    Name         = string.Empty,
                    AutomationId = data.AutomationId,
                    Class        = data.Class,
                    Value        = string.Empty,
                    ControlType  = new string[] { "Window" }
                };

                resultList.AddRange(
                    ReturnOnlyRightElements(
                        elementsByProcessId,
                        controlSearcherData,
                        false,
                        true));
            }

            elementsByProcessId = resultList;

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

            return(elementsByProcessId);
        }
Esempio n. 6
0
        List <IUiElement> GetWindowCollectionByName(
            IUiElement rootElement,
            WindowSearcherData data)
        {
            var windowCollectionByProperties =
                new List <IUiElement>();
            var resultCollection =
                new List <IUiElement>();

            if (null == data.Name)
            {
                // 20141001
                // data.Name = new string[]{ string.Empty };
                data.Name = new [] { string.Empty };
            }

            classic.OrCondition conditionsSet = null;
            if (data.Recurse)
            {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        classic.Condition.FalseCondition);
            }
            else
            {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Pane),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Menu));
            }

            foreach (string windowTitle in data.Name)
            {
                IUiEltCollection windowCollection =
                    rootElement.FindAll(data.Recurse ? classic.TreeScope.Descendants : classic.TreeScope.Children, conditionsSet);

                var controlSearcherData =
                    new ControlSearcherData {
                    Name         = windowTitle,
                    AutomationId = data.AutomationId,
                    Class        = data.Class,
                    Value        = string.Empty,
                    // 20141001
                    // ControlType = (new string[]{ "Window", "Pane", "Menu" })
                    ControlType = (new [] { "Window", "Pane", "Menu" })
                };

                windowCollectionByProperties =
                    ReturnOnlyRightElements(
                        windowCollection,
                        controlSearcherData,
                        false,
                        true);

                try {
                    if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count)
                    {
                        foreach (IUiElement aeWndByTitle in windowCollectionByProperties
                                 .Where(aeWndByTitle => aeWndByTitle != null && (int)aeWndByTitle.GetCurrent().ProcessId > 0))
                        {
                            resultCollection.Add(aeWndByTitle);
                        }

                        windowCollectionByProperties.Clear();
                    }
                    else
                    {
                        IUiElement tempElement = null;

                        // one more attempt using the FindWindow function
                        IntPtr wndHandle = NativeMethods.FindWindowByCaption(IntPtr.Zero, windowTitle);
                        // 20141001
                        // if (wndHandle != null && wndHandle != IntPtr.Zero) {
                        if (wndHandle != IntPtr.Zero)
                        {
                            tempElement =
                                UiElement.FromHandle(wndHandle);
                        }

                        if (null == tempElement || (int)tempElement.GetCurrent().ProcessId <= 0)
                        {
                            continue;
                        }

                        resultCollection.Add(tempElement);
                    }
                }
                catch {}

                // 20140122
                // AutomationFactory.DisposeChildKernel();

                // 20140131
//                if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count) {
//                    foreach (IUiElement element in windowCollectionByProperties) {
//                        element.Dispose();
//                    }
//                }
//                if (null != windowCollection && 0 < windowCollection.Count) {
//                    foreach (IUiElement element in windowCollection) {
//                        element.Dispose();
//                    }
//                }
            }

            return(resultCollection);
        }
Esempio n. 7
0
 internal List<IUiElement> GetWindowCollectionByPid(
     IUiElement rootElement,
     WindowSearcherData data)
 {
     classic.AndCondition conditionsForRecurseSearch = null;
     
     var elementsByProcessId =
         new List<IUiElement>();
     
     // 20141001
     // if ((null != data.Name && 0 < data.Name.Count()) ||
     if ((null != data.Name && data.Name.Any()) ||
         !string.IsNullOrEmpty(data.AutomationId) ||
         !string.IsNullOrEmpty(data.Class)) {
         
         data.Recurse = true;
     }
     
     var conditionWindowPaneMenu =
         new classic.OrCondition(
             new classic.PropertyCondition(
                 classic.AutomationElement.ControlTypeProperty,
                 classic.ControlType.Window),
             new classic.PropertyCondition(
                 classic.AutomationElement.ControlTypeProperty,
                 classic.ControlType.Pane),
             new classic.PropertyCondition(
                 classic.AutomationElement.ControlTypeProperty,
                 classic.ControlType.Menu));
     
     foreach (int processId in data.ProcessIds) {
         
         conditionsForRecurseSearch =
             new classic.AndCondition(
                 new classic.PropertyCondition(
                     classic.AutomationElement.ProcessIdProperty,
                     processId),
                 new classic.PropertyCondition(
                     classic.AutomationElement.ControlTypeProperty,
                     classic.ControlType.Window));
             
         var conditionsProcessId =
             new classic.AndCondition(
                 new classic.PropertyCondition(
                     classic.AutomationElement.ProcessIdProperty,
                     processId),
                 conditionWindowPaneMenu);
         
         try {
             
             if (data.Recurse) {
                 if (data.First) {
                     
                     IUiElement rootWindowElement =
                         rootElement.FindFirst(
                             classic.TreeScope.Children,
                             conditionsProcessId);
                     
                     if (null != rootWindowElement) {
                         elementsByProcessId.Add(rootWindowElement);
                     }
                     
                 } else {
                     
                     IUiEltCollection rootCollection =
                         rootElement.FindAll(
                             classic.TreeScope.Children,
                             conditionsProcessId);
                     
                     if (null != rootCollection && 0 < rootCollection.Count)
                     {
                         elementsByProcessId.AddRange(rootCollection.Cast<IUiElement>());
                     }
                 }
                 
             } else {
                 
                 if (data.First) {
                     
                     IUiElement tempElement =
                         rootElement.FindFirst(
                             classic.TreeScope.Children,
                             conditionsProcessId);
                     
                     if (null != tempElement) {
                         
                         elementsByProcessId.Add(tempElement);
                     }
                 } else {
                     
                     IUiEltCollection tempCollection =
                         rootElement.FindAll(
                             classic.TreeScope.Children,
                             conditionsProcessId);
                     
                     if (null != tempCollection && 0 < tempCollection.Count) {
                         
                         elementsByProcessId.AddRange(tempCollection.Cast<IUiElement>());
                     }
                 }
             }
         } catch (Exception) {
             
             // WriteVerbose(
             //     this,
             //     "exception: " +
             //     eGetFirstChildOfRootByProcessId.Message);
         }
     }
     
     if (!data.Recurse ||
         // 20141001
         // ((null == data.Name || 0 == data.Name.Count()) && string.IsNullOrEmpty(data.AutomationId) &&
         ((null == data.Name || !data.Name.Any()) && string.IsNullOrEmpty(data.AutomationId) &&
          string.IsNullOrEmpty(data.Class))) return elementsByProcessId;
     
     var resultList =
         new List<IUiElement>();
     /*
     List<IUiElement> resultList =
         new List<IUiElement>();
     */
     
     // 20141001
     // if (null != data.Name && 0 < data.Name.Count()) {
     if (null != data.Name && data.Name.Any()) {
         foreach (string name in data.Name) {
             
             var controlSearcherData =
                 new ControlSearcherData {
                 Name = name,
                 AutomationId = data.AutomationId,
                 Class = data.Class,
                 Value = string.Empty,
                 ControlType = new string[]{ "Window" } 
             };
             
             resultList.AddRange(
                 ReturnOnlyRightElements(
                     elementsByProcessId,
                     controlSearcherData,
                     false,
                     true));
             
         }
     } else {
         
         var controlSearcherData =
             new ControlSearcherData {
             Name = string.Empty,
             AutomationId = data.AutomationId,
             Class = data.Class,
             Value = string.Empty,
             ControlType = new string[]{ "Window" } 
         };
         
         resultList.AddRange(
             ReturnOnlyRightElements(
                 elementsByProcessId,
                 controlSearcherData,
                 false,
                 true));
     }
     
     elementsByProcessId = resultList;
     
     // 20140121
     // never !
     //            if (null != resultList) {
     //                resultList.Clear();
     //                resultList = null;
     //            }
     
     return elementsByProcessId;
 }
Esempio n. 8
0
        List<IUiElement> GetWindowCollectionByName(
            IUiElement rootElement,
            WindowSearcherData data)
        {
            var windowCollectionByProperties =
                new List<IUiElement>();
            var resultCollection =
                new List<IUiElement>();
            
            if (null == data.Name) {
                // 20141001
                // data.Name = new string[]{ string.Empty };
                data.Name = new []{ string.Empty };
            }
            
            classic.OrCondition conditionsSet = null;
            if (data.Recurse) {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        classic.Condition.FalseCondition);
            } else {
                conditionsSet =
                    new classic.OrCondition(
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Window),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Pane),
                        new classic.PropertyCondition(
                            classic.AutomationElement.ControlTypeProperty,
                            classic.ControlType.Menu));
            }
            
            foreach (string windowTitle in data.Name) {
                
                IUiEltCollection windowCollection =
                    rootElement.FindAll(data.Recurse ? classic.TreeScope.Descendants : classic.TreeScope.Children, conditionsSet);
                
                var controlSearcherData =
                    new ControlSearcherData {
                    Name = windowTitle,
                    AutomationId = data.AutomationId,
                    Class = data.Class,
                    Value = string.Empty,
                    // 20141001
                    // ControlType = (new string[]{ "Window", "Pane", "Menu" })
                    ControlType = (new []{ "Window", "Pane", "Menu" })
                };
                
                windowCollectionByProperties =
                    ReturnOnlyRightElements(
                        windowCollection,
                        controlSearcherData,
                        false,
                        true);
                    
                try {
                    
                    if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count) {
                        
                        foreach (IUiElement aeWndByTitle in windowCollectionByProperties
                            .Where(aeWndByTitle => aeWndByTitle != null && (int)aeWndByTitle.GetCurrent().ProcessId > 0))
                        {
                            resultCollection.Add(aeWndByTitle);
                        }
                        
                        windowCollectionByProperties.Clear();
                        
                    } else {
                        
                        IUiElement tempElement = null;
                        
                        // one more attempt using the FindWindow function
                        IntPtr wndHandle = NativeMethods.FindWindowByCaption(IntPtr.Zero, windowTitle);
                        // 20141001
                        // if (wndHandle != null && wndHandle != IntPtr.Zero) {
                        if (wndHandle != IntPtr.Zero) {
                            tempElement =
                                UiElement.FromHandle(wndHandle);
                        }
                        
                        if (null == tempElement || (int) tempElement.GetCurrent().ProcessId <= 0) continue;
                        
                        resultCollection.Add(tempElement);
                    }
                }
                catch {}
                
                // 20140122
                // AutomationFactory.DisposeChildKernel();
                
                // 20140131
//                if (null != windowCollectionByProperties && 0 < windowCollectionByProperties.Count) {
//                    foreach (IUiElement element in windowCollectionByProperties) {
//                        element.Dispose();
//                    }
//                }
//                if (null != windowCollection && 0 < windowCollection.Count) {
//                    foreach (IUiElement element in windowCollection) {
//                        element.Dispose();
//                    }
//                }
            }
            
            return resultCollection;
        }