private void AddSubscription(Subscription sub) { lock (_syncRoot) { if (_subscriptions.ContainsKey(sub.Topic.Key) == true) throw new Exception("Multiple subscriptions for the same topic are not supported."); _subscriptions[sub.Topic.Key] = sub; } }
internal static void Add(ITopic topic, Action<RealTimeMessage> handler) { if (handler == null) throw new ArgumentException("Event handler cannot be null."); var subscriptionManager = ObjectFactory.Build<ISubscriptionManager>(); lock (_lock) { // Get existing var sub = subscriptionManager.Get(topic); // Create if not exists. if (sub == null) { sub = new Subscription { Topic = topic }; sub.Triggered += handler; subscriptionManager.Subscribe(sub); } else { sub.Triggered += handler; } } }
public void Subscribe(Subscription subscription) { AddSubscription(subscription); }