public static async Task HandleUploadPhoto(Server server, CommunicationClient client) { var name = ConversionHandler.ConvertBytesToString(await client.StreamCommunication.ReadAsync(Photo.PhotoNameLength)); var extension = ConversionHandler.ConvertBytesToString(await client.StreamCommunication.ReadAsync(Photo.PhotoExtensionLength)); var fileSize = ConversionHandler.ConvertBytesToLong(await client.StreamCommunication.ReadAsync(ProtocolConstants.LongTypeLength)); if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(extension)) { ProtocolHelpers.SendMessageCommand(ProtocolConstants.ResponseCommands.Ok, client, "Input Error"); } var photo = new PhotoDto() { Name = name, Extension = extension, FileSize = fileSize, UserEmail = client.User.Email }; await server.Service.UploadPhotoAsync(photo); var fileName = $"{PhotosPath}\\Image_{photo.Id}{extension}"; await FileHandler.ReceiveFileWithStreams(fileSize, fileName, client.StreamCommunication); loggerService.SendMessages("Image uploaded"); ProtocolHelpers.SendMessageCommand(ProtocolConstants.ResponseCommands.Ok, client, "Added succesfully"); }
public static async Task HandleCommentPhoto(Server server, CommunicationClient client) { var photoIdParsed = ConversionHandler.ConvertBytesToLong(await client.StreamCommunication.ReadAsync(ProtocolConstants.LongTypeLength)); var message = ConversionHandler.ConvertBytesToString(await client.StreamCommunication.ReadAsync(Comment.CommentLength)); if (string.IsNullOrWhiteSpace(message)) { ProtocolHelpers.SendMessageCommand(ProtocolConstants.ResponseCommands.Ok, client, "Input Error"); } var comment = new CommentDto() { PhotoId = photoIdParsed, Message = message, UserEmail = client.User.Email, }; await server.Service.AddCommentAsync(comment); loggerService.SendMessages("Image commented"); ProtocolHelpers.SendMessageCommand(ProtocolConstants.ResponseCommands.Ok, client, "Added Sucessfully"); }