internal static AuthorizationRules ParseFromXElement(XElement xElement)
        {
            var rules  = new AuthorizationRules();
            var xRules = xElement.Elements(XName.Get("AuthorizationRule", AdministrationClientConstants.ServiceBusNamespace));

            rules.AddRange(xRules.Select(rule => AuthorizationRule.ParseFromXElement(rule)));
            return(rules);
        }
        internal AuthorizationRules Clone()
        {
            var rules = new AuthorizationRules();

            foreach (AuthorizationRule rule in this)
            {
                rules.Add(rule.Clone());
            }
            return(rules);
        }
        /// <summary>
        /// Determines whether the specified object is equal to the current object.
        /// </summary>
        public bool Equals(AuthorizationRules other)
        {
            if (other is null || 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 async Task <TopicProperties> ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics)
        {
            var name     = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value;
            var topicXml = xEntry.Element(XName.Get("content", AdministrationClientConstants.AtomNamespace))?
                           .Element(XName.Get("TopicDescription", AdministrationClientConstants.ServiceBusNamespace));

            if (topicXml == null)
            {
                throw new ServiceBusException(
                          "Topic was not found",
                          ServiceBusFailureReason.MessagingEntityNotFound,
                          innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false));
            }

            var topicProperties = new TopicProperties(name);

            foreach (var element in topicXml.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "DefaultMessageTimeToLive":
                    topicProperties.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(element.Value);
                    break;

                case "MaxSizeInMegabytes":
                    topicProperties.MaxSizeInMegabytes = long.Parse(element.Value, CultureInfo.InvariantCulture);
                    break;

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

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

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

                case "FilteringMessagesBeforePublishing":
                    topicProperties.FilteringMessagesBeforePublishing = bool.Parse(element.Value);
                    break;

                case "IsAnonymousAccessible":
                    topicProperties.IsAnonymousAccessible = bool.Parse(element.Value);
                    break;

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

                case "Status":
                    topicProperties.Status = element.Value;
                    break;

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

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

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

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

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

                case "EnableSubscriptionPartitioning":
                    topicProperties.EnableSubscriptionPartitioning = bool.Parse(element.Value);
                    break;

                case "EnableExpress":
                    topicProperties.EnableExpress = bool.Parse(element.Value);
                    break;

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

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

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

            return(topicProperties);
        }
Example #5
0
        private static async Task <QueueProperties> ParseFromEntryElementAsync(XElement xEntry, Response response, ClientDiagnostics diagnostics)
        {
            var name       = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value;
            var properties = new QueueProperties(name);

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

            if (qdXml == null)
            {
                throw new ServiceBusException(
                          "Queue was not found",
                          ServiceBusFailureReason.MessagingEntityNotFound,
                          innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false));
            }

            foreach (var element in qdXml.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "MaxSizeInMegabytes":
                    properties.MaxSizeInMegabytes = int.Parse(element.Value, CultureInfo.InvariantCulture);
                    break;

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

                case "RequiresSession":
                    properties.RequiresSession = bool.Parse(element.Value);
                    break;

                case "DeadLetteringOnMessageExpiration":
                    properties.DeadLetteringOnMessageExpiration = bool.Parse(element.Value);
                    break;

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

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

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

                case "MaxDeliveryCount":
                    properties.MaxDeliveryCount = int.Parse(element.Value, CultureInfo.InvariantCulture);
                    break;

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

                case "Status":
                    properties.Status = element.Value;
                    break;

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

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

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

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

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

                case "AuthorizationRules":
                    properties.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 (properties.UnknownProperties == null)
                    {
                        properties.UnknownProperties = new List <object>();
                    }

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

            return(properties);
        }
Example #6
0
        private static TopicProperties ParseFromEntryElement(XElement xEntry)
        {
            var name      = xEntry.Element(XName.Get("title", AdministrationClientConstants.AtomNamespace)).Value;
            var topicDesc = new TopicProperties(name);

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

            if (qdXml == null)
            {
                throw new ServiceBusException("Topic was not found", ServiceBusFailureReason.MessagingEntityNotFound);
            }

            foreach (var element in qdXml.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "MaxSizeInMegabytes":
                    topicDesc.MaxSizeInMegabytes = long.Parse(element.Value, CultureInfo.InvariantCulture);
                    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 = 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);
        }