Пример #1
0
        public override async Task Handle()
        {
            try
            {
                var account = await GetAccountByToken(Context.Message.Payload.AuthToken);

                var response = new Messages.Server.AuthMessage()
                {
                    UsersList = Context.ConnectionManager.GetOnlineUsers()
                };
                Context.ConnectionManager.AddSocket(account, Context.Socket);
                await Context.ConnectionManager.SendMessageAsync(Context.Socket, response);

                var connectionMessage = new Messages.Server.UserConnectionMessage()
                {
                    Account = account,
                    Status  = ConnectionStatus.Connect
                };
                await Context.ConnectionManager.SendMessageToAllExcludeOneAsync(Context.Socket, connectionMessage);
            }
            catch (Exception ex)
            {
                logger.LogCritical(ex, "Unhandled exception in AuthMessageHandler in method 'Handle'.");
            }
        }
Пример #2
0
        private async Task RemoveSocketAsync(UserDto user)
        {
            try
            {
                ConnectedSockets.TryRemove(user, out var socket);

                var connectionMessage = new Messages.Server.UserConnectionMessage()
                {
                    User   = user,
                    Status = Messages.ConnectionStatus.Disconnect
                };
                await this.SendMessageToAllExcludeOneAsync(socket, connectionMessage);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occurred while removing the socket.");
            }
        }
Пример #3
0
        private async Task RemoveSocketAsync(AccountDto account)
        {
            try
            {
                ConnectedSockets.TryRemove(account, out var socket);

                var connectionMessage = new Messages.Server.UserConnectionMessage()
                {
                    Account = account,
                    Status  = Messages.ConnectionStatus.Disconnect,
                };
                await this.SendMessageToAllExcludeOneAsync(socket, connectionMessage);

                await commandFactory.Execute(new UpdateLastOnlineCommand(account.Id));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occurred while removing the socket.");
            }
            finally
            {
                Metrics.UsersOnline.Set(ConnectedSockets.Count());
            }
        }