GetAutomationElementsViaWildcards_FindAll() private method

private GetAutomationElementsViaWildcards_FindAll ( ControlSearcherData data, IUiElement inputObject, UIANET::System.Windows.Automation conditions, bool caseSensitive, bool onlyOneResult, bool onlyTopLevel, bool viaWildcardOrRegex ) : List
data ControlSearcherData
inputObject IUiElement
conditions UIANET::System.Windows.Automation
caseSensitive bool
onlyOneResult bool
onlyTopLevel bool
viaWildcardOrRegex bool
return List
Esempio n. 1
0
        internal void SearchByWildcardViaUIA(
            //GetControlCmdletBase cmdlet,
            //T cmdlet,
            //CommonCmdletBase cmdlet,
            //HasTimeoutCmdletBase cmdlet,
            GetCmdletBase cmdlet,
            ref ArrayList resultCollection,
            AutomationElement inputObject,
            string name,
            string automationId,
            string className,
            string strValue,
            System.Windows.Automation.AndCondition conditionsForWildCards)
        {
            this.WriteVerbose((cmdlet as PSTestLib.PSCmdletBase), "[getting the control] using WildCard search");
            try {
            //                string cmdletValue = string.Empty;
            //                try {
            //                    cmdletValue = cmdlet.Value;
            //                }
            //                catch {}
                // 20130220
                GetControlCollectionCmdletBase cmdlet1 =
                    new GetControlCollectionCmdletBase(
                        //cmdlet.InputObject,
                        null != cmdlet.InputObject ? cmdlet.InputObject : (new AutomationElement[]{ AutomationElement.RootElement }),
                        //null,
                        name, //cmdlet.Name,
                        automationId, //cmdlet.AutomationId,
                        className, //cmdlet.Class,
                        //cmdlet.Value,
                        //string.Empty != cmdlet.Value ? cmdlet.Value : null,
                        strValue,
                        (new string[] {}),
                        this.caseSensitive);
                try {
                    this.WriteVerbose((cmdlet as PSTestLib.PSCmdletBase), "using the GetAutomationElementsViaWildcards_FindAll method");

                    ArrayList tempList =
                        cmdlet1.GetAutomationElementsViaWildcards_FindAll(
                            cmdlet1,
                            inputObject,
                            conditionsForWildCards,
                            cmdlet1.CaseSensitive,
                            false,
                            false);

                    cmdlet.WriteVerbose(
                        cmdlet,
                        "there are " +
                        tempList.Count.ToString() +
                        " elements that match the conditions");

                    foreach (AutomationElement tempElement2 in tempList) {

                        if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {

                            resultCollection.Add(tempElement2);
                            cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (no SearchCriteria)");
                        } else {

                            cmdlet.WriteVerbose(cmdlet, "WildCardSearch: checking search criteria");
                            if (testControlWithAllSearchCriteria(cmdlet, cmdlet.SearchCriteria, tempElement2)) {

                                cmdlet.WriteVerbose(cmdlet, "WildCardSearch: the control matches the search criteria");
                                resultCollection.Add(tempElement2);
                                cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (SearchCriteria)");
                            }
                            // cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (SearchCriteria) (2)");
                        }
                        // cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element added to the result collection (SearchCriteria) (3)");
                    }
                    cmdlet.WriteVerbose(cmdlet, "WildCardSearch: element(s) added to the result collection: " + resultCollection.Count.ToString());
                } catch (Exception eUnexpected) {
                    // this.WriteVerbose(this, eUnexpected.Message);
                    this.WriteError(
                        this,
                        "The input control or window has been possibly lost." +
                        eUnexpected.Message,
                        "UnexpectedError",
                        ErrorCategory.ObjectNotFound,
                        true);
                }
            } catch (Exception eWildCardSearch) {
                this.WriteError(
                    cmdlet,
                    "The input control or window has been possibly lost." +
                    eWildCardSearch.Message,
                    "UnexpectedError",
                    ErrorCategory.ObjectNotFound,
                    true);
            }
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
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);
            }
        }