示例#1
0
        public override void OnStartHook()
        {
            UsedSearchType = UsedSearchType.None;

            var data = SearcherData as ControlSearcherData;

            #region conditions
            notTextSearch = true;
            if (!string.IsNullOrEmpty(data.ContainsText) && !data.Regex)
            {
                notTextSearch = false;

                conditionsForTextSearch =
                    GetTextSearchCondition(
                        data.ContainsText,
                        data.ControlType,
                        data.CaseSensitive);
            }
            else
            {
                conditionsForExactSearch = GetExactSearchCondition(data);

                conditionsForWildCards =
                    GetWildcardSearchCondition(data);
            }
            #endregion conditions

            ResultCollection = new List <IUiElement>();
        }
示例#2
0
 public override void OnStartHook()
 {
     UsedSearchType = UsedSearchType.None;
     
     var data = SearcherData as ControlSearcherData;
     
     #region conditions
     notTextSearch = true;
     if (!string.IsNullOrEmpty(data.ContainsText) && !data.Regex) {
         
         notTextSearch = false;
         
         conditionsForTextSearch =
             GetTextSearchCondition(
                 data.ContainsText,
                 data.ControlType,
                 data.CaseSensitive);
         
     } else {
         
         conditionsForExactSearch = GetExactSearchCondition(data);
         
         conditionsForWildCards =
             GetWildcardSearchCondition(data);
     }
     #endregion conditions
     
     ResultCollection = new List<IUiElement>();            
 }
示例#3
0
        internal static List <IUiElement> SearchByContainsTextViaUia(
            IUiElement inputObject,
            classic.Condition conditionsForTextSearch)
        {
            IUiEltCollection textSearchCollection = inputObject.FindAll(classic.TreeScope.Descendants, conditionsForTextSearch);

            return(textSearchCollection.Cast <IUiElement>().ToList());
        }
示例#4
0
 internal static classic.Condition GetWildcardSearchCondition(ControlSearcherData data)
 {
     classic.Condition controlTypeCondition = classic.Condition.TrueCondition;
     if (null == data.ControlType || 0 == data.ControlType.Length)
     {
         return(controlTypeCondition);
     }
     controlTypeCondition =
         GetControlTypeCondition(
             data.ControlType);
     return(controlTypeCondition);
 }
示例#5
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);
        }
示例#6
0
        public override void OnStartHook()
        {
            var data = SearcherData as ContextMenuSearcherData;

            conditionsForContextMenuSearch =
                new classic.AndCondition(
                    new classic.PropertyCondition(
                        classic.AutomationElement.ProcessIdProperty,
                        data.ProcessId),
                    new classic.PropertyCondition(
                        classic.AutomationElement.ControlTypeProperty,
                        classic.ControlType.Menu));

            ResultCollection = new List <IUiElement>();
        }
示例#7
0
 public override void OnStartHook()
 {
     var data = SearcherData as ContextMenuSearcherData;
     
     conditionsForContextMenuSearch =
         new classic.AndCondition(
             new classic.PropertyCondition(
                 classic.AutomationElement.ProcessIdProperty,
                 data.ProcessId),
             new classic.PropertyCondition(
                 classic.AutomationElement.ControlTypeProperty,
                 classic.ControlType.Menu));
     
     ResultCollection = new List<IUiElement>();
 }
        // 20130127
//        [UiaParameterNotUsed][Parameter(Mandatory = false)]
//        public SwitchParameter CaseSensitive { get; set; }
        #endregion Parameters

        // not used
//        protected void GetAutomationElementsViaWildcards_FindAll(
//            IUiElement inputObject,
//            classic.AndCondition conditions,
//            bool caseSensitive,
//            bool onlyOneResult,
//            bool onlyTopLevel,
//            bool viaWildcardOrRegex)
//        {
//            if (!CheckAndPrepareInput(this)) { return; }
//
//            var controlSearcherData =
//                new ControlSearcherData {
//                Name = this.Name,
//                AutomationId = this.AutomationId,
//                Class = this.Class,
//                Value = this.Value,
//                ControlType = this.ControlType
//            };
//
//            GetAutomationElementsWithFindAll(
//                inputObject,
//                controlSearcherData,
//                conditions,
//                caseSensitive,
//                onlyOneResult,
//                onlyTopLevel,
//                viaWildcardOrRegex);
//        }

        internal List <IUiElement> GetAutomationElementsViaWildcards_FindAll(
            ControlSearcherData data,
            IUiElement inputObject,
            classic.Condition conditions,
            bool caseSensitive,
            bool onlyOneResult,
            bool onlyTopLevel,
            bool viaWildcardOrRegex)
        {
            var resultCollection = new List <IUiElement>(); // ? make it null ??

            resultCollection =
                GetAutomationElementsWithFindAll(
                    inputObject,
                    data,
                    conditions,
                    caseSensitive,
                    onlyOneResult,
                    onlyTopLevel,
                    viaWildcardOrRegex);

            return(resultCollection);
        }
