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