Esempio n. 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="config"></param>
 /// <param name="ec"></param>
 /// <param name="listener"></param>
 private ListenAction(ListenScope listenScope, ElementContext ec, HandleUIAutomationEventMessage listener)
 {
     this.Id               = Guid.NewGuid();
     this.ElementContext   = ec;
     this.EventListener    = new EventListenerFactory(ec.Element, listenScope);
     this.ExternalListener = listener;
 }
 public FocusChangedEventListener(CUIAutomation uia, HandleUIAutomationEventMessage peDelegate)
 {
     this.UIAutomation       = uia;
     this.ListenEventMessage = peDelegate;
     this.UIAutomation.AddFocusChangedEventHandler(null, this);
     IsHooked = true;
 }
Esempio n. 3
0
        /// <summary>
        /// Create new Instance of ListenAction
        /// </summary>
        /// <param name="config"></param>
        /// <param name="ecId"></param>
        /// <param name="listener"></param>
        /// <returns></returns>
        public static Guid CreateInstance(ListenScope listenScope, Guid ecId, HandleUIAutomationEventMessage listener)
        {
            var ec = DataManager.GetDefaultInstance().GetElementContext(ecId);
            var la = new ListenAction(listenScope, ec, listener);

            sListenActions.Add(la.Id, la);

            return(la.Id);
        }
Esempio n. 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="config"></param>
 /// <param name="ec"></param>
 /// <param name="listener"></param>
 private ListenAction(RecorderSetting config, ElementContext ec, HandleUIAutomationEventMessage listener)
 {
     this.Id               = Guid.NewGuid();
     this.Config           = config;
     this.ElementContext   = ec;
     this.EventListener    = new EventListenerFactory(ec.Element, config.ListenScope);
     this.EventRecords     = new List <IA11yEventMessage>();
     this.ExternalListener = listener;
 }
Esempio n. 5
0
 /// <summary>
 /// Register a single event listener
 /// in case of property listening, since it is monolithic, you need to stop existing property listener first.
 /// the implicit cleanup is not defined.
 /// </summary>
 /// <param name="eventId"></param>
 /// <param name="peDelegate"></param>
 /// <param name="properties">required only for PropertyChanged Event listening</param>
 public void RegisterAutomationEventListener(int eventId, HandleUIAutomationEventMessage peDelegate, int[] properties = null)
 {
     AddMessageToQueue(new EventListenerFactoryMessage()
     {
         MessageType = EventListenerFactoryMessageType.RegisterEventListener,
         Listener    = peDelegate,
         EventId     = eventId,
         Properties  = properties
     });
 }
        /// <summary>
        /// Register a single event listener
        /// in case of property listening, since it is monolithic, you need to stop existing property listener first.
        /// the implicit cleanup is not defined.
        /// </summary>
        /// <param name="eventId"></param>
        /// <param name="peDelegate"></param>
        /// <param name="properties">required only for PropertyChanged Event listening</param>
        public void RegisterAutomationEventListener(int eventId, HandleUIAutomationEventMessage peDelegate, int[] properties = null)
        {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
            AddMessageToQueue(new EventListenerFactoryMessage()
            {
                MessageType = EventListenerFactoryMessageType.RegisterEventListener,
                Listener    = peDelegate,
                EventId     = eventId,
                Properties  = properties
            });
#pragma warning restore CA2000
        }
        public FocusChangedEventListener(CUIAutomation uia, HandleUIAutomationEventMessage peDelegate)
        {
            if (uia == null)
            {
                throw new ArgumentNullException(nameof(uia));
            }

            this.UIAutomation       = uia;
            this.ListenEventMessage = peDelegate;
            this.UIAutomation.AddFocusChangedEventHandler(null, this);
            IsHooked = true;
        }
        /// <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
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Ctor to create an event handler (with CUIAutomation) and register it.
 /// </summary>
 public EventListenerBase(CUIAutomation uia, IUIAutomationElement element, TreeScope scope, int eventId, HandleUIAutomationEventMessage peDelegate)
     : this(element, scope, eventId, peDelegate)
 {
     this.UIAutomation = uia;
 }
 /// <summary>
 /// Create an event handler and register it.
 /// </summary>
 public StructureChangedEventListener(CUIAutomation uia, IUIAutomationElement element, TreeScope scope, HandleUIAutomationEventMessage peDelegate) : base(uia, element, scope, EventType.UIA_StructureChangedEventId, peDelegate)
 {
     Init();
 }
Esempio n. 13
0
 /// <summary>
 /// Create an event handler and register it.
 /// </summary>
 public EventListener(CUIAutomation uia, IUIAutomationElement element, TreeScope scope, int eventId, HandleUIAutomationEventMessage peDelegate) : base(uia, element, scope, eventId, peDelegate)
 {
     Init();
 }
Esempio n. 14
0
 /// <summary>
 /// Private ctor to set common fields
 /// </summary>
 private EventListenerBase(IUIAutomationElement element, TreeScope scope, int eventId, HandleUIAutomationEventMessage peDelegate)
 {
     this.EventId            = eventId;
     this.Element            = element;
     this.ListenEventMessage = peDelegate;
     this.Scope = scope;
 }
 /// <summary>
 /// Create an event handler and register it.
 /// </summary>
 public NotificationEventListener(CUIAutomation8 uia8, IUIAutomationElement element, TreeScope scope, HandleUIAutomationEventMessage peDelegate) : base(uia8, element, scope, EventType.UIA_NotificationEventId, peDelegate)
 {
     Init();
 }
 /// <summary>
 /// Create an event handler and register it.
 /// </summary>
 public PropertyChangedEventListener(CUIAutomation uia, IUIAutomationElement element, TreeScope scope, HandleUIAutomationEventMessage peDelegate, int[] properties) : base(uia, element, scope, EventType.UIA_AutomationPropertyChangedEventId, peDelegate)
 {
     this.propertyArray = properties;
     Init();
 }
 /// <summary>
 /// Create an event handler and register it.
 /// </summary>
 public TextEditTextChangedEventListener(CUIAutomation8 uia8, IUIAutomationElement element, TreeScope scope, HandleUIAutomationEventMessage peDelegate) : base(uia8, element, scope, EventType.UIA_TextEdit_TextChangedEventId, peDelegate)
 {
     Init();
 }
 /// <summary>
 /// Ctor to create an event handler (with CUIAutomation8) and register it.
 /// </summary>
 protected EventListenerBase(CUIAutomation8 uia8, IUIAutomationElement element, TreeScope scope, int eventId, HandleUIAutomationEventMessage peDelegate)
     : this(element, scope, eventId, peDelegate)
 {
     this.UIAutomation8 = uia8;
 }