#pragma warning disable CA1725 // Parameter names should match base declaration
        public void HandleTextEditTextChangedEvent(IUIAutomationElement sender, TextEditChangeType textEditChangeType, string[] eventStrings)
#pragma warning restore CA1725 // Parameter names should match base declaration
        {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
            var m = EventMessage.GetInstance(this.EventId, sender);

            if (m != null)
            {
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("TextEditChangeType", textEditChangeType.ToString()),
                };

                if (eventStrings != null)
                {
                    for (int i = 0; i < eventStrings.Length; i++)
                    {
                        m.Properties.Add(new KeyValuePair <string, dynamic>(Invariant($"[{i}]"), eventStrings.GetValue(i)));
                    }
                }

                this.ListenEventMessage(m);
            }
#pragma warning restore CA2000
        }
 public void HandleAutomationEvent(IUIAutomationElement sender, int eventId)
 {
     var m = EventMessage.GetInstance(eventId, sender);
     if (m != null)
     {
         this.ListenEventMessage(m);
     }
 }
        public void HandleChangesEvent(IUIAutomationElement sender, ref UiaChangeInfo uiaChanges, int changesCount)
        {
            var m = EventMessage.GetInstance(this.EventId, sender);

            if (m != null)
            {
                this.ListenEventMessage(m);
            }
        }
 public void HandleFocusChangedEvent(IUIAutomationElement sender)
 {
     if (ReadyToListen)
     {
         var m = EventMessage.GetInstance(EventType.UIA_AutomationFocusChangedEventId, sender);
         if (m != null)
         {
             ListenEventMessage(m);
         }
     }
 }
        public void HandleAutomationEvent(IUIAutomationElement sender, int eventId)
        {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
            var m = EventMessage.GetInstance(eventId, sender);
#pragma warning restore CA2000

            if (m != null)
            {
                this.ListenEventMessage(m);
            }
        }
        public void HandleChangesEvent(IUIAutomationElement sender, ref UiaChangeInfo uiaChanges, int changesCount)
        {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
            var m = EventMessage.GetInstance(this.EventId, sender);
#pragma warning restore CA2000

            if (m != null)
            {
                this.ListenEventMessage(m);
            }
        }
        public void HandleStructureChangedEvent(IUIAutomationElement sender, StructureChangeType changeType, int[] runtimeId)
        {
            var m = EventMessage.GetInstance(EventType.UIA_StructureChangedEventId, sender);

            if (m != null)
            {
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("StructureChangeType", changeType),
                    new KeyValuePair <string, dynamic>("Runtime Id", runtimeId.ConvertInt32ArrayToString()),
                };
                this.ListenEventMessage(m);
            }
        }
        public void HandleFocusChangedEvent(IUIAutomationElement sender)
        {
            if (ReadyToListen)
            {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
                var m = EventMessage.GetInstance(EventType.UIA_AutomationFocusChangedEventId, sender);
#pragma warning restore CA2000

                if (m != null)
                {
                    ListenEventMessage(m);
                }
            }
        }
        public void HandleActiveTextPositionChangedEvent(IUIAutomationElement sender, IUIAutomationTextRange range)
        {
            var m = EventMessage.GetInstance(this.EventId, sender);

            if (m != null)
            {
                const int maxTextLengthToInclude = 100;
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("Type", range.GetType()),
                    new KeyValuePair <string, dynamic>("Text", range.GetText(maxTextLengthToInclude))
                };

                this.ListenEventMessage(m);
            }
        }
        public void HandleNotificationEvent(IUIAutomationElement sender, NotificationKind kind, NotificationProcessing process, string displayString, string activityId)
        {
            var m = EventMessage.GetInstance(this.EventId, sender);

            if (m != null)
            {
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("NotificationKind", kind.ToString()),
                    new KeyValuePair <string, dynamic>("NotificationProcessing", process.ToString()),
                    new KeyValuePair <string, dynamic>("Display", displayString),
                    new KeyValuePair <string, dynamic>("ActivityId", activityId),
                };
                this.ListenEventMessage(m);
            }
        }
