예제 #1
0
        static void PerformSubscribe(object subscriber, string identifier, Type argType, Action <object> callback)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier));
            }
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            var key = new MessageSignature(identifier, argType);

            var value = new MessageSubscription(subscriber, callback);

            if (Callbacks.ContainsKey(key))
            {
                Callbacks [key].Add(value);
            }
            else
            {
                Callbacks [key] = new List <MessageSubscription> {
                    value
                };
            }
        }
예제 #2
0
        static void PerformUnsubscribe(object subscriber, string identifier, Type argType)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier));
            }

            var key = new MessageSignature(identifier, argType);

            if (!Callbacks.ContainsKey(key))
            {
                return;
            }

            if (Callbacks [key].Any())
            {
                var deleted = new List <MessageSubscription> ();
                while (Callbacks.TryRemove(key, out deleted))
                {
                }
            }
        }
예제 #3
0
        static void PerformSend(string identifier, Type argType, object args)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier));
            }

            var key = new MessageSignature(identifier, argType);

            if (!Callbacks.ContainsKey(key))
            {
                return;
            }

            var actions = Callbacks [key];

            if (actions == null || !actions.Any())
            {
                return;
            }

            foreach (var action in actions)
            {
                if (action.Item1.Target != null && actions.Contains(action))
                {
                    action.Item2(args);
                }
            }
        }