private Message AmqpMessageToChannelMessage(AmqpMessage amqpMessage) { string empty; if (amqpMessage == null) { return(null); } if (amqpMessage.ApplicationProperties == null || !amqpMessage.ApplicationProperties.Map.TryGetValue <string>("Action", out empty)) { empty = string.Empty; } Message uri = null; if (amqpMessage.BodyType == SectionFlag.AmqpValue) { uri = Message.CreateMessage(System.ServiceModel.Channels.MessageVersion.Default, empty, amqpMessage.ValueBody.Value); amqpMessage.Dispose(); } else if (amqpMessage.BodyType == SectionFlag.Data) { Data datum = null; foreach (Data dataBody in amqpMessage.DataBody) { Fx.AssertAndThrow(datum == null, "Serialization of AMQP messages with multiple body frames is not implemented."); datum = dataBody; } ArraySegment <byte> value = (ArraySegment <byte>)datum.Value; uri = this.ChannelListener.MessageEncoderFactory.Encoder.ReadMessage(value, AmqpChannelListenerBase.GCBufferManager); uri.Properties["AmqpMessageProperty"] = amqpMessage; } if (uri == null) { throw Fx.AssertAndThrow(string.Concat("Serialization of this type of AmqpMessage is not yet implemented: ", amqpMessage.BodyType.ToString())); } uri.Properties.Via = this.LocalAddress.Uri; if (amqpMessage.Properties != null) { if (amqpMessage.Properties.To != null) { uri.Headers.To = new System.Uri(amqpMessage.Properties.To.ToString()); } if (amqpMessage.Properties.MessageId != null) { uri.Headers.MessageId = new UniqueId(amqpMessage.Properties.MessageId.ToString()); } } return(uri); }
private void OnReceiveMessage(AmqpMessage message) { if (this.messageListener != null) { this.messageListener(message); return; } ReceivingAmqpLink.ReceiveAsyncResult value = null; int num = 0; bool flag = false; lock (this.syncRoot) { if (this.waiterList != null && this.waiterList.Count > 0) { value = this.waiterList.First.Value; this.waiterList.RemoveFirst(); value.OnRemoved(); num = (base.Settings.AutoSendFlow ? 0 : this.GetOnDemandReceiveCredit()); } else if (!base.Settings.AutoSendFlow && base.Settings.SettleType != SettleMode.SettleOnSend) { flag = true; } else if (this.messageQueue != null) { this.messageQueue.Enqueue(message); } } if (flag) { this.ReleaseMessage(message); message.Dispose(); } if (num > 0) { base.IssueCredit((uint)num, false, AmqpConstants.NullBinary); } if (value != null) { Action <object> action = (object o) => { Tuple <ReceivingAmqpLink.ReceiveAsyncResult, IEnumerable <AmqpMessage> > tuple = (Tuple <ReceivingAmqpLink.ReceiveAsyncResult, IEnumerable <AmqpMessage> >)o; tuple.Item1.Signal(tuple.Item2, false); }; AmqpMessage[] amqpMessageArray = new AmqpMessage[] { message }; ActionItem.Schedule(action, new Tuple <ReceivingAmqpLink.ReceiveAsyncResult, IEnumerable <AmqpMessage> >(value, amqpMessageArray)); } }
protected override void AbortInternal() { Queue <AmqpMessage> amqpMessages = null; this.CancelPendingOperations(true, out amqpMessages); if (amqpMessages != null) { foreach (AmqpMessage amqpMessage in amqpMessages) { amqpMessage.Dispose(); } } AmqpMessage amqpMessage1 = this.currentMessage; if (amqpMessage1 != null) { amqpMessage1.Dispose(); } base.AbortInternal(); }
protected override bool CloseInternal() { Queue <AmqpMessage> amqpMessages = null; this.CancelPendingOperations(false, out amqpMessages); if (amqpMessages != null) { foreach (AmqpMessage amqpMessage in amqpMessages) { this.ReleaseMessage(amqpMessage); amqpMessage.Dispose(); } } AmqpMessage amqpMessage1 = this.currentMessage; if (amqpMessage1 != null) { amqpMessage1.Dispose(); } return(base.CloseInternal()); }