Exemplo n.º 1
0
        protected virtual IObjectServer OpenServerWith(IMessageRecipient recipient)
        {
            var config = MemoryIoConfiguration();

            SetMessageRecipient(config, recipient);
            return(OpenServer(config));
        }
Exemplo n.º 2
0
        internal void Unregister(IMessageRecipient recipient, Type messageType)
        {
            if (messageType != typeof(MessageBase) &&
                !messageType.IsSubclassOf(typeof(MessageBase)))
            {
                throw new ArgumentException("Parameter must be a MessageBase", "messageType");
            }

            OldUnregisterFromLists(recipient, messageType, _recipientsStrict);
            OldUnregisterFromLists(recipient, messageType, _recipientsOfSubclasses);
        }
Exemplo n.º 3
0
        internal void Register(IMessageRecipient recipient, Type messageType, bool receiveDerivedMessagesToo)
        {
            if (messageType != typeof(MessageBase) &&
                !messageType.IsSubclassOf(typeof(MessageBase)))
            {
                throw new ArgumentException("Parameter must be a MessageBase", "messageType");
            }

            Dictionary <Type, List <WeakReference> > recipients;

            if (receiveDerivedMessagesToo)
            {
                if (_recipientsOfSubclasses == null)
                {
                    _recipientsOfSubclasses = new Dictionary <Type, List <WeakReference> >();
                }

                recipients = _recipientsOfSubclasses;
            }
            else
            {
                if (_recipientsStrict == null)
                {
                    _recipientsStrict = new Dictionary <Type, List <WeakReference> >();
                }

                recipients = _recipientsStrict;
            }

            List <WeakReference> list;

            if (!recipients.ContainsKey(messageType))
            {
                list = new List <WeakReference>();
                recipients.Add(messageType, list);
            }
            else
            {
                list = recipients[messageType];
            }

            var reference = new WeakReference(recipient);

            list.Add(reference);

            Cleanup();
        }
Exemplo n.º 4
0
        internal void Register(IMessageRecipient recipient, Type messageType, bool receiveDerivedMessagesToo)
        {
            if (messageType != typeof(MessageBase)
                && !messageType.IsSubclassOf(typeof(MessageBase)))
            {
                throw new ArgumentException("Parameter must be a MessageBase", "messageType");
            }

            Dictionary<Type, List<WeakReference>> recipients;

            if (receiveDerivedMessagesToo)
            {
                if (_recipientsOfSubclasses == null)
                {
                    _recipientsOfSubclasses = new Dictionary<Type, List<WeakReference>>();
                }

                recipients = _recipientsOfSubclasses;
            }
            else
            {
                if (_recipientsStrict == null)
                {
                    _recipientsStrict = new Dictionary<Type, List<WeakReference>>();
                }

                recipients = _recipientsStrict;
            }

            List<WeakReference> list;

            if (!recipients.ContainsKey(messageType))
            {
                list = new List<WeakReference>();
                recipients.Add(messageType, list);
            }
            else
            {
                list = recipients[messageType];
            }

            var reference = new WeakReference(recipient);
            list.Add(reference);

            Cleanup();
        }
Exemplo n.º 5
0
        private static void OldUnregisterFromLists(
            IMessageRecipient recipient,
            Dictionary <Type, List <WeakReference> > lists)
        {
            if (lists == null)
            {
                return;
            }

            var types = new Type[lists.Keys.Count];

            lists.Keys.CopyTo(types, 0);

            foreach (var type in types)
            {
                OldUnregisterFromLists(recipient, type, lists);
            }
        }
Exemplo n.º 6
0
        private bool ProcessUserMessage()
        {
            IMessageRecipient recipient = MessageRecipient();

            if (recipient == null)
            {
                return(true);
            }
            try
            {
                recipient.ProcessMessage(new MUserMessage.MessageContextImpl(this), ReadUserMessage
                                             ());
            }
            catch (Exception x)
            {
                // TODO: use MessageContext.sender() to send
                // error back to client
                Sharpen.Runtime.PrintStackTrace(x);
            }
            return(true);
        }
Exemplo n.º 7
0
        private static void OldUnregisterFromLists(
            IMessageRecipient recipient,
            Type messageType,
            IDictionary <Type, List <WeakReference> > lists)
        {
            if (recipient == null ||
                messageType == null ||
                lists == null ||
                lists.Count == 0 ||
                !lists.ContainsKey(messageType))
            {
                return;
            }

            var           list = lists[messageType];
            WeakReference referenceToRemove = null;

            foreach (var reference in list)
            {
                if (reference.Target == recipient)
                {
                    referenceToRemove = reference;
                    break;
                }
            }

            if (referenceToRemove != null)
            {
                list.Remove(referenceToRemove);
            }

            if (list.Count == 0)
            {
                lists.Remove(messageType);
            }
        }
