Ejemplo n.º 1
0
        private static AmqpMessage CreateAmqpMessageFromSbmpMessage(BrokeredMessage brokeredMessage)
        {
            AmqpMessage amqpMessage;
            object      obj  = brokeredMessage.ClearBodyObject();
            object      obj1 = null;

            if (obj != null)
            {
                MessageConverter.TryGetAmqpObjectFromNetObject(obj, MappingType.MessageBody, out obj1);
            }
            if (obj1 != null)
            {
                AmqpValue amqpValue = new AmqpValue()
                {
                    Value = obj1
                };
                amqpMessage = AmqpMessage.Create(amqpValue);
            }
            else if (brokeredMessage.BodyStream == null)
            {
                amqpMessage = AmqpMessage.Create();
            }
            else
            {
                if (brokeredMessage.BodyStream.CanSeek && brokeredMessage.BodyStream.Position != (long)0)
                {
                    throw new InvalidOperationException(SRClient.CannotSerializeMessageWithPartiallyConsumedBodyStream);
                }
                amqpMessage = AmqpMessage.Create(brokeredMessage.BodyStream, false);
            }
            return(amqpMessage);
        }
Ejemplo n.º 2
0
            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);
            }
Ejemplo n.º 3
0
            public void Send(object value, Action <object> callback, object state)
            {
                this.EnsureLink();
                AmqpMessage message = AmqpMessage.Create(new AmqpValue()
                {
                    Value = value
                });

                message.CompleteCallback = callback;
                message.UserToken        = state;
                this.sender.DoWork(message);
            }
Ejemplo n.º 4
0
            public AmqpMessage GetMessage()
            {
                AmqpMessage message = AmqpMessage.Create(this.bufferList.ToArray());

                this.bufferList = null;

                message.DeliveryTag  = this.DeliveryTag;
                message.DeliveryId   = this.DeliveryId;
                message.TxnId        = this.TxnId;
                message.Settled      = this.Settled;
                message.Batchable    = this.Batchable;
                message.State        = this.State;
                message.StateChanged = this.StateChanged;
                message.Link         = this.Link;

                return(message);
            }
Ejemplo n.º 5
0
            protected override void OnInitialize()
            {
                // mask off immutable sections except footer
                this.properties            = null;
                this.applicationProperties = null;
                this.footer = null;

                BufferListStream stream = this.messageStream as BufferListStream;

                if (stream != null && !this.ownStream)
                {
                    stream = (BufferListStream)stream.Clone();
                }
                else
                {
                    int length = 0;
                    ArraySegment <byte>[] buffers = AmqpMessage.ReadStream(this.messageStream, 512, out length);
                    stream = new BufferListStream(buffers);
                }

                AmqpMessageReader reader       = new AmqpMessageReader(stream);
                AmqpMessage       emptyMessage = AmqpMessage.Create();

                reader.ReadMessage(emptyMessage, SectionFlag.Header | SectionFlag.DeliveryAnnotations | SectionFlag.MessageAnnotations);
                this.UpdateHeader(emptyMessage.header);
                this.UpdateDeliveryAnnotations(emptyMessage.deliveryAnnotations);
                this.UpdateMessageAnnotations(emptyMessage.messageAnnotations);

                // read out the remaining buffers
                bool unused = false;

                this.buffers = stream.ReadBuffers(int.MaxValue, true, out unused);

                stream.Dispose();
                if (this.ownStream)
                {
                    this.messageStream.Dispose();
                }
            }
            protected override IEnumerator <IteratorAsyncResult <AmqpSubscriptionClient.RuleAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                if (!this.client.controlLink.TryGetOpenedObject(out this.amqpLink))
                {
                    AmqpSubscriptionClient.RuleAsyncResult ruleAsyncResult = this;
                    IteratorAsyncResult <AmqpSubscriptionClient.RuleAsyncResult> .BeginCall beginCall = (AmqpSubscriptionClient.RuleAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.client.controlLink.BeginGetInstance(t, c, s);
                    yield return(ruleAsyncResult.CallAsync(beginCall, (AmqpSubscriptionClient.RuleAsyncResult thisPtr, IAsyncResult r) => thisPtr.amqpLink = thisPtr.client.controlLink.EndGetInstance(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
                }
                AmqpValue amqpValue = new AmqpValue()
                {
                    Value = this.CreateCommand()
                };
                AmqpMessage amqpMessage = AmqpMessage.Create(amqpValue);

                amqpMessage.Batchable = false;
                AmqpSubscriptionClient.RuleAsyncResult ruleAsyncResult1 = this;
                IteratorAsyncResult <AmqpSubscriptionClient.RuleAsyncResult> .BeginCall beginCall1 = (AmqpSubscriptionClient.RuleAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.amqpLink.BeginSendMessage(amqpMessage, thisPtr.client.GetControlMessageDeliveryTag(), new ArraySegment <byte>(), t, c, s);
                yield return(ruleAsyncResult1.CallAsync(beginCall1, (AmqpSubscriptionClient.RuleAsyncResult thisPtr, IAsyncResult r) => thisPtr.outcome = thisPtr.amqpLink.EndSendMessage(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));

                if (this.outcome.DescriptorCode == Rejected.Code)
                {
                    base.Complete(ExceptionHelper.ToMessagingContract(((Rejected)this.outcome).Error));
                }
            }