| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.ServiceBus.Management |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | |
|
| | 9 | | /// <summary> |
| | 10 | | /// Represents the metadata description of the topic. |
| | 11 | | /// </summary> |
| | 12 | | public class TopicDescription : IEquatable<TopicDescription> |
| | 13 | | { |
| 0 | 14 | | internal TimeSpan duplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(1); |
| | 15 | | internal string path; |
| 0 | 16 | | TimeSpan defaultMessageTimeToLive = TimeSpan.MaxValue; |
| 0 | 17 | | TimeSpan autoDeleteOnIdle = TimeSpan.MaxValue; |
| | 18 | | string userMetadata = null; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Initializes a new instance of TopicDescription class with the specified relative path. |
| | 22 | | /// </summary> |
| | 23 | | /// <param name="path">Path of the topic relative to the namespace base address.</param> |
| 0 | 24 | | public TopicDescription(string path) |
| | 25 | | { |
| 0 | 26 | | this.Path = path; |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// The default time to live value for the messages. This is the duration after which the message expires, start |
| | 31 | | /// the message is sent to Service Bus. </summary> |
| | 32 | | /// <remarks> |
| | 33 | | /// This is the default value used when <see cref="Message.TimeToLive"/> is not set on a |
| | 34 | | /// message itself. Messages older than their TimeToLive value will expire and no longer be retained in the mes |
| | 35 | | /// Subscribers will be unable to receive expired messages. |
| | 36 | | /// Default value is <see cref="TimeSpan.MaxValue"/>. |
| | 37 | | /// </remarks> |
| | 38 | | public TimeSpan DefaultMessageTimeToLive |
| | 39 | | { |
| 0 | 40 | | get => this.defaultMessageTimeToLive; |
| | 41 | | set |
| | 42 | | { |
| 0 | 43 | | if (value < ManagementClientConstants.MinimumAllowedTimeToLive || value > ManagementClientConstants.Maxi |
| | 44 | | { |
| 0 | 45 | | throw new ArgumentOutOfRangeException(nameof(DefaultMessageTimeToLive), |
| 0 | 46 | | $"The value must be between {ManagementClientConstants.MinimumAllowedTimeToLive} and {Management |
| | 47 | | } |
| | 48 | |
|
| 0 | 49 | | this.defaultMessageTimeToLive = value; |
| 0 | 50 | | } |
| | 51 | | } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// The <see cref="TimeSpan"/> idle interval after which the topic is automatically deleted. |
| | 55 | | /// </summary> |
| | 56 | | /// <remarks>The minimum duration is 5 minutes. Default value is <see cref="TimeSpan.MaxValue"/>.</remarks> |
| | 57 | | public TimeSpan AutoDeleteOnIdle |
| | 58 | | { |
| 0 | 59 | | get => this.autoDeleteOnIdle; |
| | 60 | | set |
| | 61 | | { |
| 0 | 62 | | if (value < ManagementClientConstants.MinimumAllowedAutoDeleteOnIdle) |
| | 63 | | { |
| 0 | 64 | | throw new ArgumentOutOfRangeException(nameof(AutoDeleteOnIdle), |
| 0 | 65 | | $"The value must be greater than {ManagementClientConstants.MinimumAllowedAutoDeleteOnIdle}"); |
| | 66 | | } |
| | 67 | |
|
| 0 | 68 | | this.autoDeleteOnIdle = value; |
| 0 | 69 | | } |
| | 70 | | } |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// The maximum size of the topic in megabytes, which is the size of memory allocated for the topic. |
| | 74 | | /// </summary> |
| | 75 | | /// <remarks>Default value is 1024.</remarks> |
| 0 | 76 | | public long MaxSizeInMB { get; set; } = 1024; |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// This value indicates if the topic requires guard against duplicate messages. If true, duplicate messages hav |
| | 80 | | /// <see cref="Message.MessageId"/> and sent to topic within duration of <see cref="DuplicateDetectionHistoryTim |
| | 81 | | /// will be discarded. |
| | 82 | | /// </summary> |
| | 83 | | /// <remarks>Defaults to false.</remarks> |
| 0 | 84 | | public bool RequiresDuplicateDetection { get; set; } = false; |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// The <see cref="TimeSpan"/> duration of duplicate detection history that is maintained by the service. |
| | 88 | | /// </summary> |
| | 89 | | /// <remarks> |
| | 90 | | /// The default value is 1 minute. Max value is 7 days and minimum is 20 seconds. |
| | 91 | | /// </remarks> |
| | 92 | | public TimeSpan DuplicateDetectionHistoryTimeWindow |
| | 93 | | { |
| 0 | 94 | | get => this.duplicateDetectionHistoryTimeWindow; |
| | 95 | | set |
| | 96 | | { |
| 0 | 97 | | if (value < ManagementClientConstants.MinimumDuplicateDetectionHistoryTimeWindow || value > ManagementCl |
| | 98 | | { |
| 0 | 99 | | throw new ArgumentOutOfRangeException(nameof(DuplicateDetectionHistoryTimeWindow), |
| 0 | 100 | | $"The value must be between {ManagementClientConstants.MinimumDuplicateDetectionHistoryTimeWindo |
| | 101 | | } |
| | 102 | |
|
| 0 | 103 | | this.duplicateDetectionHistoryTimeWindow = value; |
| 0 | 104 | | } |
| | 105 | | } |
| | 106 | |
|
| | 107 | | /// <summary> |
| | 108 | | /// Path of the topic relative to the namespace base address. |
| | 109 | | /// </summary> |
| | 110 | | /// <remarks>Max length is 260 chars. Cannot start or end with a slash. |
| | 111 | | /// Cannot have restricted characters: '@','?','#','*'</remarks> |
| | 112 | | public string Path |
| | 113 | | { |
| 0 | 114 | | get => this.path; |
| | 115 | | set |
| | 116 | | { |
| 0 | 117 | | EntityNameHelper.CheckValidTopicName(value, nameof(Path)); |
| 0 | 118 | | this.path = value; |
| 0 | 119 | | } |
| | 120 | | } |
| | 121 | |
|
| | 122 | | /// <summary> |
| | 123 | | /// The <see cref="AuthorizationRules"/> on the topic to control user access at entity level. |
| | 124 | | /// </summary> |
| 0 | 125 | | public AuthorizationRules AuthorizationRules { get; internal set; } = new AuthorizationRules(); |
| | 126 | |
|
| | 127 | | /// <summary> |
| | 128 | | /// The current status of the topic (Enabled / Disabled). |
| | 129 | | /// </summary> |
| | 130 | | /// <remarks>When an entity is disabled, that entity cannot send or receive messages.</remarks> |
| 0 | 131 | | public EntityStatus Status { get; set; } = EntityStatus.Active; |
| | 132 | |
|
| | 133 | | /// <summary> |
| | 134 | | /// Indicates whether the topic is to be partitioned across multiple message brokers. |
| | 135 | | /// </summary> |
| | 136 | | /// <remarks>Defaults to false.</remarks> |
| 0 | 137 | | public bool EnablePartitioning { get; set; } = false; |
| | 138 | |
|
| | 139 | | /// <summary> |
| | 140 | | /// Defines whether ordering needs to be maintained. If true, messages sent to topic will be |
| | 141 | | /// forwarded to the subscription in order. |
| | 142 | | /// </summary> |
| | 143 | | /// <remarks>Defaults to false.</remarks> |
| 0 | 144 | | public bool SupportOrdering { get; set; } = false; |
| | 145 | |
|
| | 146 | | /// <summary> |
| | 147 | | /// Indicates whether server-side batched operations are enabled. |
| | 148 | | /// </summary> |
| | 149 | | /// <remarks>Defaults to true.</remarks> |
| 0 | 150 | | public bool EnableBatchedOperations { get; set; } = true; |
| | 151 | |
|
| | 152 | | /// <summary> |
| | 153 | | /// Custom metdata that user can associate with the description. |
| | 154 | | /// </summary> |
| | 155 | | /// <remarks>Cannot be null. Max length is 1024 chars.</remarks> |
| | 156 | | public string UserMetadata |
| | 157 | | { |
| 0 | 158 | | get => this.userMetadata; |
| | 159 | | set |
| | 160 | | { |
| 0 | 161 | | if (value == null) |
| | 162 | | { |
| 0 | 163 | | throw new ArgumentNullException(nameof(UserMetadata), $"Value cannot be null"); |
| | 164 | | } |
| | 165 | |
|
| 0 | 166 | | if (value.Length > ManagementClientConstants.MaxUserMetadataLength) |
| | 167 | | { |
| 0 | 168 | | throw new ArgumentOutOfRangeException(nameof(UserMetadata), $"Length cannot cross {ManagementClientC |
| | 169 | | } |
| | 170 | |
|
| 0 | 171 | | this.userMetadata = value; |
| 0 | 172 | | } |
| | 173 | | } |
| | 174 | |
|
| | 175 | | /// <summary> |
| | 176 | | /// List of properties that were retrieved using GetTopic but are not understood by this version of client is st |
| | 177 | | /// The list will be sent back when an already retrieved TopicDescription will be used in UpdateTopic call. |
| | 178 | | /// </summary> |
| 0 | 179 | | internal List<object> UnknownProperties { get; set; } |
| | 180 | |
|
| | 181 | | public override int GetHashCode() |
| | 182 | | { |
| 0 | 183 | | return this.Path?.GetHashCode() ?? base.GetHashCode(); |
| | 184 | | } |
| | 185 | |
|
| | 186 | | public override bool Equals(object obj) |
| | 187 | | { |
| 0 | 188 | | var other = obj as TopicDescription; |
| 0 | 189 | | return this.Equals(other); |
| | 190 | | } |
| | 191 | |
|
| | 192 | | public bool Equals(TopicDescription otherDescription) |
| | 193 | | { |
| 0 | 194 | | if (otherDescription is TopicDescription other |
| 0 | 195 | | && this.Path.Equals(other.Path, StringComparison.OrdinalIgnoreCase) |
| 0 | 196 | | && this.AutoDeleteOnIdle.Equals(other.AutoDeleteOnIdle) |
| 0 | 197 | | && this.DefaultMessageTimeToLive.Equals(other.DefaultMessageTimeToLive) |
| 0 | 198 | | && (!this.RequiresDuplicateDetection || this.DuplicateDetectionHistoryTimeWindow.Equals(other.DuplicateD |
| 0 | 199 | | && this.EnableBatchedOperations == other.EnableBatchedOperations |
| 0 | 200 | | && this.EnablePartitioning == other.EnablePartitioning |
| 0 | 201 | | && this.MaxSizeInMB == other.MaxSizeInMB |
| 0 | 202 | | && this.RequiresDuplicateDetection.Equals(other.RequiresDuplicateDetection) |
| 0 | 203 | | && this.Status.Equals(other.Status) |
| 0 | 204 | | && string.Equals(this.userMetadata, other.userMetadata, StringComparison.OrdinalIgnoreCase) |
| 0 | 205 | | && (this.AuthorizationRules != null && other.AuthorizationRules != null |
| 0 | 206 | | || this.AuthorizationRules == null && other.AuthorizationRules == null) |
| 0 | 207 | | && (this.AuthorizationRules == null || this.AuthorizationRules.Equals(other.AuthorizationRules))) |
| | 208 | | { |
| 0 | 209 | | return true; |
| | 210 | | } |
| | 211 | |
|
| 0 | 212 | | return false; |
| | 213 | | } |
| | 214 | |
|
| | 215 | | public static bool operator ==(TopicDescription o1, TopicDescription o2) |
| | 216 | | { |
| 0 | 217 | | if (ReferenceEquals(o1, o2)) |
| | 218 | | { |
| 0 | 219 | | return true; |
| | 220 | | } |
| | 221 | |
|
| 0 | 222 | | if (ReferenceEquals(o1, null) || ReferenceEquals(o2, null)) |
| | 223 | | { |
| 0 | 224 | | return false; |
| | 225 | | } |
| | 226 | |
|
| 0 | 227 | | return o1.Equals(o2); |
| | 228 | | } |
| | 229 | |
|
| | 230 | | public static bool operator !=(TopicDescription o1, TopicDescription o2) |
| | 231 | | { |
| 0 | 232 | | return !(o1 == o2); |
| | 233 | | } |
| | 234 | | } |
| | 235 | | } |