public void AddAutomationEventHandler (AutomationEvent eventId,
IElement element,
TreeScope scope,
AutomationEventHandler eventHandler)
{
if (element == null) {
//the element is the RootElement
// TODO clean up registered handlers when they're removed
int handlerId = eventHandlerManager.RegisterAutomationEventHandler (eventHandler);
RootElementEventsManager.AddAutomationEventRequest (eventId.Id, scope, handlerId);
foreach (var entry in GetUiaApplications ()) {
string busName = entry.Key;
var app = entry.Value;
EnsureAutomationEventsSetUp (app, busName);
app.AddRootElementAutomationEventHandler (eventId.Id, scope, handlerId);
}
} else {
UiaDbusElement uiaDbusElement = element as UiaDbusElement;
if (uiaDbusElement == null) {
Log.Error ("[AddAutomationEventHandler] The element sent to UiaDbusSource is not UiaDbusElement");
return;
}
string busName = uiaDbusElement.BusName;
DCI.IApplication app = Bus.Session.GetObject<DCI.IApplication> (busName,
new ObjectPath (DC.Constants.ApplicationPath));
int [] runtimeId = uiaDbusElement.RuntimeId;
int handlerId = eventHandlerManager.RegisterAutomationEventHandler (eventHandler);
EnsureAutomationEventsSetUp (app, busName);
app.AddAutomationEventHandler (eventId.Id, runtimeId, scope, handlerId);
}
}