Exemple #1
0
        public static async Task <MessageResponse> HandleImageUpload(Client client, string filePath)
        {
            if (!FileHandler.FileExists(filePath))
            {
                return new MessageResponse()
                       {
                           responseCommands = ProtocolConstants.ResponseCommands.Error,
                           Message          = "Invalid File",
                       }
            }
            ;

            var nameData      = ConversionHandler.ConvertStringToBytes(FileHandler.FileName(filePath), Photo.PhotoNameLength);
            var extensionData = ConversionHandler.ConvertStringToBytes(FileHandler.FileExtension(filePath), Photo.PhotoExtensionLength);
            var fileSize      = FileHandler.GetFileSize(filePath);
            var fileSizeData  = ConversionHandler.ConvertLongToBytes(fileSize);

            ProtocolHelpers.SendRequestCommand(ProtocolConstants.RequestCommands.UPLOAD_PHOTO, client.StreamCommunication);

            client.StreamCommunication.Write(nameData);
            client.StreamCommunication.Write(extensionData);
            client.StreamCommunication.Write(fileSizeData);

            FileHandler.SendFileWithStream(fileSize, filePath, client.StreamCommunication);

            return(await ProtocolHelpers.RecieveMessageCommand(client.StreamCommunication));
        }
Exemple #2
0
        public static async Task <MessageResponse> HandleCommentCreation(Client client, Comment comment)
        {
            ProtocolHelpers.SendRequestCommand(ProtocolConstants.RequestCommands.COMMENT_PHOTO, client.StreamCommunication);

            var photoIdData = ConversionHandler.ConvertLongToBytes(comment.Photo.Id);
            var commentData = ConversionHandler.ConvertStringToBytes(comment.Message, Comment.CommentLength);

            client.StreamCommunication.Write(photoIdData);
            client.StreamCommunication.Write(commentData);

            return(await ProtocolHelpers.RecieveMessageCommand(client.StreamCommunication));
        }
Exemple #3
0
        public static async Task <MessageResponse> HandleLogin(Client client, User user)
        {
            ProtocolHelpers.SendRequestCommand(ProtocolConstants.RequestCommands.LOGIN, client.StreamCommunication);

            var email    = ConversionHandler.ConvertStringToBytes(user.Email, User.UserEmailLength);
            var password = ConversionHandler.ConvertStringToBytes(user.Password, User.UserPasswordLength);

            client.StreamCommunication.Write(email);
            client.StreamCommunication.Write(password);

            return(await ProtocolHelpers.RecieveMessageCommand(client.StreamCommunication));
        }
Exemple #4
0
        public static async Task <MessageResponse> HandleRegister(Client client, User user)
        {
            ProtocolHelpers.SendRequestCommand(ProtocolConstants.RequestCommands.CREATE_USER, client.StreamCommunication);

            var name     = ConversionHandler.ConvertStringToBytes(user.Name, User.UserNameLength);
            var email    = ConversionHandler.ConvertStringToBytes(user.Email, User.UserEmailLength);
            var password = ConversionHandler.ConvertStringToBytes(user.Password, User.UserPasswordLength);

            client.StreamCommunication.Write(email);
            client.StreamCommunication.Write(name);
            client.StreamCommunication.Write(password);
            var response = await ProtocolHelpers.RecieveMessageCommand(client.StreamCommunication);

            return(response);
        }