Ejemplo n.º 1
0
        /// <summary>
        /// Register new chat handle and associate it with the connection id.
        /// Exception is thrown if handle is in use or invalid
        /// </summary>
        /// <param name="handle">Handle to register</param>
        public async Task RegisterHandle(string handle)
        {
            if (string.IsNullOrWhiteSpace(handle))
            {
                throw new ChatHubException("Illegal handle");
            }

            var activeUsers = await _activeUserRepository.GetActiveUsers();

            if (activeUsers.Select(u => u.Handle).Contains(handle))
            {
                throw new ChatHubException("Handle is taken");
            }

            await Clients.All.SendAsync(NewUserMethod, handle);

            await _activeUserRepository.AddActiveUser(new User
            {
                Id     = Context.ConnectionId,
                Handle = handle
            });
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <string> > GetAllActive()
        {
            var users = await _activeUserRepository.GetActiveUsers();

            return(users.Select(m => m.Handle));
        }