Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BJsonEnumerable<T> : IEnumerator<T>, IEnumerable<T> where T : class
- {
- public IEnumerator<T> GetEnumerator()
- {
- if (check) new BJsonEnumerable<T>(this.bsonData, this.maxOffset);
- return this;
- }
- ILiteQueryable<T> bsonData;
- IBsonDataReader bsonDataReader;
- bool check;
- public BJsonEnumerable(ILiteQueryable<T> bsonData, int maxOffset = 10000)
- {
- this.bsonData = bsonData;
- check = false;
- this.maxOffset = maxOffset;
- }
- public void Begin()
- {
- bsonDataReader = bsonData.Offset(this.offset).ExecuteReader();
- }
- int offset = 0;
- int abstract_offset = 0;
- int maxOffset;
- public T Current { get { return current; } set { current = value; } }
- private T current;
- object IEnumerator.Current { get { return current; } }
- public void Dispose()
- {
- this.current = null;
- this.bsonDataReader = null;
- }
- public bool MoveNext()
- {
- this.check = true;
- if (bsonDataReader == null) Reset();
- bool read = bsonDataReader.Read();
- if (read == false)
- {
- this.current = default;
- return false;
- }
- var bJson = bsonDataReader.Current ;
- string json = bJson.ToString();
- bJson.RawValue = null;
- this.current = JsonConvert.DeserializeObject<T>(json);
- offset++;
- abstract_offset++;
- //if (abstract_offset > maxOffset)
- //{
- // abstract_offset = 0;
- // bsonDataReader.Dispose();
- // Begin();
- //}
- return read;
- }
- public void Reset()
- {
- this.current = null;
- if (this.bsonDataReader == null) Begin();
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- if (check) new BJsonEnumerable<T>(this.bsonData, this.maxOffset);
- return this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement