/// <summary> /// This method creates children nodes. /// </summary> private void CreateChildrenNodes(bool beAwareOfExisting) { //join flags together beAwareOfExisting |= this._newChildElementInserted; System.Diagnostics.Debug.WriteLine("CreateChildrenNodes ENTER"); AutomationElement element = null; //set waiting cursor for this block using (new Misc.WaitCursor()) { //here we store all new child nodes LinkedList <TreeNode> childNodes = new LinkedList <TreeNode>(); // Do FirstChild System.Diagnostics.Debug.WriteLine("CreateChildrenNodes, Getting firstChild"); try { element = AutomationElementTreeControl.TreeWalker.GetFirstChild(this.AutomationElement); Trace.WriteLine("GetChildren(start)" + "".PadRight(80, '-')); while (null != element) { childNodes.AddLast(CreateTreeNodeForAutomationElement(element)); // Do NextSibling element = AutomationElementTreeControl.TreeWalker.GetNextSibling(element); } this._errorInPopulatingChildren = false; Trace.WriteLine("GetChildren(end)" + "".PadRight(80, '-')); } catch (ElementNotAvailableException) { this._errorInPopulatingChildren = true; Debug.WriteLine("\n\nGetting children automation elements FAILED. Element not available.\n\n"); } catch (ThreadAbortException) { this._errorInPopulatingChildren = true; Debug.WriteLine("\n\nGetting children automation elements FAILED\n\n"); } catch (Exception ex) { Debug.Fail(ex.Message, ex.StackTrace); throw; } //add new children to collection; we can call clear when there is no element inserted before AddChildrenNodesToTreeNode(childNodes, !beAwareOfExisting, false); this._childrenStatus = ChildrenElementsStatus.Populated; this._newChildElementInserted = false; //we merged new children and child nodes inserted before //set image to this currentTestTypeRootNode SetTreeNodeImageIndex(); } System.Diagnostics.Debug.WriteLine("CreateChildrenNodes EXIT"); }
/// <summary> /// This method will refresh children nodes /// </summary> public void RefreshChildrenNodes() { using (SynchronizationManager.Lock()) { if (this._childrenStatus != ChildrenElementsStatus.NotPopulated) { this._childrenStatus = ChildrenElementsStatus.NotPopulated; SetTreeNodeImageIndex(); CreateChildrenNodes(true); } } }
/// <summary> /// This method creates children nodes. /// </summary> private void CreateChildrenNodes(bool beAwareOfExisting) { //join flags together beAwareOfExisting |= this._newChildElementInserted; System.Diagnostics.Debug.WriteLine("CreateChildrenNodes ENTER"); AutomationElement element = null; //set waiting cursor for this block using (new Misc.WaitCursor()) { //here we store all new child nodes LinkedList<TreeNode> childNodes = new LinkedList<TreeNode>(); // Do FirstChild System.Diagnostics.Debug.WriteLine("CreateChildrenNodes, Getting firstChild"); try { element = AutomationElementTreeControl.TreeWalker.GetFirstChild(this.AutomationElement); Trace.WriteLine("GetChildren(start)" + "".PadRight(80, '-')); while (null != element) { childNodes.AddLast(CreateTreeNodeForAutomationElement(element)); // Do NextSibling element = AutomationElementTreeControl.TreeWalker.GetNextSibling(element); } this._errorInPopulatingChildren = false; Trace.WriteLine("GetChildren(end)" + "".PadRight(80, '-')); } catch (ElementNotAvailableException) { this._errorInPopulatingChildren = true; Debug.WriteLine("\n\nGetting children automation elements FAILED. Element not available.\n\n"); } catch (ThreadAbortException) { this._errorInPopulatingChildren = true; Debug.WriteLine("\n\nGetting children automation elements FAILED\n\n"); } catch (Exception ex) { Debug.Fail(ex.Message, ex.StackTrace); throw; } //add new children to collection; we can call clear when there is no element inserted before AddChildrenNodesToTreeNode(childNodes, !beAwareOfExisting, false); this._childrenStatus = ChildrenElementsStatus.Populated; this._newChildElementInserted = false; //we merged new children and child nodes inserted before //set image to this currentTestTypeRootNode SetTreeNodeImageIndex(); } System.Diagnostics.Debug.WriteLine("CreateChildrenNodes EXIT"); }