Beispiel #1
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 #2
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);
            }
        }
        /// <inheritdoc />
        public Guid?TryGetAdapter(string key)
        {
            if (key.IsEmpty())
            {
                throw new ArgumentNullException(nameof(key));
            }

            return(_adapters.TryGetValue2(key));
        }
Beispiel #4
0
        /// <inheritdoc />
        public Guid?TryGetAdapter(string portfolioName)
        {
            if (portfolioName.IsEmpty())
            {
                throw new ArgumentNullException(nameof(portfolioName));
            }

            return(_adapters.TryGetValue2(portfolioName));
        }
            public int this[IMessageSessionHolder sessionHolder]
            {
                get { return(_enables.TryGetValue2(sessionHolder) ?? -1); }
                set
                {
                    if (value < -1)
                    {
                        throw new ArgumentOutOfRangeException();
                    }

                    if (!Contains(sessionHolder))
                    {
                        Add(sessionHolder);
                    }

                    _enables[sessionHolder] = value;
                }
            }
Beispiel #6
0
 /// <inheritdoc />
 public Guid?TryGetAdapter(Key key)
 {
     return(_adapters.TryGetValue2(key));
 }
Beispiel #7
0
        private int GetAccountId(string portfolioName = null)
        {
            var accountId = portfolioName == null?_accountIds.CachedValues.FirstOr() : _accountIds.TryGetValue2(portfolioName);

            if (accountId != null)
            {
                return(accountId.Value);
            }

            if (portfolioName == null)
            {
                throw new InvalidOperationException(LocalizedStrings.Str3453);
            }
            else
            {
                throw new InvalidOperationException(LocalizedStrings.Str3454Params.Put(portfolioName));
            }
        }