diff --git a/src/Microsoft.Azure.EventHubs/EventData.cs b/src/Microsoft.Azure.EventHubs/EventData.cs index f77e515..2905f13 100644 --- a/src/Microsoft.Azure.EventHubs/EventData.cs +++ b/src/Microsoft.Azure.EventHubs/EventData.cs @@ -58,27 +58,18 @@ public EventData(ArraySegment arraySegment) /// Get the actual Payload/Data wrapped by EventData. /// This is intended to be used after receiving EventData using . /// - public ArraySegment Body - { - get; - } + public ArraySegment Body { get; } /// /// Application property bag /// - public IDictionary Properties - { - get; internal set; - } + public IDictionary Properties { get; internal set; } /// /// SystemProperties that are populated by EventHubService. /// As these are populated by Service, they are only present on a Received EventData. /// - public SystemPropertiesCollection SystemProperties - { - get; internal set; - } + public SystemPropertiesCollection SystemProperties { get; internal set; } internal AmqpMessage AmqpMessage { get; set; } @@ -104,10 +95,7 @@ void Dispose(bool disposing) { if (disposing) { - if (this.AmqpMessage != null) - { - this.AmqpMessage.Dispose(); - } + AmqpMessage?.Dispose(); } disposed = true; @@ -133,10 +121,8 @@ public long SequenceNumber { return (long)value; } - else - { - throw new ArgumentException(Resources.MissingSystemProperty.FormatForUser(ClientConstants.SequenceNumberName)); - } + + throw new ArgumentException(Resources.MissingSystemProperty.FormatForUser(ClientConstants.SequenceNumberName)); } } @@ -151,10 +137,8 @@ public DateTime EnqueuedTimeUtc { return (DateTime)value; } - else - { - throw new ArgumentException(Resources.MissingSystemProperty.FormatForUser(ClientConstants.EnqueuedTimeUtcName)); - } + + throw new ArgumentException(Resources.MissingSystemProperty.FormatForUser(ClientConstants.EnqueuedTimeUtcName)); } } @@ -170,10 +154,8 @@ public string Offset { return (string)value; } - else - { - throw new ArgumentException(Resources.MissingSystemProperty.FormatForUser(ClientConstants.OffsetName)); - } + + throw new ArgumentException(Resources.MissingSystemProperty.FormatForUser(ClientConstants.OffsetName)); } } @@ -187,12 +169,11 @@ public string PartitionKey { return (string)value; } - else - { - return null; - } + + return null; } } } } } + diff --git a/src/Microsoft.Azure.EventHubs/EventDataBatch.cs b/src/Microsoft.Azure.EventHubs/EventDataBatch.cs index 5c9f0c6..e21e3b6 100644 --- a/src/Microsoft.Azure.EventHubs/EventDataBatch.cs +++ b/src/Microsoft.Azure.EventHubs/EventDataBatch.cs @@ -76,10 +76,7 @@ public bool TryAdd(EventData eventData) return true; } - internal string PartitionKey - { - get; set; - } + internal string PartitionKey { get; set; } long GetEventSizeForBatch(EventData eventData) { @@ -89,15 +86,10 @@ long GetEventSizeForBatch(EventData eventData) eventData.AmqpMessage = amqpMessage; // Calculate overhead depending on the message size. - if (eventData.AmqpMessage.SerializedMessageSize < 256) - { - // Overhead is smaller for messages smaller than 256 bytes. - return eventData.AmqpMessage.SerializedMessageSize + 5; - } - else - { - return eventData.AmqpMessage.SerializedMessageSize + 8; - } + // Overhead is smaller for messages smaller than 256 bytes. + long overhead = eventData.AmqpMessage.SerializedMessageSize < 256 ? 5 : 8; + + return eventData.AmqpMessage.SerializedMessageSize + overhead; } /// diff --git a/src/Microsoft.Azure.EventHubs/EventDataSender.cs b/src/Microsoft.Azure.EventHubs/EventDataSender.cs index a8e0222..449a3e4 100644 --- a/src/Microsoft.Azure.EventHubs/EventDataSender.cs +++ b/src/Microsoft.Azure.EventHubs/EventDataSender.cs @@ -89,10 +89,6 @@ async Task> ProcessEvents(IEnumerable eventDat return processedEventList; } - internal long MaxMessageSize - { - get; - set; - } + internal long MaxMessageSize { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.Azure.EventHubs/EventHubsDiagnosticSource.cs b/src/Microsoft.Azure.EventHubs/EventHubsDiagnosticSource.cs index a832de3..146f409 100644 --- a/src/Microsoft.Azure.EventHubs/EventHubsDiagnosticSource.cs +++ b/src/Microsoft.Azure.EventHubs/EventHubsDiagnosticSource.cs @@ -61,7 +61,7 @@ internal static Activity StartSendActivity(string clientId, EventHubsConnectionS DiagnosticListener.StartActivity(activity, new { - Endpoint = csb.Endpoint, + csb.Endpoint, Entity = csb.EntityPath, PartitionKey = partitionKey, EventDatas = eventDatas @@ -87,7 +87,7 @@ internal static void FailSendActivity(Activity activity, EventHubsConnectionStri DiagnosticListener.Write(SendActivityExceptionName, new { - Endpoint = csb.Endpoint, + csb.Endpoint, Entity = csb.EntityPath, PartitionKey = partitionKey, EventDatas = eventDatas, @@ -105,19 +105,19 @@ internal static void StopSendActivity(Activity activity, EventHubsConnectionStri DiagnosticListener.StopActivity(activity, new { - Endpoint = csb.Endpoint, + csb.Endpoint, Entity = csb.EntityPath, PartitionKey = partitionKey, EventDatas = eventDatas, - Status = sendTask?.Status + sendTask?.Status }); } internal static Activity StartReceiveActivity( - string clientId, - EventHubsConnectionStringBuilder csb, - string partitionKey, - string consumerGroup, + string clientId, + EventHubsConnectionStringBuilder csb, + string partitionKey, + string consumerGroup, EventPosition eventPosition) { // skip if diagnostic source not enabled @@ -168,7 +168,6 @@ internal static Activity StartReceiveActivity( internal static void FailReceiveActivity(Activity activity, EventHubsConnectionStringBuilder csb, string partitionKey, string consumerGroup, Exception ex) { // TODO consider enriching activity with data from exception - if (!DiagnosticListener.IsEnabled() || !DiagnosticListener.IsEnabled(ReceiveActivityExceptionName)) { return; @@ -177,7 +176,7 @@ internal static void FailReceiveActivity(Activity activity, EventHubsConnectionS DiagnosticListener.Write(ReceiveActivityExceptionName, new { - Endpoint = csb.Endpoint, + csb.Endpoint, Entity = csb.EntityPath, PartitionKey = partitionKey, ConsumerGroup = consumerGroup, @@ -198,12 +197,12 @@ internal static void StopReceiveActivity(Activity activity, EventHubsConnectionS DiagnosticListener.StopActivity(activity, new { - Endpoint = csb.Endpoint, + csb.Endpoint, Entity = csb.EntityPath, PartitionKey = partitionKey, ConsumerGroup = consumerGroup, EventDatas = events, - Status = receiveTask?.Status + receiveTask?.Status }); } @@ -237,11 +236,9 @@ private static void Inject(EventData eventData, string id, string correlationCon internal static string SerializeCorrelationContext(IList> baggage) { - if (baggage.Any()) - { - return string.Join(",", baggage.Select(kvp => kvp.Key + "=" + kvp.Value)); - } - return null; + return baggage.Any() + ? string.Join(",", baggage.Select(kvp => kvp.Key + "=" + kvp.Value)) + : null; } private static void SetRelatedOperations(Activity activity, IEnumerable eventDatas) diff --git a/src/Microsoft.Azure.EventHubs/EventPosition.cs b/src/Microsoft.Azure.EventHubs/EventPosition.cs index 45044b5..2fa6b76 100644 --- a/src/Microsoft.Azure.EventHubs/EventPosition.cs +++ b/src/Microsoft.Azure.EventHubs/EventPosition.cs @@ -40,7 +40,7 @@ public static EventPosition FromEnd() { return EventPosition.FromOffset(EndOfStream); } - + /// /// Creates a position at the given offset. /// @@ -50,6 +50,7 @@ public static EventPosition FromEnd() public static EventPosition FromOffset(string offset, bool inclusive = false) { Guard.ArgumentNotNullOrWhiteSpace(nameof(offset), offset); + return new EventPosition { Offset = offset, IsInclusive = inclusive }; } @@ -96,11 +97,7 @@ public static EventPosition FromEnqueuedTime(DateTime enqueuedTimeUtc) /// Gets the sequence number of the event at the position. It can be null if the position is just created /// from an offset or an enqueued time. /// - public long? SequenceNumber - { - get; - internal set; - } + public long? SequenceNumber { get; internal set; } internal string GetExpression() { diff --git a/src/Microsoft.Azure.EventHubs/PartitionReceiver.cs b/src/Microsoft.Azure.EventHubs/PartitionReceiver.cs index 73b5c39..0f8f742 100644 --- a/src/Microsoft.Azure.EventHubs/PartitionReceiver.cs +++ b/src/Microsoft.Azure.EventHubs/PartitionReceiver.cs @@ -57,9 +57,13 @@ protected internal PartitionReceiver( this.prefetchCount = DefaultPrefetchCount; this.Epoch = epoch; this.RuntimeInfo = new ReceiverRuntimeInformation(partitionId); - this.ReceiverRuntimeMetricEnabled = receiverOptions == null ? this.EventHubClient.EnableReceiverRuntimeMetric + this.ReceiverRuntimeMetricEnabled = receiverOptions == null + ? this.EventHubClient.EnableReceiverRuntimeMetric : receiverOptions.EnableReceiverRuntimeMetric; - this.Identifier = receiverOptions != null ? receiverOptions.Identifier : null; + + this.Identifier = receiverOptions != null + ? receiverOptions.Identifier + : null; this.RetryPolicy = eventHubClient.RetryPolicy.Clone(); EventHubsEventSource.Log.ClientCreated(this.ClientId, this.FormatTraceDetails()); @@ -87,10 +91,7 @@ protected internal PartitionReceiver( /// The upper limit of events this receiver will actively receive regardless of whether a receive operation is pending. public int PrefetchCount { - get - { - return this.prefetchCount; - } + get => this.prefetchCount; set { @@ -118,11 +119,7 @@ public int PrefetchCount /// Gets the identifier of a receiver which was set during the creation of the receiver. /// A string representing the identifier of a receiver. It will return null if the identifier is not set. - public string Identifier - { - get; - private set; - } + public string Identifier { get; private set; } /// /// Receive a batch of 's from an EventHub partition @@ -256,18 +253,10 @@ public sealed override Task CloseAsync() /// Gets the approximate receiver runtime information for a logical partition of an Event Hub. /// To enable the setting, refer to and /// - public ReceiverRuntimeInformation RuntimeInfo - { - get; - private set; - } + public ReceiverRuntimeInformation RuntimeInfo { get; private set; } /// Gets a value indicating whether the runtime metric of a receiver is enabled. - public bool ReceiverRuntimeMetricEnabled - { - get; - private set; - } + public bool ReceiverRuntimeMetricEnabled { get; private set; } /// /// diff --git a/src/Microsoft.Azure.EventHubs/PartitionSender.cs b/src/Microsoft.Azure.EventHubs/PartitionSender.cs index df5f237..ddc8944 100644 --- a/src/Microsoft.Azure.EventHubs/PartitionSender.cs +++ b/src/Microsoft.Azure.EventHubs/PartitionSender.cs @@ -47,7 +47,7 @@ public EventDataBatch CreateBatch() { return this.CreateBatch(new BatchOptions()); } - + /// Creates a batch where event data objects can be added for later SendAsync call. /// to define partition key and max message size. /// Returns . @@ -172,11 +172,11 @@ public async Task SendAsync(EventDataBatch eventDataBatch) await this.SendAsync(eventDataBatch.ToEnumerable()); } - + /// - /// Closes and releases resources for the . - /// - /// An asynchronous operation + /// Closes and releases resources for the . + /// + /// An asynchronous operation public override async Task CloseAsync() { EventHubsEventSource.Log.ClientCloseStart(this.ClientId); diff --git a/src/Microsoft.Azure.EventHubs/Primitives/AsyncLock.cs b/src/Microsoft.Azure.EventHubs/Primitives/AsyncLock.cs index 214107b..235a9ea 100644 --- a/src/Microsoft.Azure.EventHubs/Primitives/AsyncLock.cs +++ b/src/Microsoft.Azure.EventHubs/Primitives/AsyncLock.cs @@ -14,16 +14,15 @@ namespace Microsoft.Azure.EventHubs /// public class AsyncLock : IDisposable { - readonly SemaphoreSlim asyncSemaphore; + readonly SemaphoreSlim asyncSemaphore = new SemaphoreSlim(1); readonly Task lockRelease; - bool disposed = false; + bool disposed; /// /// Returns a new AsyncLock. /// public AsyncLock() { - asyncSemaphore = new SemaphoreSlim(1); lockRelease = Task.FromResult(new LockRelease(this)); } diff --git a/src/Microsoft.Azure.EventHubs/Primitives/ClientEntity.cs b/src/Microsoft.Azure.EventHubs/Primitives/ClientEntity.cs index cb51811..5ade18d 100644 --- a/src/Microsoft.Azure.EventHubs/Primitives/ClientEntity.cs +++ b/src/Microsoft.Azure.EventHubs/Primitives/ClientEntity.cs @@ -46,10 +46,7 @@ public string ClientId /// public RetryPolicy RetryPolicy { - get - { - return this.retryPolicy; - } + get => this.retryPolicy; set { diff --git a/src/Microsoft.Azure.EventHubs/Primitives/Fx.cs b/src/Microsoft.Azure.EventHubs/Primitives/Fx.cs index 4cd56ee..08fb61d 100644 --- a/src/Microsoft.Azure.EventHubs/Primitives/Fx.cs +++ b/src/Microsoft.Azure.EventHubs/Primitives/Fx.cs @@ -10,13 +10,7 @@ static class Fx { private static readonly Lazy exceptionUtility = new Lazy(() => new ExceptionUtility()); - public static ExceptionUtility Exception - { - get - { - return exceptionUtility.Value; - } - } + public static ExceptionUtility Exception => exceptionUtility.Value; [Conditional("DEBUG")] public static void Assert(bool condition, string message) diff --git a/src/Microsoft.Azure.EventHubs/Primitives/ITokenProvider.cs b/src/Microsoft.Azure.EventHubs/Primitives/ITokenProvider.cs index f1c4fd9..3b0bd7c 100644 --- a/src/Microsoft.Azure.EventHubs/Primitives/ITokenProvider.cs +++ b/src/Microsoft.Azure.EventHubs/Primitives/ITokenProvider.cs @@ -4,9 +4,6 @@ namespace Microsoft.Azure.EventHubs { using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; using System.Threading.Tasks; /// diff --git a/src/Microsoft.Azure.EventHubs/Primitives/SharedAccessSignatureTokenProvider.cs b/src/Microsoft.Azure.EventHubs/Primitives/SharedAccessSignatureTokenProvider.cs index 8362141..494c12a 100644 --- a/src/Microsoft.Azure.EventHubs/Primitives/SharedAccessSignatureTokenProvider.cs +++ b/src/Microsoft.Azure.EventHubs/Primitives/SharedAccessSignatureTokenProvider.cs @@ -18,8 +18,6 @@ namespace Microsoft.Azure.EventHubs /// public class SharedAccessSignatureTokenProvider : TokenProvider { - const TokenScope DefaultTokenScope = TokenScope.Entity; - internal static readonly TimeSpan DefaultTokenTimeout = TimeSpan.FromMinutes(60); /// diff --git a/src/Microsoft.Azure.EventHubs/Primitives/Ticks.cs b/src/Microsoft.Azure.EventHubs/Primitives/Ticks.cs index 83d9fe5..fe9b304 100644 --- a/src/Microsoft.Azure.EventHubs/Primitives/Ticks.cs +++ b/src/Microsoft.Azure.EventHubs/Primitives/Ticks.cs @@ -18,7 +18,7 @@ public static long Now public static long FromMilliseconds(int milliseconds) { - return checked((long)milliseconds * TimeSpan.TicksPerMillisecond); + return checked(milliseconds * TimeSpan.TicksPerMillisecond); } public static int ToMilliseconds(long ticks) diff --git a/src/Microsoft.Azure.EventHubs/Primitives/TimeoutHelper.cs b/src/Microsoft.Azure.EventHubs/Primitives/TimeoutHelper.cs index 88bfbee..650180c 100644 --- a/src/Microsoft.Azure.EventHubs/Primitives/TimeoutHelper.cs +++ b/src/Microsoft.Azure.EventHubs/Primitives/TimeoutHelper.cs @@ -34,10 +34,7 @@ public TimeoutHelper(TimeSpan timeout, bool startTimeout) } } - public TimeSpan OriginalTimeout - { - get { return this.originalTimeout; } - } + public TimeSpan OriginalTimeout => this.originalTimeout; public static bool IsTooLarge(TimeSpan timeout) { @@ -46,14 +43,9 @@ public static bool IsTooLarge(TimeSpan timeout) public static TimeSpan FromMilliseconds(int milliseconds) { - if (milliseconds == Timeout.Infinite) - { - return TimeSpan.MaxValue; - } - else - { - return TimeSpan.FromMilliseconds(milliseconds); - } + return milliseconds == Timeout.Infinite + ? TimeSpan.MaxValue + : TimeSpan.FromMilliseconds(milliseconds); } public static int ToMilliseconds(TimeSpan timeout) @@ -62,39 +54,22 @@ public static int ToMilliseconds(TimeSpan timeout) { return Timeout.Infinite; } - else - { - long ticks = Ticks.FromTimeSpan(timeout); - if (ticks / TimeSpan.TicksPerMillisecond > int.MaxValue) - { - return int.MaxValue; - } - return Ticks.ToMilliseconds(ticks); - } + + long ticks = Ticks.FromTimeSpan(timeout); + + return ticks / TimeSpan.TicksPerMillisecond > int.MaxValue + ? int.MaxValue + : Ticks.ToMilliseconds(ticks); } public static TimeSpan Min(TimeSpan val1, TimeSpan val2) { - if (val1 > val2) - { - return val2; - } - else - { - return val1; - } + return val1 > val2 ? val2 : val1; } public static DateTime Min(DateTime val1, DateTime val2) { - if (val1 > val2) - { - return val2; - } - else - { - return val1; - } + return val1 > val2 ? val2 : val1; } public static TimeSpan Add(TimeSpan timeout1, TimeSpan timeout2) @@ -122,12 +97,9 @@ public static DateTime Subtract(DateTime time, TimeSpan timeout) public static TimeSpan Divide(TimeSpan timeout, int factor) { - if (timeout == TimeSpan.MaxValue) - { - return TimeSpan.MaxValue; - } - - return Ticks.ToTimeSpan((Ticks.FromTimeSpan(timeout) / factor) + 1); + return timeout == TimeSpan.MaxValue + ? TimeSpan.MaxValue + : Ticks.ToTimeSpan((Ticks.FromTimeSpan(timeout) / factor) + 1); } public TimeSpan RemainingTime() @@ -137,22 +109,14 @@ public TimeSpan RemainingTime() this.SetDeadline(); return this.originalTimeout; } - else if (this.deadline == DateTime.MaxValue) + + if (this.deadline == DateTime.MaxValue) { return TimeSpan.MaxValue; } - else - { - TimeSpan remaining = this.deadline - DateTime.UtcNow; - if (remaining <= TimeSpan.Zero) - { - return TimeSpan.Zero; - } - else - { - return remaining; - } - } + + TimeSpan remaining = this.deadline - DateTime.UtcNow; + return remaining <= TimeSpan.Zero ? TimeSpan.Zero : remaining; } public TimeSpan ElapsedTime() @@ -201,10 +165,8 @@ public static bool WaitOne(WaitHandle waitHandle, TimeSpan timeout) waitHandle.WaitOne(); return true; } - else - { - return waitHandle.WaitOne(timeout); - } + + return waitHandle.WaitOne(timeout); } } } \ No newline at end of file diff --git a/src/Microsoft.Azure.EventHubs/ReceiverOptions.cs b/src/Microsoft.Azure.EventHubs/ReceiverOptions.cs index 7d58870..d66836f 100644 --- a/src/Microsoft.Azure.EventHubs/ReceiverOptions.cs +++ b/src/Microsoft.Azure.EventHubs/ReceiverOptions.cs @@ -15,17 +15,14 @@ public class ReceiverOptions /// Thrown if the length of the value is greater than the maximum length of 64. public string Identifier { - get - { - return this.identifier; - } + get => this.identifier; set { ReceiverOptions.ValidateReceiverIdentifier(value); this.identifier = value; } } - + /// Gets or sets a value indicating whether the runtime metric of a receiver is enabled. /// true if a client wants to access using . public bool EnableReceiverRuntimeMetric diff --git a/src/Microsoft.Azure.EventHubs/ReceiverRuntimeInfo.cs b/src/Microsoft.Azure.EventHubs/ReceiverRuntimeInfo.cs index 287c80f..d704ad7 100644 --- a/src/Microsoft.Azure.EventHubs/ReceiverRuntimeInfo.cs +++ b/src/Microsoft.Azure.EventHubs/ReceiverRuntimeInfo.cs @@ -15,42 +15,22 @@ internal ReceiverRuntimeInformation(string partitionId) /// Gets the partition ID for a logical partition of an Event Hub. /// The partition identifier. - public string PartitionId - { - get; - internal set; - } + public string PartitionId { get; internal set; } /// Gets the last sequence number of the event within the partition stream of the Event Hub. /// The logical sequence number of the event. - public long LastSequenceNumber - { - get; - internal set; - } + public long LastSequenceNumber { get; internal set; } /// Gets the enqueued UTC time of the last event. /// The enqueued time of the last event. - public DateTime LastEnqueuedTimeUtc - { - get; - internal set; - } + public DateTime LastEnqueuedTimeUtc { get; internal set; } /// Gets the offset of the last enqueued event. /// The offset of the last enqueued event. - public string LastEnqueuedOffset - { - get; - internal set; - } + public string LastEnqueuedOffset { get; internal set; } /// Gets the time of when the runtime info was retrieved. /// The enqueued time of the last event. - public DateTime RetrievalTime - { - get; - internal set; - } + public DateTime RetrievalTime { get; internal set; } } }