Пример #1
0
        public static async Task HandleViewPhotos(Server server, CommunicationClient client)
        {
            ProtocolHelpers.SendResponseCommand(ProtocolConstants.ResponseCommands.ListPhotos,
                                                client.StreamCommunication);

            var photos = await server.Service.GetPhotosAsync();

            var length = photos.Count() * (User.UserEmailLength + ProtocolConstants.LongTypeLength + Photo.PhotoNameLength + Photo.PhotoExtensionLength + ProtocolConstants.LongTypeLength);

            var data = ConversionHandler.ConvertIntToBytes(length);

            client.StreamCommunication.Write(data);
            photos.ForEach((elem) =>
            {
                var photo = new Photo()
                {
                    Id        = elem.Id,
                    Name      = elem.Name,
                    Extension = elem.Extension,
                    FileSize  = elem.FileSize,
                    User      = new User()
                    {
                        Email = elem.UserEmail
                    }
                };
                ProtocolHelpers.SendPhotoData(client.StreamCommunication, photo);
            });

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