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