| | 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) => |
| 50 | 24 | | new EventHubsRetryOptions |
| 50 | 25 | | { |
| 50 | 26 | | Mode = instance.Mode, |
| 50 | 27 | | CustomRetryPolicy = instance.CustomRetryPolicy, |
| 50 | 28 | | MaximumRetries = instance.MaximumRetries, |
| 50 | 29 | | Delay = instance.Delay, |
| 50 | 30 | | MaximumDelay = instance.MaximumDelay, |
| 50 | 31 | | TryTimeout = instance.TryTimeout |
| 50 | 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) => |
| 0 | 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 | |
|
| 2 | 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 | |
|
| 2 | 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 | |
|
| 2 | 77 | | return |
| 2 | 78 | | ( |
| 2 | 79 | | instance.Mode == other.Mode |
| 2 | 80 | | && instance.MaximumRetries == other.MaximumRetries |
| 2 | 81 | | && instance.Delay == other.Delay |
| 2 | 82 | | && instance.MaximumDelay == other.MaximumDelay |
| 2 | 83 | | && instance.TryTimeout == other.TryTimeout |
| 2 | 84 | | && instance.CustomRetryPolicy == other.CustomRetryPolicy |
| 2 | 85 | | ); |
| | 86 | | } |
| | 87 | | } |
| | 88 | | } |