| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Threading; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | |
| | | 8 | | namespace Azure.Messaging.ServiceBus |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// The <see cref="ProcessSessionEventArgs"/> contain event args related to the session being processed. |
| | | 12 | | /// </summary> |
| | | 13 | | public class ProcessSessionEventArgs : EventArgs |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// The processor's <see cref="System.Threading.CancellationToken"/> instance which will be |
| | | 17 | | /// cancelled in the event that <see cref="ServiceBusProcessor.StopProcessingAsync"/> is called. |
| | | 18 | | /// </summary> |
| | 0 | 19 | | public CancellationToken CancellationToken { get; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// The <see cref="ServiceBusSessionReceiver"/> that will be used for setting and getting session |
| | | 23 | | /// state. |
| | | 24 | | /// </summary> |
| | | 25 | | private readonly ServiceBusSessionReceiver _sessionReceiver; |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// The Session Id associated with the session being processed. |
| | | 29 | | /// </summary> |
| | 0 | 30 | | public string SessionId => _sessionReceiver.SessionId; |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Gets the <see cref="DateTimeOffset"/> that the current session is locked until. |
| | | 34 | | /// </summary> |
| | 0 | 35 | | public DateTimeOffset SessionLockedUntil => _sessionReceiver.SessionLockedUntil; |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Initializes a new instance of the <see cref="ProcessSessionEventArgs"/> class. |
| | | 39 | | /// </summary> |
| | | 40 | | /// |
| | | 41 | | /// <param name="receiver">The <see cref="ServiceBusSessionReceiver"/> that will be used for all settlement meth |
| | | 42 | | /// for the args.</param> |
| | | 43 | | /// <param name="cancellationToken">The processor's <see cref="System.Threading.CancellationToken"/> instance wh |
| | 0 | 44 | | internal ProcessSessionEventArgs( |
| | 0 | 45 | | ServiceBusSessionReceiver receiver, |
| | 0 | 46 | | CancellationToken cancellationToken) |
| | | 47 | | { |
| | 0 | 48 | | _sessionReceiver = receiver; |
| | 0 | 49 | | CancellationToken = cancellationToken; |
| | 0 | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Gets the session state. |
| | | 54 | | /// </summary> |
| | | 55 | | /// |
| | | 56 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 57 | | /// |
| | | 58 | | /// <returns>The session state as byte array.</returns> |
| | | 59 | | public virtual async Task<byte[]> GetSessionStateAsync( |
| | | 60 | | CancellationToken cancellationToken = default) => |
| | 0 | 61 | | await _sessionReceiver.GetSessionStateAsync(cancellationToken).ConfigureAwait(false); |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Set a custom state on the session which can be later retrieved using <see cref="GetSessionStateAsync"/> |
| | | 65 | | /// </summary> |
| | | 66 | | /// |
| | | 67 | | /// <param name="sessionState">A byte array of session state</param> |
| | | 68 | | /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request t |
| | | 69 | | /// |
| | | 70 | | /// <remarks>This state is stored on Service Bus forever unless you set an empty state on it.</remarks> |
| | | 71 | | /// |
| | | 72 | | /// <returns>A task to be resolved on when the operation has completed.</returns> |
| | | 73 | | public virtual async Task SetSessionStateAsync( |
| | | 74 | | byte[] sessionState, |
| | | 75 | | CancellationToken cancellationToken = default) => |
| | 0 | 76 | | await _sessionReceiver.SetSessionStateAsync(sessionState, cancellationToken).ConfigureAwait(false); |
| | | 77 | | } |
| | | 78 | | } |