private void ApolloClient_SubscriptionRouteAdded(object sender, ApolloSubscriptionFieldEventArgs e) { var client = sender as ApolloClientProxy <TSchema>; if (client == null) { return; } var names = SubscriptionEventName.FromGraphField(_schema, e.Field); foreach (var name in names) { lock (_syncLock) { if (!_subCountByName.ContainsKey(name)) { _subCountByName.Add(name, new HashSet <ApolloClientProxy <TSchema> >()); } _subCountByName[name].Add(client); if (_subCountByName[name].Count == 1) { _eventRouter.AddReceiver(name, this); _logger?.EventMonitorStarted(name); } } } }
private void ApolloClient_SubscriptionRouteRemoved(object sender, ApolloSubscriptionFieldEventArgs e) { var client = sender as ApolloClientProxy <TSchema>; if (client == null) { return; } var names = SubscriptionEventName.FromGraphField(_schema, e.Field); foreach (var name in names) { lock (_syncLock) { if (_subCountByName.TryGetValue(name, out var clients)) { if (clients.Contains(client)) { clients.Remove(client); if (clients.Count == 0) { _subCountByName.Remove(name); _eventRouter.RemoveReceiver(name, this); _logger?.EventMonitorEnded(name); } } } } } }