public override Task OnReconnected() { var userId = Context.User.GetCurrentUserAccount(_context.Accounts).Id; if (!_userConnections.GetConnections(userId).Contains(Context.ConnectionId)) { _userConnections.Add(userId, Context.ConnectionId); } return(base.OnReconnected()); }
public override Task OnReconnected() { var deviceId = Context.User.GetCurrentUserAccount(_context.Devices).Id; if (!_connections.GetConnections(deviceId).Contains(Context.ConnectionId)) { _connections.Add(deviceId, Context.ConnectionId); } return(base.OnReconnected()); }
public T SendMessageAndWaitForResponse( K connectionMappingKey, U parameter) { var requestId = Guid.NewGuid(); var tcs = new TaskCompletionSource <T>(); _taskCompletionSources[requestId] = tcs; var connection = _connectionMapping.GetConnections(connectionMappingKey) .FirstOrDefault(); if (string.IsNullOrEmpty(connection)) { throw new ConnectionNotFoundException <K>(connectionMappingKey); } Clients.Client(connection) .getResponse(requestId, parameter); Task.Delay(Timeout) .ContinueWith(task => tcs.TrySetCanceled()); try { tcs.Task.Wait(); } catch (AggregateException ex) { if (ex.InnerException is TaskCanceledException) { throw new ClientNotRespondingException <K>(connectionMappingKey, Timeout); } } finally { _taskCompletionSources.Remove(requestId); } return(tcs.Task.Result); }