| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.Batch |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using Protocol; |
| | 8 | | using Protocol.Models; |
| | 9 | |
|
| | 10 | | /// <summary> |
| | 11 | | /// Interceptor which contains a function used to generate a client request id to set as <see cref="IOptions.ClientR |
| | 12 | | /// If there are multiple instances of this then the last set wins. |
| | 13 | | /// </summary> |
| | 14 | | public class ClientRequestIdProvider : Protocol.RequestInterceptor |
| | 15 | | { |
| 7 | 16 | | internal /*readonly*/ Func<IBatchRequest, Guid> GenerateClientRequestIdFunc { get; private set; } |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Initializes a new <see cref="ClientRequestIdProvider"/> for use in setting the client request id of a reques |
| | 20 | | /// </summary> |
| | 21 | | /// <param name="generateClientRequestIdFunc"> |
| | 22 | | /// A function used to generate the client request id. This function may be called more than once for any |
| | 23 | | /// given operation due to retries. |
| | 24 | | /// </param> |
| 1 | 25 | | public ClientRequestIdProvider(Func<IBatchRequest, Guid> generateClientRequestIdFunc) |
| | 26 | | { |
| 1 | 27 | | this.GenerateClientRequestIdFunc = generateClientRequestIdFunc; |
| | 28 | |
|
| 1 | 29 | | base.ModificationInterceptHandler = SetClientRequestIdInterceptor; |
| 1 | 30 | | } |
| | 31 | |
|
| | 32 | | private void SetClientRequestIdInterceptor(Protocol.IBatchRequest request) |
| | 33 | | { |
| | 34 | | // if there is a factory, call it |
| 0 | 35 | | if (null != this.GenerateClientRequestIdFunc) |
| | 36 | | { |
| 0 | 37 | | request.ClientRequestIdProvider = this; |
| | 38 | | } |
| 0 | 39 | | } |
| | 40 | | } |
| | 41 | | } |