Exemple #1
0
 /// <summary>
 /// Returns the first document of a cursor returned by a cursor source.
 /// </summary>
 /// <typeparam name="TDocument">The type of the document.</typeparam>
 /// <param name="source">The source.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The first document.</returns>
 public static TDocument First <TDocument>(this IAsyncCursorSource <TDocument> source, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var cursor = source.ToCursor(cancellationToken))
     {
         return(cursor.First(cancellationToken));
     }
 }
Exemple #2
0
 private void GetCache(bool reset)
 {
     lock (_lock)
     {
         if (_cursor == null || reset)
         {
             _cursor       = _finder.ToCursor();
             _elementCache = _cursor.MoveNext() ? _cursor.Current.ToList() : new List <BsonDocument>();
         }
         if (_elementCache != null && _position >= _elementCache.Count())
         {
             _elementCache?.Clear();
             _elementCache    = _cursor.MoveNext() ? _cursor.Current.ToList() : new List <BsonDocument>();
             _passedElements += _position;
             _position        = 0;
         }
     }
 }
        // public methods
        public IEnumerator <TDocument> GetEnumerator()
        {
            var cursor = _source.ToCursor(_cancellationToken);

            return(new AsyncCursorEnumerator <TDocument>(cursor, _cancellationToken));
        }