| | 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 AsyncListSupportedImagesEnumerator : PagedEnumeratorBase<ImageInformation> |
| | 12 | | { |
| | 13 | | private readonly PoolOperations _parentPoolOps; |
| | 14 | | private readonly BehaviorManager _behaviorMgr; |
| | 15 | | private readonly DetailLevel _detailLevel; |
| | 16 | |
|
| | 17 | | #region // constructors |
| | 18 | |
|
| 1 | 19 | | internal AsyncListSupportedImagesEnumerator( |
| 1 | 20 | | PoolOperations parentPoolOps, |
| 1 | 21 | | BehaviorManager behaviorMgr, |
| 1 | 22 | | DetailLevel detailLevel) |
| | 23 | | { |
| 1 | 24 | | _parentPoolOps = parentPoolOps; |
| 1 | 25 | | _behaviorMgr = behaviorMgr; |
| 1 | 26 | | _detailLevel = detailLevel; |
| 1 | 27 | | } |
| | 28 | |
|
| | 29 | | #endregion // constructors |
| | 30 | |
|
| | 31 | | public override ImageInformation Current // for IPagedEnumerator<T> and IEnumerator<T> |
| | 32 | | { |
| | 33 | | get |
| | 34 | | { |
| | 35 | | // start with the current object off of base |
| 0 | 36 | | object curObj = base._currentBatch[base._currentIndex]; |
| | 37 | |
|
| | 38 | | // it must be a protocol object from previous call |
| 0 | 39 | | Models.ImageInformation protocolObj = curObj as Models.ImageInformation; |
| | 40 | |
|
| | 41 | | Debug.Assert(null != protocolObj); |
| | 42 | |
|
| | 43 | | // wrap protocol object |
| 0 | 44 | | ImageInformation wrapped = new ImageInformation(protocolObj); |
| | 45 | |
|
| 0 | 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 |
| 1 | 58 | | var asyncTask = _parentPoolOps.ParentBatchClient.ProtocolLayer.ListSupportedImages( |
| 1 | 59 | | skipHandler.SkipToken, |
| 1 | 60 | | _behaviorMgr, |
| 1 | 61 | | _detailLevel, |
| 1 | 62 | | cancellationToken); |
| | 63 | |
|
| | 64 | | // wait for protocol call to complete |
| 1 | 65 | | var response = await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| | 66 | |
|
| | 67 | | // remember any skiptoken returned. This also sets the bool |
| 0 | 68 | | skipHandler.SkipToken = response.Body.NextPageLink; |
| | 69 | |
|
| | 70 | | // remember the protocol objects returned |
| 0 | 71 | | base._currentBatch = null; |
| | 72 | |
|
| 0 | 73 | | if (null != response.Body.GetEnumerator()) |
| | 74 | | { |
| 0 | 75 | | base._currentBatch = response.Body.ToArray(); |
| | 76 | | } |
| | 77 | | } |
| | 78 | | // it is possible for there to be no results so we keep trying |
| 0 | 79 | | while (skipHandler.ThereIsMoreData && ((null == _currentBatch) || (_currentBatch.Length <= 0))); |
| 0 | 80 | | } |
| | 81 | | } |
| | 82 | | } |