Exemplo n.º 1
0
        public static async Task HandleViewCommentsPhoto(FileServer.Server server, CommunicationClient client)
        {
            var photoIdParsed = ConversionHandler.ConvertBytesToLong(await client.StreamCommunication.ReadAsync(ProtocolConstants.LongTypeLength));

            ProtocolHelpers.SendResponseCommand(ProtocolConstants.ResponseCommands.ListComments,
                                                client.StreamCommunication);

            var photo = new PhotoDto()
            {
                Id = photoIdParsed
            };
            var comments = await server.Service.GetCommentsAsync(photo);

            var length = comments.Count() * (User.UserEmailLength + User.UserNameLength + Comment.CommentLength);

            var data = ConversionHandler.ConvertIntToBytes(length);

            client.StreamCommunication.Write(data);

            comments.ToList().ForEach((elem) =>
            {
                var comment = new Comment()
                {
                    Message     = elem.Message,
                    Commentator = new User()
                    {
                        Email = elem.UserEmail,
                        Name  = elem.UserName
                    }
                };
                ProtocolHelpers.SendCommentData(client.StreamCommunication, comment);
            });

            loggerService.SendMessages("Comments listed correctly");
        }