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 <List <Comment> > HandleViewComments(Client client, Photo photo)
        {
            ProtocolHelpers.SendRequestCommand(ProtocolConstants.RequestCommands.VIEW_COMMENTS, client.StreamCommunication);

            client.StreamCommunication.Write(ConversionHandler.ConvertLongToBytes(photo.Id));

            ConversionHandler.ConvertBytesToShort(await client.StreamCommunication.ReadAsync(ProtocolConstants.ShortTypeLength));
            ConversionHandler.ConvertBytesToShort(await client.StreamCommunication.ReadAsync(ProtocolConstants.ShortTypeLength));

            var data = await client.StreamCommunication.ReadAsync(ProtocolConstants.IntegerTypeLength);

            var dataLength = ConversionHandler.ConvertBytesToInt(data);

            var result = new List <Comment>();

            while (dataLength != 0)
            {
                var name    = ConversionHandler.ConvertBytesToString(await client.StreamCommunication.ReadAsync(User.UserNameLength));
                var email   = ConversionHandler.ConvertBytesToString(await client.StreamCommunication.ReadAsync(User.UserEmailLength));
                var message = ConversionHandler.ConvertBytesToString(await client.StreamCommunication.ReadAsync(Comment.CommentLength));

                dataLength -= User.UserNameLength + User.UserEmailLength + Comment.CommentLength;
                result.Add(new Comment()
                {
                    Commentator = new User
                    {
                        Email = email,
                        Name  = name
                    },
                    Message = message,
                });
            }

            return(result);
        }
Exemple #3
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));
        }