Object used to store an event that is processed by CodeGenEventObject.OnEvent(). This object is them stored in the EventObject._eventList field.
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal static bool Equals(EventItem newEvent, EventItem storedEvent)
        {
            // WindowClosedEvent does not pass the element in as it is gone...
            if (newEvent.m_le == null && storedEvent.m_le == null)
            {
                if (((AutomationEventArgs)newEvent.m_EventArg).EventId != storedEvent.m_EventArg)
                    return false;
                else
                    return true;
            }

            if (Automation.Compare(newEvent.m_le, storedEvent.m_le))
            {
                if (newEvent.m_EventArg is AutomationFocusChangedEventArgs && (storedEvent.m_EventArg == null))
                {
                    return true;
                }
                else
                {
                    if (((newEvent.m_EventArg == null) || (storedEvent.m_EventArg == null)))
                    {
                        return false;
                    }
                    else
                    {
                        object obj = newEvent.m_EventArg;

                        if (obj.GetType().Equals(typeof(AutomationPropertyChangedEventArgs)))
                        {
                            return (((AutomationPropertyChangedEventArgs)obj).Property == storedEvent.m_EventArg);
                        }
                        else
                        {
                            if (obj.GetType().Equals(typeof(AutomationEventArgs)))
                            {
                                return (((AutomationEventArgs)obj).EventId == storedEvent.m_EventArg);
                            }
                            else
                            {
                                if (obj.GetType().Equals(typeof(StructureChangedEventArgs)))
                                {
                                    return (((StructureChangedEventArgs)(obj)).StructureChangeType == (StructureChangeType)storedEvent.m_EventArg);
                                }
                                return false;
                            }
                        }
                    }
                }
            }
            else
            {
                return false;
            }
        }
Exemple #2
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Called by the inheriting EventFramework class to determine if an event has been fired
        /// </summary>
        /// -------------------------------------------------------------------
        internal static EventFired WasEventFired(EventItem eventItem)
        {
            if (_waitedForEventToFire == false)
            {
                throw new Exception("Did not wait for event to happen.  Call TSC_WaitForEvents() first");
            }

            if (_eventList == null)
            {
                return(EventFired.False);
            }

            string eventName = string.Empty;

            if (eventItem.m_EventArg != null)
            {
                if (eventItem.m_EventArg is StructureChangeType)
                {
                    eventName = eventItem.m_EventArg.ToString();
                }
                else if (eventItem.m_EventArg is AutomationIdentifier)
                {
                    eventName = ((AutomationIdentifier)(eventItem.m_EventArg)).ProgrammaticName;
                }
            }
            else
            {
                eventName = "AutomationFocusChangedEvent";
            }

            Comment(_eventList.Count + " was/were fired");

            for (int index = 0; (index < _eventList.Count); index++)
            {
                EventItem tempEventItem = (EventItem)_eventList[index];

                // Focused events are a bit complex.  You can set focus to a combobox with
                // and edit window and the edit window is the one that gets the focus...so
                // need to search up tree and see if it or one of it's parent controls
                // received the focus. Since we cannot instantiate an AutomationFocusChangedEventArgs
                // we set it to null and this is the flag to tell us that we are testing focus change
                // events
                if (eventItem.m_EventArg == null & tempEventItem.m_EventArg is AutomationFocusChangedEventArgs) // focus event
                {
                    AutomationElement eventListElement = tempEventItem.m_le;
                    while (!Automation.Compare(eventListElement, AutomationElement.RootElement) && !Automation.Compare(eventListElement, eventItem.m_le))
                    {
                        eventListElement = TreeWalker.ControlViewWalker.GetParent(eventListElement);
                    }
                    if (Automation.Compare(eventListElement, eventItem.m_le))
                    {
                        return(EventFired.True);
                    }
                }
                else
                {
                    if (EventItem.Equals(tempEventItem, eventItem))
                    {
                        {
                            Comment("{0} was fired on ({1})", eventName, Library.GetUISpyLook(eventItem.m_le));
                            return(EventFired.True);
                        }
                    }
                }
            }

            Comment(eventName + " was not fired");

            return(EventFired.False);
        }
