Beispiel #1
0
        private void contextStopTracing_Click(object sender, System.EventArgs e)
        {
            HighlightTrackTreeView tv = contextMenu.SourceControl as HighlightTrackTreeView;

            if (tv == null)
            {
                return;
            }

            TreeNode node = tv.LastRightClickNode;

            if (node == null)
            {
                return;
            }

            ControlEvent ce = node.Tag as ControlEvent;

            if (ce == null)
            {
                return;
            }

            if (node != null)
            {
                ce.TrackEnabled = false;
                UpdateFocusedControl();
            }
        }
Beispiel #2
0
        private void checkedListBox1_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
        {
            ControlEvent ce = checkedListBox1.SelectedItem as ControlEvent;

            if (ce == null)
            {
                return;
            }

            ce.TrackEnabled = (e.NewValue == CheckState.Checked);
        }
Beispiel #3
0
        // emit the assembly, create an instance
        // and get the interface
        public ControlEvent GetEventConsumerType(Type eventHandlerType)
        {
            Type eventConsumerType;

            if (typeCollection.Contains(eventHandlerType))
            {
                eventConsumerType = (Type)typeCollection[eventHandlerType];
            }
            else
            {
                eventConsumerType = GenerateEventConsumerType(eventHandlerType);

                typeCollection[eventHandlerType] = eventConsumerType;
            }

            ControlEvent ev = (ControlEvent)Activator.CreateInstance(eventConsumerType);

            return(ev);
        }
Beispiel #4
0
        /// <summary>
        /// Process generic inbound events and populate them to the appropriate tab page(s)
        /// </summary>
        private void eventFired(object sender, EventArgs e)
        {
            ControlEvent ce = sender as ControlEvent;

            if (ce == null)
            {
                return;
            }

            if (this.TrackingEnabled)
            {
                if (ce.TrackEnabled)
                {
                    if (traceEventCheckbox.Checked)
                    {
                        Trace.WriteLine(String.Format("hIgHlItE{0}::{1}", ce.ControlName, ce.EventName));
                    }

                    AddEventsToTreeView(ce, treeView1, true);
                    AddEventsToTreeView(ce, ce.EventTrackInfo.TreeView, false);
                }
            }
        }
Beispiel #5
0
        void AddEventsToTreeView(ControlEvent ce, TreeView treeView, bool includeControlName)
        {
            string eventName;

            if (includeControlName)
            {
                eventName = String.Format("{0}::{1}", ce.ControlName, ce.EventName);
            }
            else
            {
                eventName = ce.EventName;
            }

            TreeNode node = new TreeNode(String.Format("{0} {1}",
                                                       DateTime.Now.Ticks - startTicks, eventName));

            node.Tag = ce;
            treeView.Nodes.Add(node);

            TreeNode eventArgsNode = new TreeNode(ce.EventArgs.GetType().FullName);

            eventArgsNode.Tag = ce;
            node.Nodes.Add(eventArgsNode);

            // Special case: save reflection overhead if this is an EventArgs
            // as this contains no values

            if (ce.EventArgs.GetType() != typeof(EventArgs))
            {
                Type eventArgsType = ce.EventArgs.GetType();

                // Iterate through properties and add details of each to the tree view.
                foreach (PropertyInfo member in eventArgsType.GetProperties())
                {
                    try
                    {
                        TreeNode newNode = new TreeNode(
                            String.Format("[prop] {0} = {1}", member.Name,
                                          eventArgsType.GetProperty(member.Name).GetValue(ce.EventArgs, null).ToString()));
                        newNode.Tag = ce;
                        eventArgsNode.Nodes.Add(newNode);
                    }
                    catch (Exception) { }
                }
                // Iterate through public types
                foreach (MemberInfo type in eventArgsType.GetMembers())
                {
                    try
                    {
                        if (type.MemberType == MemberTypes.Field)
                        {
                            TreeNode newNode = new TreeNode(
                                String.Format("[field] {0} = {1}", type.Name,
                                              eventArgsType.GetField(type.Name).GetValue(ce.EventArgs).ToString()));
                            newNode.Tag = ce;
                            eventArgsNode.Nodes.Add(newNode);
                        }
                    }
                    catch (Exception) { }
                }
            }

            if (this.ScrollingEnabled)
            {
                treeView.SelectedNode = node;
            }
        }
Beispiel #6
0
        public void HookEvents(object o, string name)
        {
            if (recursion_counter_ >= recursion_depth_)
            {
                return;
            }

            recursion_counter_++;

            Type t = o.GetType();

            EventTrackInfo trackInfo        = AddTabPage(name, o);
            ArrayList      controlEventList = new ArrayList();

            foreach (EventInfo ei in t.GetEvents())
            {
                // Discover type of event handler
                Type eventHandlerType = ei.EventHandlerType;

                // eventHandlerType is the type of the delegate (eg System.EventHandler)
                // what we need, is to find the type of the second parameter of the
                // delegate, eg System.EventArgs

                MethodInfo      mi = eventHandlerType.GetMethod("Invoke");
                ParameterInfo[] pi = mi.GetParameters();

                if (pi == null || pi.Length < 2)
                {
                    continue;
                }

                // Get a class derived from ControlEvent which has a HandleEvent method
                // taking the appropriate parameters
                ControlEvent ce = GenerateEventAssembly.Instance.GetEventConsumerType(pi[1].ParameterType);

                // Hook onto this control event to get the details of all events fired
                ce.ControlName    = name;
                ce.EventName      = ei.Name;
                ce.EventTrackInfo = trackInfo;
                ce.EventFired    += new EventHandler(eventFired);

                controlEventList.Add(ce);

                // Wire up the event handler to our new consumer
                Delegate d = Delegate.CreateDelegate(eventHandlerType, ce, "HandleEvent");
                ei.AddEventHandler(o, d);
            }

            trackInfo.EventList = controlEventList;

            if (is_recursive_)
            {
                if (o is Control)
                {
                    Control c = (Control)o;

                    if (c.Controls != null)
                    {
                        foreach (Control subControl in c.Controls)
                        {
                            HookEvents(subControl, name + "/" + ControlName(subControl));
                        }
                    }

                    if (c is Form)
                    {
                        Form f = (Form)c;
                        if (f.Menu != null)
                        {
                            foreach (MenuItem m in f.Menu.MenuItems)
                            {
                                HookEvents(m, name + "/" + ControlName(m));
                            }
                        }
                    }

                    if (c.ContextMenu != null)
                    {
                        foreach (MenuItem m in c.ContextMenu.MenuItems)
                        {
                            HookEvents(m, name + "/" + ControlName(m));
                        }
                    }
                }

                if (o is MenuItem)
                {
                    MenuItem m = (MenuItem)o;
                    foreach (MenuItem mi in m.MenuItems)
                    {
                        HookEvents(mi, name + "/" + ControlName(mi));
                    }
                }
            }

            recursion_counter_--;
        }