public void AddClient(ChatUser user, string clientId) { var client = new ChatClient { Id = clientId, User = user }; _repository.Add(client); _repository.CommitChanges(); }
public ChatClient AddClient(ChatUser user, string clientId, string userAgent) { ChatClient client = _repository.GetClientById(clientId); if (client != null) { return client; } client = new ChatClient { Id = clientId, User = user, UserAgent = userAgent, LastActivity = DateTimeOffset.UtcNow }; _repository.Add(client); _repository.CommitChanges(); return client; }
// This is an uber hack to make sure the db is in sync with SignalR private void EnsureClientConnected(ILogger logger, IJabbrRepository repo, ITrackingConnection connection) { var contextField = connection.GetType().GetField("_context", BindingFlags.NonPublic | BindingFlags.Instance); if (contextField == null) { return; } var context = contextField.GetValue(connection) as HostContext; if (context == null) { return; } string connectionData = context.Request.QueryString["connectionData"]; if (String.IsNullOrEmpty(connectionData)) { return; } var hubs = JsonConvert.DeserializeObject<HubConnectionData[]>(connectionData); if (hubs.Length != 1) { return; } // We only care about the chat hub if (!hubs[0].Name.Equals("chat", StringComparison.OrdinalIgnoreCase)) { return; } logger.Log("Connection {0} exists but isn't tracked.", connection.ConnectionId); string userId = context.Request.User.GetUserId(); ChatUser user = repo.GetUserById(userId); if (user == null) { logger.Log("Unable to find user with id {0}", userId); return; } var client = new ChatClient { Id = connection.ConnectionId, User = user, UserAgent = context.Request.Headers["User-Agent"], LastActivity = DateTimeOffset.UtcNow, LastClientActivity = user.LastActivity }; repo.Add(client); repo.CommitChanges(); }
public void Add(ChatClient client) { _db.Clients.Add(client); _db.SaveChanges(); }
public void Remove(ChatClient client) { _db.Clients.Remove(client); _db.SaveChanges(); }
public void Remove(ChatClient client) { var user = _users.FirstOrDefault(u => client.User == u); user.ConnectedClients.Remove(client); }
public void AddClient(ChatUser user, string clientId, string userAgent) { var client = new ChatClient { Id = clientId, User = user, UserAgent = userAgent, LastActivity = DateTimeOffset.UtcNow }; _repository.Add(client); _repository.CommitChanges(); }
public void Remove(ChatClient client) { _db.Clients.Remove(client); _db.SaveChanges(); }
public void Add(ChatClient client) { _db.Clients.Add(client); _db.SaveChanges(); }
public void Remove(ChatClient client) { var user = _users.FirstOrDefault(u => client.User == u); user.ConnectedClients.Remove(client); }