internal static AuthorizationRules ParseFromXElement(XElement xElement) { var rules = new AuthorizationRules(); var xRules = xElement.Elements(XName.Get("AuthorizationRule", ManagementClientConstants.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 QueueProperties ParseFromEntryElement(XElement xEntry) { var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value; var properties = new QueueProperties(name); var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))? .Element(XName.Get("QueueDescription", ManagementClientConstants.ServiceBusNamespace)); if (qdXml == null) { throw new ServiceBusException("Queue was not found", ServiceBusException.FailureReason.MessagingEntityNotFound); } 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); }
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 ServiceBusException("Topic was not found", ServiceBusException.FailureReason.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); }