| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | |
|
| | 6 | | namespace Azure.Messaging.EventHubs.Core |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// The set of extension methods for the <see cref="EventHubsRetryOptions" /> |
| | 10 | | /// class. |
| | 11 | | /// </summary> |
| | 12 | | /// |
| | 13 | | internal static class EventHubsRetryOptionsExtensions |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Creates a new copy of the current <see cref="EventHubsRetryOptions" />, cloning its attributes into a new |
| | 17 | | /// </summary> |
| | 18 | | /// |
| | 19 | | /// <param name="instance">The instance that this method was invoked on.</param> |
| | 20 | | /// |
| | 21 | | /// <returns>A new copy of <see cref="EventHubsRetryOptions" />.</returns> |
| | 22 | | /// |
| | 23 | | public static EventHubsRetryOptions Clone(this EventHubsRetryOptions instance) => |
| 166 | 24 | | new EventHubsRetryOptions |
| 166 | 25 | | { |
| 166 | 26 | | Mode = instance.Mode, |
| 166 | 27 | | CustomRetryPolicy = instance.CustomRetryPolicy, |
| 166 | 28 | | MaximumRetries = instance.MaximumRetries, |
| 166 | 29 | | Delay = instance.Delay, |
| 166 | 30 | | MaximumDelay = instance.MaximumDelay, |
| 166 | 31 | | TryTimeout = instance.TryTimeout |
| 166 | 32 | | }; |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Converts the options into a retry policy for use. |
| | 36 | | /// </summary> |
| | 37 | | /// |
| | 38 | | /// <param name="instance">The instance that this method was invoked on.</param> |
| | 39 | | /// |
| | 40 | | /// <returns>The <see cref="EventHubsRetryPolicy" /> represented by the options.</returns> |
| | 41 | | /// |
| | 42 | | public static EventHubsRetryPolicy ToRetryPolicy(this EventHubsRetryOptions instance) => |
| 634 | 43 | | instance.CustomRetryPolicy ?? new BasicRetryPolicy(instance); |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Compares retry options between two instances to determine if the |
| | 47 | | /// instances represent the same set of options. |
| | 48 | | /// </summary> |
| | 49 | | /// |
| | 50 | | /// <param name="instance">The instance that this method was invoked on.</param> |
| | 51 | | /// <param name="other">The other set of retry options to consider.</param> |
| | 52 | | /// |
| | 53 | | /// <returns><c>true</c>, if the two sets of options are structurally equivalent; otherwise, <c>false</c>.</retu |
| | 54 | | /// |
| | 55 | | public static bool IsEquivalentTo(this EventHubsRetryOptions instance, |
| | 56 | | EventHubsRetryOptions other) |
| | 57 | | { |
| | 58 | | // If the events are the same instance, they're equal. This should only happen |
| | 59 | | // if both are null or they are the exact same instance. |
| | 60 | |
|
| 26 | 61 | | if (Object.ReferenceEquals(instance, other)) |
| | 62 | | { |
| 0 | 63 | | return true; |
| | 64 | | } |
| | 65 | |
|
| | 66 | | // If one or the other is null, then they cannot be equal, since we know that |
| | 67 | | // they are not both null. |
| | 68 | |
|
| 26 | 69 | | if ((instance == null) || (other == null)) |
| | 70 | | { |
| 0 | 71 | | return false; |
| | 72 | | } |
| | 73 | |
|
| | 74 | | // If the contents of each attribute are equal, the instance are |
| | 75 | | // equal. |
| | 76 | |
|
| 26 | 77 | | return |
| 26 | 78 | | ( |
| 26 | 79 | | instance.Mode == other.Mode |
| 26 | 80 | | && instance.MaximumRetries == other.MaximumRetries |
| 26 | 81 | | && instance.Delay == other.Delay |
| 26 | 82 | | && instance.MaximumDelay == other.MaximumDelay |
| 26 | 83 | | && instance.TryTimeout == other.TryTimeout |
| 26 | 84 | | && instance.CustomRetryPolicy == other.CustomRetryPolicy |
| 26 | 85 | | ); |
| | 86 | | } |
| | 87 | | } |
| | 88 | | } |