示例#1
0
        //
        // Summary:
        //   Gets all the users connected to a given chat room across all application instances hosting such room.
        //   If the room is not found, it raises an exception.
        //
        // Raises:
        //   ObjectDoesNotExistException - if the chat room was not found.
        public async Task <ChatRoomConnectionPool> GetChatRoomConnectionPool(string chatRoomName)
        {
            _logger.LogInformation("Getting connection store for chat room name: {chatRoomName:l}", chatRoomName);
            var chatRoom = await GetChatRoom(chatRoomName);

            _logger.LogInformation("Chat room exists, attempting to retrieve a previous connection pool from Redis...");
            var chatRoomActiveConnectionPool = await _redis.GetKey <ChatRoomConnectionPool>(chatRoom.Id);

            if (chatRoomActiveConnectionPool != null)
            {
                return(chatRoomActiveConnectionPool);
            }

            _logger.LogInformation("Chat room had no previous connection pool on Redis. Creating a new one...");
            var newChatRoomConnectionPool = new ChatRoomConnectionPool
            {
                ChatRoomId             = chatRoom.Id,
                ActiveConnectionsLimit = chatRoom.ActiveConnectionsLimit,
                TotalActiveConnections = 0,
                ServerInstances        = new List <ServerInstance>()
            };

            return(newChatRoomConnectionPool);
        }