public virtual IUiElement FindFirst(classic.TreeScope scope, UIANET.System.Windows.Automation.Condition condition) { switch (_innerElementType) { case InnerElementTypes.AutomationElementNet: return(AutomationFactory.GetUiElement(_elementHolderNet.FindFirst(scope, condition))); // case InnerElementTypes.AutomationElementCom: // // case InnerElementTypes.UiElement: return(_elementHolderAdapter.FindFirst(scope, condition)); default: return(AutomationFactory.GetUiElement(_elementHolderNet.FindFirst(scope, condition))); } }
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); }
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; }