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