< Summary

Class:Azure.Messaging.ServiceBus.Management.ServiceBusManagementClient
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\ServiceBusManagementClient.cs
Covered lines:417
Uncovered lines:94
Coverable lines:511
Total lines:1604
Line coverage:81.6% (417 of 511)
Covered branches:20
Total branches:36
Branch coverage:55.5% (20 of 36)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
.ctor(...)-0%100%
.ctor(...)-96.55%50%
.ctor(...)-0%100%
.ctor(...)-95.24%66.67%
GetNamespacePropertiesAsync()-78.57%100%
DeleteQueueAsync()-100%100%
DeleteTopicAsync()-100%100%
DeleteSubscriptionAsync()-100%100%
DeleteRuleAsync()-70%100%
GetQueueAsync()-100%100%
GetTopicAsync()-100%100%
GetSubscriptionAsync()-100%100%
GetRuleAsync()-100%100%
GetQueueRuntimePropertiesAsync()-0%100%
GetTopicRuntimePropertiesAsync()-72.73%100%
GetSubscriptionRuntimePropertiesAsync()-0%100%
GetQueuesAsync(...)-72.73%100%
GetTopicsAsync(...)-72.73%100%
GetSubscriptionsAsync(...)-75%100%
GetRulesAsync(...)-76.92%100%
GetQueuesRuntimePropertiesAsync(...)-0%100%
GetTopicsRuntimePropertiesAsync(...)-72.73%100%
GetSubscriptionsRuntimePropertiesAsync(...)-0%0%
CreateQueueAsync()-100%100%
CreateQueueAsync()-100%100%
CreateTopicAsync()-100%100%
CreateTopicAsync()-100%100%
CreateSubscriptionAsync()-100%100%
CreateSubscriptionAsync(...)-100%50%
CreateSubscriptionAsync()-100%50%
CreateRuleAsync()-85.71%50%
UpdateQueueAsync()-100%50%
UpdateTopicAsync()-100%50%
UpdateSubscriptionAsync()-100%50%
UpdateRuleAsync()-85%50%
QueueExistsAsync()-80%100%
TopicExistsAsync()-80%100%
SubscriptionExistsAsync()-81.25%100%
RuleExistsAsync()-81.25%100%
ReadAsString()-100%100%
BuildAudienceResource(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\ServiceBusManagementClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Globalization;
 6using System.IO;
 7using System.Threading;
 8using System.Threading.Tasks;
 9using Azure.Core;
 10using Azure.Core.Pipeline;
 11using Azure.Messaging.ServiceBus.Authorization;
 12using Azure.Messaging.ServiceBus.Core;
 13
 14namespace Azure.Messaging.ServiceBus.Management
 15{
 16    /// <summary>
 17    /// The <see cref="ServiceBusManagementClient"/> is the client through which all Service Bus
 18    /// entities can be created, updated, fetched and deleted.
 19    /// </summary>
 20    public class ServiceBusManagementClient
 21    {
 22        private readonly string _fullyQualifiedNamespace;
 23        private readonly HttpRequestAndResponse _httpRequestAndResponse;
 24        private readonly ClientDiagnostics _clientDiagnostics;
 25
 26        /// <summary>
 27        /// Path to get the namespce properties.
 28        /// </summary>
 29        private const string NamespacePath = "$namespaceinfo";
 30
 31        /// <summary>
 32        /// Path to get the list of queues.
 33        /// </summary>
 34        private const string QueuesPath = "$Resources/queues";
 35
 36        /// <summary>
 37        /// Path to get the list of topics.
 38        /// </summary>
 39        private const string TopicsPath = "$Resources/topics";
 40
 41        /// <summary>
 42        /// Path to get the list of subscriptions for a given topic.
 43        /// </summary>
 44        private const string SubscriptionsPath = "{0}/Subscriptions";
 45
 46        /// <summary>
 47        /// Path to get the list of rules for a given subscription and topic.
 48        /// </summary>
 49        private const string RulesPath = "{0}/Subscriptions/{1}/rules";
 50
 51        /// <summary>
 52        /// Parameterless constructor to allow mocking.
 53        /// </summary>
 8854        protected ServiceBusManagementClient() { }
 55
 56        /// <summary>
 57        /// Initializes a new <see cref="ServiceBusManagementClient"/> which can be used to perform management operation
 58        /// </summary>
 59        ///
 60        /// <param name="connectionString">Namespace connection string.</param>
 61        public ServiceBusManagementClient(string connectionString)
 062            : this(connectionString, new ServiceBusManagementClientOptions())
 63        {
 064        }
 65
 66        /// <summary>
 67        /// Initializes a new <see cref="ServiceBusManagementClient"/> which can be used to perform management operation
 68        /// </summary>
 69        ///
 70        /// <param name="connectionString">Namespace connection string.</param>
 71        /// <param name="options"></param>
 4072        public ServiceBusManagementClient(
 4073            string connectionString,
 4074            ServiceBusManagementClientOptions options)
 75        {
 4076            Argument.AssertNotNullOrEmpty(connectionString, nameof(connectionString));
 4077            options ??= new ServiceBusManagementClientOptions();
 4078            ConnectionStringProperties connectionStringProperties = ConnectionStringParser.Parse(connectionString);
 79
 4080            if (string.IsNullOrEmpty(connectionStringProperties.Endpoint?.Host)
 4081                || string.IsNullOrEmpty(connectionStringProperties.SharedAccessKeyName)
 4082                || string.IsNullOrEmpty(connectionStringProperties.SharedAccessKey))
 83            {
 084                throw new ArgumentException(Resources.MissingConnectionInformation, nameof(connectionString));
 85            }
 86
 4087            _fullyQualifiedNamespace = connectionStringProperties.Endpoint.Host;
 88
 4089            var sharedAccessSignature = new SharedAccessSignature
 4090          (
 4091               BuildAudienceResource(connectionStringProperties.Endpoint.Host),
 4092              connectionStringProperties.SharedAccessKeyName,
 4093               connectionStringProperties.SharedAccessKey
 4094          );
 95
 4096            var sharedCredential = new SharedAccessSignatureCredential(sharedAccessSignature);
 4097            var tokenCredential = new ServiceBusTokenCredential(
 4098                sharedCredential,
 4099                BuildAudienceResource(connectionStringProperties.Endpoint.Host));
 100
 40101            HttpPipeline pipeline = HttpPipelineBuilder.Build(options);
 40102            _httpRequestAndResponse = new HttpRequestAndResponse(
 40103                pipeline,
 40104                new ClientDiagnostics(options),
 40105                tokenCredential,
 40106                _fullyQualifiedNamespace);
 40107            _clientDiagnostics = new ClientDiagnostics(options);
 40108        }
 109
 110        /// <summary>
 111        /// Initializes a new <see cref="ServiceBusManagementClient"/> which can be used to perform management operation
 112        /// </summary>
 113        ///
 114        /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace to connect to.  This is like
 115        /// <param name="credential">The Azure managed identity credential to use for authorization.  Access controls ma
 116        public ServiceBusManagementClient(
 117            string fullyQualifiedNamespace,
 118            TokenCredential credential)
 0119            : this(fullyQualifiedNamespace, credential, new ServiceBusManagementClientOptions())
 120        {
 0121        }
 122
 123        /// <summary>
 124        /// Initializes a new <see cref="ServiceBusManagementClient"/> which can be used to perform management operation
 125        /// </summary>
 126        ///
 127        /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace to connect to.  This is like
 128        /// <param name="credential">The Azure managed identity credential to use for authorization.  Access controls ma
 129        /// <param name="options">A set of options to apply when configuring the connection.</param>
 4130        public ServiceBusManagementClient(
 4131            string fullyQualifiedNamespace,
 4132            TokenCredential credential,
 4133            ServiceBusManagementClientOptions options)
 134        {
 4135            Argument.AssertWellFormedServiceBusNamespace(fullyQualifiedNamespace, nameof(fullyQualifiedNamespace));
 4136            Argument.AssertNotNull(credential, nameof(credential));
 137
 4138            options ??= new ServiceBusManagementClientOptions();
 4139            _fullyQualifiedNamespace = fullyQualifiedNamespace;
 140
 141            switch (credential)
 142            {
 143                case SharedAccessSignatureCredential _:
 144                    break;
 145
 146                case ServiceBusSharedKeyCredential sharedKeyCredential:
 0147                    credential = sharedKeyCredential.AsSharedAccessSignatureCredential(BuildAudienceResource(fullyQualif
 148                    break;
 149            }
 4150            var tokenCredential = new ServiceBusTokenCredential(credential, BuildAudienceResource(fullyQualifiedNamespac
 151
 4152            var authenticationPolicy = new BearerTokenAuthenticationPolicy(credential, Constants.DefaultScope);
 4153            HttpPipeline pipeline = HttpPipelineBuilder.Build(
 4154                options,
 4155                 authenticationPolicy);
 4156            _clientDiagnostics = new ClientDiagnostics(options);
 157
 4158            _httpRequestAndResponse = new HttpRequestAndResponse(
 4159                pipeline,
 4160                _clientDiagnostics,
 4161                tokenCredential,
 4162                _fullyQualifiedNamespace);
 163
 4164        }
 165
 166        /// <summary>
 167        /// Gets information related to the currently used namespace.
 168        /// </summary>
 169        ///
 170        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 171        ///
 172        /// <remarks>Works with any claim (Send/Listen/Manage).</remarks>
 173        /// <returns><see cref="NamespaceProperties"/> containing namespace information.</returns>
 174        public virtual async Task<Response<NamespaceProperties>> GetNamespacePropertiesAsync(CancellationToken cancellat
 175        {
 4176            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetNames
 4177            scope.Start();
 178
 179            try
 180            {
 4181                Response response = await _httpRequestAndResponse.GetEntityAsync(
 4182                    NamespacePath,
 4183                    null,
 4184                    false,
 4185                    cancellationToken).ConfigureAwait(false);
 4186                var result = await ReadAsString(response).ConfigureAwait(false);
 4187                NamespaceProperties properties = NamespacePropertiesExtensions.ParseFromContent(result);
 188
 4189                return Response.FromValue(properties, response);
 190            }
 0191            catch (Exception ex)
 192            {
 0193                scope.Failed(ex);
 0194                throw;
 195            }
 4196        }
 197
 198        #region DeleteEntity
 199
 200        /// <summary>
 201        /// Deletes the queue described by the name relative to the service namespace base address.
 202        /// </summary>
 203        ///
 204        /// <param name="name">The name of the queue relative to the service namespace base address.</param>
 205        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 206        ///
 207        /// <exception cref="ArgumentException"><paramref name="name"/> is empty or null, or name starts or ends with "/
 208        /// <exception cref="ArgumentOutOfRangeException">The length of name is greater than 260.</exception>
 209        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 210        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Queue with this name does not exist.</exce
 211        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 212        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 213        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 214        public virtual async Task<Response> DeleteQueueAsync(
 215            string name,
 216            CancellationToken cancellationToken = default)
 217        {
 20218            EntityNameFormatter.CheckValidQueueName(name);
 20219            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.DeleteQu
 20220            scope.Start();
 221
 222            try
 223            {
 20224                return await _httpRequestAndResponse.DeleteEntityAsync(name, cancellationToken).ConfigureAwait(false);
 225            }
 4226            catch (Exception ex)
 227            {
 4228                scope.Failed(ex);
 4229                throw;
 230            }
 16231        }
 232
 233        /// <summary>
 234        /// Deletes the topic described by the name relative to the service namespace base address.
 235        /// </summary>
 236        ///
 237        /// <param name="name">The name of the topic relative to the service namespace base address.</param>
 238        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 239        ///
 240        /// <exception cref="ArgumentException"><paramref name="name"/> is empty or null, or name starts or ends with "/
 241        /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260.</exception>
 242        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 243        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic with this name does not exist.</exce
 244        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 245        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 246        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 247        public virtual async Task<Response> DeleteTopicAsync(
 248            string name,
 249            CancellationToken cancellationToken = default)
 250        {
 40251            EntityNameFormatter.CheckValidTopicName(name);
 40252            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.DeleteTo
 40253            scope.Start();
 254
 255            try
 256            {
 40257                return await _httpRequestAndResponse.DeleteEntityAsync(name, cancellationToken).ConfigureAwait(false);
 258            }
 4259            catch (Exception ex)
 260            {
 4261                scope.Failed(ex);
 4262                throw;
 263            }
 36264        }
 265
 266        /// <summary>
 267        /// Deletes the subscription with the specified topic and subscription name.
 268        /// </summary>
 269        ///
 270        /// <param name="topicName">The name of the topic relative to the service namespace base address.</param>
 271        /// <param name="subscriptionName">The name of the subscription to delete.</param>
 272        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 273        ///
 274        /// <exception cref="ArgumentException"><paramref name="topicName"/> or <paramref name="subscriptionName"/> is e
 275        /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs
 276        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 277        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Subscription with this name does not exist
 278        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 279        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 280        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 281        public virtual async Task<Response> DeleteSubscriptionAsync(
 282            string topicName,
 283            string subscriptionName,
 284            CancellationToken cancellationToken = default)
 285        {
 8286            EntityNameFormatter.CheckValidTopicName(topicName);
 8287            EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 8288            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.DeleteSu
 8289            scope.Start();
 290
 291            try
 292            {
 8293                return await _httpRequestAndResponse.DeleteEntityAsync(EntityNameFormatter.FormatSubscriptionPath(topicN
 294            }
 4295            catch (Exception ex)
 296            {
 4297                scope.Failed(ex);
 4298                throw;
 299            }
 4300        }
 301
 302        /// <summary>
 303        /// Deletes the rule described by <paramref name="ruleName"/> from <paramref name="subscriptionName"/> under <pa
 304        /// </summary>
 305        ///
 306        /// <param name="topicName">The name of the topic relative to the service namespace base address.</param>
 307        /// <param name="subscriptionName">The name of the subscription to delete.</param>
 308        /// <param name="ruleName">The name of the rule to delete.</param>
 309        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 310        ///
 311        /// <exception cref="ArgumentException">Thrown if <paramref name="topicName"/>, <paramref name="subscriptionName
 312        /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs
 313        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 314        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Rule with this name does not exist.</excep
 315        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 316        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 317        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 318        public virtual async Task<Response> DeleteRuleAsync(
 319            string topicName,
 320            string subscriptionName,
 321            string ruleName,
 322            CancellationToken cancellationToken = default)
 323        {
 4324            EntityNameFormatter.CheckValidTopicName(topicName);
 4325            EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 4326            EntityNameFormatter.CheckValidRuleName(ruleName);
 4327            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.DeleteRu
 4328            scope.Start();
 329
 330            try
 331            {
 4332                return await _httpRequestAndResponse.DeleteEntityAsync(EntityNameFormatter.FormatRulePath(topicName, sub
 333            }
 0334            catch (Exception ex)
 335            {
 0336                scope.Failed(ex);
 0337                throw;
 338            }
 4339        }
 340
 341        #endregion
 342
 343        #region GetEntity
 344
 345        /// <summary>
 346        /// Retrieves a queue from the service namespace.
 347        /// </summary>
 348        ///
 349        /// <param name="name">The name of the queue relative to service bus namespace.</param>
 350        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 351        ///
 352        /// <returns><see cref="QueueProperties"/> containing information about the queue.</returns>
 353        /// <exception cref="ArgumentException">Thrown if <paramref name="name"/> is null, white space empty or not in t
 354        /// <exception cref="ArgumentOutOfRangeException">The length of queue name is greater than 260.</exception>
 355        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 356        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Queue with this name does not exist.</exce
 357        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 358        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 359        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 360        public virtual async Task<Response<QueueProperties>> GetQueueAsync(
 361            string name,
 362            CancellationToken cancellationToken = default)
 363        {
 20364            EntityNameFormatter.CheckValidQueueName(name);
 20365            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetQueue
 20366            scope.Start();
 367
 368            try
 369            {
 20370                Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).C
 20371                var result = await ReadAsString(response).ConfigureAwait(false);
 20372                QueueProperties properties = QueuePropertiesExtensions.ParseFromContent(result);
 4373                return Response.FromValue(properties, response);
 374            }
 16375            catch (Exception ex)
 376            {
 16377                scope.Failed(ex);
 16378                throw;
 379            }
 4380        }
 381
 382        /// <summary>
 383        /// Retrieves a topic from the service namespace.
 384        /// </summary>
 385        ///
 386        /// <param name="name">The name of the topic relative to service bus namespace.</param>
 387        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 388        ///
 389        /// <returns><see cref="TopicProperties"/> containing information about the topic.</returns>
 390        /// <exception cref="ArgumentException">Thrown if <paramref name="name"/> is null, white space empty or not in t
 391        /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260.</exception>
 392        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 393        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic with this name does not exist.</exce
 394        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 395        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 396        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 397        public virtual async Task<Response<TopicProperties>> GetTopicAsync(
 398            string name,
 399            CancellationToken cancellationToken = default)
 400        {
 16401            EntityNameFormatter.CheckValidTopicName(name);
 16402            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetTopic
 16403            scope.Start();
 404
 405            try
 406            {
 16407                Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).C
 16408                var result = await ReadAsString(response).ConfigureAwait(false);
 16409                TopicProperties properties = TopicPropertiesExtensions.ParseFromContent(result);
 410
 8411                return Response.FromValue(properties, response);
 412            }
 8413            catch (Exception ex)
 414            {
 8415                scope.Failed(ex);
 8416                throw;
 417            }
 8418        }
 419
 420        /// <summary>
 421        /// Retrieves a subscription from the service namespace.
 422        /// </summary>
 423        ///
 424        /// <param name="topicName">The name of the topic relative to service bus namespace.</param>
 425        /// <param name="subscriptionName">The subscription name.</param>
 426        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 427        ///
 428        /// <returns><see cref="SubscriptionProperties"/> containing information about the subscription.</returns>
 429        /// <exception cref="ArgumentException">Thrown if <paramref name="topicName"/>, <paramref name="subscriptionName
 430        /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs
 431        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 432        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic or Subscription with this name does 
 433        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 434        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 435        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 436        public virtual async Task<Response<SubscriptionProperties>> GetSubscriptionAsync(
 437            string topicName,
 438            string subscriptionName,
 439            CancellationToken cancellationToken = default)
 440        {
 16441            EntityNameFormatter.CheckValidTopicName(topicName);
 16442            EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 16443            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetSubsc
 16444            scope.Start();
 445            try
 446            {
 16447                Response response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatSubscriptionP
 12448                var result = await ReadAsString(response).ConfigureAwait(false);
 12449                SubscriptionProperties properties = SubscriptionPropertiesExtensions.ParseFromContent(topicName, result)
 450
 8451                return Response.FromValue(properties, response);
 452            }
 8453            catch (Exception ex)
 454            {
 8455                scope.Failed(ex);
 8456                throw;
 457            }
 8458        }
 459
 460        /// <summary>
 461        /// Retrieves a rule from the service namespace.
 462        /// </summary>
 463        ///
 464        /// <param name="topicName">The name of the topic relative to service bus namespace.</param>
 465        /// <param name="subscriptionName">The subscription name the rule belongs to.</param>
 466        /// <param name="ruleName">The name of the rule to retrieve.</param>
 467        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 468        ///
 469        /// <remarks>Note - Only following data types are deserialized in Filters and Action parameters - string,int,lon
 470        /// Other data types would return its string value.</remarks>
 471        /// <returns><see cref="RuleProperties"/> containing information about the rule.</returns>
 472        /// <exception cref="ArgumentException">Thrown if <paramref name="topicName"/>, <paramref name="subscriptionName
 473        /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs
 474        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 475        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic/Subscription/Rule with this name doe
 476        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 477        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 478        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 479        public virtual async Task<Response<RuleProperties>> GetRuleAsync(
 480            string topicName,
 481            string subscriptionName,
 482            string ruleName,
 483            CancellationToken cancellationToken = default)
 484        {
 16485            EntityNameFormatter.CheckValidTopicName(topicName);
 16486            EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 16487            EntityNameFormatter.CheckValidRuleName(ruleName);
 488
 16489            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetRule"
 16490            scope.Start();
 491
 492            try
 493            {
 16494                Response response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatRulePath(topi
 12495                var result = await ReadAsString(response).ConfigureAwait(false);
 12496                RuleProperties rule = RuleDescriptionExtensions.ParseFromContent(result);
 497
 12498                return Response.FromValue(rule, response);
 499            }
 4500            catch (Exception ex)
 501            {
 4502                scope.Failed(ex);
 4503                throw;
 504            }
 12505        }
 506
 507        #endregion
 508
 509        #region GetRuntimeProperties
 510        /// <summary>
 511        /// Retrieves the runtime properties of a queue.
 512        /// </summary>
 513        ///
 514        /// <param name="name">The name of the queue relative to service bus namespace.</param>
 515        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 516        ///
 517        /// <returns><see cref="QueueRuntimeProperties"/> containing runtime properties about the queue.</returns>
 518        /// <exception cref="ArgumentException">Thrown if <paramref name="name"/> is null, white space empty or not in t
 519        /// <exception cref="ArgumentOutOfRangeException">The length of queue name is greater than 260.</exception>
 520        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 521        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Queue with this name does not exist.</exce
 522        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 523        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 524        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 525        public virtual async Task<Response<QueueRuntimeProperties>> GetQueueRuntimePropertiesAsync(
 526            string name,
 527            CancellationToken cancellationToken = default)
 528        {
 0529            EntityNameFormatter.CheckValidQueueName(name);
 0530            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetQueue
 0531            scope.Start();
 532
 533            try
 534            {
 0535                Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, true, cancellationToken).Co
 0536                var result = await ReadAsString(response).ConfigureAwait(false);
 0537                QueueRuntimeProperties runtimeProperties = QueueRuntimePropertiesExtensions.ParseFromContent(result);
 538
 0539                return Response.FromValue(runtimeProperties, response);
 540            }
 0541            catch (Exception ex)
 542            {
 0543                scope.Failed(ex);
 0544                throw;
 545            }
 0546        }
 547
 548        /// <summary>
 549        /// Retrieves the runtime properties of a topic.
 550        /// </summary>
 551        /// <param name="name">The name of the topic relative to service bus namespace.</param>
 552        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 553        ///
 554        /// <returns><see cref="TopicRuntimeProperties"/> containing runtime properties about the topic.</returns>
 555        /// <exception cref="ArgumentException">Thrown if <paramref name="name"/> is null, white space empty or not in t
 556        /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260.</exception>
 557        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 558        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic with this name does not exist.</exce
 559        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 560        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 561        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 562        public virtual async Task<Response<TopicRuntimeProperties>> GetTopicRuntimePropertiesAsync(
 563            string name,
 564            CancellationToken cancellationToken = default)
 565        {
 4566            EntityNameFormatter.CheckValidTopicName(name);
 4567            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetTopic
 4568            scope.Start();
 569
 570            try
 571            {
 4572                Response response = await _httpRequestAndResponse.GetEntityAsync(name, null, true, cancellationToken).Co
 4573                var result = await ReadAsString(response).ConfigureAwait(false);
 4574                TopicRuntimeProperties runtimeProperties = TopicRuntimePropertiesExtensions.ParseFromContent(result);
 575
 4576                return Response.FromValue(runtimeProperties, response);
 577            }
 0578            catch (Exception ex)
 579            {
 0580                scope.Failed(ex);
 0581                throw;
 582            }
 4583        }
 584
 585        /// <summary>
 586        /// Retrieves the runtime properties of a subscription.
 587        /// </summary>
 588        ///
 589        /// <param name="topicName">The name of the topic relative to service bus namespace.</param>
 590        /// <param name="subscriptionName">The subscription name.</param>
 591        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 592        ///
 593        /// <returns><see cref="SubscriptionRuntimeProperties"/> containing runtime properties about the subscription.</
 594        /// <exception cref="ArgumentException">Thrown if <paramref name="topicName"/>, <paramref name="subscriptionName
 595        /// <exception cref="ArgumentOutOfRangeException">The length of topic name is greater than 260 or length of subs
 596        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 597        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Topic or Subscription with this name does 
 598        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 599        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 600        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 601        public virtual async Task<Response<SubscriptionRuntimeProperties>> GetSubscriptionRuntimePropertiesAsync(
 602            string topicName,
 603            string subscriptionName,
 604            CancellationToken cancellationToken = default)
 605        {
 0606            EntityNameFormatter.CheckValidTopicName(topicName);
 0607            EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 0608            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetSubsc
 0609            scope.Start();
 610
 611            try
 612            {
 0613                Response response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatSubscriptionP
 0614                var result = await ReadAsString(response).ConfigureAwait(false);
 0615                SubscriptionRuntimeProperties runtimeProperties = SubscriptionRuntimePropertiesExtensions.ParseFromConte
 616
 0617                return Response.FromValue(runtimeProperties, response);
 618            }
 0619            catch (Exception ex)
 620            {
 0621                scope.Failed(ex);
 0622                throw;
 623            }
 0624        }
 625
 626        #endregion
 627
 628        #region GetEntities
 629        /// <summary>
 630        /// Retrieves the list of queues present in the namespace.
 631        /// </summary>
 632        ///
 633        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 634        ///
 635        /// <returns>An <see cref="AsyncPageable{T}"/> describing the queues.</returns>
 636        /// <remarks>Maximum value allowed is 100 per page.</remarks>
 637        /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception>
 638        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 639        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 640        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 641        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 642        public virtual AsyncPageable<QueueProperties> GetQueuesAsync(CancellationToken cancellationToken = default)
 643        {
 4644            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetQueue
 4645            scope.Start();
 646
 647            try
 648            {
 8649                return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA
 8650                    QueuesPath,
 8651                    nextSkip,
 12652                    rawResult => QueuePropertiesExtensions.ParseCollectionFromContent(rawResult),
 8653                    cancellationToken));
 654            }
 0655            catch (Exception ex)
 656            {
 0657                scope.Failed(ex);
 0658                throw;
 659            }
 4660        }
 661
 662        /// <summary>
 663        /// Retrieves the list of topics present in the namespace.
 664        /// </summary>
 665        ///
 666        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 667        ///
 668        /// <returns>An <see cref="AsyncPageable{T}"/> describing the topics.</returns>
 669        /// <remarks>Maximum value allowed is 100 per page.</remarks>
 670        /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception>
 671        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 672        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 673        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 674        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 675        public virtual AsyncPageable<TopicProperties> GetTopicsAsync(CancellationToken cancellationToken = default)
 676        {
 4677            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetTopic
 4678            scope.Start();
 679
 680            try
 681            {
 8682                return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA
 8683                    TopicsPath,
 8684                    nextSkip,
 12685                    rawResult => TopicPropertiesExtensions.ParseCollectionFromContent(rawResult),
 8686                    cancellationToken));
 687            }
 0688            catch (Exception ex)
 689            {
 0690                scope.Failed(ex);
 0691                throw;
 692            }
 4693        }
 694
 695        /// <summary>
 696        /// Retrieves the list of subscriptions present in the topic.
 697        /// </summary>
 698        ///
 699        /// <param name="topicName">The topic name under which all the subscriptions need to be retrieved.</param>
 700        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 701        ///
 702        /// <returns>An <see cref="AsyncPageable{T}"/> describing the subscriptions.</returns>
 703        /// <remarks>Maximum value allowed is 100 per page.</remarks>
 704        /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception>
 705        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 706        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 707        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 708        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 709        public virtual AsyncPageable<SubscriptionProperties> GetSubscriptionsAsync(
 710            string topicName,
 711            CancellationToken cancellationToken = default)
 712        {
 4713            EntityNameFormatter.CheckValidTopicName(topicName);
 4714            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetSubsc
 4715            scope.Start();
 716            try
 717            {
 8718                return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA
 8719                    string.Format(CultureInfo.CurrentCulture, SubscriptionsPath, topicName),
 8720                    nextSkip,
 12721                    rawResult => SubscriptionPropertiesExtensions.ParseCollectionFromContent(topicName, rawResult),
 8722                    cancellationToken));
 723            }
 0724            catch (Exception ex)
 725            {
 0726                scope.Failed(ex);
 0727                throw;
 728            }
 4729        }
 730
 731        /// <summary>
 732        /// Retrieves the list of rules for a given subscription in a topic.
 733        /// </summary>
 734        ///
 735        /// <param name="topicName">The topic name.</param>
 736        /// <param name="subscriptionName"> The subscription for which all the rules need to be retrieved.</param>
 737        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 738        ///
 739        /// <returns>An <see cref="AsyncPageable{T}"/> describing the rules.</returns>
 740        /// <remarks>Maximum value allowed is 100 per page.</remarks>
 741        /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception>
 742        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 743        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 744        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 745        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 746        public virtual AsyncPageable<RuleProperties> GetRulesAsync(
 747            string topicName,
 748            string subscriptionName,
 749            CancellationToken cancellationToken = default)
 750        {
 4751            EntityNameFormatter.CheckValidTopicName(topicName);
 4752            EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 4753            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetRules
 4754            scope.Start();
 755
 756            try
 757            {
 8758                return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA
 8759                    string.Format(CultureInfo.CurrentCulture, RulesPath, topicName, subscriptionName),
 8760                    nextSkip,
 12761                    rawResult => RuleDescriptionExtensions.ParseCollectionFromContent(rawResult),
 8762                    cancellationToken));
 763            }
 0764            catch (Exception ex)
 765            {
 0766                scope.Failed(ex);
 0767                throw;
 768            }
 4769        }
 770
 771        #endregion
 772
 773        #region GetEntitiesRuntimeProperties
 774        /// <summary>
 775        /// Retrieves the list of runtime properties for queues present in the namespace.
 776        /// </summary>
 777        ///
 778        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 779        ///
 780        /// <returns>An <see cref="AsyncPageable{T}"/> describing the queues runtime properties.</returns>
 781        /// <remarks>Maximum value allowed is 100 per page.</remarks>
 782        /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception>
 783        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 784        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 785        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 786        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 787        public virtual AsyncPageable<QueueRuntimeProperties> GetQueuesRuntimePropertiesAsync(CancellationToken cancellat
 788        {
 0789            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetQueue
 0790            scope.Start();
 791
 792            try
 793            {
 0794                return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA
 0795                    QueuesPath,
 0796                    nextSkip,
 0797                    rawResult => QueueRuntimePropertiesExtensions.ParseCollectionFromContent(rawResult),
 0798                    cancellationToken));
 799            }
 0800            catch (Exception ex)
 801            {
 0802                scope.Failed(ex);
 0803                throw;
 804            }
 0805        }
 806
 807        /// <summary>
 808        /// Retrieves the list of runtime properties for topics present in the namespace.
 809        /// </summary>
 810        ///
 811        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 812        ///
 813        /// <returns>An <see cref="AsyncPageable{T}"/> describing the topics runtime properties.</returns>
 814        /// <remarks>Maximum value allowed is 100 per page.</remarks>
 815        /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception>
 816        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 817        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 818        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 819        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 820        public virtual AsyncPageable<TopicRuntimeProperties> GetTopicsRuntimePropertiesAsync(CancellationToken cancellat
 821        {
 4822            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetTopic
 4823            scope.Start();
 824            try
 825            {
 8826                return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA
 8827                    TopicsPath,
 8828                    nextSkip,
 12829                    rawResult => TopicRuntimePropertiesExtensions.ParseCollectionFromContent(rawResult),
 8830                    cancellationToken));
 831            }
 0832            catch (Exception ex)
 833            {
 0834                scope.Failed(ex);
 0835                throw;
 836            }
 4837        }
 838        /// <summary>
 839        /// Retrieves the list of runtime properties for subscriptions present in the namespace.
 840        /// </summary>
 841        ///
 842        /// <param name="topicName">The name of the topic relative to service bus namespace.</param>
 843        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 844        ///
 845        ///  <returns>An <see cref="AsyncPageable{T}"/> describing the subscriptions runtime properties.</returns>
 846        /// <remarks>Maximum value allowed is 100 per page.</remarks>
 847        /// <exception cref="ArgumentOutOfRangeException">If the parameters are out of range.</exception>
 848        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 849        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 850        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 851        /// <exception cref="ServiceBusException">An internal error or an unexpected exception occured.</exception>
 852        public virtual AsyncPageable<SubscriptionRuntimeProperties> GetSubscriptionsRuntimePropertiesAsync(
 853            string topicName,
 854            CancellationToken cancellationToken = default)
 855        {
 0856            EntityNameFormatter.CheckValidTopicName(topicName);
 0857            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.GetSubsc
 0858            scope.Start();
 859            try
 860            {
 0861                return PageResponseEnumerator.CreateAsyncEnumerable(nextSkip => _httpRequestAndResponse.GetEntitiesPageA
 0862                    string.Format(CultureInfo.CurrentCulture, SubscriptionsPath, topicName),
 0863                    nextSkip,
 0864                    rawResult => SubscriptionRuntimePropertiesExtensions.ParseCollectionFromContent(topicName, rawResult
 0865                    cancellationToken));
 866            }
 0867            catch (Exception ex)
 868            {
 0869                scope.Failed(ex);
 0870                throw;
 871            }
 0872        }
 873
 874        #endregion
 875
 876        #region CreateEntity
 877
 878        /// <summary>
 879        /// Creates a new queue in the service namespace with the given name.
 880        /// </summary>
 881        ///
 882        /// <param name="name">The name of the queue relative to the service namespace base address.</param>
 883        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 884        ///
 885        /// <remarks>Throws if a queue already exists. <see cref="QueueProperties"/> for default values of queue propert
 886        /// <returns>The <see cref="QueueProperties"/> of the newly created queue.</returns>
 887        /// <exception cref="ArgumentNullException">Queue name is null or empty.</exception>
 888        /// <exception cref="ArgumentOutOfRangeException">The length of <paramref name="name"/> is greater than 260 char
 889        /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">An entity with the same name exists u
 890        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 891        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 892        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 893        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 894        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 895        public virtual async Task<Response<QueueProperties>> CreateQueueAsync(
 896            string name,
 897            CancellationToken cancellationToken = default) =>
 12898            await CreateQueueAsync(
 12899                new CreateQueueOptions(name),
 12900                cancellationToken).ConfigureAwait(false);
 901
 902        /// <summary>
 903        /// Creates a new queue in the service namespace with the given name.
 904        /// </summary>
 905        /// <param name="options">A <see cref="CreateQueueOptions"/> object describing the attributes with which the new
 906        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 907        ///
 908        /// <remarks>Throws if a queue already exists.</remarks>
 909        /// <returns>The <see cref="QueueProperties"/> of the newly created queue.</returns>
 910        /// <exception cref="ArgumentNullException">Queue name is null or empty.</exception>
 911        /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">An entity with the same name exists u
 912        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 913        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 914        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 915        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 916        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 917        public virtual async Task<Response<QueueProperties>> CreateQueueAsync(
 918            CreateQueueOptions options,
 919            CancellationToken cancellationToken = default)
 920        {
 20921            Argument.AssertNotNull(options, nameof(options));
 20922            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.CreateQu
 20923            scope.Start();
 924            try
 925            {
 20926                var queue = new QueueProperties(options);
 20927                queue.NormalizeDescription(_fullyQualifiedNamespace);
 20928                var atomRequest = queue.Serialize().ToString();
 20929                Response response = await _httpRequestAndResponse.PutEntityAsync(
 20930                    queue.Name,
 20931                    atomRequest,
 20932                    false,
 20933                    queue.ForwardTo,
 20934                    queue.ForwardDeadLetteredMessagesTo,
 20935                    cancellationToken).ConfigureAwait(false);
 936
 16937                var result = await ReadAsString(response).ConfigureAwait(false);
 16938                QueueProperties description = QueuePropertiesExtensions.ParseFromContent(result);
 16939                return Response.FromValue(description, response);
 940            }
 4941            catch (Exception ex)
 942            {
 4943                scope.Failed(ex);
 4944                throw;
 945            }
 16946        }
 947
 948        /// <summary>
 949        /// Creates a new topic in the service namespace with the given name.
 950        /// </summary>
 951        ///
 952        /// <param name="name">The name of the topic relative to the service namespace base address.</param>
 953        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 954        ///
 955        /// <remarks>Throws if a topic already exists. <see cref="TopicProperties"/> for default values of topic propert
 956        /// <returns>The <see cref="TopicProperties"/> of the newly created topic.</returns>
 957        /// <exception cref="ArgumentNullException">Topic name is null or empty.</exception>
 958        /// <exception cref="ArgumentOutOfRangeException">The length of <paramref name="name"/> is greater than 260 char
 959        /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A topic with the same name exists und
 960        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 961        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 962        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 963        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 964        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 965        public virtual async Task<Response<TopicProperties>> CreateTopicAsync(
 966            string name,
 967            CancellationToken cancellationToken = default) =>
 32968            await CreateTopicAsync(
 32969                new CreateTopicOptions(name),
 32970                cancellationToken).ConfigureAwait(false);
 971
 972        /// <summary>
 973        /// Creates a new topic in the service namespace with the given name.
 974        /// </summary>
 975        ///
 976        /// <param name="options">A <see cref="TopicProperties"/> object describing the attributes with which the new to
 977        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 978        ///
 979        /// <remarks>Throws if a topic already exists. <see cref="TopicProperties"/> for default values of topic propert
 980        /// <returns>The <see cref="TopicProperties"/> of the newly created topic.</returns>
 981        /// <exception cref="ArgumentNullException">Topic description is null.</exception>
 982        /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A topic with the same name exists und
 983        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 984        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 985        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 986        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 987        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 988        public virtual async Task<Response<TopicProperties>> CreateTopicAsync(
 989            CreateTopicOptions options,
 990            CancellationToken cancellationToken = default)
 991        {
 40992            Argument.AssertNotNull(options, nameof(options));
 40993            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.CreateTo
 40994            scope.Start();
 995
 996            try
 997            {
 40998                var topic = new TopicProperties(options);
 40999                var atomRequest = topic.Serialize().ToString();
 1000
 401001                Response response = await _httpRequestAndResponse.PutEntityAsync(
 401002                    topic.Name,
 401003                    atomRequest,
 401004                    false,
 401005                    null,
 401006                    null,
 401007                    cancellationToken).ConfigureAwait(false);
 361008                var result = await ReadAsString(response).ConfigureAwait(false);
 361009                TopicProperties description = TopicPropertiesExtensions.ParseFromContent(result);
 1010
 361011                return Response.FromValue(description, response);
 1012            }
 41013            catch (Exception ex)
 1014            {
 41015                scope.Failed(ex);
 41016                throw;
 1017            }
 361018        }
 1019
 1020        /// <summary>
 1021        /// Creates a new subscription within a topic in the service namespace with the given name.
 1022        /// </summary>
 1023        ///
 1024        /// <param name="topicName">The name of the topic relative to the service namespace base address.</param>
 1025        /// <param name="subscriptionName">The name of the subscription.</param>
 1026        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1027        ///
 1028        /// <remarks>Throws if a subscription already exists. <see cref="SubscriptionProperties"/> for default values of
 1029        /// By default, A "pass-through" filter is created for this subscription, which means it will allow all messages
 1030        /// <see cref="CreateSubscriptionAsync(CreateSubscriptionOptions, CreateRuleOptions, CancellationToken)"/> for c
 1031        /// <returns>The <see cref="SubscriptionProperties"/> of the newly created subscription.</returns>
 1032        /// <exception cref="ArgumentNullException">Topic name or subscription name is null or empty.</exception>
 1033        /// <exception cref="ArgumentOutOfRangeException">The length of <paramref name="topicName"/> is greater than 260
 1034        /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A subscription with the same name exi
 1035        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 1036        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1037        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 1038        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1039        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1040        public virtual async Task<Response<SubscriptionProperties>> CreateSubscriptionAsync(
 1041            string topicName,
 1042            string subscriptionName,
 1043            CancellationToken cancellationToken = default) =>
 201044            await CreateSubscriptionAsync(
 201045                new CreateSubscriptionOptions(topicName, subscriptionName),
 201046                cancellationToken).ConfigureAwait(false);
 1047
 1048        /// <summary>
 1049        /// Creates a new subscription within a topic in the service namespace with the given name.
 1050        /// </summary>
 1051        ///
 1052        /// <param name="options">A <see cref="SubscriptionProperties"/> object describing the attributes with which the
 1053        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1054        ///
 1055        /// <remarks>Throws if a subscription already exists.
 1056        /// Be default, A "pass-through" filter is created for this subscription, which means it will allow all messages
 1057        /// <see cref="CreateSubscriptionAsync(CreateSubscriptionOptions, CreateRuleOptions, CancellationToken)"/> for c
 1058        /// <returns>The <see cref="SubscriptionProperties"/> of the newly created subscription.</returns>
 1059        /// <exception cref="ArgumentNullException">Subscription description is null.</exception>
 1060        /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A subscription with the same name exi
 1061        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 1062        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1063        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 1064        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1065        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1066        public virtual Task<Response<SubscriptionProperties>> CreateSubscriptionAsync(
 1067            CreateSubscriptionOptions options,
 1068            CancellationToken cancellationToken = default)
 1069        {
 241070            options = options ?? throw new ArgumentNullException(nameof(options));
 241071            return CreateSubscriptionAsync(options, new CreateRuleOptions(), cancellationToken);
 1072        }
 1073
 1074        /// <summary>
 1075        /// Creates a new subscription within a topic with the provided default rule.
 1076        /// </summary>
 1077        ///
 1078        /// <param name="options">A <see cref="SubscriptionProperties"/> object describing the attributes with which the
 1079        /// <param name="rule"> A <see cref="RuleProperties"/> object describing the default rule. If null, then pass-th
 1080        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1081        ///
 1082        /// <remarks>Throws if a subscription already exists. </remarks>
 1083        /// <returns>The <see cref="SubscriptionProperties"/> of the newly created subscription.</returns>
 1084        /// <exception cref="ArgumentNullException">Subscription description is null.</exception>
 1085        /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A subscription with the same name exi
 1086        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 1087        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1088        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 1089        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1090        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1091        public virtual async Task<Response<SubscriptionProperties>> CreateSubscriptionAsync(
 1092            CreateSubscriptionOptions options,
 1093            CreateRuleOptions rule,
 1094            CancellationToken cancellationToken = default)
 1095        {
 281096            options = options ?? throw new ArgumentNullException(nameof(options));
 281097            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.CreateSu
 281098            scope.Start();
 1099
 1100            try
 1101            {
 281102                var subscription = new SubscriptionProperties(options);
 281103                subscription.NormalizeDescription(_fullyQualifiedNamespace);
 281104                subscription.Rule = new RuleProperties(rule);
 281105                var atomRequest = subscription.Serialize().ToString();
 1106
 281107                Response response = await _httpRequestAndResponse.PutEntityAsync(
 281108                    EntityNameFormatter.FormatSubscriptionPath(subscription.TopicName, subscription.SubscriptionName),
 281109                    atomRequest,
 281110                    false,
 281111                    subscription.ForwardTo,
 281112                    subscription.ForwardDeadLetteredMessagesTo,
 281113                    cancellationToken).ConfigureAwait(false);
 241114                var result = await ReadAsString(response).ConfigureAwait(false);
 241115                SubscriptionProperties description = SubscriptionPropertiesExtensions.ParseFromContent(subscription.Topi
 1116
 241117                return Response.FromValue(description, response);
 1118            }
 41119            catch (Exception ex)
 1120            {
 41121                scope.Failed(ex);
 41122                throw;
 1123            }
 241124        }
 1125
 1126        /// <summary>
 1127        /// Adds a new rule to the subscription under given topic.
 1128        /// </summary>
 1129        ///
 1130        /// <param name="topicName">The topic name relative to the service namespace base address.</param>
 1131        /// <param name="subscriptionName">The name of the subscription.</param>
 1132        /// <param name="options">A <see cref="CreateRuleOptions"/> object describing the attributes with which the mess
 1133        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1134        ///
 1135        /// <exception cref="ArgumentNullException">Subscription or rule description is null.</exception>
 1136        /// <exception cref="ServiceBusFailureReason.MessagingEntityAlreadyExists">A subscription with the same name exi
 1137        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out. The timeout period is init
 1138        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1139        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 1140        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1141        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1142        /// <returns><see cref="RuleProperties"/> of the recently created rule.</returns>
 1143        public virtual async Task<Response<RuleProperties>> CreateRuleAsync(
 1144            string topicName,
 1145            string subscriptionName,
 1146            CreateRuleOptions options,
 1147            CancellationToken cancellationToken = default)
 1148        {
 161149            EntityNameFormatter.CheckValidTopicName(topicName);
 161150            EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 161151            options = options ?? throw new ArgumentNullException(nameof(options));
 1152
 161153            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.CreateRu
 161154            scope.Start();
 1155
 1156            try
 1157            {
 161158                var rule = new RuleProperties(options);
 161159                var atomRequest = rule.Serialize().ToString();
 1160
 161161                Response response = await _httpRequestAndResponse.PutEntityAsync(
 161162                    EntityNameFormatter.FormatRulePath(topicName, subscriptionName, rule.Name),
 161163                    atomRequest,
 161164                    false,
 161165                    null,
 161166                    null,
 161167                    cancellationToken).ConfigureAwait(false);
 161168                var result = await ReadAsString(response).ConfigureAwait(false);
 161169                RuleProperties description = RuleDescriptionExtensions.ParseFromContent(result);
 1170
 161171                return Response.FromValue(description, response);
 1172            }
 01173            catch (Exception ex)
 1174            {
 01175                scope.Failed(ex);
 01176                throw;
 1177            }
 161178        }
 1179
 1180        #endregion CreateEntity
 1181
 1182        #region UpdateEntity
 1183        /// <summary>
 1184        /// Updates an existing queue.
 1185        /// </summary>
 1186        ///
 1187        /// <param name="queue">A <see cref="QueueProperties"/> object describing the attributes with which the queue wi
 1188        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1189        ///
 1190        /// <returns>The <see cref="QueueProperties"/> of the updated queue.</returns>
 1191        /// <exception cref="ArgumentNullException">Queue descriptor is null.</exception>
 1192        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Described queue was not found.</exception>
 1193        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception>
 1194        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1195        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 1196        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1197        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1198        public virtual async Task<Response<QueueProperties>> UpdateQueueAsync(
 1199            QueueProperties queue,
 1200            CancellationToken cancellationToken = default)
 1201        {
 81202            queue = queue ?? throw new ArgumentNullException(nameof(queue));
 1203
 81204            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.UpdateQu
 81205            scope.Start();
 1206
 1207            try
 1208            {
 81209                queue.NormalizeDescription(_fullyQualifiedNamespace);
 81210                var atomRequest = queue.Serialize().ToString();
 1211
 81212                Response response = await _httpRequestAndResponse.PutEntityAsync(
 81213                    queue.Name,
 81214                    atomRequest,
 81215                    true,
 81216                    queue.ForwardTo,
 81217                    queue.ForwardDeadLetteredMessagesTo,
 81218                    cancellationToken).ConfigureAwait(false);
 41219                var result = await ReadAsString(response).ConfigureAwait(false);
 41220                QueueProperties description = QueuePropertiesExtensions.ParseFromContent(result);
 1221
 41222                return Response.FromValue(description, response);
 1223            }
 41224            catch (Exception ex)
 1225            {
 41226                scope.Failed(ex);
 41227                throw;
 1228            }
 41229        }
 1230
 1231        /// <summary>
 1232        /// Updates an existing topic.
 1233        /// </summary>
 1234        ///
 1235        /// <param name="topic">A <see cref="TopicProperties"/> object describing the attributes with which the topic wi
 1236        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1237        ///
 1238        /// <returns>The <see cref="TopicProperties"/> of the updated topic.</returns>
 1239        /// <exception cref="ArgumentNullException">Topic descriptor is null.</exception>
 1240        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Described topic was not found.</exception>
 1241        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception>
 1242        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1243        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 1244        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1245        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1246        public virtual async Task<Response<TopicProperties>> UpdateTopicAsync(
 1247            TopicProperties topic,
 1248            CancellationToken cancellationToken = default)
 1249        {
 121250            topic = topic ?? throw new ArgumentNullException(nameof(topic));
 121251            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.UpdateTo
 121252            scope.Start();
 1253
 1254            try
 1255            {
 121256                var atomRequest = topic.Serialize().ToString();
 1257
 121258                Response response = await _httpRequestAndResponse.PutEntityAsync(
 121259                    topic.Name,
 121260                    atomRequest,
 121261                    true,
 121262                    forwardTo: null,
 121263                    fwdDeadLetterTo: null,
 121264                    cancellationToken).ConfigureAwait(false);
 81265                var result = await ReadAsString(response).ConfigureAwait(false);
 81266                TopicProperties description = TopicPropertiesExtensions.ParseFromContent(result);
 1267
 81268                return Response.FromValue(description, response);
 1269            }
 41270            catch (Exception ex)
 1271            {
 41272                scope.Failed(ex);
 41273                throw;
 1274            }
 81275        }
 1276
 1277        /// <summary>
 1278        /// Updates an existing subscription under a topic.
 1279        /// </summary>
 1280        ///
 1281        /// <param name="subscription">A <see cref="SubscriptionProperties"/> object describing the attributes with whic
 1282        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1283        ///
 1284        /// <returns>The <see cref="SubscriptionProperties"/> of the updated subscription.</returns>
 1285        /// <exception cref="ArgumentNullException">subscription descriptor is null.</exception>
 1286        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Described subscription was not found.</exc
 1287        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception>
 1288        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1289        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 1290        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1291        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1292        public virtual async Task<Response<SubscriptionProperties>> UpdateSubscriptionAsync(
 1293            SubscriptionProperties subscription,
 1294            CancellationToken cancellationToken = default)
 1295        {
 81296            subscription = subscription ?? throw new ArgumentNullException(nameof(subscription));
 1297
 81298            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.UpdateSu
 81299            scope.Start();
 1300
 1301            try
 1302            {
 81303                subscription.NormalizeDescription(_fullyQualifiedNamespace);
 81304                var atomRequest = subscription.Serialize().ToString();
 1305
 81306                Response response = await _httpRequestAndResponse.PutEntityAsync(
 81307                    EntityNameFormatter.FormatSubscriptionPath(subscription.TopicName, subscription.SubscriptionName),
 81308                    atomRequest,
 81309                    true,
 81310                    subscription.ForwardTo,
 81311                    subscription.ForwardDeadLetteredMessagesTo,
 81312                    cancellationToken).ConfigureAwait(false);
 41313                var result = await ReadAsString(response).ConfigureAwait(false);
 41314                SubscriptionProperties description = SubscriptionPropertiesExtensions.ParseFromContent(subscription.Topi
 1315
 41316                return Response.FromValue(description, response);
 1317            }
 41318            catch (Exception ex)
 1319            {
 41320                scope.Failed(ex);
 41321                throw;
 1322            }
 41323        }
 1324
 1325        /// <summary>
 1326        /// Updates an existing rule for a topic-subscription.
 1327        /// </summary>
 1328        ///
 1329        /// <param name="topicName">Name of the topic.</param>
 1330        /// <param name="subscriptionName">Name of the subscription.</param>
 1331        /// <param name="rule">A <see cref="RuleProperties"/> object describing the attributes with which the rule will 
 1332        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1333        ///
 1334        /// <returns>The <see cref="RuleProperties"/> of the updated rule.</returns>
 1335        /// <exception cref="ArgumentNullException">rule descriptor is null.</exception>
 1336        /// <exception cref="ServiceBusFailureReason.MessagingEntityNotFound">Described topic/subscription/rule was not 
 1337        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception>
 1338        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1339        /// <exception cref="ServiceBusFailureReason.QuotaExceeded">Either the specified size in the description is not 
 1340        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1341        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1342        public virtual async Task<Response<RuleProperties>> UpdateRuleAsync(
 1343            string topicName,
 1344            string subscriptionName,
 1345            RuleProperties rule,
 1346            CancellationToken cancellationToken = default)
 1347        {
 41348            rule = rule ?? throw new ArgumentNullException(nameof(rule));
 1349
 41350            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.UpdateRu
 41351            scope.Start();
 1352
 1353            try
 1354            {
 41355                EntityNameFormatter.CheckValidTopicName(topicName);
 41356                EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 1357
 41358                var atomRequest = rule.Serialize().ToString();
 41359                Response response = await _httpRequestAndResponse.PutEntityAsync(
 41360                    EntityNameFormatter.FormatRulePath(topicName, subscriptionName, rule.Name),
 41361                    atomRequest,
 41362                    true,
 41363                    null,
 41364                    null,
 41365                    cancellationToken).ConfigureAwait(false);
 41366                var result = await ReadAsString(response).ConfigureAwait(false);
 41367                RuleProperties description = RuleDescriptionExtensions.ParseFromContent(result);
 1368
 41369                return Response.FromValue(description, response);
 1370            }
 01371            catch (Exception ex)
 1372            {
 01373                scope.Failed(ex);
 01374                throw;
 1375            }
 41376        }
 1377
 1378        #endregion
 1379
 1380        #region Exists
 1381        /// <summary>
 1382        /// Checks whether a given queue exists or not.
 1383        /// </summary>
 1384        ///
 1385        /// <param name="name">Name of the queue entity to check.</param>
 1386        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1387        ///
 1388        /// <returns>True if queue exists, false otherwise.</returns>
 1389        /// <exception cref="ArgumentException">Queue name provided is not valid.</exception>
 1390        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception>
 1391        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1392        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1393        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1394        public virtual async Task<Response<bool>> QueueExistsAsync(
 1395            string name,
 1396            CancellationToken cancellationToken = default)
 1397        {
 81398            EntityNameFormatter.CheckValidQueueName(name);
 81399            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.QueueExi
 81400            scope.Start();
 1401            try
 1402            {
 81403                Response response = null;
 1404                try
 1405                {
 81406                    response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).Config
 81407                    var result = await ReadAsString(response).ConfigureAwait(false);
 81408                    QueueProperties description = QueuePropertiesExtensions.ParseFromContent(result);
 41409                }
 41410                catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound)
 1411                {
 41412                    return Response.FromValue(false, response);
 1413                }
 1414
 41415                return Response.FromValue(true, response);
 1416            }
 01417            catch (Exception ex)
 1418            {
 01419                scope.Failed(ex);
 01420                throw;
 1421            }
 81422        }
 1423
 1424        /// <summary>
 1425        /// Checks whether a given topic exists or not.
 1426        /// </summary>
 1427        ///
 1428        /// <param name="name">Name of the topic entity to check.</param>
 1429        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1430        ///
 1431        /// <returns>True if topic exists, false otherwise.</returns>
 1432        /// <exception cref="ArgumentException">topic name provided is not valid.</exception>
 1433        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception>
 1434        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1435        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1436        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1437        public virtual async Task<Response<bool>> TopicExistsAsync(
 1438            string name,
 1439            CancellationToken cancellationToken = default)
 1440        {
 81441            EntityNameFormatter.CheckValidTopicName(name);
 81442            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.TopicExi
 81443            scope.Start();
 1444
 1445            try
 1446            {
 81447                Response response = null;
 1448
 1449                try
 1450                {
 81451                    response = await _httpRequestAndResponse.GetEntityAsync(name, null, false, cancellationToken).Config
 81452                    var result = await ReadAsString(response).ConfigureAwait(false);
 81453                    TopicProperties description = TopicPropertiesExtensions.ParseFromContent(result);
 41454                }
 41455                catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound)
 1456                {
 41457                    return Response.FromValue(false, response);
 1458                }
 1459
 41460                return Response.FromValue(true, response);
 1461            }
 01462            catch (Exception ex)
 1463            {
 01464                scope.Failed(ex);
 01465                throw;
 1466            }
 81467        }
 1468
 1469        /// <summary>
 1470        /// Checks whether a given subscription exists or not.
 1471        /// </summary>
 1472        ///
 1473        /// <param name="topicName">Name of the topic.</param>
 1474        /// <param name="subscriptionName">Name of the subscription to check.</param>
 1475        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1476        ///
 1477        /// <returns>True if subscription exists, false otherwise.</returns>
 1478        /// <exception cref="ArgumentException">topic or subscription name provided is not valid.</exception>
 1479        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception>
 1480        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1481        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1482        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1483        public virtual async Task<Response<bool>> SubscriptionExistsAsync(
 1484            string topicName,
 1485            string subscriptionName,
 1486            CancellationToken cancellationToken = default)
 1487        {
 81488            EntityNameFormatter.CheckValidTopicName(topicName);
 81489            EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 81490            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.Subscrip
 81491            scope.Start();
 1492
 1493            try
 1494            {
 81495                Response response = null;
 1496
 1497                try
 1498                {
 81499                    response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatSubscriptionPath(t
 81500                    var result = await ReadAsString(response).ConfigureAwait(false);
 81501                    SubscriptionProperties description = SubscriptionPropertiesExtensions.ParseFromContent(topicName, re
 41502                }
 41503                catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound)
 1504                {
 41505                    return Response.FromValue(false, response);
 1506                }
 1507
 41508                return Response.FromValue(true, response);
 1509            }
 01510            catch (Exception ex)
 1511            {
 01512                scope.Failed(ex);
 01513                throw;
 1514            }
 81515        }
 1516
 1517        /// <summary>
 1518        /// Checks whether a given rule exists or not.
 1519        /// </summary>
 1520        ///
 1521        /// <param name="topicName">Name of the topic.</param>
 1522        /// <param name="subscriptionName">Name of the subscription to check.</param>
 1523        /// <param name="ruleName">The name of the rule to retrieve.</param>
 1524        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t
 1525        ///
 1526        /// <returns>True if subscription exists, false otherwise.</returns>
 1527        /// <exception cref="ArgumentException">topic or subscription name provided is not valid.</exception>
 1528        /// <exception cref="ServiceBusFailureReason.ServiceTimeout">The operation times out.</exception>
 1529        /// <exception cref="UnauthorizedAccessException">No sufficient permission to perform this operation. You should
 1530        /// <exception cref="ServiceBusFailureReason.ServiceBusy">The server is busy. You should wait before you retry t
 1531        /// <exception cref="ServiceBusException">An internal error or unexpected exception occurs.</exception>
 1532        public virtual async Task<Response<bool>> RuleExistsAsync(
 1533            string topicName,
 1534            string subscriptionName,
 1535            string ruleName,
 1536            CancellationToken cancellationToken = default)
 1537        {
 81538            EntityNameFormatter.CheckValidTopicName(topicName);
 81539            EntityNameFormatter.CheckValidSubscriptionName(subscriptionName);
 81540            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ServiceBusManagementClient)}.RuleExis
 81541            scope.Start();
 1542
 1543            try
 1544            {
 81545                Response response = null;
 1546
 1547                try
 1548                {
 81549                    response = await _httpRequestAndResponse.GetEntityAsync(EntityNameFormatter.FormatRulePath(topicName
 41550                    var result = await ReadAsString(response).ConfigureAwait(false);
 41551                    RuleProperties description = RuleDescriptionExtensions.ParseFromContent(result);
 41552                }
 41553                catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound)
 1554                {
 41555                    return Response.FromValue(false, response);
 1556                }
 1557
 41558                return Response.FromValue(true, response);
 1559            }
 01560            catch (Exception ex)
 1561            {
 01562                scope.Failed(ex);
 01563                throw;
 1564            }
 81565        }
 1566
 1567        #endregion
 1568
 1569        private static async Task<string> ReadAsString(Response response)
 1570        {
 1571            string exceptionMessage;
 2081572            using StreamReader reader = new StreamReader(response.ContentStream);
 2081573            exceptionMessage = await reader.ReadToEndAsync().ConfigureAwait(false);
 2081574            return exceptionMessage;
 2081575        }
 1576
 1577        /// <summary>
 1578        /// Builds the audience for use in the signature.
 1579        /// </summary>
 1580        ///
 1581        /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace.  This is likely to be simil
 1582        ///
 1583        /// <returns>The value to use as the audience of the signature.</returns>
 1584        private static string BuildAudienceResource(string fullyQualifiedNamespace)
 1585        {
 841586            var builder = new UriBuilder(fullyQualifiedNamespace)
 841587            {
 841588                Scheme = Uri.UriSchemeHttps,
 841589                Port = -1,
 841590                Fragment = string.Empty,
 841591                Password = string.Empty,
 841592                UserName = string.Empty,
 841593            };
 1594
 841595            if (builder.Path.EndsWith("/", StringComparison.InvariantCultureIgnoreCase))
 1596            {
 841597                builder.Path = builder.Path.TrimEnd('/');
 1598            }
 1599
 841600            return builder.Uri.AbsoluteUri.ToLowerInvariant();
 1601        }
 1602    }
 1603
 1604}