コード例 #1
0
        public static async Task HandleViewUsers(Server server, CommunicationClient client)
        {
            ProtocolHelpers.SendResponseCommand(ProtocolConstants.ResponseCommands.ListUsers,
                                                client.StreamCommunication);

            var clients = (await server.Service.GetUsersAsync()).ToList();
            var length  = clients.Count() * (User.UserEmailLength + User.UserNameLength + ProtocolConstants.DateTimeTypeLength);

            var data = ConversionHandler.ConvertIntToBytes(length);

            client.StreamCommunication.Write(data);
            clients.ForEach((elem) =>
            {
                var user = new User()
                {
                    Name           = elem.Name,
                    Email          = elem.Email,
                    LastConnection = elem.LastConnection
                };
                ProtocolHelpers.SendUserData(client.StreamCommunication, user);
            });
            loggerService.SendMessages("Users listed correctly");
        }