コード例 #1
0
ファイル: ChatService.cs プロジェクト: skalinets/JabbR
        public void AddClient(ChatUser user, string clientId)
        {
            var client = new ChatClient
            {
                Id = clientId,
                User = user
            };

            _repository.Add(client);
            _repository.CommitChanges();
        }
コード例 #2
0
ファイル: ChatService.cs プロジェクト: alexkopy/JabbR
        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;
        }
コード例 #3
0
        // 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();
        }
コード例 #4
0
 public void Add(ChatClient client)
 {
     _db.Clients.Add(client);
     _db.SaveChanges();
 }
コード例 #5
0
 public void Remove(ChatClient client)
 {
     _db.Clients.Remove(client);
     _db.SaveChanges();
 }
コード例 #6
0
 public void Remove(ChatClient client)
 {
     var user = _users.FirstOrDefault(u => client.User == u);
     user.ConnectedClients.Remove(client);
 }
コード例 #7
0
ファイル: ChatService.cs プロジェクト: stevesloka/JabbR
        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();
        }
コード例 #8
0
 public void Remove(ChatClient client)
 {
     _db.Clients.Remove(client);
     _db.SaveChanges();
 }
コード例 #9
0
 public void Add(ChatClient client)
 {
     _db.Clients.Add(client);
     _db.SaveChanges();
 }
コード例 #10
0
        public void Remove(ChatClient client)
        {
            var user = _users.FirstOrDefault(u => client.User == u);

            user.ConnectedClients.Remove(client);
        }