Beispiel #1
0
        public void Register(object subscriber)
        {
            if (_syncContext == null && SynchronizationContext.Current != null)
            {
                _syncContext = SynchronizationContext.Current;
            }

            List <Type> subscriptTypes = new List <Type>();

            if (_subscriberDictWithType.ContainsKey(subscriber))
            {
                return;
            }

            IList <Subscription> subscriptionList = SubscriptionHandler.CreateSubscription(subscriber);

            foreach (var subscription in subscriptionList)
            {
                var subscriptionsOfType = _subscriptionDictByType.GetOrAdd(subscription.EventType, new List <Subscription>());

                lock (_locksForSubscription.GetOrAdd(subscription.EventType, new object()))
                {
                    subscriptionsOfType.Add(subscription);
                    subscriptionsOfType.Sort();
                }

                if (!subscriptTypes.Contains(subscription.EventType))
                {
                    subscriptTypes.Add(subscription.EventType);
                }
            }

            _subscriberDictWithType.Add(subscriber, subscriptTypes);
        }