Exemple #11
0
        public void HandleTextEditTextChangedEvent(IUIAutomationElement sender, TextEditChangeType type, string[] array)
        {
            var m = EventMessage.GetInstance(this.EventId, sender);

            if (m != null)
            {
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("TextEditChangeType", type.ToString()),
                };
                for (int i = 0; i < array.Length; i++)
                {
                    m.Properties.Add(new KeyValuePair <string, dynamic>(Invariant($"[{i}]"), array.GetValue(i)));
                }
                ;

                this.ListenEventMessage(m);
            }
        }
        public void HandlePropertyChangedEvent(IUIAutomationElement sender, int propertyId, object newValue)
        {
            var m = EventMessage.GetInstance(this.EventId, sender);

            if (m != null)
            {
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("Property Id", propertyId),
                    new KeyValuePair <string, dynamic>("Property Name", PropertyType.GetInstance().GetNameById(propertyId)),
                };
                if (newValue != null)
                {
                    m.Properties.Add(new KeyValuePair <string, dynamic>(newValue.GetType().Name, newValue));
                }

                this.ListenEventMessage(m);
            }
        }
#pragma warning disable CA1725 // Parameter names should match base declaration
        public void HandleNotificationEvent(IUIAutomationElement sender, NotificationKind notificationKind, NotificationProcessing notificationProcessing, string displayString, string activityId)
#pragma warning restore CA1725 // Parameter names should match base declaration
        {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
            var m = EventMessage.GetInstance(this.EventId, sender);
#pragma warning restore CA2000

            if (m != null)
            {
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("NotificationKind", notificationKind.ToString()),
                    new KeyValuePair <string, dynamic>("NotificationProcessing", notificationProcessing.ToString()),
                    new KeyValuePair <string, dynamic>("Display", displayString),
                    new KeyValuePair <string, dynamic>("ActivityId", activityId),
                };
                this.ListenEventMessage(m);
            }
        }
        public void HandleActiveTextPositionChangedEvent(IUIAutomationElement sender, IUIAutomationTextRange range)
        {
            if (range == null)
            {
                return;
            }

#pragma warning disable CA2000 // Call IDisposable.Dispose()
            var m = EventMessage.GetInstance(this.EventId, sender);
#pragma warning restore CA2000

            if (m != null)
            {
                const int maxTextLengthToInclude = 100;
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("Type", range.GetType()),
                    new KeyValuePair <string, dynamic>("Text", range.GetText(maxTextLengthToInclude))
                };

                this.ListenEventMessage(m);
            }
        }
        public void HandleTextEditTextChangedEvent(IUIAutomationElement sender, TextEditChangeType type, string[] array)
        {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
            var m = EventMessage.GetInstance(this.EventId, sender);

            if (m != null)
            {
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("TextEditChangeType", type.ToString()),
                };

                if (array != null)
                {
                    for (int i = 0; i < array.Length; i++)
                    {
                        m.Properties.Add(new KeyValuePair <string, dynamic>(Invariant($"[{i}]"), array.GetValue(i)));
                    }
                }

                this.ListenEventMessage(m);
            }
