public static void SendRequestCommand(ProtocolConstants.RequestCommands command, StreamCommunication streamCommunication) { var requestData = ConversionHandler.ConvertCommandToByte(ProtocolConstants.Commands.REQUEST); var commandData = ConversionHandler.ConvertRequestCommandToByte(command); streamCommunication.Write(requestData); streamCommunication.Write(commandData); }
public static void SendCommentData(StreamCommunication streamCommunication, Comment comment) { var nameData = ConversionHandler.ConvertStringToBytes(comment.Commentator.Name, User.UserNameLength); var emailData = ConversionHandler.ConvertStringToBytes(comment.Commentator.Email, User.UserEmailLength); var commentData = ConversionHandler.ConvertStringToBytes(comment.Message, Comment.CommentLength); streamCommunication.Write(nameData); streamCommunication.Write(emailData); streamCommunication.Write(commentData); }
public static void SendUserData(StreamCommunication streamCommunication, User user) { var nameData = ConversionHandler.ConvertStringToBytes(user.Name, User.UserNameLength); var emailData = ConversionHandler.ConvertStringToBytes(user.Email, User.UserEmailLength); var lastConnectionData = ConversionHandler.ConvertLongToBytes(user.LastConnection.ToBinary()); streamCommunication.Write(nameData); streamCommunication.Write(emailData); streamCommunication.Write(lastConnectionData); }
public static void SendPhotoData(StreamCommunication streamCommunication, Photo photo) { var email = ConversionHandler.ConvertStringToBytes(photo.User.Email, User.UserEmailLength); var photoId = ConversionHandler.ConvertLongToBytes(photo.Id); var nameData = ConversionHandler.ConvertStringToBytes(photo.Name, Photo.PhotoNameLength); var extData = ConversionHandler.ConvertStringToBytes(photo.Extension, Photo.PhotoExtensionLength); var sizeData = ConversionHandler.ConvertLongToBytes(photo.FileSize); streamCommunication.Write(email); streamCommunication.Write(photoId); streamCommunication.Write(nameData); streamCommunication.Write(extData); streamCommunication.Write(sizeData); }
public static void SendFileWithStream(long fileSize, string path, StreamCommunication streamCommunication) { long fileParts = ProtocolHelpers.CalculateFileParts(fileSize); long offset = 0; long currentPart = 1; while (fileSize > offset) { byte[] data; if (currentPart == fileParts) { var lastPartSize = (int)(fileSize - offset); data = FileStreamHandler.Read(path, offset, lastPartSize); offset += lastPartSize; } else { data = FileStreamHandler.Read(path, offset, ProtocolConstants.MaxPacketSize); offset += ProtocolConstants.MaxPacketSize; } streamCommunication.Write(data); currentPart++; } }