| | 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 AsyncListSubtasksEnumerator : PagedEnumeratorBase<SubtaskInformation> |
| | 12 | | { |
| | 13 | | private readonly JobOperations _parentJobOperations; |
| | 14 | | private readonly string _jobId; |
| | 15 | | private readonly string _taskId; |
| | 16 | | private readonly BehaviorManager _behaviorMgr; |
| | 17 | | private readonly DetailLevel _detailLevel; |
| | 18 | |
|
| | 19 | | #region // constructors |
| | 20 | |
|
| 1 | 21 | | internal AsyncListSubtasksEnumerator( |
| 1 | 22 | | JobOperations parentJobOperations, |
| 1 | 23 | | string jobId, |
| 1 | 24 | | string taskId, |
| 1 | 25 | | BehaviorManager behaviorMgr, |
| 1 | 26 | | DetailLevel detailLevel) |
| | 27 | | { |
| 1 | 28 | | _parentJobOperations = parentJobOperations; |
| 1 | 29 | | _jobId = jobId; |
| 1 | 30 | | _taskId = taskId; |
| 1 | 31 | | _behaviorMgr = behaviorMgr; |
| 1 | 32 | | _detailLevel = detailLevel; |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | #endregion // constructors |
| | 36 | |
|
| | 37 | | public override SubtaskInformation Current // for IPagedEnumerator<T> and IEnumerator<T> |
| | 38 | | { |
| | 39 | | get |
| | 40 | | { |
| | 41 | | // start with the current object off of base |
| 0 | 42 | | object curObj = base._currentBatch[base._currentIndex]; |
| | 43 | |
|
| | 44 | | // it must be a protocol object from previous call |
| 0 | 45 | | Models.SubtaskInformation protoSubtask = curObj as Models.SubtaskInformation; |
| | 46 | |
|
| | 47 | | Debug.Assert(null != protoSubtask); |
| | 48 | |
|
| | 49 | | // wrap protocol object |
| 0 | 50 | | SubtaskInformation wrapped = new SubtaskInformation(protoSubtask); |
| | 51 | |
|
| 0 | 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 |
| 1 | 64 | | var asyncTask = _parentJobOperations.ParentBatchClient.ProtocolLayer.ListSubtasks( |
| 1 | 65 | | _jobId, |
| 1 | 66 | | _taskId, |
| 1 | 67 | | skipHandler.SkipToken, |
| 1 | 68 | | _behaviorMgr, |
| 1 | 69 | | _detailLevel, |
| 1 | 70 | | cancellationToken); |
| | 71 | |
|
| 1 | 72 | | var response = await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| | 73 | |
|
| | 74 | | //TODO: For now this is always null because the service doesn't ever return a skiptoken for this operati |
| | 75 | | //TODO: Do not follow this code pattern elsewhere as it will not correctly traverse the skiptoken. |
| | 76 | | //TODO: Note that setting this to null sets the "_hasBeenCalled" boolean which is important for the func |
| | 77 | | //TODO: list functionality (see the code). |
| 0 | 78 | | skipHandler.SkipToken = null; |
| | 79 | | // remember the protocol tasks returned |
| 0 | 80 | | base._currentBatch = null; |
| | 81 | |
|
| 0 | 82 | | if (null != response.Body.Value.GetEnumerator()) |
| | 83 | | { |
| 0 | 84 | | base._currentBatch = response.Body.Value.ToArray(); |
| | 85 | | } |
| | 86 | | } |
| | 87 | | // it is possible for there to be no results so we keep trying |
| 0 | 88 | | while (skipHandler.ThereIsMoreData && ((null == base._currentBatch) || base._currentBatch.Length <= 0)); |
| 0 | 89 | | } |
| | 90 | | } |
| | 91 | | } |