@@ -269,7 +269,8 @@ public async Task<AmqpIoTOutcome> DisposeMessageAsync(string lockToken, AmqpIoTD
269269 {
270270 await EnsureMessageReceivingLinkAsync ( timeout ) . ConfigureAwait ( false ) ;
271271 disposeOutcome = await _messageReceivingLink . DisposeMessageAsync ( lockToken , AmqpIoTResultAdapter . GetResult ( disposeAction ) , timeout ) . ConfigureAwait ( false ) ;
272- } else
272+ }
273+ else
273274 {
274275 await EnableEventReceiveAsync ( timeout ) . ConfigureAwait ( false ) ;
275276 disposeOutcome = await _eventReceivingLink . DisposeMessageAsync ( lockToken , AmqpIoTResultAdapter . GetResult ( disposeAction ) , timeout ) . ConfigureAwait ( false ) ;
@@ -281,14 +282,14 @@ public async Task<AmqpIoTOutcome> DisposeMessageAsync(string lockToken, AmqpIoTD
281282 #endregion
282283
283284 #region Event
284- private async Task EnsureEventReceivingLinkAsync ( TimeSpan timeout )
285+ public async Task EnableEventReceiveAsync ( TimeSpan timeout )
285286 {
286287 if ( _closed )
287288 {
288289 throw new IotHubException ( "Device is now offline." , false ) ;
289290 }
290291
291- if ( Logging . IsEnabled ) Logging . Enter ( this , timeout , $ "{ nameof ( EnsureEventReceivingLinkAsync ) } ") ;
292+ if ( Logging . IsEnabled ) Logging . Enter ( this , timeout , $ "{ nameof ( EnableEventReceiveAsync ) } ") ;
292293 AmqpIoTSession amqpIoTSession = await EnsureSessionAsync ( timeout ) . ConfigureAwait ( false ) ;
293294 bool gain = await _eventReceivingLinkLock . WaitAsync ( timeout ) . ConfigureAwait ( false ) ;
294295 if ( ! gain )
@@ -301,30 +302,16 @@ private async Task EnsureEventReceivingLinkAsync(TimeSpan timeout)
301302 if ( _eventReceivingLink == null || _eventReceivingLink . IsClosing ( ) )
302303 {
303304 _eventReceivingLink = await amqpIoTSession . OpenEventsReceiverLinkAsync ( _deviceIdentity , timeout ) . ConfigureAwait ( false ) ;
304-
305305 _eventReceivingLink . Closed += ( obj , arg ) => {
306306 amqpIoTSession . SafeClose ( ) ;
307307 } ;
308- if ( Logging . IsEnabled ) Logging . Associate ( this , this , _eventReceivingLink , $ "{ nameof ( EnsureEventReceivingLinkAsync ) } ") ;
308+ _eventReceivingLink . RegisterEventListener ( OnEventsReceived ) ;
309+ if ( Logging . IsEnabled ) Logging . Associate ( this , this , _eventReceivingLink , $ "{ nameof ( EnableEventReceiveAsync ) } ") ;
309310 }
310311 }
311312 finally
312313 {
313314 _eventReceivingLinkLock . Release ( ) ;
314- if ( Logging . IsEnabled ) Logging . Exit ( this , timeout , $ "{ nameof ( EnsureEventReceivingLinkAsync ) } ") ;
315- }
316- }
317-
318- public async Task EnableEventReceiveAsync ( TimeSpan timeout )
319- {
320- if ( Logging . IsEnabled ) Logging . Enter ( this , timeout , $ "{ nameof ( EnableEventReceiveAsync ) } ") ;
321- try
322- {
323- await EnsureEventReceivingLinkAsync ( timeout ) . ConfigureAwait ( false ) ;
324- _eventReceivingLink . RegisterEventListener ( OnEventsReceived ) ;
325- }
326- finally
327- {
328315 if ( Logging . IsEnabled ) Logging . Exit ( this , timeout , $ "{ nameof ( EnableEventReceiveAsync ) } ") ;
329316 }
330317 }
0 commit comments