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); }); }
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); }
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); }