| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | using Azure.Core; |
| | | 7 | | |
| | | 8 | | namespace Azure.Messaging.EventHubs.Consumer |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// A set of information about the enqueued state of a partition, as observed by the consumer. |
| | | 12 | | /// </summary> |
| | | 13 | | /// |
| | | 14 | | public struct LastEnqueuedEventProperties : IEquatable<LastEnqueuedEventProperties> |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// The sequence number of the last observed event to be enqueued in the partition. |
| | | 18 | | /// </summary> |
| | | 19 | | /// |
| | 94 | 20 | | public long? SequenceNumber { get; } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// The offset of the last observed event to be enqueued in the partition. |
| | | 24 | | /// </summary> |
| | | 25 | | /// |
| | 110 | 26 | | public long? Offset { get; } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// The date and time, in UTC, that the last observed event was enqueued in the partition. |
| | | 30 | | /// </summary> |
| | | 31 | | /// |
| | 78 | 32 | | public DateTimeOffset? EnqueuedTime { get; } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// The date and time, in UTC, that the information about the last enqueued event was received. |
| | | 36 | | /// </summary> |
| | | 37 | | /// |
| | 62 | 38 | | public DateTimeOffset? LastReceivedTime { get; } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Initializes a new instance of the <see cref="LastEnqueuedEventProperties"/> class. |
| | | 42 | | /// </summary> |
| | | 43 | | /// |
| | | 44 | | /// <param name="lastSequenceNumber">The sequence number observed the last event to be enqueued in the partition |
| | | 45 | | /// <param name="lastOffset">The offset of the last event to be enqueued in the partition.</param> |
| | | 46 | | /// <param name="lastEnqueuedTime">The date and time, in UTC, that the last event was enqueued in the partition. |
| | | 47 | | /// <param name="lastReceivedTime">The date and time, in UTC, that the information was last received.</param> |
| | | 48 | | /// |
| | | 49 | | public LastEnqueuedEventProperties(long? lastSequenceNumber, |
| | | 50 | | long? lastOffset, |
| | | 51 | | DateTimeOffset? lastEnqueuedTime, |
| | | 52 | | DateTimeOffset? lastReceivedTime) |
| | | 53 | | { |
| | 48 | 54 | | SequenceNumber = lastSequenceNumber; |
| | 48 | 55 | | Offset = lastOffset; |
| | 48 | 56 | | EnqueuedTime = lastEnqueuedTime; |
| | 48 | 57 | | LastReceivedTime = lastReceivedTime; |
| | 48 | 58 | | } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Initializes a new instance of the <see cref="LastEnqueuedEventProperties"/> class. |
| | | 62 | | /// </summary> |
| | | 63 | | /// |
| | | 64 | | /// <param name="sourceEvent">The event to use as the source for the partition information.</param> |
| | | 65 | | /// |
| | | 66 | | internal LastEnqueuedEventProperties(EventData sourceEvent) : |
| | 18 | 67 | | this(sourceEvent?.LastPartitionSequenceNumber, |
| | 18 | 68 | | sourceEvent?.LastPartitionOffset, |
| | 18 | 69 | | sourceEvent?.LastPartitionEnqueuedTime, |
| | 18 | 70 | | sourceEvent?.LastPartitionPropertiesRetrievalTime) |
| | | 71 | | { |
| | 18 | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Determines whether the specified <see cref="LastEnqueuedEventProperties" /> is equal to this instance. |
| | | 76 | | /// </summary> |
| | | 77 | | /// |
| | | 78 | | /// <param name="other">The <see cref="LastEnqueuedEventProperties" /> to compare with this instance.</param> |
| | | 79 | | /// |
| | | 80 | | /// <returns><c>true</c> if the specified <see cref="LastEnqueuedEventProperties" /> is equal to this instance; |
| | | 81 | | /// |
| | | 82 | | public bool Equals(LastEnqueuedEventProperties other) |
| | | 83 | | { |
| | 48 | 84 | | return (Offset == other.Offset) |
| | 48 | 85 | | && (SequenceNumber == other.SequenceNumber) |
| | 48 | 86 | | && (EnqueuedTime == other.EnqueuedTime) |
| | 48 | 87 | | && (LastReceivedTime == other.LastReceivedTime); |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// Determines whether the specified <see cref="System.Object" /> is equal to this instance. |
| | | 92 | | /// </summary> |
| | | 93 | | /// |
| | | 94 | | /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param> |
| | | 95 | | /// |
| | | 96 | | /// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c> |
| | | 97 | | /// |
| | | 98 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | | 99 | | public override bool Equals(object obj) => |
| | 10 | 100 | | obj switch |
| | 10 | 101 | | { |
| | 20 | 102 | | LastEnqueuedEventProperties other => Equals(other), |
| | 0 | 103 | | _ => false |
| | 10 | 104 | | }; |
| | | 105 | | |
| | | 106 | | /// <summary> |
| | | 107 | | /// Returns a hash code for this instance. |
| | | 108 | | /// </summary> |
| | | 109 | | /// |
| | | 110 | | /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a ha |
| | | 111 | | /// |
| | | 112 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | | 113 | | public override int GetHashCode() |
| | | 114 | | { |
| | 4 | 115 | | var hashCode = new HashCodeBuilder(); |
| | 4 | 116 | | hashCode.Add(Offset); |
| | 4 | 117 | | hashCode.Add(SequenceNumber); |
| | 4 | 118 | | hashCode.Add(EnqueuedTime); |
| | 4 | 119 | | hashCode.Add(LastReceivedTime); |
| | | 120 | | |
| | 4 | 121 | | return hashCode.ToHashCode(); |
| | | 122 | | } |
| | | 123 | | |
| | | 124 | | /// <summary> |
| | | 125 | | /// Converts the instance to string representation. |
| | | 126 | | /// </summary> |
| | | 127 | | /// |
| | | 128 | | /// <returns>A <see cref="System.String" /> that represents this instance.</returns> |
| | | 129 | | /// |
| | | 130 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 2 | 131 | | public override string ToString() => $"Sequence: [{ SequenceNumber }] | Offset: [{ Offset }] | Enqueued: [{ Enqu |
| | | 132 | | |
| | | 133 | | /// <summary> |
| | | 134 | | /// Determines whether the specified <see cref="LastEnqueuedEventProperties" /> instances are equal to each ot |
| | | 135 | | /// </summary> |
| | | 136 | | /// |
| | | 137 | | /// <param name="left">The first <see cref="LastEnqueuedEventProperties" /> to consider.</param> |
| | | 138 | | /// <param name="right">The second <see cref="LastEnqueuedEventProperties" /> to consider.</param> |
| | | 139 | | /// |
| | | 140 | | /// <returns><c>true</c> if the two specified <see cref="LastEnqueuedEventProperties" /> instances are equal; ot |
| | | 141 | | /// |
| | | 142 | | public static bool operator ==(LastEnqueuedEventProperties left, |
| | 10 | 143 | | LastEnqueuedEventProperties right) => left.Equals(right); |
| | | 144 | | |
| | | 145 | | /// <summary> |
| | | 146 | | /// Determines whether the specified <see cref="LastEnqueuedEventProperties" /> instances are not equal to eac |
| | | 147 | | /// </summary> |
| | | 148 | | /// |
| | | 149 | | /// <param name="left">The first <see cref="LastEnqueuedEventProperties" /> to consider.</param> |
| | | 150 | | /// <param name="right">The second <see cref="LastEnqueuedEventProperties" /> to consider.</param> |
| | | 151 | | /// |
| | | 152 | | /// <returns><c>true</c> if the two specified <see cref="LastEnqueuedEventProperties" /> instances are not equal |
| | | 153 | | /// |
| | | 154 | | public static bool operator !=(LastEnqueuedEventProperties left, |
| | 10 | 155 | | LastEnqueuedEventProperties right) => (!left.Equals(right)); |
| | | 156 | | } |
| | | 157 | | } |