示例#1
0
        // Creates a Message object from a string.
        public static Message CreateMessage(byte messageType, string messageText, User to, User from)
        {
            MessageBody messageBody = new MessageBody();

            messageBody.Body = messageText;

            if (messageType == 1)
            {
                // Creates a Message.
                return(new PlainMessage(to, from, messageBody));
            }
            else if (messageType == 2)
            {
                // For Camilla's server.
                Message message = new Message(to, from, messageBody);

                // For the class server.
                // SocketMessage message = new SocketMessage(to, from, messageBody);

                // Creates an XMLMessage.
                return(new XMLMessage(to, from, messageBody, SerializeElement(message)));
            }
            else if (messageType == 3)
            {
                // Encrypts the message.
                messageBody.Body = Convert.ToBase64String(EncryptSymmetricMessage(messageBody.Body));

                // For Camilla's server.
                Message message = new Message(to, from, messageBody);

                // For the class server.
                // SocketMessage message = new SocketMessage(to, from, messageBody);

                // Creates a SymmetricMessage.
                return(new SymmetricMessage(to, from, messageBody, SerializeElement(message)));
            }
            else if (messageType == 4)
            {
                // Creates a AsymmetricMessage.
                throw new NotImplementedException();
            }
            else
            {
                // Returns null in case of error.
                return(null);
            }
        }
示例#2
0
 public AsymmetricMessage(User to, User from, MessageBody mb) : base(to, from, mb)
 {
 }
示例#3
0
 public Message(User to, User from, MessageBody mb)
 {
     To   = to;
     From = from;
     Mb   = mb;
 }
 public XMLMessage(User to, User from, MessageBody mb, byte[] messageBuffer) : base(to, from, mb)
 {
     MessageBuffer = messageBuffer;
 }