Ejemplo n.º 1
0
        public static EventHubRuntimeInformation GetEventHubRuntimeInfo(AmqpMessage amqpMessage)
        {
            EventHubRuntimeInformation eventHubRuntimeInformation = null;
            object obj = null;

            if (MessageConverter.TryGetNetObjectFromAmqpObject(amqpMessage.ValueBody.Value, MappingType.MessageBody, out obj))
            {
                Dictionary <string, object> strs = obj as Dictionary <string, object>;
                if (strs != null)
                {
                    eventHubRuntimeInformation = new EventHubRuntimeInformation();
                    object obj1 = null;
                    if (strs.TryGetValue("name", out obj1))
                    {
                        eventHubRuntimeInformation.Path = (string)obj1;
                    }
                    if (strs.TryGetValue("partition_count", out obj1))
                    {
                        eventHubRuntimeInformation.PartitionCount = (int)obj1;
                    }
                    if (strs.TryGetValue("created_at", out obj1))
                    {
                        eventHubRuntimeInformation.CreatedAt = (DateTime)obj1;
                    }
                    if (strs.TryGetValue("partition_ids", out obj1))
                    {
                        eventHubRuntimeInformation.PartitionIds = (string[])obj1;
                    }
                }
            }
            return(eventHubRuntimeInformation);
        }
Ejemplo n.º 2
0
        public static BrokeredMessage ConvertAmqpToSbmp(BrokeredMessage brokeredMessage, ReceiveMode receiveMode)
        {
            BrokeredMessage encoder = brokeredMessage.CreateCopy();

            encoder.MessageFormat  = BrokeredMessageFormat.Sbmp;
            encoder.MessageEncoder = BrokeredMessageEncoder.GetEncoder(BrokeredMessageFormat.Sbmp);
            if (receiveMode == ReceiveMode.PeekLock && brokeredMessage.IsLockTokenSet)
            {
                encoder.LockToken      = brokeredMessage.LockToken;
                encoder.LockedUntilUtc = brokeredMessage.LockedUntilUtc;
            }
            if (encoder.BodyStream != null)
            {
                using (Stream stream = BrokeredMessage.CloneStream(encoder.BodyStream, false))
                {
                    using (AmqpMessage amqpMessage = AmqpMessage.CreateAmqpStreamMessageBody(stream))
                    {
                        encoder.BodyStream = null;
                        if ((int)(amqpMessage.BodyType & SectionFlag.Data) != 0 || (int)(amqpMessage.BodyType & SectionFlag.AmqpSequence) != 0)
                        {
                            encoder.BodyStream = MessageConverter.GetMessageBodyStream(amqpMessage);
                        }
                        else if ((int)(amqpMessage.BodyType & SectionFlag.AmqpValue) != 0)
                        {
                            object value = null;
                            if (!MessageConverter.TryGetNetObjectFromAmqpObject(amqpMessage.ValueBody.Value, MappingType.MessageBody, out value))
                            {
                                value = amqpMessage.ValueBody.Value;
                            }
                            if (value != null)
                            {
                                DataContractBinarySerializer dataContractBinarySerializer = new DataContractBinarySerializer(value.GetType());
                                MemoryStream memoryStream = new MemoryStream(256);
                                dataContractBinarySerializer.WriteObject(memoryStream, value);
                                memoryStream.Flush();
                                memoryStream.Position = (long)0;
                                encoder.BodyStream    = memoryStream;
                            }
                        }
                    }
                }
            }
            return(encoder);
        }
Ejemplo n.º 3
0
        public static void UpdateBrokeredMessageHeaderAndProperties(AmqpMessage amqpMessage, BrokeredMessage message)
        {
            DateTime    dateTime;
            string      str;
            string      str1;
            SectionFlag sections = amqpMessage.Sections;

            if ((int)(sections & SectionFlag.Header) != 0 && amqpMessage.Header.Ttl.HasValue)
            {
                uint?ttl = amqpMessage.Header.Ttl;
                message.TimeToLive = TimeSpan.FromMilliseconds((double)((float)ttl.Value));
            }
            if ((int)(sections & SectionFlag.Properties) != 0)
            {
                if (amqpMessage.Properties.MessageId != null)
                {
                    message.MessageId = amqpMessage.Properties.MessageId.ToString();
                }
                if (amqpMessage.Properties.CorrelationId != null)
                {
                    message.CorrelationId = amqpMessage.Properties.CorrelationId.ToString();
                }
                if (amqpMessage.Properties.ContentType.Value != null)
                {
                    message.ContentType = amqpMessage.Properties.ContentType.Value;
                }
                if (amqpMessage.Properties.Subject != null)
                {
                    message.Label = amqpMessage.Properties.Subject;
                }
                if (amqpMessage.Properties.To != null)
                {
                    message.To = amqpMessage.Properties.To.ToString();
                }
                if (amqpMessage.Properties.ReplyTo != null)
                {
                    message.ReplyTo = amqpMessage.Properties.ReplyTo.ToString();
                }
                if (amqpMessage.Properties.GroupId != null)
                {
                    message.SessionId = amqpMessage.Properties.GroupId;
                }
                if (amqpMessage.Properties.ReplyToGroupId != null)
                {
                    message.ReplyToSessionId = amqpMessage.Properties.ReplyToGroupId;
                }
            }
            if ((int)(sections & SectionFlag.MessageAnnotations) != 0)
            {
                if (amqpMessage.MessageAnnotations.Map.TryGetValue <DateTime>("x-opt-scheduled-enqueue-time", out dateTime))
                {
                    message.ScheduledEnqueueTimeUtc = dateTime;
                }
                if (amqpMessage.MessageAnnotations.Map.TryGetValue <string>("x-opt-publisher", out str))
                {
                    message.Publisher = str;
                }
                if (amqpMessage.MessageAnnotations.Map.TryGetValue <string>("x-opt-partition-key", out str1))
                {
                    message.PartitionKey = str1;
                }
            }
            if ((int)(sections & SectionFlag.ApplicationProperties) != 0)
            {
                foreach (KeyValuePair <MapKey, object> map in (IEnumerable <KeyValuePair <MapKey, object> >)amqpMessage.ApplicationProperties.Map)
                {
                    object obj = null;
                    if (!MessageConverter.TryGetNetObjectFromAmqpObject(map.Value, MappingType.ApplicationProperty, out obj))
                    {
                        continue;
                    }
                    message.InternalProperties[map.Key.ToString()] = obj;
                }
            }
        }