示例#9
0
        internal static List <IUiElement> SearchByExactConditionsViaUia(
            IUiElement inputObject,
            Hashtable[] searchCriteria,
            classic.Condition conditions)
        {
            if (conditions == null)
            {
                return(new List <IUiElement>());
            }

            if (inputObject == null || (int)inputObject.GetCurrent().ProcessId <= 0)
            {
                return(new List <IUiElement>());
            }

            IUiEltCollection tempCollection = inputObject.FindAll(classic.TreeScope.Descendants, conditions);

            if (null == searchCriteria || 0 == searchCriteria.Length)
            {
                return(tempCollection.ToArray().ToList <IUiElement>());
            }

            return(tempCollection.ToArray().Where(element => TestControlWithAllSearchCriteria(searchCriteria, element)).ToList <IUiElement>());
        }
        internal List <IUiElement> GetAutomationElementsWithFindAll(
            IUiElement element,
            ControlSearcherData data,
            classic.Condition conditions,
            bool caseSensitiveParam,
            bool onlyOneResult,
            bool onlyTopLevel,
            bool viaWildcardOrRegex)
        {
            var resultCollection = new List <IUiElement>();

            try {
                IUiEltCollection results =
                    element.FindAll(
                        classic.TreeScope.Descendants,
                        conditions);

                resultCollection =
                    WindowSearcher.ReturnOnlyRightElements(
                        results,
                        data,
                        caseSensitiveParam,
                        viaWildcardOrRegex);

                if (null != results)
                {
                    // results.Dispose(); // taboo!
                    results = null;
                }
                // results = null;
            }
            catch { //(Exception eWildCardSearch) {
            }

            return(resultCollection);
        }
示例#11
0
        internal static classic.Condition GetExactSearchCondition(ControlSearcherData data)
        {
            classic.PropertyConditionFlags flags =
                data.CaseSensitive ? classic.PropertyConditionFlags.None : classic.PropertyConditionFlags.IgnoreCase;

            classic.Condition controlTypeCondition = classic.Condition.TrueCondition;
            if (null != data.ControlType && 0 < data.ControlType.Length)
            {
                controlTypeCondition =
                    GetControlTypeCondition(
                        data.ControlType);
            }

            var propertyCollection =
                new List <classic.PropertyCondition>();

            if (!string.IsNullOrEmpty(data.Name))
            {
                propertyCollection.Add(
                    new classic.PropertyCondition(
                        classic.AutomationElement.NameProperty,
                        data.Name));
            }
            if (!string.IsNullOrEmpty(data.AutomationId))
            {
                propertyCollection.Add(
                    new classic.PropertyCondition(
                        classic.AutomationElement.AutomationIdProperty,
                        data.AutomationId));
            }
            if (!string.IsNullOrEmpty(data.Class))
            {
                propertyCollection.Add(
                    new classic.PropertyCondition(
                        classic.AutomationElement.ClassNameProperty,
                        data.Class));
            }
            if (!string.IsNullOrEmpty(data.Value))
            {
                propertyCollection.Add(
                    new classic.PropertyCondition(
                        classic.ValuePattern.ValueProperty,
                        data.Value));
            }

            classic.Condition propertyCondition =
                0 == propertyCollection.Count ? null : (
                    1 == propertyCollection.Count ? propertyCollection[0] : (classic.Condition)GetAndCondition(propertyCollection)
                    );

            if (null == propertyCondition)
            {
                return(controlTypeCondition);
            }
            else
            {
                return(null == controlTypeCondition ? propertyCondition : new classic.AndCondition(
                           new classic.Condition[] {
                    propertyCondition,
                    controlTypeCondition
                }));
            }
        }
