Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PagedCursor.cs
1using System;
2using System.Collections;
3using System.Threading.Tasks;
5
7{
12 internal class PagesCursor<T> : ICursor<T>
13 {
14 private int offset;
15 private int maxCount;
16 private readonly ICursor<T> cursor;
17
24 internal PagesCursor(int Offset, int MaxCount, ICursor<T> Cursor)
25 {
26 this.offset = Offset;
27 this.maxCount = MaxCount;
28 this.cursor = Cursor;
29 }
30
36 public T Current => this.cursor.Current;
37
41 public IObjectSerializer CurrentSerializer => this.cursor.CurrentSerializer;
42
47 public bool CurrentTypeCompatible => this.cursor.CurrentTypeCompatible;
48
54 public Guid CurrentObjectId => this.cursor.CurrentObjectId;
55
59 public void Dispose()
60 {
61 }
62
70 Task<bool> IAsyncEnumerator.MoveNextAsync() => this.MoveNextAsyncLocked();
71
77 object IEnumerator.Current => this.Current;
78
86 public bool MoveNext() => this.MoveNextAsyncLocked().Result;
87
91 public void Reset() => this.cursor.Reset();
92
99 public async Task<bool> MoveNextAsyncLocked()
100 {
101 while (true)
102 {
103 if (this.maxCount <= 0)
104 return false;
105
106 if (!await this.cursor.MoveNextAsyncLocked())
107 return false;
108
109 if (!this.cursor.CurrentTypeCompatible)
110 continue;
111
112 if (this.offset > 0)
113 {
114 this.offset--;
115 continue;
116 }
117
118 this.maxCount--;
119 return true;
120 }
121 }
122
129 public Task<bool> MovePreviousAsyncLocked()
130 {
131 return this.MoveNextAsyncLocked(); // Ordering only in one direction.
132 }
133
141 public bool SameSortOrder(string[] ConstantFields, string[] SortOrder)
142 {
143 return this.cursor.SameSortOrder(ConstantFields, SortOrder);
144 }
145
153 public bool ReverseSortOrder(string[] ConstantFields, string[] SortOrder)
154 {
155 return this.cursor.ReverseSortOrder(ConstantFields, SortOrder);
156 }
157
162 public Task ContinueAfterLocked(T LastItem)
163 {
164 return this.cursor.ContinueAfterLocked(LastItem);
165 }
166
171 public Task ContinueBeforeLocked(T LastItem)
172 {
173 return this.cursor.ContinueBeforeLocked(LastItem);
174 }
175 }
176}
Interface for asynchronous enumerators.
Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.