private void UpdateClient(RemoteClient remoteClient, T data) { var found = false; foreach (var entry in Swarm) { if (entry.Key.Equals(remoteClient)) { entry.Key.State = remoteClient.State; Swarm.TryUpdate(entry.Key, data, entry.Value); ClientChanged?.Invoke(remoteClient, entry.Value); found = true; } if (DateTime.UtcNow.Subtract(entry.Key.LastMessage.Sent) > _coordinator.ClientExpiryTime) { T removed; if (Swarm.TryRemove(entry.Key, out removed)) { ClientExpired?.Invoke(remoteClient, removed); } } } if (!found) { Swarm.TryAdd(remoteClient, data); ClientAdded?.Invoke(remoteClient, data); } ClientsUpdated?.Invoke(); }
private void OnClientsUpdated() { ClientsUpdated?.Invoke(clients.Values.ToList()); }