Beispiel #1
0
        internal static AuthorizationRules ParseFromXElement(XElement xElement)
        {
            var rules  = new AuthorizationRules();
            var xRules = xElement.Elements(XName.Get("AuthorizationRule", ManagementClientConstants.SbNs));

            rules.AddRange(xRules.Select(rule => AuthorizationRule.ParseFromXElement(rule)));
            return(rules);
        }
Beispiel #2
0
        public bool Equals(AuthorizationRules other)
        {
            if (other == null || this.Count != other.Count)
            {
                return(false);
            }

            var cnt = new Dictionary <string, AuthorizationRule>();

            foreach (AuthorizationRule rule in this)
            {
                cnt[rule.KeyName] = rule;
            }

            foreach (AuthorizationRule otherRule in other)
            {
                if (!cnt.TryGetValue(otherRule.KeyName, out var rule) || !rule.Equals(otherRule))
                {
                    return(false);
                }
            }

            return(true);
        }
        private static QueueDescription ParseFromEntryElement(XElement xEntry)
        {
            var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value;
            var qd   = new QueueDescription(name);

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

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

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

                case "RequiresDuplicateDetection":
                    qd.RequiresDuplicateDetection = Boolean.Parse(element.Value);
                    break;

                case "RequiresSession":
                    qd.RequiresSession = Boolean.Parse(element.Value);
                    break;

                case "DeadLetteringOnMessageExpiration":
                    qd.EnableDeadLetteringOnMessageExpiration = Boolean.Parse(element.Value);
                    break;

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

                case "LockDuration":
                    qd.LockDuration = XmlConvert.ToTimeSpan(element.Value);
                    break;

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

                case "MaxDeliveryCount":
                    qd.MaxDeliveryCount = Int32.Parse(element.Value);
                    break;

                case "EnableBatchedOperations":
                    qd.EnableBatchedOperations = Boolean.Parse(element.Value);
                    break;

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

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

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

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

                case "ForwardTo":
                    if (!string.IsNullOrWhiteSpace(element.Value))
                    {
                        qd.ForwardTo = element.Value;
                    }
                    break;

                case "ForwardDeadLetteredMessagesTo":
                    if (!string.IsNullOrWhiteSpace(element.Value))
                    {
                        qd.ForwardDeadLetteredMessagesTo = element.Value;
                    }
                    break;

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

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

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

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

            return(qd);
        }
        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);
        }
Beispiel #5
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);
        }