public XElement Serialize(Message message, string elementName = "message")
        {
            message.ThrowIfNull("message");
            elementName.ThrowIfNull("elementName");

            return new XElement(
                elementName,
                MessagePartSerializer.Instance.Serialize(message.Parts),
                new XAttribute("id", message.Id),
                new XAttribute("name", message.Name),
                new XAttribute("description", message.Description),
                new XAttribute("backgroundColor", ColorSerializer.Instance.Serialize(message.BackgroundColor)));
        }
        public byte[] Serialize(Message message)
        {
            message.ThrowIfNull("message");

            var serializer = new CompactSerializer();

            serializer[0] = message.Id.ToByteArray();
            serializer[1] = Encoding.UTF8.GetBytes(message.Name);
            serializer[2] = Encoding.UTF8.GetBytes(message.Description);
            serializer[3] = ColorSerializer.Instance.Serialize(message.BackgroundColor);

            var partSerializer = new CompactSerializer();
            int index = 0;

            foreach (IMessagePart part in message.Parts)
            {
                partSerializer[index++] = MessagePartSerializer.Instance.Serialize(part);
            }

            serializer[4] = partSerializer.Serialize();

            return serializer.Serialize();
        }
        public MessageCommand(Message message)
        {
            message.ThrowIfNull("message");

            _message = message;
        }
Exemple #4
0
 public static MessageCommand Message(Message message)
 {
     return new MessageCommand(message);
 }