Example #1
0
 public UnpackedMessage(MessageHeader header, MessageAttributesContract attributes, object content, Type contractType)
 {
     Header       = header;
     ContractType = contractType;
     Attributes   = attributes;
     Content      = content;
 }
Example #2
0
        /// <summary>
        /// Nicely prints the attributes to the text writer.
        /// </summary>
        /// <param name="attributes">The attributes.</param>
        /// <param name="writer">The writer.</param>
        /// <param name="indent">The indent.</param>
        public static void PrintAttributes(MessageAttributesContract attributes, TextWriter writer, string indent = "")
        {
            var max = attributes.Items.Max(a => a.GetName().Length);

            foreach (var item in attributes.Items)
            {
                writer.Write(indent);
                writer.WriteLine("{0,-" + (max + 2) + "} : {1}", item.GetName(), GetNiceValue(item));
            }
        }
        /// <summary>
        /// Nicely prints the attributes to the text writer.
        /// </summary>
        /// <param name="attributes">The attributes.</param>
        /// <param name="writer">The writer.</param>
        /// <param name="indent">The indent.</param>
        public static void PrintAttributes(MessageAttributesContract attributes, TextWriter writer, string indent = "")
        {
            var max = attributes.Items.Max(a => a.GetName().Length);

            foreach (var item in attributes.Items)
            {
                writer.Write(indent);
                writer.WriteLine("{0,-" + (max + 2) + "} : {1}", item.GetName(), GetNiceValue(item));
            }
        }
Example #4
0
        public static MemoryStream SaveReferenceMessageToStream(MessageAttributesContract attributes)
        {
            var stream = new MemoryStream();

            // skip header
            stream.Seek(MessageHeader.FixedSize, SeekOrigin.Begin);

            // write reference
            Serializer.Serialize(stream, attributes);
            long attributesLength = stream.Position - MessageHeader.FixedSize;

            // write header
            stream.Seek(0, SeekOrigin.Begin);
            Serializer.Serialize(stream, MessageHeader.ForReference(attributesLength, 0));
            return(stream);
        }
Example #5
0
        public static MemoryStream SaveDataMessageToStream(MessageAttributesContract messageAttributes, Action <Stream> message)
        {
            var stream = new MemoryStream();

            // skip header
            stream.Seek(MessageHeader.FixedSize, SeekOrigin.Begin);

            // save attributes

            Serializer.Serialize(stream, messageAttributes);
            var attributesLength = stream.Position - MessageHeader.FixedSize;

            // save message
            message(stream);
            var bodyLength = stream.Position - attributesLength - MessageHeader.FixedSize;

            // write the header
            stream.Seek(0, SeekOrigin.Begin);
            var messageHeader = MessageHeader.ForData(attributesLength, bodyLength, 0);

            Serializer.Serialize(stream, messageHeader);
            return(stream);
        }
 public MessageAttributeBuilder(MessageAttributesContract attributes)
     : this(attributes.Items)
 {
 }
 public MessageAttributeBuilder(MessageAttributesContract attributes) : this(attributes.Items)
 {
 }