/// <summary> /// Gets the session state. /// </summary> /// /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// /// <returns>The session state as <see cref="BinaryData"/>.</returns> public virtual async Task <BinaryData> GetSessionStateAsync(CancellationToken cancellationToken = default) { Argument.AssertNotDisposed(IsClosed, nameof(ServiceBusSessionReceiver)); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); Logger.GetSessionStateStart(Identifier, SessionId); using DiagnosticScope scope = ScopeFactory.CreateScope( DiagnosticProperty.GetSessionStateActivityName, sessionId: SessionId); scope.Start(); BinaryData sessionState; try { sessionState = await InnerReceiver.GetStateAsync(cancellationToken).ConfigureAwait(false); } catch (Exception exception) { Logger.GetSessionStateException(Identifier, exception.ToString()); scope.Failed(exception); throw; } Logger.GetSessionStateComplete(Identifier); return(sessionState); }
/// <summary> /// Gets the session state. /// </summary> /// /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// /// <returns>The session state as byte array.</returns> public virtual async Task <byte[]> GetStateAsync(CancellationToken cancellationToken = default) { Argument.AssertNotClosed(IsDisposed, nameof(ServiceBusSessionReceiver)); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ServiceBusEventSource.Log.GetSessionStateStart(Identifier, SessionId); byte[] sessionState = null; try { sessionState = await InnerReceiver.GetStateAsync(cancellationToken).ConfigureAwait(false); } catch (Exception exception) { ServiceBusEventSource.Log.GetSessionStateException(Identifier, exception); throw; } cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ServiceBusEventSource.Log.GetSessionStateComplete(Identifier); return(sessionState); }