Ejemplo n.º 4
0
        public static BrokeredMessage ClientGetMessage(AmqpMessage amqpMessage)
        {
            BrokeredMessage brokeredMessage;

            if ((int)(amqpMessage.BodyType & SectionFlag.Data) != 0 || (int)(amqpMessage.BodyType & SectionFlag.AmqpSequence) != 0)
            {
                brokeredMessage = new BrokeredMessage(MessageConverter.GetMessageBodyStream(amqpMessage), true);
            }
            else if ((int)(amqpMessage.BodyType & SectionFlag.AmqpValue) == 0)
            {
                brokeredMessage = new BrokeredMessage();
            }
            else
            {
                object value = null;
                if (!MessageConverter.TryGetNetObjectFromAmqpObject(amqpMessage.ValueBody.Value, MappingType.MessageBody, out value))
                {
                    value = amqpMessage.ValueBody.Value;
                }
                brokeredMessage = new BrokeredMessage(value, amqpMessage.BodyStream);
            }
            SectionFlag sections = amqpMessage.Sections;

            if ((int)(sections & SectionFlag.Header) != 0)
            {
                if (amqpMessage.Header.Ttl.HasValue)
                {
                    uint?ttl = amqpMessage.Header.Ttl;
                    brokeredMessage.TimeToLive = TimeSpan.FromMilliseconds((double)((float)ttl.Value));
                }
                if (amqpMessage.Header.DeliveryCount.HasValue)
                {
                    brokeredMessage.DeliveryCount = (int)(amqpMessage.Header.DeliveryCount.Value + 1);
                }
            }
            if ((int)(sections & SectionFlag.Properties) != 0)
            {
                if (amqpMessage.Properties.MessageId != null)
                {
                    brokeredMessage.MessageId = amqpMessage.Properties.MessageId.ToString();
                }
                if (amqpMessage.Properties.CorrelationId != null)
                {
                    brokeredMessage.CorrelationId = amqpMessage.Properties.CorrelationId.ToString();
                }
                if (amqpMessage.Properties.ContentType.Value != null)
                {
                    brokeredMessage.ContentType = amqpMessage.Properties.ContentType.Value;
                }
                if (amqpMessage.Properties.Subject != null)
                {
                    brokeredMessage.Label = amqpMessage.Properties.Subject;
                }
                if (amqpMessage.Properties.To != null)
                {
                    brokeredMessage.To = amqpMessage.Properties.To.ToString();
                }
                if (amqpMessage.Properties.ReplyTo != null)
                {
                    brokeredMessage.ReplyTo = amqpMessage.Properties.ReplyTo.ToString();
                }
                if (amqpMessage.Properties.GroupId != null)
                {
                    brokeredMessage.SessionId = amqpMessage.Properties.GroupId;
                }
                if (amqpMessage.Properties.ReplyToGroupId != null)
                {
                    brokeredMessage.ReplyToSessionId = amqpMessage.Properties.ReplyToGroupId;
                }
            }
            if ((int)(sections & SectionFlag.ApplicationProperties) != 0)
            {
                foreach (KeyValuePair <MapKey, object> map in (IEnumerable <KeyValuePair <MapKey, object> >)amqpMessage.ApplicationProperties.Map)
                {
                    object obj = null;
                    if (!MessageConverter.TryGetNetObjectFromAmqpObject(map.Value, MappingType.ApplicationProperty, out obj))
                    {
                        continue;
                    }
                    brokeredMessage.Properties[map.Key.ToString()] = obj;
                }
            }
            if ((int)(sections & SectionFlag.MessageAnnotations) != 0)
            {
                foreach (KeyValuePair <MapKey, object> keyValuePair in (IEnumerable <KeyValuePair <MapKey, object> >)amqpMessage.MessageAnnotations.Map)
                {
                    string str  = keyValuePair.Key.ToString();
                    string str1 = str;
                    string str2 = str1;
                    if (str1 != null)
                    {
                        switch (str2)
                        {
                        case "x-opt-enqueued-time":
                        {
                            brokeredMessage.EnqueuedTimeUtc = (DateTime)keyValuePair.Value;
                            continue;
                        }

                        case "x-opt-scheduled-enqueue-time":
                        {
                            brokeredMessage.ScheduledEnqueueTimeUtc = (DateTime)keyValuePair.Value;
                            continue;
                        }

                        case "x-opt-sequence-number":
                        {
                            brokeredMessage.SequenceNumber = (long)keyValuePair.Value;
                            continue;
                        }

                        case "x-opt-offset":
                        {
                            brokeredMessage.EnqueuedSequenceNumber = (long)keyValuePair.Value;
                            continue;
                        }

                        case "x-opt-locked-until":
                        {
                            brokeredMessage.LockedUntilUtc = (DateTime)keyValuePair.Value;
                            continue;
                        }

                        case "x-opt-publisher":
                        {
                            brokeredMessage.Publisher = (string)keyValuePair.Value;
                            continue;
                        }

                        case "x-opt-partition-key":
                        {
                            brokeredMessage.PartitionKey = (string)keyValuePair.Value;
                            continue;
                        }
                        }
                    }
                    object obj1 = null;
                    if (!MessageConverter.TryGetNetObjectFromAmqpObject(keyValuePair.Value, MappingType.ApplicationProperty, out obj1))
                    {
                        continue;
                    }
                    brokeredMessage.Properties[str] = obj1;
                }
            }
            if (amqpMessage.DeliveryTag.Count == 16)
            {
                byte[] numArray = new byte[16];
                byte[] array    = amqpMessage.DeliveryTag.Array;
                ArraySegment <byte> deliveryTag = amqpMessage.DeliveryTag;
                Buffer.BlockCopy((Array)array, deliveryTag.Offset, numArray, 0, 16);
                brokeredMessage.LockToken = new Guid(numArray);
            }
            brokeredMessage.AttachDisposables(new AmqpMessage[] { amqpMessage });
            return(brokeredMessage);
        }
