Beispiel #1
0
        public static int ChangeSubscribers <T>(this CachedSynchronizedDictionary <T, int> subscribers, T subscriber, int delta)
        {
            if (subscribers == null)
            {
                throw new ArgumentNullException("subscribers");
            }

            lock (subscribers.SyncRoot)
            {
                var value = subscribers.TryGetValue2(subscriber) ?? 0;

                value += delta;

                if (value > 0)
                {
                    subscribers[subscriber] = value;
                }
                else
                {
                    subscribers.Remove(subscriber);
                }

                return(value);
            }
        }
Beispiel #2
0
        public static int ChangeSubscribers <T>(this CachedSynchronizedDictionary <T, int> subscribers, T subscriber, bool isSubscribe)
        {
            if (subscribers == null)
            {
                throw new ArgumentNullException(nameof(subscribers));
            }

            lock (subscribers.SyncRoot)
            {
                var value = subscribers.TryGetValue2(subscriber) ?? 0;

                if (isSubscribe)
                {
                    value++;
                }
                else
                {
                    if (value > 0)
                    {
                        value--;
                    }
                }

                if (value > 0)
                {
                    subscribers[subscriber] = value;
                }
                else
                {
                    subscribers.Remove(subscriber);
                }

                return(value);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WeightedIndexSecurity"/>.
 /// </summary>
 public WeightedIndexSecurity()
 {
     _weights = new CachedSynchronizedDictionary <SecurityId, decimal>();
 }
Beispiel #4
0
 private static bool TryUnSubscribe <T>(CachedSynchronizedDictionary <T, int> subscribers, T subscriber)
 {
     return(subscribers.ChangeSubscribers(subscriber, -1) == 0);
 }