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