Exemple #3
0
        /// -------------------------------------------------------------------
        /// <summary>
        /// Method that is called from the inherited OnEvent() and will store the event in the _eventList ArrayList.
        /// </summary>
        /// -------------------------------------------------------------------
        internal void OnEvent(object eventElement, object argument)
        {
            // Validate the element by calling something on it
            AutomationElement element = null;

            if (eventElement is AutomationElement)
            {
                element = eventElement as AutomationElement;
            }
            string elName    = Helpers.GetXmlPathFromAutomationElement(element);
            string uiSpyLook = Library.GetUISpyLook(element);

            Comment("Got event on...({0})", uiSpyLook);

#pragma warning suppress 6517
            lock (this)
            {
                // Let WaitForEvents() know when the last event has occured.
                _lastEvent = DateTime.Now;

                if (_eventList == null)
                {
                    _eventList = new ArrayList();
                }

                // Stop here and wait until we are ready to process events by a call into WaitForEvents().
                _haveNotifiedEvent.WaitOne(1000, true);

                EventItem ei = new EventItem(element, argument);

                int i = _eventList.Add(ei);

                StringBuilder buffer = new StringBuilder("   FIRED!! EVENT[" + i + "/" + _eventList.Count + "](" + uiSpyLook + ")...INFO(");

                if (argument is AutomationPropertyChangedEventArgs)
                {
                    AutomationPropertyChangedEventArgs arg = argument as AutomationPropertyChangedEventArgs;

                    if (arg == null)
                    {
                        throw new ArgumentException();
                    }

                    buffer.Append(arg.Property.ProgrammaticName + " Property[" + arg.Property + "] NewValue[" + arg.NewValue + "] OldValue[" + arg.OldValue + "])");
                }
                else
                {
                    if (argument is AutomationEventArgs)
                    {
                        AutomationEventArgs arg = argument as AutomationEventArgs;

                        if (arg == null)
                        {
                            throw new ArgumentException();
                        }

                        buffer.Append(arg.EventId.ProgrammaticName + ")");
                    }
                    else
                    {
                        if (argument is StructureChangedEventArgs)
                        {
                            StructureChangedEventArgs arg = argument as StructureChangedEventArgs;

                            if (arg == null)
                            {
                                throw new ArgumentException();
                            }

                            Comment("StructureChangedEventArgs:" + ((StructureChangedEventArgs)argument).StructureChangeType.ToString());

                            buffer.Append(arg.EventId.ProgrammaticName + ") StructureChangeType[" + arg.StructureChangeType.ToString() + "])");
                        }
                        else
                        {
                            if (argument is WindowClosedEventArgs)
                            {
                                Comment("WindowClosedEventArgs");
                                WindowClosedEventArgs arg = argument as WindowClosedEventArgs;

                                if (arg == null)
                                {
                                    throw new ArgumentException();
                                }

                                buffer.Append(arg.EventId.ProgrammaticName + ")");
                            }
                            else
                            {
                                if (argument is AutomationFocusChangedEventArgs)
                                {
                                    AutomationFocusChangedEventArgs arg = argument as AutomationFocusChangedEventArgs;

                                    if (arg == null)
                                    {
                                        throw new ArgumentException();
                                    }

                                    buffer.Append(arg.EventId.ProgrammaticName + ") ChildId[" + arg.ChildId + "] ObjectId[" + arg.ObjectId + "])");
                                }
                            }
                        }
                    }
                }

                Comment(buffer.ToString() + " Control Path = " + elName);

                // _haveNotifiedEvent.Reset() will let _haveNotifiedEvent.WaitOne() to pause at the top of this procedure next time in.
                _haveNotifiedEvent.Reset();

                // _gotNotifiedEvent.Set() will allow WaitForEvents() to continue to process at the _gotNotifiedEvent.WaitOne() call.
                _gotNotifiedEvent.Set();
            }
        }
        /// -------------------------------------------------------------------
        /// <summary>
        /// Called by the inheriting EventFramework class to determine if an event has been fired 
        /// </summary>
        /// -------------------------------------------------------------------
        internal static EventFired WasEventFired(EventItem eventItem)
        {
            if (_waitedForEventToFire == false)
                throw new Exception("Did not wait for event to happen.  Call TSC_WaitForEvents() first");

            if (_eventList == null)
                return EventFired.False;

            string eventName = string.Empty;

            if (eventItem.m_EventArg != null)
            {
                if (eventItem.m_EventArg is StructureChangeType)
                    eventName = eventItem.m_EventArg.ToString();
                else if (eventItem.m_EventArg is AutomationIdentifier)
                    eventName = ((AutomationIdentifier)(eventItem.m_EventArg)).ProgrammaticName;
            }
            else
                eventName = "AutomationFocusChangedEvent";

            Comment(_eventList.Count + " was/were fired");

            for (int index = 0; (index < _eventList.Count); index++)
            {
                EventItem tempEventItem = (EventItem)_eventList[index];

                // Focused events are a bit complex.  You can set focus to a combobox with
                // and edit window and the edit window is the one that gets the focus...so
                // need to search up tree and see if it or one of it's parent controls
                // received the focus. Since we cannot instantiate an AutomationFocusChangedEventArgs
                // we set it to null and this is the flag to tell us that we are testing focus change
                // events
                if (eventItem.m_EventArg == null & tempEventItem.m_EventArg is AutomationFocusChangedEventArgs) // focus event 
                {
                    AutomationElement eventListElement = tempEventItem.m_le;
                    while (!Automation.Compare(eventListElement, AutomationElement.RootElement) && !Automation.Compare(eventListElement, eventItem.m_le))
                        eventListElement = TreeWalker.ControlViewWalker.GetParent(eventListElement);
                    if (Automation.Compare(eventListElement, eventItem.m_le))
                        return EventFired.True;

                }
                else
                {

                    if (EventItem.Equals(tempEventItem, eventItem))
                    {
                        {
                            Comment("{0} was fired on ({1})", eventName, Library.GetUISpyLook(eventItem.m_le));
                            return EventFired.True;
                        }
                    }
                }
            }

            Comment(eventName + " was not fired");

            return EventFired.False;
        }
        /// -------------------------------------------------------------------
        /// <summary>
        /// Method that is called from the inherited OnEvent() and will store the event in the _eventList ArrayList.
        /// </summary>
        /// -------------------------------------------------------------------
        internal void OnEvent(object eventElement, object argument)
        {
            // Validate the element by calling something on it
            AutomationElement element = null;
            if (eventElement is AutomationElement)
            {
                element = eventElement as AutomationElement;
            }
            string elName = Helpers.GetXmlPathFromAutomationElement(element);
            string uiSpyLook = Library.GetUISpyLook(element);
            Comment("Got event on...({0})", uiSpyLook);

#pragma warning suppress 6517
            lock (this)
            {
                // Let WaitForEvents() know when the last event has occured.
                _lastEvent = DateTime.Now;

                if (_eventList == null)
                    _eventList = new ArrayList();

                // Stop here and wait until we are ready to process events by a call into WaitForEvents().
                _haveNotifiedEvent.WaitOne(1000, true);

                EventItem ei = new EventItem(element, argument);

                int i = _eventList.Add(ei);

                StringBuilder buffer = new StringBuilder("   FIRED!! EVENT[" + i + "/" + _eventList.Count + "](" + uiSpyLook + ")...INFO(");

                if (argument is AutomationPropertyChangedEventArgs)
                {
                    AutomationPropertyChangedEventArgs arg = argument as AutomationPropertyChangedEventArgs;

                    if (arg == null)
                        throw new ArgumentException();

                    buffer.Append(arg.Property.ProgrammaticName + " Property[" + arg.Property + "] NewValue[" + arg.NewValue + "] OldValue[" + arg.OldValue + "])");
                }
                else
                {
                    if (argument is AutomationEventArgs)
                    {
                        AutomationEventArgs arg = argument as AutomationEventArgs;

                        if (arg == null)
                            throw new ArgumentException();

                        buffer.Append(arg.EventId.ProgrammaticName + ")");
                    }
                    else
                    {
                        if (argument is StructureChangedEventArgs)
                        {
                            StructureChangedEventArgs arg = argument as StructureChangedEventArgs;

                            if (arg == null)
                                throw new ArgumentException();

                            Comment("StructureChangedEventArgs:" + ((StructureChangedEventArgs)argument).StructureChangeType.ToString());

                            buffer.Append(arg.EventId.ProgrammaticName + ") StructureChangeType[" + arg.StructureChangeType.ToString() + "])");
                        }
                        else
                        {
                            if (argument is WindowClosedEventArgs)
                            {
                                Comment("WindowClosedEventArgs");
                                WindowClosedEventArgs arg = argument as WindowClosedEventArgs;

                                if (arg == null)
                                    throw new ArgumentException();

                                buffer.Append(arg.EventId.ProgrammaticName + ")");
                            }
                            else
                            {
                                if (argument is AutomationFocusChangedEventArgs)
                                {
                                    AutomationFocusChangedEventArgs arg = argument as AutomationFocusChangedEventArgs;

                                    if (arg == null)
                                        throw new ArgumentException();

                                    buffer.Append(arg.EventId.ProgrammaticName + ") ChildId[" + arg.ChildId + "] ObjectId[" + arg.ObjectId + "])");
                                }
                            }
                        }
                    }
                }

                Comment(buffer.ToString() + " Control Path = " + elName);

                // _haveNotifiedEvent.Reset() will let _haveNotifiedEvent.WaitOne() to pause at the top of this procedure next time in.
                _haveNotifiedEvent.Reset();

                // _gotNotifiedEvent.Set() will allow WaitForEvents() to continue to process at the _gotNotifiedEvent.WaitOne() call.
                _gotNotifiedEvent.Set();

            }
        }