ToBytes() public method

public ToBytes ( ) : byte[]
return byte[]
 protected override Task Send(int streamIndex, IList<Message> messages)
 {
     return Task.Factory.StartNew(() =>
         {
             ScaleoutMessage msg = new ScaleoutMessage(messages);
             Bus.Send<DistributeMessages>(m => { m.Payload = msg.ToBytes(); m.StreamIndex = streamIndex; });
         });
 }
        public static string ToScaleoutString(this IList<Message> messages)
        {
            if (messages == null)
            {
                throw new ArgumentNullException("messages");
            }

            var message = new ScaleoutMessage(messages);
            return Convert.ToBase64String(message.ToBytes());
        }
Ejemplo n.º 3
0
        public static byte[] ToBytes(IList<Message> messages)
        {
            if (messages == null)
            {
                throw new ArgumentNullException("messages");
            }

            var message = new ScaleoutMessage(messages);
            return message.ToBytes();
        }
Ejemplo n.º 4
0
        public static Stream ToStream(IList<Message> messages)
        {
            if (messages == null)
            {
                throw new ArgumentNullException("messages");
            }

            var scaleoutMessage = new ScaleoutMessage(messages);
            return new MemoryStream(scaleoutMessage.ToBytes());
        }
Ejemplo n.º 5
0
        public static byte[] ToBytes(IList<Message> messages)
        {
            using (var ms = new MemoryStream())
            {
                var binaryWriter = new BinaryWriter(ms);

                var scaleoutMessage = new ScaleoutMessage(messages);
                var buffer = scaleoutMessage.ToBytes();

                binaryWriter.Write(buffer.Length);
                binaryWriter.Write(buffer);

                return ms.ToArray();
            }
        }
        void FromBytesToBytesProducesCorrectValues()
        {
            var message = new Message("source", "key", "value");
            var message2 = new Message("string", "more", "str");
            var message3 = new Message("s", "l", "n");
            var scaleoutMessage = new ScaleoutMessage(new List<Message>() { message, message2, message3 });

            var bytes = scaleoutMessage.ToBytes();
            var msg = ScaleoutMessage.FromBytes(bytes);

            Assert.True(scaleoutMessage.Messages.Count == 3);
            Assert.True(scaleoutMessage.Messages[0].Source == msg.Messages[0].Source, "Source is not the same");
            Assert.True(scaleoutMessage.Messages[0].Key == msg.Messages[0].Key, "Key is not the same");
            Assert.True(scaleoutMessage.Messages[0].GetString() == msg.Messages[0].GetString(), "Value is not the same");
        }
        protected override Task Send(int streamIndex, IList<Message> messages)
        {
            return Task.Run(() =>
            {
                var scaleoutMsg = new ScaleoutMessage(messages);

                var msg = new RmqMessage
                {
                    StreamIndex = streamIndex,
                    Id = 0,
                    Body = scaleoutMsg.ToBytes()
                };

                var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(msg));

                model.BasicPublish("messages", "", true, new BasicProperties(), body);
            });
        }
Ejemplo n.º 8
0
        public static byte[] ToBytes(IList<Message> messages)
        {
            if (messages == null)
            {
                throw new ArgumentNullException("messages");
            }

            using (var ms = new MemoryStream())
            {
                var binaryWriter = new BinaryWriter(ms);

                var scaleoutMessage = new ScaleoutMessage(messages);
                var buffer = scaleoutMessage.ToBytes();

                binaryWriter.Write(buffer.Length);
                binaryWriter.Write(buffer);

                return ms.ToArray();
            }
        }
Ejemplo n.º 9
0
 public static byte[] ToBytes([NotNull] IList<Message> messages)
 {
     var message = new ScaleoutMessage(messages);
     return message.ToBytes();
 }