예제 #1
0
파일: ChatHub.cs 프로젝트: ewol123/chat.net
        public async Task CreateUser(CreateUserRequest request)
        {
            try
            {
                request.socketId = Context.ConnectionId;

                var ctx     = new ValidationContext(request);
                var results = new List <ValidationResult>();
                Validator.TryValidateObject(request, ctx, results, true);
                if (results.Count > 0)
                {
                    throw new ApplicationError("[CreateUser]", 4);
                }

                var response = await _userService.CreateUser(request);

                await Clients.Caller.UserCreated(response);
            }
            catch (Exception e)
            {
                var errorResponse = ApplicationError.GetError <CreateUserResponse>(e, "[CreateUser]");
                _logger.LogError(e.Message);
                await Clients.Caller.UserCreated(errorResponse);
            }
        }
예제 #2
0
파일: ChatHub.cs 프로젝트: ewol123/chat.net
        public async Task JoinRoom(JoinRoomRequest request)
        {
            try
            {
                var ctx     = new ValidationContext(request);
                var results = new List <ValidationResult>();
                Validator.TryValidateObject(request, ctx, results, true);
                if (results.Count > 0)
                {
                    throw new ApplicationError("[JoinRoom]", 4);
                }

                var response = await _roomService.JoinRoom(request);

                await Groups.AddToGroupAsync(Context.ConnectionId, response.roomIdentifier.ToString());

                await Clients.Caller.JoinedRoom(response);

                // do not broadcast all the messages for already joined users.
                response.messages = null;
                await Clients.OthersInGroup(response.roomIdentifier.ToString()).BrJoinedRoom(response);
            }
            catch (Exception e)
            {
                var errorResponse = ApplicationError.GetError <JoinRoomResponse>(e, "[JoinRoom]");
                _logger.LogError(e.Message);
                await Clients.Caller.JoinedRoom(errorResponse);
            }
        }
예제 #3
0
파일: ChatHub.cs 프로젝트: ewol123/chat.net
        public async Task LeaveRoom(LeaveRoomRequest request)
        {
            try
            {
                var ctx     = new ValidationContext(request);
                var results = new List <ValidationResult>();
                Validator.TryValidateObject(request, ctx, results, true);
                if (results.Count > 0)
                {
                    throw new ApplicationError("[LeaveRoom]", 4);
                }

                var response = await _roomService.LeaveRoom(request);

                await Groups.RemoveFromGroupAsync(Context.ConnectionId, response.roomIdentifier.ToString());

                await Clients.OthersInGroup(response.roomIdentifier.ToString()).BrLeftRoom(response);

                //user who left the room does not care anymore about the others.
                response.users = null;
                await Clients.Caller.LeftRoom(response);
            }
            catch (Exception e)
            {
                var errorResponse = ApplicationError.GetError <JoinRoomResponse>(e, "[LeaveRoom]");
                _logger.LogError(e.Message);
                await Clients.Caller.JoinedRoom(errorResponse);
            }
        }
예제 #4
0
파일: ChatHub.cs 프로젝트: ewol123/chat.net
        public async Task CreateMessage(CreateMessageRequest request)
        {
            try
            {
                var ctx     = new ValidationContext(request);
                var results = new List <ValidationResult>();
                Validator.TryValidateObject(request, ctx, results, true);
                if (results.Count > 0)
                {
                    throw new ApplicationError("[CreateMessage]", 4);
                }

                var response = await _messageService.CreateMessage(request);

                await Clients.Caller.MessageCreated(response);

                await Clients.OthersInGroup(response.roomIdentifier.ToString()).BrMessageCreated(response);
            }
            catch (Exception e)
            {
                var errorResponse = ApplicationError.GetError <CreateMessageResponse>(e, "[CreateMessage]");
                _logger.LogError(e.Message);
                await Clients.Caller.MessageCreated(errorResponse);
            }
        }
예제 #5
0
파일: ChatHub.cs 프로젝트: ewol123/chat.net
        public async Task CreateChimeMeeting(CreateChimeMeetingRequest request)
        {
            try
            {
                var ctx     = new ValidationContext(request);
                var results = new List <ValidationResult>();
                Validator.TryValidateObject(request, ctx, results, true);
                if (results.Count > 0)
                {
                    throw new ApplicationError("[CreateChimeMeeting]", 4);
                }

                var response = await _chimeService.CreateChimeMeeting(request);

                await Clients.Caller.ChimeMeetingCreated(response);
            }
            catch (Exception e)
            {
                var errorResponse = ApplicationError.GetError <CreateChimeMeetingResponse>(e, "[CreateChimeMeeting]");
                _logger.LogError(e.Message);
                await Clients.Caller.ChimeMeetingCreated(errorResponse);
            }
        }