I need to get the list of chat conversation from the Skype UI Automation tree.
The Automation tree is shown below:
So, in the automation ui tree above, the tree nodes that ends with "nodes" are the conversations along with few system messages/texts. I need to get the list of these.
My Code to extract the list of conversation:
AutomationElement parentAutomationElement= AutomationElement.FromHandle(skypeHandle);
var firstChild = TreeWalker.ControlViewWalker.GetFirstChild(parentAutomationElement); //AE of node -> "Skype Preview"
var firstGrandChild = TreeWalker.ControlViewWalker.GetFirstChild(firstChild); //AE of first child of above node. (3rd node in picture)
//info : the reason behind to extract the firstGrandChild was to be able to query the children of long automation element list.
//querying descendent from the first or second node is time consuming as each node can further have sub elements.
var chats = firstGrandChild.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "pane"));
Automation Element properties for one of the chat conversations:
Now the problem is, it usually takes around 2-4 seconds to extract these conversations. The conversation list count range is from 1 to 90(as per observation).
I have a timer which extracts these conversation list in the interval of 5 seconds, I would like to be able to decrease the timer to 2-3 seconds to frequently monitor the change in conversation but to do so, I must be able to extract the conversation list within 1 sec duration.
Questions:
- Any proper, fast and effective way to do so?
- I am thinking if I could get the last conversation within few milliseconds, I could cache it and always compare if the last text has changed before extracting the list of conversation. This way, I can reduce the workload of extracting the conversation again and again if there is no new conversation at all. Although, I have devised the solution, it took me about 3.6 seconds on average (for conversation list count : 89). So, again the same issue as above.
Code to extract last conversation message:
var expressionAe = firstGrandChild.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Open Expression picker"));
var lastChatAe = TreeWalker.ControlViewWalker.GetPreviousSibling(expressionAe);
var lastChatText = lastChatAe.Current.Name;