Exemple #1
0
        public void ListenerWithMessageInheritance()
        {
            MessageListener listener = new MessageListener();

            bool removed = false;

            Action <ListenerWrapper> remove = (m) =>
            {
                removed = true;
            };

            ListenerWrapper wrapper = new ListenerWrapper(listener, remove, true, true);

            Assert.That(wrapper, Is.Not.Null);
            Assert.That(wrapper.Count, Is.EqualTo(1));
            Assert.That(removed, Is.False);


            Assert.That(wrapper.TryDispatch <Message>(new Message()), Is.True);
            Assert.That(wrapper.TryDispatch <Message>(new InheritedMessage()), Is.True);
            Assert.That(wrapper.TryDispatch <InheritedMessage>(new InheritedMessage()), Is.True);

            Assert.That(wrapper.TryDispatch <DifferentMessage>(new DifferentMessage()), Is.False);

            Assert.That(wrapper.ListenerInstance, Is.EqualTo(listener));
        }
Exemple #2
0
        private bool TryGetListenerWrapperByListener(object listener, out ListenerWrapper listenerWrapper)
        {
            lock (syncLock)
                listenerWrapper = listeners.SingleOrDefault(x => x.ListenerInstance == listener);

            return(listenerWrapper != null);
        }
Exemple #3
0
        public void AddListener(object listener, bool holdStrongReference, bool supportMessageInheritance)
        {
            lock (syncLock)
            {
                if (ContainsListener(listener))
                {
                    return;
                }

                var listenerWrapper = new ListenerWrapper(listener, RemoveListenerWrapper, holdStrongReference, supportMessageInheritance);
                if (listenerWrapper.Count == 0)
                {
                    throw new ArgumentException("IListener<T> is not implemented", "listener");
                }
                listeners.Add(listenerWrapper);
            }
        }
Exemple #4
0
 private void RemoveListenerWrapper(ListenerWrapper listenerWrapper)
 {
     lock (syncLock)
         listeners.Remove(listenerWrapper);
 }