internal void FilterResultCollectionByWithControlParameter() { var filteredWindows = new List <IUiElement>(); bool exitInnerCycle; foreach (IUiElement window in ResultCollection) { if (!window.IsValid()) { continue; } var ControlSearcherData = new ControlSearcherData { InputObject = new UiElement[] { (UiElement)window } }; exitInnerCycle = false; bool addToResultCollection = false; foreach (Hashtable ht in (SearcherData as WindowSearcherData).WithControl) { ControlSearcherData.SearchCriteria = new Hashtable[] { ht }; try { var controlSearch = AutomationFactory.GetSearcherImpl <ControlSearcher>() as ControlSearcher; List <IUiElement> controlsList = controlSearch.GetElements(ControlSearcherData, 0); if (null == controlsList || 0 == controlsList.Count) { exitInnerCycle = true; addToResultCollection = false; continue; } else { addToResultCollection = true; break; } } catch (Exception) { // forcing to a next loop ResultCollection.Clear(); break; } } ControlSearcherData = null; if (addToResultCollection) { filteredWindows.Add(window); } } ResultCollection = filteredWindows; }
internal static IUiElement InvokeContextMenu(this IUiElement inputObject, HasControlInputCmdletBase cmdlet, int x, int y) { IUiElement resultElement = null; try { if (!cmdlet.ClickControl( cmdlet, inputObject, new ClickSettings() { RightClick = true, RelativeX = (x < 0 ? Preferences.ClickOnControlByCoordX : x), RelativeY = (y < 0 ? Preferences.ClickOnControlByCoordY : y) })) { } } catch (Exception) { throw new Exception("failed to click on the control"); } // 20140116 // what are these x and y? // int x = Cursor.Position.X; // int y = Cursor.Position.Y; var contextMenuSearcher = AutomationFactory.GetSearcherImpl <ContextMenuSearcher>(); var contextMenuSearcherData = new ContextMenuSearcherData { InputObject = inputObject, ProcessId = inputObject.GetCurrent().ProcessId }; var elementsMenuRoot = contextMenuSearcher.GetElements( contextMenuSearcherData, Preferences.Timeout); resultElement = elementsMenuRoot.First(element => null != element); return(resultElement); }
internal static IUiEltCollection PerformFindAll(this IExtendedModelHolder holder, classic.ControlType controlType) { try { var controlSearcherData = new ControlSearcherData { ControlType = controlType.ConvertControlTypeToStringArray(), InputObject = new IUiElement[] { holder.GetParentElement() } }; var controlSearcher = AutomationFactory.GetSearcherImpl <ControlSearcher>(); return(AutomationFactory.GetUiEltCollection( controlSearcher.GetElements( controlSearcherData, holder.Seconds))); } catch (Exception) { return(new UiEltCollection(true)); } }
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; } } }