| | 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.Diagnostics; |
| | 7 | | using System.Linq; |
| | 8 | | using System.Threading; |
| | 9 | | using Models = Microsoft.Azure.Batch.Protocol.Models; |
| | 10 | |
|
| | 11 | | internal class AsyncListPoolsEnumerator : PagedEnumeratorBase<CloudPool> |
| | 12 | | { |
| | 13 | | private readonly PoolOperations _parentPoolOperations; |
| | 14 | | private readonly BehaviorManager _behaviorMgr; |
| | 15 | | private readonly DetailLevel _detailLevel; |
| | 16 | |
|
| | 17 | | #region // constructors |
| | 18 | |
|
| 3 | 19 | | internal AsyncListPoolsEnumerator( |
| 3 | 20 | | PoolOperations parentPoolOperations, |
| 3 | 21 | | BehaviorManager behaviorMgr, |
| 3 | 22 | | DetailLevel detailLevel) |
| | 23 | | { |
| 3 | 24 | | _parentPoolOperations = parentPoolOperations; |
| 3 | 25 | | _behaviorMgr = behaviorMgr; |
| 3 | 26 | | _detailLevel = detailLevel; |
| 3 | 27 | | } |
| | 28 | |
|
| | 29 | | #endregion // constructors |
| | 30 | |
|
| | 31 | | public override CloudPool Current // for IPagedEnumerator<T> and IEnumerator<T> |
| | 32 | | { |
| | 33 | | get |
| | 34 | | { |
| | 35 | | // start with the current object off of base |
| 2 | 36 | | object curObj = base._currentBatch[base._currentIndex]; |
| | 37 | |
|
| | 38 | | // it must be a protocol object from previous call |
| 2 | 39 | | Models.CloudPool protocolObj = curObj as Models.CloudPool; |
| | 40 | |
|
| | 41 | | Debug.Assert(null != protocolObj); |
| | 42 | |
|
| | 43 | | // wrap protocol object |
| 2 | 44 | | CloudPool wrapped = new CloudPool(_parentPoolOperations.ParentBatchClient, protocolObj, _behaviorMgr.Bas |
| | 45 | |
|
| 2 | 46 | | return wrapped; |
| | 47 | | } |
| | 48 | | } |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// fetch another batch of objects from the server |
| | 52 | | /// </summary> |
| | 53 | | protected async override System.Threading.Tasks.Task GetNextBatchFromServerAsync(SkipTokenHandler skipHandler, C |
| | 54 | | { |
| | 55 | | do |
| | 56 | | { |
| | 57 | | // start the protocol layer call |
| 4 | 58 | | var asyncTask = _parentPoolOperations.ParentBatchClient.ProtocolLayer.ListPools( |
| 4 | 59 | | skipHandler.SkipToken, |
| 4 | 60 | | _behaviorMgr, |
| 4 | 61 | | _detailLevel, |
| 4 | 62 | | cancellationToken); |
| | 63 | |
|
| 4 | 64 | | var response = await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| | 65 | |
|
| | 66 | | // remember any skiptoken returned. This also sets the bool |
| 3 | 67 | | skipHandler.SkipToken = response.Body.NextPageLink; |
| | 68 | |
|
| | 69 | | // remember the protocol tasks returned |
| 3 | 70 | | base._currentBatch = null; |
| | 71 | |
|
| 3 | 72 | | if (null != response.Body.GetEnumerator()) |
| | 73 | | { |
| 3 | 74 | | base._currentBatch = response.Body.ToArray(); |
| | 75 | | } |
| | 76 | | } |
| | 77 | | // it is possible for there to be no results so we keep trying |
| 3 | 78 | | while (skipHandler.ThereIsMoreData && ((null == _currentBatch) || _currentBatch.Length <= 0)); |
| 2 | 79 | | } |
| | 80 | | } |
| | 81 | | } |