示例#12
0
        internal static List <IUiElement> SearchByWildcardOrRegexViaUia(
            IUiElement inputObject,
            ControlSearcherData data,
            classic.Condition conditionsForWildCards,
            bool viaWildcardOrRegex)
        {
            var resultCollection =
                new List <IUiElement>();

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

            try {
                var controlSearcherData =
                    new ControlSearcherData {
                    InputObject   = data.InputObject ?? (new UiElement[] { (UiElement)UiElement.RootElement }),
                    Name          = data.Name,
                    AutomationId  = data.AutomationId,
                    Class         = data.Class,
                    Value         = data.Value,
                    ControlType   = null != data.ControlType && 0 < data.ControlType.Length ? data.ControlType : (new string[] {}),
                    CaseSensitive = caseSensitive
                };

                var cmdlet1 = new GetControlCollectionCmdletBase(controlSearcherData);

                try {
                    List <IUiElement> tempList =
                        cmdlet1.GetAutomationElementsViaWildcards_FindAll(
                            controlSearcherData,
                            inputObject,
                            conditionsForWildCards,
                            cmdlet1.CaseSensitive,
                            false,
                            false,
                            viaWildcardOrRegex);

                    if (null == data.SearchCriteria || 0 == data.SearchCriteria.Length)
                    {
                        resultCollection.AddRange(tempList);
                    }
                    else
                    {
                        foreach (IUiElement tempElement2 in tempList.Where(elt => TestControlWithAllSearchCriteria(data.SearchCriteria, elt)))
                        {
                            resultCollection.Add(tempElement2);
                        }
                    }

                    if (null != tempList)
                    {
                        tempList.Clear();
                        tempList = null;
                    }

                    return(resultCollection);
                } catch (Exception eUnexpected) {
                    (new GetControlCmdletBase()).WriteError(
                        new GetControlCmdletBase(),
                        "The input control or window has been possibly lost." +
                        eUnexpected.Message,
                        "UnexpectedError",
                        ErrorCategory.ObjectNotFound,
                        true);
                }

                cmdlet1 = null;

                return(resultCollection);
            } catch (Exception eWildCardSearch) {
                (new GetControlCmdletBase()).WriteError(
                    new GetControlCmdletBase(),
                    "The input control or window has been possibly lost." +
                    eWildCardSearch.Message,
                    "UnexpectedError",
                    ErrorCategory.ObjectNotFound,
                    true);

                return(resultCollection);
            }
        }
        protected void GetAutomationElements(classic.TreeScope scope)
        {
            if (!CheckAndPrepareInput(this))
            {
                return;
            }

            foreach (IUiElement inputObject in InputObject)
            {
                var searchResults =
                    new List <IUiElement>();

                if (scope == classic.TreeScope.Children ||
                    scope == classic.TreeScope.Descendants)
                {
                    // WriteVerbose(this, "selected TreeScope." + scope.ToString());

                    var controlSearch =
                        AutomationFactory.GetSearcherImpl <ControlSearcher>() as ControlSearcher;

                    classic.Condition conditions =
                        ControlSearcher.GetWildcardSearchCondition(
                            controlSearch.ConvertCmdletToControlSearcherData(this));

                    IUiEltCollection temporaryResults = null;
                    if (conditions != null)
                    {
                        temporaryResults =
                            inputObject.FindAll(
                                scope,
                                conditions);

                        searchResults.AddRange(temporaryResults.Cast <IUiElement>());
                    }
                    else
                    {
                        // WriteVerbose(this, "no conditions. Performing search with TrueCondition");
                        temporaryResults =
                            inputObject.FindAll(
                                scope,
                                classic.Condition.TrueCondition);
                        if (temporaryResults.Count > 0)
                        {
//                            WriteVerbose(this,
//                                         "returned " +
//                                         temporaryResults.Count.ToString() +
//                                         " results");
                            searchResults.AddRange(temporaryResults.Cast <IUiElement>());
                        }
                    }
                    // WriteVerbose(this, "results found: " + searchResults.Count.ToString());
                    WriteObject(this, searchResults.ToArray());
                }

                if (null != searchResults)
                {
                    searchResults.Clear();
                    searchResults = null;
                }

                if (scope != classic.TreeScope.Parent && scope != classic.TreeScope.Ancestors)
                {
                    continue;
                }

                IUiElement[] outResult = inputObject.GetParentOrAncestor(scope);
                WriteObject(this, outResult);

                if (null != outResult)
                {
                    outResult = null;
                }
            }
        }