protected override AmqpMessage CreateAmqpMessage() { AmqpMessage nullable = null; int num = this.eventDatas.Count <EventData>(); if (this.eventDatas != null && num > 1) { IList <Data> datas = new List <Data>(); EventData eventDatum = null; foreach (EventData eventData in this.eventDatas) { if (eventDatum != null) { if (eventDatum.PartitionKey != eventData.PartitionKey) { throw Fx.Exception.AsError(new InvalidOperationException(SRClient.EventHubSendBatchMismatchPartitionKey(eventDatum.PartitionKey ?? "(null)", eventData.PartitionKey ?? "(null)")), null); } if (eventDatum.Publisher != eventData.Publisher) { throw Fx.Exception.AsError(new InvalidOperationException(SRClient.EventHubSendBatchMismatchPublisher(eventDatum.Publisher ?? "(null)", eventData.Publisher ?? "(null)")), null); } } else { eventDatum = eventData; } AmqpMessage amqpMessage = eventData.ToAmqpMessage(); amqpMessage.Batchable = base.Batchable; if ((int)(amqpMessage.Sections & (SectionFlag.DeliveryAnnotations | SectionFlag.MessageAnnotations | SectionFlag.Properties | SectionFlag.ApplicationProperties)) == 0 && (eventData.BodyStream == null || eventData.BodyStream == Stream.Null)) { throw new InvalidOperationException(SRClient.CannotSendAnEmptyEvent(eventData.GetType().Name)); } ArraySegment <byte> nums = MessageConverter.ReadStream(amqpMessage.ToStream()); datas.Add(new Data() { Value = nums }); } nullable = AmqpMessage.Create(datas); nullable.Batchable = true; nullable.MessageFormat = new uint?(-2147404032); MessageConverter.UpdateAmqpMessageHeadersAndProperties(nullable, eventDatum, false); } else if (this.eventDatas != null && num == 1) { EventData eventDatum1 = this.eventDatas.First <EventData>(); nullable = eventDatum1.ToAmqpMessage(); nullable.Batchable = base.Batchable; if ((int)(nullable.Sections & (SectionFlag.DeliveryAnnotations | SectionFlag.MessageAnnotations | SectionFlag.Properties | SectionFlag.ApplicationProperties)) == 0 && (eventDatum1.BodyStream == null || eventDatum1.BodyStream == Stream.Null)) { throw new InvalidOperationException(SRClient.CannotSendAnEmptyEvent(eventDatum1.GetType().Name)); } } return(nullable); }
public static BrokeredMessage BrokerGetMessage(AmqpMessage amqpMessage, bool shouldOptimizeForPassthrough) { BrokeredMessage brokeredMessage; if (!shouldOptimizeForPassthrough) { amqpMessage.Deserialize(SectionFlag.All); brokeredMessage = new BrokeredMessage(amqpMessage.GetNonBodySectionsStream(), true, amqpMessage.GetBodySectionStream(), true, BrokeredMessageFormat.Amqp); } else { amqpMessage.Deserialize(SectionFlag.Header | SectionFlag.DeliveryAnnotations | SectionFlag.MessageAnnotations | SectionFlag.Properties | SectionFlag.ApplicationProperties); brokeredMessage = new BrokeredMessage(null, false, amqpMessage.ToStream(), true, BrokeredMessageFormat.PassthroughAmqp); } if (amqpMessage.RawByteBuffers != null) { brokeredMessage.AttachDisposables(amqpMessage.RawByteBuffers.GetClones()); } MessageConverter.UpdateBrokeredMessageHeaderAndProperties(amqpMessage, brokeredMessage); return(brokeredMessage); }