| | 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.Collections; |
| | 8 | | using System.Collections.Generic; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// Exposes synchronous and asynchronous enumerators based on async calls to server. |
| | 13 | | /// </summary> |
| | 14 | | internal class PagedEnumerable<EnumerationType> : IPagedEnumerable<EnumerationType> |
| | 15 | | { |
| | 16 | | private readonly NewEnumeratorFactory _enumeratorFactory; |
| | 17 | |
|
| | 18 | | #region //constructors |
| | 19 | |
|
| 0 | 20 | | private PagedEnumerable() |
| | 21 | | { |
| 0 | 22 | | } |
| | 23 | |
|
| 41 | 24 | | internal PagedEnumerable(NewEnumeratorFactory enumeratorFactory) |
| | 25 | | { |
| 41 | 26 | | _enumeratorFactory = enumeratorFactory; |
| 41 | 27 | | } |
| | 28 | |
|
| | 29 | | #endregion // constructors |
| | 30 | |
|
| | 31 | | // this factory is called on every call to "GetEnumerator()" |
| | 32 | | // it returns the derived class that implements the specific |
| | 33 | | // protocol calls to traverse the collection |
| | 34 | | internal delegate PagedEnumeratorBase<EnumerationType> NewEnumeratorFactory(); |
| | 35 | |
|
| | 36 | |
|
| | 37 | | // IEnumerable |
| | 38 | | IEnumerator System.Collections.IEnumerable.GetEnumerator() |
| | 39 | | { |
| 0 | 40 | | PagedEnumeratorBase<EnumerationType> newEnumerator = _enumeratorFactory(); |
| | 41 | |
|
| 0 | 42 | | return newEnumerator; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | // IEnumerable<T> |
| | 46 | | public IEnumerator<EnumerationType> GetEnumerator() |
| | 47 | | { |
| 13 | 48 | | PagedEnumeratorBase<EnumerationType> newEnumerator = _enumeratorFactory(); |
| | 49 | |
|
| 13 | 50 | | return newEnumerator; |
| | 51 | | } |
| | 52 | |
|
| | 53 | | // IPagedEnumerable |
| | 54 | | public IPagedEnumerator<EnumerationType> GetPagedEnumerator() |
| | 55 | | { |
| 27 | 56 | | PagedEnumeratorBase<EnumerationType> newEnumerator = _enumeratorFactory(); |
| | 57 | |
|
| 27 | 58 | | return newEnumerator; |
| | 59 | | } |
| | 60 | | } |
| | 61 | | } |