Skip to content

Commit

Permalink
Port ATOM fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLove-msft committed Nov 20, 2020
1 parent 6e86d1c commit f3b5fc8
Show file tree
Hide file tree
Showing 20 changed files with 972 additions and 681 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
using Azure.Core;

namespace Azure.Messaging.ServiceBus.Administration
Expand Down Expand Up @@ -287,11 +289,29 @@ public string UserMetadata
}
}

internal bool IsAnonymousAccessible { get; set; } = false;

internal bool SupportOrdering
{
get
{
return _internalSupportOrdering ?? !EnablePartitioning;
}
set
{
_internalSupportOrdering = value;
}
}

internal bool? _internalSupportOrdering = null;

internal bool EnableExpress { get; set; } = false;

/// <summary>
/// List of properties that were retrieved using GetQueue but are not understood by this version of client is stored here.
/// The list will be sent back when an already retrieved QueueDescription will be used in UpdateQueue call.
/// </summary>
internal List<object> UnknownProperties { get; set; }
internal List<XElement> UnknownProperties { get; set; }

/// <summary>
/// Returns a hash code for this instance.
Expand Down Expand Up @@ -327,6 +347,9 @@ public bool Equals(QueueProperties other)
&& RequiresDuplicateDetection.Equals(otherDescription.RequiresDuplicateDetection)
&& RequiresSession.Equals(otherDescription.RequiresSession)
&& Status.Equals(otherDescription.Status)
&& _internalSupportOrdering.Equals(other.SupportOrdering)
&& EnableExpress == other.EnableExpress
&& IsAnonymousAccessible == other.IsAnonymousAccessible
&& string.Equals(_userMetadata, otherDescription._userMetadata, StringComparison.OrdinalIgnoreCase)
&& (AuthorizationRules != null && otherDescription.AuthorizationRules != null
|| AuthorizationRules == null && otherDescription.AuthorizationRules == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ public static XDocument Serialize(this QueueProperties description)
: null,
new XElement(XName.Get("MaxDeliveryCount", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.MaxDeliveryCount)),
new XElement(XName.Get("EnableBatchedOperations", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnableBatchedOperations)),
new XElement(XName.Get("IsAnonymousAccessible", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.IsAnonymousAccessible)),
description.AuthorizationRules?.Serialize(),
new XElement(XName.Get("Status", AdministrationClientConstants.ServiceBusNamespace), description.Status.ToString()),
description.ForwardTo != null ? new XElement(XName.Get("ForwardTo", AdministrationClientConstants.ServiceBusNamespace), description.ForwardTo) : null,
description.UserMetadata != null ? new XElement(XName.Get("UserMetadata", AdministrationClientConstants.ServiceBusNamespace), description.UserMetadata) : null,
description._internalSupportOrdering.HasValue ? new XElement(XName.Get("SupportOrdering", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description._internalSupportOrdering.Value)) : null,
description.AutoDeleteOnIdle != TimeSpan.MaxValue ? new XElement(XName.Get("AutoDeleteOnIdle", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.AutoDeleteOnIdle)) : null,
new XElement(XName.Get("EnablePartitioning", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnablePartitioning)),
description.ForwardDeadLetteredMessagesTo != null ? new XElement(XName.Get("ForwardDeadLetteredMessagesTo", AdministrationClientConstants.ServiceBusNamespace), description.ForwardDeadLetteredMessagesTo) : null
description.ForwardDeadLetteredMessagesTo != null ? new XElement(XName.Get("ForwardDeadLetteredMessagesTo", AdministrationClientConstants.ServiceBusNamespace), description.ForwardDeadLetteredMessagesTo) : null,
new XElement(XName.Get("EnableExpress", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnableExpress))
};

// Insert unknown properties in the exact order they were in the received xml.
// Expectation is that servicebus will add any new elements only at the bottom of the xml tree.
if (description.UnknownProperties != null)
{
queueDescriptionElements.AddRange(description.UnknownProperties);
Expand All @@ -50,9 +55,6 @@ public static XDocument Serialize(this QueueProperties description)
queueDescriptionElements.ToArray()))));
}

/// <summary>
///
/// </summary>
public static async Task<QueueProperties> ParseResponseAsync(Response response, ClientDiagnostics diagnostics)
{
try
Expand Down Expand Up @@ -81,7 +83,6 @@ public static async Task<QueueProperties> ParseResponseAsync(Response response,
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));
Expand All @@ -94,10 +95,14 @@ private static async Task<QueueProperties> ParseFromEntryElementAsync(XElement x
innerException: await diagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false));
}