Exemplo n.º 8
0
		protected virtual IObjectServer OpenServerWith(IMessageRecipient recipient)
		{
			IConfiguration config = MemoryIoConfiguration();
			SetMessageRecipient(config, recipient);
			return OpenServer(config);
		}
Exemplo n.º 9
0
        private static void OldUnregisterFromLists(
            IMessageRecipient recipient,
            Type messageType,
            IDictionary<Type, List<WeakReference>> lists)
        {
            if (recipient == null
                || messageType == null
                    || lists == null
                        || lists.Count == 0
                            || !lists.ContainsKey(messageType))
            {
                return;
            }

            var list = lists[messageType];
            WeakReference referenceToRemove = null;
            foreach (var reference in list)
            {
                if (reference.Target == recipient)
                {
                    referenceToRemove = reference;
                    break;
                }
            }

            if (referenceToRemove != null)
            {
                list.Remove(referenceToRemove);
            }

            if (list.Count == 0)
            {
                lists.Remove(messageType);
            }
        }
Exemplo n.º 10
0
 private void SetMessageRecipient(IConfiguration config, IMessageRecipient recipient
                                  )
 {
     config.ClientServer().SetMessageRecipient(recipient);
 }
Exemplo n.º 11
0
 public void SetMessageRecipient(IMessageRecipient messageRecipient)
 {
     _config.Put(MessageRecipientKey, messageRecipient);
 }
Exemplo n.º 12
0
 public void Unregister(IMessageRecipient recipient, Type messageType)
 {
     _oldMessenger.Unregister(recipient, messageType);
 }
Exemplo n.º 13
0
 public void Unregister(IMessageRecipient recipient)
 {
     _oldMessenger.Unregister(recipient);
 }
Exemplo n.º 14
0
 public void Register(IMessageRecipient recipient, Type messageType, bool receiveDerivedMessagesToo)
 {
     _oldMessenger.Register(recipient, messageType, receiveDerivedMessagesToo);
 }
Exemplo n.º 15
0
 public void RegisterRecipient(IMessageRecipient recipient)
 {
     _recipients.Add(recipient);
 }
Exemplo n.º 16
0
		protected virtual void SetMessageRecipient(IObjectContainer container, IMessageRecipient
			 recipient)
		{
			SetMessageRecipient(container.Ext().Configure(), recipient);
		}
Exemplo n.º 17
0
		private void SetMessageRecipient(IConfiguration config, IMessageRecipient recipient
			)
		{
			config.ClientServer().SetMessageRecipient(recipient);
		}
Exemplo n.º 18
0
 public void Register(IMessageRecipient recipient, Type messageType)
 {
     Register(recipient, messageType, false);
 }
Exemplo n.º 19
0
		public void SetMessageRecipient(IMessageRecipient messageRecipient)
		{
			_config.Put(MessageRecipientKey, messageRecipient);
		}
Exemplo n.º 20
0
 internal void Unregister(IMessageRecipient recipient)
 {
     OldUnregisterFromLists(recipient, _recipientsStrict);
     OldUnregisterFromLists(recipient, _recipientsOfSubclasses);
 }
Exemplo n.º 21
0
 protected virtual void SetMessageRecipient(IObjectContainer container, IMessageRecipient
                                            recipient)
 {
     SetMessageRecipient(container.Ext().Configure(), recipient);
 }
Exemplo n.º 22
0
        internal void Unregister(IMessageRecipient recipient, Type messageType)
        {
            if (messageType != typeof(MessageBase)
                && !messageType.IsSubclassOf(typeof(MessageBase)))
            {
                throw new ArgumentException("Parameter must be a MessageBase", "messageType");
            }

            OldUnregisterFromLists(recipient, messageType, _recipientsStrict);
            OldUnregisterFromLists(recipient, messageType, _recipientsOfSubclasses);
        }
Exemplo n.º 23
0
        private static void OldUnregisterFromLists(
            IMessageRecipient recipient,
            Dictionary<Type, List<WeakReference>> lists)
        {
            if (lists == null)
            {
                return;
            }

            var types = new Type[lists.Keys.Count];
            lists.Keys.CopyTo(types, 0);

            foreach (var type in types)
            {
                OldUnregisterFromLists(recipient, type, lists);
            }
        }
Exemplo n.º 24
0
 internal void Unregister(IMessageRecipient recipient)
 {
     OldUnregisterFromLists(recipient, _recipientsStrict);
     OldUnregisterFromLists(recipient, _recipientsOfSubclasses);
 }