< Summary

Class:Microsoft.Azure.Batch.AsyncListJobsEnumerator
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\AsyncListJobs.cs
Covered lines:43
Uncovered lines:4
Coverable lines:47
Total lines:126
Line coverage:91.4% (43 of 47)
Covered branches:10
Total branches:10
Branch coverage:100% (10 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
.ctor(...)-100%100%
get_Current()-0%100%
GetNextBatchFromServerAsync()-100%100%
ProcessPage(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\AsyncListJobs.cs

#LineLine coverage
 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
 4namespace Microsoft.Azure.Batch
 5{
 6    using System.Diagnostics;
 7    using System.Linq;
 8    using System.Threading;
 9    using System.Threading.Tasks;
 10    using Microsoft.Rest.Azure;
 11    using Models = Microsoft.Azure.Batch.Protocol.Models;
 12
 13    internal class AsyncListJobsEnumerator : PagedEnumeratorBase<CloudJob>
 14    {
 15        private readonly BatchClient _parentBatchClient;
 16        private readonly BehaviorManager _behaviorMgr;
 17        private readonly string _jobScheduleIdForcesListByJobSchedule; // if non-null this triggers list-jobs-by-schedul
 18        private readonly DetailLevel _detailLevel;
 19
 20        #region // constructors
 21
 22        /// <summary>
 23        /// An iterator that lists-jobs (not by schedule)
 24        /// </summary>
 225        internal AsyncListJobsEnumerator(
 226                BatchClient parentBatchClient,
 227                BehaviorManager behaviorMgr,
 228                DetailLevel detailLevel)
 29        {
 230            this._parentBatchClient = parentBatchClient;
 231            this._behaviorMgr = behaviorMgr;
 232            this._detailLevel = detailLevel;
 233        }
 34
 35        /// <summary>
 36        /// An iterator that calls list-jobs-by-schedule
 37        /// </summary>
 238        internal AsyncListJobsEnumerator(
 239                BatchClient parentBatchClient,
 240                string jobScheduleId,
 241                BehaviorManager behaviorMgr,
 242                DetailLevel detailLevel)
 43        {
 244            this._parentBatchClient = parentBatchClient;
 245            this._jobScheduleIdForcesListByJobSchedule = jobScheduleId;
 246            this._behaviorMgr = behaviorMgr;
 247            this._detailLevel = detailLevel;
 248        }
 49
 50        #endregion // constructors
 51
 52        public override CloudJob Current  // for IPagedEnumerator<T> and IEnumerator<T>
 53        {
 54            get
 55            {
 56                // start with the current object off of base
 057                object curObj = base._currentBatch[base._currentIndex];
 58
 59                // it must be a protocol object from previous call
 060                Models.CloudJob protocolObj = curObj as Models.CloudJob;
 61
 62                Debug.Assert(null != protocolObj);
 63
 64                // wrap protocol object
 065                CloudJob wrapped = new CloudJob(this._parentBatchClient, protocolObj, _behaviorMgr.BaseBehaviors);
 66
 067                return wrapped;
 68            }
 69        }
 70
 71        /// <summary>
 72        /// fetch another batch of objects from the server
 73        /// </summary>
 74        protected async override System.Threading.Tasks.Task GetNextBatchFromServerAsync(SkipTokenHandler skipHandler, C
 75        {
 76            do
 77            {
 78                // start the protocol layer call
 679                if (string.IsNullOrEmpty(_jobScheduleIdForcesListByJobSchedule))
 80                {
 481                    Task<AzureOperationResponse<IPage<Models.CloudJob>, Models.JobListHeaders>> asyncTask =
 482                        this._parentBatchClient.ProtocolLayer.ListJobsAll(
 483                            skipHandler.SkipToken,
 484                            _behaviorMgr,
 485                            _detailLevel,
 486                            cancellationToken);
 87
 488                    var response = await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
 89
 290                    this.ProcessPage(response.Body, skipHandler);
 91                }
 92                else
 93                {
 294                    Task<AzureOperationResponse<IPage<Models.CloudJob>, Models.JobListFromJobScheduleHeaders>> asyncTask
 295                        this._parentBatchClient.ProtocolLayer.ListJobsBySchedule(
 296                            _jobScheduleIdForcesListByJobSchedule,
 297                            skipHandler.SkipToken,
 298                            _behaviorMgr,
 299                            _detailLevel,
 2100                            cancellationToken);
 101
 2102                    var response = await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
 103
 2104                    this.ProcessPage(response.Body, skipHandler);
 105                }
 106
 107            }
 108            // it is possible for there to be no results so we keep trying
 4109            while (skipHandler.ThereIsMoreData && ((null == _currentBatch) || _currentBatch.Length <= 0));
 2110        }
 111
 112        private void ProcessPage(IPage<Models.CloudJob> currentPage, SkipTokenHandler skipHandler)
 113        {
 114            // remember any skiptoken returned.  This also sets the bool
 4115            skipHandler.SkipToken = currentPage.NextPageLink;
 116
 117            // remember the protocol tasks returned
 4118            base._currentBatch = null;
 119
 4120            if (null != currentPage.GetEnumerator())
 121            {
 4122                base._currentBatch = currentPage.ToArray();
 123            }
 4124        }
 125    }
 126}