Пример #1
0
        CloudQueueMessage PrepareCloudMessage(byte[] buffer)
        {
            if (buffer.Length < AzureMessageOverflows.CloudQueueLimit)
            {
                // write message to queue
                return(new CloudQueueMessage(buffer));
            }
            // ok, we didn't fit, so create reference message
            var referenceId = DateTimeOffset.UtcNow.ToString(DateFormatInBlobName) + "-" + Guid.NewGuid().ToString().ToLowerInvariant();

            _cloudBlob.GetBlobReference(referenceId).UploadByteArray(buffer);
            var reference = new EnvelopeReference(_cloudBlob.Uri.ToString(), referenceId);
            var blob      = AzureMessageOverflows.SaveEnvelopeReference(reference);

            return(new CloudQueueMessage(blob));
        }
Пример #2
0
        MessageTransportContext DownloadPackage(CloudQueueMessage message)
        {
            var buffer = message.AsBytes;

            EnvelopeReference reference;

            if (AzureMessageOverflows.TryReadAsEnvelopeReference(buffer, out reference))
            {
                if (reference.StorageContainer != _cloudBlob.Uri.ToString())
                {
                    throw new InvalidOperationException("Wrong container used!");
                }
                var blob = _cloudBlob.GetBlobReference(reference.StorageReference);
                buffer = blob.DownloadByteArray();
            }
            return(new MessageTransportContext(message, buffer, _queueName));
        }