コード例 #1
0
 public void Write(IConfigureCloudQueueMessageEnvelope envelope, JsonWriter writer)
 {
     if (envelope == null) throw new ArgumentNullException("envelope");
     if (writer == null) throw new ArgumentNullException("writer");
     writer.WriteStartObject();
     writer.WritePropertyName("From");
     writer.WriteValue(envelope.From);
     writer.WritePropertyName("To");
     writer.WriteValue(envelope.To);
     writer.WritePropertyName("MessageId");
     writer.WriteValue(envelope.MessageId);
     if (envelope.RelatesToMessageId.HasValue)
     {
         writer.WritePropertyName("RelatesToMessageId");
         writer.WriteValue(envelope.RelatesToMessageId.Value);
     }
     writer.WritePropertyName("CorrelationId");
     writer.WriteValue(envelope.CorrelationId);
     writer.WritePropertyName("ContentType");
     writer.WriteValue(envelope.ContentType);
     writer.WritePropertyName("Content");
     writer.WriteValue(envelope.Content);
     writer.WritePropertyName("Time");
     writer.WriteValue(envelope.Time);
     writer.WriteEndObject();
 }
コード例 #2
0
 private byte[] WriteEnvelopeToContent(IConfigureCloudQueueMessageEnvelope envelope)
 {
     using (var stream = new MemoryStream())
     {
         using (var streamWriter = new StreamWriter(stream))
         {
             using (var jsonWriter = new JsonTextWriter(streamWriter))
             {
                 QueueWriter.Write(envelope, jsonWriter);
                 jsonWriter.Flush();
                 return stream.ToArray();
             }
         }
     }
 }
コード例 #3
0
        public void Send(IConfigureCloudQueueMessageEnvelope envelope)
        {
            if (envelope == null) throw new ArgumentNullException("envelope");

            var content = WriteEnvelopeToContent(envelope);
            if (content.Length > Limits.CloudQueueMessageContentLimit)
            {
                var blobId = SerialGuid.NewGuid();
                BlobWriter.Write(envelope.ToBlobEnvelope(blobId));

                envelope = envelope.
                    SetContentType(ContentTypes.BlobReference).
                    SetContent(blobId.ToByteArray());

                content = WriteEnvelopeToContent(envelope);
            }
            Sender.Send(envelope.To, new CloudQueueMessage(content));
        }