#pragma warning restore CA2000
        }
        /// <summary>
        /// Process Register event message
        /// </summary>
        /// <param name="msgData"></param>
        private void RegisterEventListener(EventListenerFactoryMessage msgData)
        {
            try
            {
                EventMessage m = null;

                var win32Helper = new Win32Helper();

                switch (msgData.EventId)
                {
                case EventType.UIA_AutomationFocusChangedEventId:
                    if (this.EventListenerFocusChanged == null)
                    {
                        var uia = (IUIAutomation)UIAutomation8 ?? UIAutomation;
                        this.EventListenerFocusChanged = new FocusChangedEventListener(uia, msgData.Listener);
                    }
                    break;

                case EventType.UIA_StructureChangedEventId:
                    if (this.EventListenerStructureChanged == null)
                    {
                        this.EventListenerStructureChanged = new StructureChangedEventListener(this.UIAutomation, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                    }
                    break;

                case EventType.UIA_AutomationPropertyChangedEventId:
                    if (this.EventListenerPropertyChanged == null)
                    {
                        this.EventListenerPropertyChanged = new PropertyChangedEventListener(this.UIAutomation, this.RootElement.PlatformObject, this.Scope, msgData.Listener, msgData.Properties);
                    }
                    break;

                case EventType.UIA_TextEdit_TextChangedEventId:
                    if (this.EventListenerTextEditTextChanged == null)
                    {
                        this.EventListenerTextEditTextChanged = new TextEditTextChangedEventListener(this.UIAutomation8, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                    }
                    break;

                case EventType.UIA_ChangesEventId:
                    if (this.EventListenerChanges == null)
                    {
                        this.EventListenerChanges = new ChangesEventListener(this.UIAutomation8, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                    }
                    break;

                case EventType.UIA_NotificationEventId:
                    if (win32Helper.IsWindowsRS3OrLater())
                    {
                        if (this.EventListenerNotification == null)
                        {
                            this.EventListenerNotification = new NotificationEventListener(this.UIAutomation8, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                        }
                    }
                    else
                    {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
                        m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000

                        m.Properties = new List <KeyValuePair <string, dynamic> >()
                        {
                            new KeyValuePair <string, dynamic>("Message", "Event listener registration is rejected."),
                            new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                            new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                            new KeyValuePair <string, dynamic>("Reason", "Not supported platform"),
                        };
                        msgData.Listener(m);
                    }
                    break;

                case EventType.UIA_ActiveTextPositionChangedEventId:
                    if (win32Helper.IsWindowsRS5OrLater())
                    {
                        if (this.EventListenerNotification == null)
                        {
                            this.EventListenerActiveTextPositionChanged = new ActiveTextPositionChangedEventListener(this.UIAutomation8, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                        }
                    }
                    else
                    {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
                        m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000

                        m.Properties = new List <KeyValuePair <string, dynamic> >()
                        {
                            new KeyValuePair <string, dynamic>("Message", "Event listener registration is rejected."),
                            new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                            new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                            new KeyValuePair <string, dynamic>("Reason", "Not supported platform"),
                        };
                        msgData.Listener(m);
                    }
                    break;

                default:
                    if (this.EventListeners.ContainsKey(msgData.EventId) == false)
                    {
                        this.EventListeners.Add(msgData.EventId, new EventListener(this.UIAutomation, this.RootElement.PlatformObject, this.Scope, msgData.EventId, msgData.Listener));
                    }
                    break;
                }

#pragma warning disable CA2000 // Call IDisposable.Dispose()
                m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000

                m.Properties = new List <KeyValuePair <string, dynamic> >()
                {
                    new KeyValuePair <string, dynamic>("Message", "Succeeded to register an event listener"),
                    new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                    new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                };
                msgData.Listener(m);
                if (msgData.EventId == EventType.UIA_AutomationFocusChangedEventId)
                {
                    this.EventListenerFocusChanged.ReadyToListen = true;
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();

#pragma warning disable CA2000 // Call IDisposable.Dispose()
                var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000

                m.Properties = new List <KeyValuePair <string, dynamic> >()
                {
                    new KeyValuePair <string, dynamic>("Message", "Failed to register an event listener"),
                    new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                    new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                    new KeyValuePair <string, dynamic>("Error", e.Message)
                };
                msgData.Listener(m);
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }
        /// <summary>
        /// Process Unregister event message
        /// </summary>
        /// <param name="msgData"></param>
        private void UnregisterEventListener(EventListenerFactoryMessage msgData)
        {
            HandleUIAutomationEventMessage listener = null;

            try
            {
                switch (msgData.EventId)
                {
                case EventType.UIA_AutomationFocusChangedEventId:
                    if (this.EventListenerFocusChanged != null)
                    {
                        listener = this.EventListenerFocusChanged.ListenEventMessage;
                        this.EventListenerFocusChanged.Dispose();
                        this.EventListenerFocusChanged = null;
                    }
                    break;

                case EventType.UIA_StructureChangedEventId:
                    if (this.EventListenerStructureChanged != null)
                    {
                        listener = this.EventListenerStructureChanged.ListenEventMessage;
                        this.EventListenerStructureChanged.Dispose();
                        this.EventListenerStructureChanged = null;
                    }
                    break;

                case EventType.UIA_AutomationPropertyChangedEventId:
                    if (this.EventListenerPropertyChanged != null)
                    {
                        listener = this.EventListenerPropertyChanged.ListenEventMessage;
                        this.EventListenerPropertyChanged.Dispose();
                        this.EventListenerPropertyChanged = null;
                    }
                    break;

                case EventType.UIA_TextEdit_TextChangedEventId:
                    if (this.EventListenerTextEditTextChanged != null)
                    {
                        listener = this.EventListenerTextEditTextChanged.ListenEventMessage;
                        this.EventListenerTextEditTextChanged.Dispose();
                        this.EventListenerTextEditTextChanged = null;
                    }
                    break;

                case EventType.UIA_ChangesEventId:
                    if (this.EventListenerChanges != null)
                    {
                        listener = this.EventListenerChanges.ListenEventMessage;
                        this.EventListenerChanges.Dispose();
                        this.EventListenerChanges = null;
                    }
                    break;

                case EventType.UIA_NotificationEventId:
                    if (this.EventListenerNotification != null)
                    {
                        listener = this.EventListenerNotification.ListenEventMessage;
                        this.EventListenerNotification.Dispose();
                        this.EventListenerNotification = null;
                    }
                    break;

                case EventType.UIA_ActiveTextPositionChangedEventId:
                    if (this.EventListenerActiveTextPositionChanged != null)
                    {
                        listener = this.EventListenerActiveTextPositionChanged.ListenEventMessage;
                        this.EventListenerActiveTextPositionChanged.Dispose();
                        this.EventListenerActiveTextPositionChanged = null;
                    }
                    break;

                default:
                    if (this.EventListeners.ContainsKey(msgData.EventId))
                    {
                        var l = this.EventListeners[msgData.EventId];
                        listener = l.ListenEventMessage;
                        this.EventListeners.Remove(msgData.EventId);
                        l.Dispose();
                    }
                    break;
                }

                if (listener != null)
                {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
                    var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000

                    m.Properties = new List <KeyValuePair <string, dynamic> >()
                    {
                        new KeyValuePair <string, dynamic>("Message", "Succeeded to unregister a event listeners"),
                        new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                        new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                    };
                    listener(m);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();

#pragma warning disable CA2000 // Call IDisposable.Dispose()
                var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000

                m.Properties = new List <KeyValuePair <string, dynamic> >()
                {
                    new KeyValuePair <string, dynamic>("Message", "Failed to unregister a event listeners"),
                    new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                    new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                    new KeyValuePair <string, dynamic>("Error", e.Message)
                };

                listener(m);
                /// it is very unexpected situation.
                /// need to figure out a way to prevent it or handle it more gracefully
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }
        private void UnregisterAllEventListener()
        {
#pragma warning disable CA2000 // Call IDisposeable.Dispose()

            /// Need to find out a way to handle
            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_AutomationFocusChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_StructureChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_AutomationPropertyChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_NotificationEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_TextEdit_TextChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_ActiveTextPositionChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_ChangesEventId
            });
#pragma warning restore CA2000

            HandleUIAutomationEventMessage listener = null;
            try
            {
                foreach (var e in this.EventListeners.Values)
                {
                    listener = e.ListenEventMessage;
                    e.Dispose();
                }
                this.EventListeners.Clear();
                if (listener != null)
                {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
                    var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000

                    m.Properties = new List <KeyValuePair <string, dynamic> > {
                        new KeyValuePair <string, dynamic>("Message", "Succeeded to unregister all event listeners.")
                    };
                    listener(m);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();

#pragma warning disable CA2000 // Call IDisposable.Dispose()
                var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
#pragma warning restore CA2000

                m.Properties = new List <KeyValuePair <string, dynamic> > {
                    new KeyValuePair <string, dynamic>("Message", $"Failed to unregister all listeners: {e.Message}")
                };
                listener(m);
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }
Exemple #19
0
        private void UnregisterAllEventListener()
        {
            /// Need to find out a way to handle
            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_AutomationFocusChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_StructureChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_AutomationPropertyChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_NotificationEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_TextEdit_TextChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_ActiveTextPositionChangedEventId
            });

            UnregisterEventListener(new EventListenerFactoryMessage
            {
                EventId = EventType.UIA_ChangesEventId
            });

            HandleUIAutomationEventMessage listener = null;

            try
            {
                foreach (var e in this.EventListeners.Values)
                {
                    listener = e.ListenEventMessage;
                    e.Dispose();
                }
                this.EventListeners.Clear();
                if (listener != null)
                {
                    var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
                    m.Properties = new List <KeyValuePair <string, dynamic> >()
                    {
                        new KeyValuePair <string, dynamic>("Message", "Succeeded to unregister all event listeners.")
                    };
                    listener(m);
                }
            }
            catch (Exception e)
            {
                var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
                m.Properties = new List <KeyValuePair <string, dynamic> >()
                {
                    new KeyValuePair <string, dynamic>("Message", $"Failed to unregister all listeners: {e.Message}")
                };
                listener(m);
            }
        }
Exemple #20
0
        /// <summary>
        /// Process Register event message
        /// </summary>
        /// <param name="msgData"></param>
        private void RegisterEventListener(EventListenerFactoryMessage msgData)
        {
            try
            {
                EventMessage m = null;

                switch (msgData.EventId)
                {
                case EventType.UIA_AutomationFocusChangedEventId:
                    if (this.EventListenerFocusChanged == null)
                    {
                        this.EventListenerFocusChanged = new FocusChangedEventListener(this.UIAutomation, msgData.Listener);
                    }
                    break;

                case EventType.UIA_StructureChangedEventId:
                    if (this.EventListenerStructureChanged == null)
                    {
                        this.EventListenerStructureChanged = new StructureChangedEventListener(this.UIAutomation, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                    }
                    break;

                case EventType.UIA_AutomationPropertyChangedEventId:
                    if (this.EventListenerPropertyChanged == null)
                    {
                        this.EventListenerPropertyChanged = new PropertyChangedEventListener(this.UIAutomation, this.RootElement.PlatformObject, this.Scope, msgData.Listener, msgData.Properties);
                    }
                    break;

                case EventType.UIA_TextEdit_TextChangedEventId:
                    if (this.EventListenerTextEditTextChanged == null)
                    {
                        this.EventListenerTextEditTextChanged = new TextEditTextChangedEventListener(this.UIAutomation8, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                    }
                    break;

                case EventType.UIA_ChangesEventId:
                    if (this.EventListenerChanges == null)
                    {
                        this.EventListenerChanges = new ChangesEventListener(this.UIAutomation8, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                    }
                    break;

                case EventType.UIA_NotificationEventId:
                    if (NativeMethods.IsWindowsRS3OrLater())
                    {
                        if (this.EventListenerNotification == null)
                        {
                            this.EventListenerNotification = new NotificationEventListener(this.UIAutomation8, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                        }
                    }
                    else
                    {
                        m            = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
                        m.Properties = new List <KeyValuePair <string, dynamic> >()
                        {
                            new KeyValuePair <string, dynamic>("Message", "Event listener registration is rejected."),
                            new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                            new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                            new KeyValuePair <string, dynamic>("Reason", "Not supported platform"),
                        };
                        msgData.Listener(m);
                    }
                    break;

                case EventType.UIA_ActiveTextPositionChangedEventId:
                    if (NativeMethods.IsWindowsRS5OrLater())
                    {
                        if (this.EventListenerNotification == null)
                        {
                            this.EventListenerActiveTextPositionChanged = new ActiveTextPositionChangedEventListener(this.UIAutomation8, this.RootElement.PlatformObject, this.Scope, msgData.Listener);
                        }
                    }
                    else
                    {
                        m            = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
                        m.Properties = new List <KeyValuePair <string, dynamic> >()
                        {
                            new KeyValuePair <string, dynamic>("Message", "Event listener registration is rejected."),
                            new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                            new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                            new KeyValuePair <string, dynamic>("Reason", "Not supported platform"),
                        };
                        msgData.Listener(m);
                    }
                    break;

                default:
                    if (this.EventListeners.ContainsKey(msgData.EventId) == false)
                    {
                        this.EventListeners.Add(msgData.EventId, new EventListener(this.UIAutomation, this.RootElement.PlatformObject, this.Scope, msgData.EventId, msgData.Listener));
                    }
                    break;
                }

                m            = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
                m.Properties = new List <KeyValuePair <string, dynamic> >()
                {
                    new KeyValuePair <string, dynamic>("Message", "Succeeded to register an event listener"),
                    new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                    new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                };
                msgData.Listener(m);
                if (msgData.EventId == EventType.UIA_AutomationFocusChangedEventId)
                {
                    this.EventListenerFocusChanged.ReadyToListen = true;
                }
            }
            catch (Exception e)
            {
                var m = EventMessage.GetInstance(EventType.UIA_EventRecorderNotificationEventId, null);
                m.Properties = new List <KeyValuePair <string, dynamic> >()
                {
                    new KeyValuePair <string, dynamic>("Message", "Failed to register an event listener"),
                    new KeyValuePair <string, dynamic>("Event Id", msgData.EventId),
                    new KeyValuePair <string, dynamic>("Event Name", EventType.GetInstance().GetNameById(msgData.EventId)),
                    new KeyValuePair <string, dynamic>("Error", e.Message)
                };
                msgData.Listener(m);
            }
        }