public UiEltCollection(IUiEltCollection elements) { foreach (IUiElement element in elements.Cast <IUiElement>().Where(element => null != element)) { _collectionHolder.Add(element); } }
public UiEltCollection(IUiEltCollection elements) { foreach (IUiElement element in elements.Cast<IUiElement>().Where(element => null != element)) { _collectionHolder.Add(element); } }
internal static List <IUiElement> SearchByContainsTextViaUia( IUiElement inputObject, classic.Condition conditionsForTextSearch) { IUiEltCollection textSearchCollection = inputObject.FindAll(classic.TreeScope.Descendants, conditionsForTextSearch); return(textSearchCollection.Cast <IUiElement>().ToList()); }
// 20140215 // public static IEnumerable GetElementsByWildcard(this IUiEltCollection collection, string name, string automationId, string className, string txtValue, bool caseSensitive = false) public static IEnumerable GetElementsByWildcard(this IUiEltCollection collection, string name, string automationId, string className, string txtValue, bool caseSensitive) { WildcardOptions options; if (caseSensitive) { options = WildcardOptions.Compiled; } else { options = WildcardOptions.IgnoreCase | WildcardOptions.Compiled; } List <IUiElement> list = collection.Cast <IUiElement>().ToList(); var wildcardName = new WildcardPattern((string.IsNullOrEmpty(name) ? "*" : name), options); var wildcardAutomationId = new WildcardPattern((string.IsNullOrEmpty(automationId) ? "*" : automationId), options); var wildcardClassName = new WildcardPattern((string.IsNullOrEmpty(className) ? "*" : className), options); var wildcardValue = new WildcardPattern((string.IsNullOrEmpty(txtValue) ? "*" : txtValue), options); var queryByBigFour = from collectionItem in list // 20140312 // where wildcardName.IsMatch(collectionItem.Current.Name) && // wildcardAutomationId.IsMatch(collectionItem.Current.AutomationId) && // wildcardClassName.IsMatch(collectionItem.Current.ClassName) && where wildcardName.IsMatch(collectionItem.GetCurrent().Name) && wildcardAutomationId.IsMatch(collectionItem.GetCurrent().AutomationId) && wildcardClassName.IsMatch(collectionItem.GetCurrent().ClassName) && // 20131209 // (collectionItem.GetSupportedPatterns().Contains(classic.ValuePattern.Pattern) ? (collectionItem.GetSupportedPatterns().AsQueryable <IBasePattern>().Any <IBasePattern>(p => p is IValuePattern) ? // 20131208 // wildcardValue.IsMatch((collectionItem.GetCurrentPattern(classic.ValuePattern.Pattern) as IValuePattern).Current.Value) : // wildcardValue.IsMatch((collectionItem.GetCurrentPattern<IValuePattern, ValuePattern>(classic.ValuePattern.Pattern) as IValuePattern).Current.Value) : wildcardValue.IsMatch(collectionItem.GetCurrentPattern <IValuePattern>(classic.ValuePattern.Pattern).Current.Value) : // check whether the -Value parameter has or hasn't value ("*" == txtValue ? true : false)) select collectionItem; // disposal list = null; return(queryByBigFour); }
public IUiElement[] GetSelection() { // 20140302 // AutomationElement[] nativeElements = (AutomationElement[])this._selectionPattern.GetParentElement().GetPatternPropertyValue(SelectionPattern.SelectionProperty, this._useCache); var nativeElements = (classic.AutomationElement[])_selectionPattern.GetParentElement().GetPatternPropertyValue(classic.SelectionPattern.SelectionProperty, _useCache); IUiEltCollection tempCollection = AutomationFactory.GetUiEltCollection(nativeElements); if (null == tempCollection || 0 == tempCollection.Count) { return(new UiElement[] {}); } else { return(tempCollection.Cast <IUiElement>().ToArray <IUiElement>()); } }
public IUiElement[] GetColumnHeaderItems() { // return (AutomationElement[])this._el.GetPatternPropertyValue(TableItemPattern.ColumnHeaderItemsProperty, this._useCache); // 20140302 // AutomationElement[] nativeElements = (AutomationElement[])this._tableItemPattern.GetParentElement().GetPatternPropertyValue(TableItemPattern.ColumnHeaderItemsProperty, this._useCache); var nativeElements = (classic.AutomationElement[])_tableItemPattern.GetParentElement().GetPatternPropertyValue(classic.TableItemPattern.ColumnHeaderItemsProperty, _useCache); IUiEltCollection tempCollection = AutomationFactory.GetUiEltCollection(nativeElements); if (null == tempCollection || 0 == tempCollection.Count) { return(new UiElement[] {}); } else { return(tempCollection.Cast <IUiElement>().ToArray()); } }
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); }
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; } } }