예제 #1
0
        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();
        }
예제 #2
0
 private void OnClientsUpdated()
 {
     ClientsUpdated?.Invoke(clients.Values.ToList());
 }