private void RemoveHandlerButtonClick(object sender, EventArgs e)
        {
            if (null != ConfigurationTreeView.SelectedNode)
            {
                if (null != ConfigurationTreeView.SelectedNode.Tag)
                {
                    if (ConfigurationTreeView.SelectedNode.Tag is IAgentEventHandler)
                    {
                        IList <IAgentEventHandler> eventHandlers =
                            (IList <IAgentEventHandler>)ConfigurationTreeView.SelectedNode.Parent.Tag;

                        IAgentEventHandler eventHandler = (IAgentEventHandler)ConfigurationTreeView.SelectedNode.Tag;

                        if (eventHandlers.IsReadOnly)
                        {
                            eventHandlers = new List <IAgentEventHandler>(eventHandlers);
                            ConfigurationTreeView.SelectedNode.Parent.Tag = eventHandlers;
                        }

                        eventHandlers.Remove(eventHandler);
                        ConfigurationTreeView.SelectedNode.Remove();
                    }
                    else if (ConfigurationTreeView.SelectedNode.Tag is IHandler)
                    {
                        IHandler handler = (IHandler)ConfigurationTreeView.SelectedNode.Tag;

                        if (ConfigurationTreeView.SelectedNode.Parent.Tag is IAgentEventHandler)
                        {
                            IAgentEventHandler eventHandler =
                                (IAgentEventHandler)ConfigurationTreeView.SelectedNode.Parent.Tag;

                            if (eventHandler.Handlers.IsReadOnly)
                            {
                                eventHandler.Handlers = new List <IHandler>(eventHandler.Handlers);
                            }

                            eventHandler.Handlers.Remove(handler);
                            ConfigurationTreeView.SelectedNode.Remove();
                        }
                        else if (ConfigurationTreeView.SelectedNode.Parent.Tag is IHandler)
                        {
                            IHandler parentHandler = (IHandler)ConfigurationTreeView.SelectedNode.Parent.Tag;

                            if (parentHandler.Handlers.IsReadOnly)
                            {
                                parentHandler.Handlers = new List <IHandler>(parentHandler.Handlers);
                            }

                            parentHandler.Handlers.Remove(handler);
                            ConfigurationTreeView.SelectedNode.Remove();
                        }
                    }
                }
            }
        }
        private void AddHandlerButtonClick(object sender, EventArgs e)
        {
            if (null != ConfigurationTreeView.SelectedNode)
            {
                if (null != ConfigurationTreeView.SelectedNode.Tag)
                {
                    IHandler handler = (IHandler)
                                       Activator.CreateInstance(AvailableHandlersTreeView.SelectedNode.Tag.GetType());

                    if (ConfigurationTreeView.SelectedNode.Tag is IAgentEventHandler)
                    {
                        IAgentEventHandler eventHandler = (IAgentEventHandler)ConfigurationTreeView.SelectedNode.Tag;

                        if (eventHandler.Handlers.IsReadOnly)
                        {
                            eventHandler.Handlers = new List <IHandler>(eventHandler.Handlers);
                        }

                        eventHandler.Handlers.Add(handler);
                        ConfigurationTreeView.SelectedNode.Nodes.Add(TreeNodeMapper.MapHandler(handler));
                    }
                    else if (ConfigurationTreeView.SelectedNode.Tag is IList <IAgentEventHandler> )
                    {
                        IList <IAgentEventHandler> eventHandlers =
                            (IList <IAgentEventHandler>)ConfigurationTreeView.SelectedNode.Tag;

                        if (eventHandlers.IsReadOnly)
                        {
                            eventHandlers = new List <IAgentEventHandler>(eventHandlers);
                            ConfigurationTreeView.SelectedNode.Tag = eventHandlers;
                        }

                        IAgentEventHandler eventHandler = new AgentEventHandler();
                        eventHandler.Handlers.Add(handler);

                        eventHandlers.Add(eventHandler);
                        ConfigurationTreeView.SelectedNode.Nodes.Add(TreeNodeMapper.MapAgentEventHandler(eventHandler));
                    }
                    else if (ConfigurationTreeView.SelectedNode.Tag is IHandler)
                    {
                        IHandler parentHandler = (IHandler)ConfigurationTreeView.SelectedNode.Tag;

                        if (parentHandler.Handlers.IsReadOnly)
                        {
                            parentHandler.Handlers = new List <IHandler>(parentHandler.Handlers);
                        }

                        parentHandler.Handlers.Add(handler);
                        ConfigurationTreeView.SelectedNode.Nodes.Add(TreeNodeMapper.MapHandler(handler));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static TreeNode MapAgentEventHandler(IAgentEventHandler agentEventHandler)
        {
            var node = new TreeNode();

            if (null != agentEventHandler)
            {
                node.Name = agentEventHandler.ToString();
                node.Text = agentEventHandler.ToString();
                node.Tag  = agentEventHandler;

                node.Nodes.AddRange(MapHandlers(agentEventHandler.Handlers));
            }

            return(node);
        }