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"); }
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"); }
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"); }