Ejemplo n.º 1
0
        private static TopicDescription ParseFromEntryElement(XElement xEntry)
        {
            var name      = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value;
            var topicDesc = new TopicDescription(name);

            var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))?
                        .Element(XName.Get("TopicDescription", ManagementClientConstants.ServiceBusNamespace));

            if (qdXml == null)
            {
                throw new MessagingEntityNotFoundException("Topic was not found");
            }

            foreach (var element in qdXml.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "MaxSizeInMegabytes":
                    topicDesc.MaxSizeInMB = long.Parse(element.Value);
                    break;

                case "RequiresDuplicateDetection":
                    topicDesc.RequiresDuplicateDetection = bool.Parse(element.Value);
                    break;

                case "DuplicateDetectionHistoryTimeWindow":
                    topicDesc.duplicateDetectionHistoryTimeWindow = XmlConvert.ToTimeSpan(element.Value);
                    break;

                case "DefaultMessageTimeToLive":
                    topicDesc.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(element.Value);
                    break;

                case "EnableBatchedOperations":
                    topicDesc.EnableBatchedOperations = bool.Parse(element.Value);
                    break;

                case "Status":
                    topicDesc.Status = (EntityStatus)Enum.Parse(typeof(EntityStatus), element.Value);
                    break;

                case "UserMetadata":
                    topicDesc.UserMetadata = element.Value;
                    break;

                case "AutoDeleteOnIdle":
                    topicDesc.AutoDeleteOnIdle = XmlConvert.ToTimeSpan(element.Value);
                    break;

                case "EnablePartitioning":
                    topicDesc.EnablePartitioning = bool.Parse(element.Value);
                    break;

                case "SupportOrdering":
                    topicDesc.SupportOrdering = bool.Parse(element.Value);
                    break;

                case "AuthorizationRules":
                    topicDesc.AuthorizationRules = AuthorizationRules.ParseFromXElement(element);
                    break;

                case "AccessedAt":
                case "CreatedAt":
                case "MessageCount":
                case "SizeInBytes":
                case "UpdatedAt":
                case "CountDetails":
                case "SubscriptionCount":
                    // Ignore known properties
                    // Do nothing
                    break;

                default:
                    // For unknown properties, keep them as-is for forward proof.
                    if (topicDesc.UnknownProperties == null)
                    {
                        topicDesc.UnknownProperties = new List <object>();
                    }

                    topicDesc.UnknownProperties.Add(element);
                    break;
                }
            }

            return(topicDesc);
        }
Ejemplo n.º 2
0
        private static TopicDescription ParseFromEntryElement(XElement xEntry)
        {
            var name      = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNs)).Value;
            var topicDesc = new TopicDescription(name);

            var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNs))?
                        .Element(XName.Get("TopicDescription", ManagementClientConstants.SbNs));

            if (qdXml == null)
            {
                throw new MessagingEntityNotFoundException("Topic was not found");
            }

            foreach (var element in qdXml.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "MaxSizeInMegabytes":
                    topicDesc.MaxSizeInMB = long.Parse(element.Value);
                    break;

                case "RequiresDuplicateDetection":
                    topicDesc.RequiresDuplicateDetection = bool.Parse(element.Value);
                    break;

                case "DuplicateDetectionHistoryTimeWindow":
                    topicDesc.duplicateDetectionHistoryTimeWindow = XmlConvert.ToTimeSpan(element.Value);
                    break;

                case "DefaultMessageTimeToLive":
                    topicDesc.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(element.Value);
                    break;

                case "EnableBatchedOperations":
                    topicDesc.EnableBatchedOperations = bool.Parse(element.Value);
                    break;

                case "Status":
                    topicDesc.Status = (EntityStatus)Enum.Parse(typeof(EntityStatus), element.Value);
                    break;

                case "UserMetadata":
                    topicDesc.UserMetadata = element.Value;
                    break;

                case "AutoDeleteOnIdle":
                    topicDesc.AutoDeleteOnIdle = XmlConvert.ToTimeSpan(element.Value);
                    break;

                case "EnablePartitioning":
                    topicDesc.EnablePartitioning = bool.Parse(element.Value);
                    break;

                case "SupportOrdering":
                    topicDesc.SupportOrdering = bool.Parse(element.Value);
                    break;

                case "AuthorizationRules":
                    topicDesc.AuthorizationRules = AuthorizationRules.ParseFromXElement(element);
                    break;
                }
            }

            return(topicDesc);
        }