public void AddOrUpdate(Guid id, SubscriptionEntry subscription)
        {
            var connectionSubscriptions =
                dictionary.AddOrUpdate(id,
                                       connection =>
            {
                var handler = SubscriptionAdded;
                if (handler != null)
                {
                    handler.Invoke(subscription, EventArgs.Empty);
                }

                return(subscription);
            },
                                       (connection, oldSubscription) =>
            {
                oldSubscription.Subscription  = subscription.Subscription;
                oldSubscription.PendingUpdate = subscription.PendingUpdate;

                var handler = SubscriptionUpdated;
                if (handler != null)
                {
                    handler.Invoke(oldSubscription, EventArgs.Empty);
                }

                return(oldSubscription);
            });
        }
Пример #2
0
        public void Subscribe(Subscription subscription)
        {
            var connection        = Context.ConnectionId;
            var subscriptionEntry = new SubscriptionEntry(subscription, Clients.Client(connection));

            subscriptionEntry.PendingUpdate = true;
            subscriptions.AddOrUpdate(Guid.Parse(connection), subscriptionEntry);
        }
Пример #3
0
        private bool UpdateSubscription(SubscriptionEntry subscription, DateTime currentTime)
        {
            if (subscription.PendingUpdate)
            {
                return(true);
            }

            if (subscription.LastUpdateTime == null)
            {
                return(true);
            }

            if (currentTime - subscription.LastUpdateTime > updateInterval)
            {
                return(true);
            }

            return(false);
        }