public virtual void eventAdded(Context con, EventDefinition ed)
        {
            var maskListenersCopy =
                new Dictionary <String, IDictionary <String, ListSet <ContextEventListener> > >(maskListeners);

            foreach (var mask in maskListenersCopy.Keys)
            {
                if (!ContextUtils.matchesToMask(mask, con.getPath()))
                {
                    continue;
                }
                var cel = getContextMaskListeners(mask);

                foreach (var ev in cel.Keys)
                {
                    if (!EventUtils.matchesToMask(ev, ed))
                    {
                        continue;
                    }
                    var listeners = cel[ev];

                    lock (listeners)
                    {
                        foreach (var el in listeners)
                        {
                            addListenerToContext(con, ed.getName(), el, true);
                        }
                    }
                }
            }
        }
        public virtual void addMaskEventListener(String mask, String eventString, ContextEventListener listener)
        {
            var contexts = ContextUtils.expandContextMaskToPaths(mask, this, listener.getCallerController());

            foreach (var con in contexts)
            {
                addEventListener(con, eventString, listener, true);
            }

            getMaskListeners(mask, eventString).Add(listener);
        }
        public virtual void removeMaskEventListener(String mask, String eventString, ContextEventListener listener)
        {
            var contexts = ContextUtils.expandContextMaskToContexts(mask, this, listener.getCallerController());

            foreach (var con in contexts)
            {
                var events = EventUtils.getEvents(con, eventString, listener.getCallerController());

                foreach (var ed in events)
                {
                    removeEventListener(con.getPath(), ed.getName(), listener, true);
                }
            }

            getMaskListeners(mask, eventString).Remove(listener);
        }
            public void visit(Context vc)
            {
                foreach (var mask in owner.maskListeners.Keys)
                {
                    if (!ContextUtils.matchesToMask(mask, vc.getPath()))
                    {
                        continue;
                    }
                    var cel = owner.getContextMaskListeners(mask);

                    foreach (var ev in cel.Keys)
                    {
                        foreach (var lis in owner.getMaskListeners(mask, ev))
                        {
                            vc.removeEventListener(ev, lis);
                        }
                    }
                }
            }
        public void contextAdded(Context con)
        {
            lock (eventListeners)
            {
                IDictionary <string, ListSet <ContextEventListener> > cel = null;

                if (eventListeners.ContainsKey(con.getPath()))
                {
                    cel = eventListeners[con.getPath()];
                }

                if (cel != null)
                {
                    foreach (var ev in cel.Keys)
                    {
                        var listeners = cel[ev];

                        lock (listeners)
                        {
                            foreach (var el in listeners)
                            {
                                if (con.getEventData(ev) != null)
                                {
                                    con.addEventListener(ev, el);
                                }
                            }
                        }
                    }
                }
            }

            lock (maskListeners)
            {
                foreach (var mask in maskListeners.Keys)
                {
                    if (!ContextUtils.matchesToMask(mask, con.getPath()))
                    {
                        continue;
                    }
                    var cel = getContextMaskListeners(mask);

                    foreach (var ev in cel.Keys)
                    {
                        var listeners = cel[ev];

                        lock (listeners)
                        {
                            foreach (var el in listeners)
                            {
                                var events = EventUtils.getEvents(con, ev,
                                                                  el.getCallerController());

                                foreach (var ed in events)
                                {
                                    addListenerToContext(con, ed.getName(), el, true);
                                }
                            }
                        }
                    }
                }
            }
        }