var properties = new QueueProperties(name);
foreach (var element in qdXml.Elements())
{
switch (element.Name.LocalName)
{
case "LockDuration":
properties.LockDuration = XmlConvert.ToTimeSpan(element.Value);
break;
case "MaxSizeInMegabytes":
properties.MaxSizeInMegabytes = int.Parse(element.Value, CultureInfo.InvariantCulture);
break;
Expand All @@ -107,65 +112,73 @@ private static async Task<QueueProperties> ParseFromEntryElementAsync(XElement x
case "RequiresSession":
properties.RequiresSession = bool.Parse(element.Value);
break;
case "DefaultMessageTimeToLive":
properties.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(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);
case "IsAnonymousAccessible":
properties.IsAnonymousAccessible = Boolean.Parse(element.Value);
break;
case "EnablePartitioning":
properties.EnablePartitioning = bool.Parse(element.Value);
case "AuthorizationRules":
properties.AuthorizationRules = AuthorizationRules.ParseFromXElement(element);
break;
case "UserMetadata":
properties.UserMetadata = element.Value;
case "Status":
properties.Status = element.Value;
break;
case "ForwardTo":
if (!string.IsNullOrWhiteSpace(element.Value))
{
properties.ForwardTo = element.Value;
}
break;
case "UserMetadata":
properties.UserMetadata = element.Value;
break;
case "SupportOrdering":
properties.SupportOrdering = Boolean.Parse(element.Value);
break;
case "AutoDeleteOnIdle":
properties.AutoDeleteOnIdle = XmlConvert.ToTimeSpan(element.Value);
break;
case "EnablePartitioning":
properties.EnablePartitioning = bool.Parse(element.Value);
break;
case "ForwardDeadLetteredMessagesTo":
if (!string.IsNullOrWhiteSpace(element.Value))
{
properties.ForwardDeadLetteredMessagesTo = element.Value;
}
break;
case "AuthorizationRules":
properties.AuthorizationRules = AuthorizationRules.ParseFromXElement(element);
case "EnableExpress":
properties.EnableExpress = bool.Parse(element.Value);
break;
case "AccessedAt":
case "CreatedAt":
case "MessageCount":
case "SizeInBytes":
case "UpdatedAt":
case "CountDetails":
case "EntityAvailabilityStatus":
case "SkippedUpdate":
// 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 = new List<XElement>();
}

properties.UnknownProperties.Add(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,54 +115,57 @@ private static async Task<SubscriptionProperties> ParseFromEntryElementAsync(str
{
switch (element.Name.LocalName)
{
case "LockDuration":
subscriptionDesc.LockDuration = XmlConvert.ToTimeSpan(element.Value);
break;
case "RequiresSession":
subscriptionDesc.RequiresSession = bool.Parse(element.Value);
break;
case "DefaultMessageTimeToLive":
subscriptionDesc.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(element.Value);
break;
case "DeadLetteringOnMessageExpiration":
subscriptionDesc.DeadLetteringOnMessageExpiration = bool.Parse(element.Value);
break;
case "DeadLetteringOnFilterEvaluationExceptions":
subscriptionDesc.EnableDeadLetteringOnFilterEvaluationExceptions = bool.Parse(element.Value);
break;
case "LockDuration":
subscriptionDesc.LockDuration = XmlConvert.ToTimeSpan(element.Value);
break;
case "DefaultMessageTimeToLive":
subscriptionDesc.DefaultMessageTimeToLive = XmlConvert.ToTimeSpan(element.Value);
break;
case "MaxDeliveryCount":
subscriptionDesc.MaxDeliveryCount = int.Parse(element.Value, CultureInfo.InvariantCulture);
break;
case "Status":
subscriptionDesc.Status = element.Value;
break;
case "EnableBatchedOperations":
subscriptionDesc.EnableBatchedOperations = bool.Parse(element.Value);
break;
case "UserMetadata":
subscriptionDesc.UserMetadata = element.Value;
break;
case "AutoDeleteOnIdle":
subscriptionDesc.AutoDeleteOnIdle = XmlConvert.ToTimeSpan(element.Value);
case "Status":
subscriptionDesc.Status = element.Value;
break;
case "ForwardTo":
if (!string.IsNullOrWhiteSpace(element.Value))
{
subscriptionDesc.ForwardTo = element.Value;
}
break;
case "UserMetadata":
subscriptionDesc.UserMetadata = element.Value;
break;
case "ForwardDeadLetteredMessagesTo":
if (!string.IsNullOrWhiteSpace(element.Value))
{
subscriptionDesc.ForwardDeadLetteredMessagesTo = element.Value;
}
break;
case "AutoDeleteOnIdle":
subscriptionDesc.AutoDeleteOnIdle = XmlConvert.ToTimeSpan(element.Value);
break;
case "AccessedAt":
case "CreatedAt":
case "MessageCount":
case "SizeInBytes":
case "UpdatedAt":
case "CountDetails":
case "DefaultRuleDescription":
case "EntityAvailabilityStatus":
case "SkippedUpdate":
// Ignore known properties
// Do nothing
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ public string UserMetadata
}
}

internal bool IsAnonymousAccessible { get; set; } = false;

internal bool FilteringMessagesBeforePublishing { get; set; } = false;

internal string ForwardTo { get; set; } = null;

internal bool EnableExpress { get; set; } = false;

internal bool EnableSubscriptionPartitioning { get; set; } = false;


/// <summary>
/// List of properties that were retrieved using GetTopic but are not understood by this version of client is stored here.
/// The list will be sent back when an already retrieved TopicDescription will be used in UpdateTopic call.
Expand Down Expand Up @@ -226,6 +237,11 @@ public bool Equals(TopicProperties other)
&& RequiresDuplicateDetection.Equals(otherDescription.RequiresDuplicateDetection)
&& Status.Equals(otherDescription.Status)
&& string.Equals(_userMetadata, otherDescription._userMetadata, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ForwardTo, other.ForwardTo, StringComparison.OrdinalIgnoreCase)
&& EnableExpress == other.EnableExpress
&& IsAnonymousAccessible == other.IsAnonymousAccessible
&& FilteringMessagesBeforePublishing == other.FilteringMessagesBeforePublishing
&& EnableSubscriptionPartitioning == other.EnableSubscriptionPartitioning
&& (AuthorizationRules != null && otherDescription.AuthorizationRules != null
|| AuthorizationRules == null && otherDescription.AuthorizationRules == null)
&& (AuthorizationRules == null || AuthorizationRules.Equals(otherDescription.AuthorizationRules)))
Expand Down
Loading

0 comments on commit f3b5fc8

Please sign in to comment.