Ejemplo n.º 5
0
        public static void UpdateEventDataHeaderAndProperties(AmqpMessage amqpMessage, EventData data)
        {
            string              str;
            string              str1;
            DateTime            dateTime;
            long                num;
            string              str2;
            ArraySegment <byte> deliveryTag = amqpMessage.DeliveryTag;

            Fx.AssertAndThrow(true, "AmqpMessage should always contain delivery tag.");
            data.DeliveryTag = amqpMessage.DeliveryTag;
            SectionFlag sections = amqpMessage.Sections;

            if ((int)(sections & SectionFlag.MessageAnnotations) != 0)
            {
                if (amqpMessage.MessageAnnotations.Map.TryGetValue <string>("x-opt-publisher", out str))
                {
                    data.Publisher = str;
                }
                if (amqpMessage.MessageAnnotations.Map.TryGetValue <string>("x-opt-partition-key", out str1))
                {
                    data.PartitionKey = str1;
                }
                if (amqpMessage.MessageAnnotations.Map.TryGetValue <DateTime>("x-opt-enqueued-time", out dateTime))
                {
                    data.EnqueuedTimeUtc = dateTime;
                }
                if (amqpMessage.MessageAnnotations.Map.TryGetValue <long>("x-opt-sequence-number", out num))
                {
                    data.SequenceNumber = num;
                }
                if (amqpMessage.MessageAnnotations.Map.TryGetValue <string>("x-opt-offset", out str2))
                {
                    data.Offset = str2;
                }
            }
            if ((int)(sections & SectionFlag.ApplicationProperties) != 0)
            {
                foreach (KeyValuePair <MapKey, object> map in (IEnumerable <KeyValuePair <MapKey, object> >)amqpMessage.ApplicationProperties.Map)
                {
                    object obj = null;
                    if (!MessageConverter.TryGetNetObjectFromAmqpObject(map.Value, MappingType.ApplicationProperty, out obj))
                    {
                        continue;
                    }
                    data.Properties[map.Key.ToString()] = obj;
                }
            }
            if ((int)(sections & SectionFlag.Properties) != 0)
            {
                foreach (KeyValuePair <string, object> dictionary in amqpMessage.Properties.ToDictionary())
                {
                    if (dictionary.Value is MessageId || dictionary.Value is Address || dictionary.Value is AmqpSymbol)
                    {
                        data.SystemProperties.Add(dictionary.Key, dictionary.Value.ToString());
                    }
                    else
                    {
                        data.SystemProperties.Add(dictionary);
                    }
                }
            }
        }