Esempio n. 1
0
        public void Subscribe(string subscription, Action<object> response)
        {
            var observer = new Observer() { Subscription = subscription, Respond = response };

            MessageBus.Instance.Subscribe(subscription, response);

            List<Observer> observers = null;
            var observersFound = _observerList.TryGetValue(subscription, out observers);

            if (!observersFound)
            {
                observers = new List<Observer>() { observer };

                _observerList.Add(subscription, observers);
            }
            else
            {
                observers.Add(observer);
            }
        }
Esempio n. 2
0
        private void Subscribe(string subscription, Action<object> response, Dictionary<string, List<Observer>> observers)
        {
            Debug.Assert(_publishingCount >= 0);

            var observer = new Observer() { Subscription = subscription, Respond = response };

            if (_publishingCount == 0)
            {
                Add(subscription, observers, observer);
            }
            else
            {
                Add(subscription, _waitingSubscribers, observer);
            }
        }
Esempio n. 3
0
        private static void Add(string subscription, Dictionary<string, List<Observer>> observers, Observer observer)
        {
            List<Observer> foundObservers = null;
            var observersExist = observers.TryGetValue(subscription, out foundObservers);

            if (observersExist)
            {
                foundObservers.Add(observer);
            }
            else
            {
                foundObservers = new List<Observer>() { observer };
                observers.Add(subscription, foundObservers);
            }
        }