예제 #1
0
        public bool MoveNext()
        {
            if (disposed)
            {
                throw new ObjectDisposedException("MongoCursorEnumerator");
            }
            if (done)
            {
                return(false);
            }

            if (!started)
            {
                reply = GetFirst();
                if (reply.Documents.Count == 0)
                {
                    reply = null;
                    done  = true;
                    return(false);
                }
                replyIndex = -1;
                started    = true;
            }

            if (positiveLimit != 0 && count == positiveLimit)
            {
                KillCursor(); // early exit
                reply = null;
                done  = true;
                return(false);
            }

            if (replyIndex < reply.Documents.Count - 1)
            {
                replyIndex++; // move to next document in the current reply
            }
            else
            {
                if (openCursorId != 0)
                {
                    reply = GetMore();
                    if (reply.Documents.Count == 0)
                    {
                        reply = null;
                        done  = true;
                        return(false);
                    }
                    replyIndex = 0;
                }
                else
                {
                    reply = null;
                    done  = true;
                    return(false);
                }
            }

            count++;
            return(true);
        }
예제 #2
0
        internal MongoReplyMessage <TDocument> ReceiveMessage <TDocument>(
            BsonBinaryReaderSettings readerSettings,
            IBsonSerializer <TDocument> serializer)
        {
            if (_state == MongoConnectionState.Closed)
            {
                throw new InvalidOperationException("Connection is closed.");
            }
            lock (_connectionLock)
            {
                try
                {
                    _lastUsedAt = DateTime.UtcNow;
                    var networkStream = GetNetworkStream();
                    var readTimeout   = (int)_serverInstance.Settings.SocketTimeout.TotalMilliseconds;
                    if (readTimeout != 0)
                    {
                        networkStream.ReadTimeout = readTimeout;
                    }

                    using (var byteBuffer = ByteBufferFactory.LoadLengthPrefixedDataFrom(networkStream))
                        using (var stream = new ByteBufferStream(byteBuffer, ownsByteBuffer: true))
                        {
                            var reply = new MongoReplyMessage <TDocument>(readerSettings, serializer);
                            reply.ReadFrom(stream);
                            return(reply);
                        }
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    throw;
                }
            }
        }
예제 #3
0
 internal MongoReplyMessage <TDocument> ReceiveMessage <TDocument>(
     BsonBinaryReaderSettings readerSettings,
     IBsonSerializationOptions serializationOptions)
 {
     if (_state == MongoConnectionState.Closed)
     {
         throw new InvalidOperationException("Connection is closed.");
     }
     lock (_connectionLock)
     {
         try
         {
             using (var buffer = new BsonBuffer())
             {
                 var networkStream = GetNetworkStream();
                 var readTimeout   = (int)_serverInstance.Settings.SocketTimeout.TotalMilliseconds;
                 if (readTimeout != 0)
                 {
                     networkStream.ReadTimeout = readTimeout;
                 }
                 buffer.LoadFrom(networkStream);
                 var reply = new MongoReplyMessage <TDocument>(readerSettings);
                 reply.ReadFrom(buffer, serializationOptions);
                 return(reply);
             }
         }
         catch (Exception ex)
         {
             HandleException(ex);
             throw;
         }
     }
 }
예제 #4
0
 internal MongoReplyMessage <TDocument> ReceiveMessage <TDocument>()
 {
     if (state == MongoConnectionState.Closed)
     {
         throw new InvalidOperationException("Connection is closed");
     }
     lock (connectionLock) {
         try {
             using (var buffer = new BsonBuffer()) {
                 var networkStream = GetNetworkStream();
                 networkStream.ReadTimeout = (int)serverInstance.Server.Settings.SocketTimeout.TotalMilliseconds;
                 buffer.LoadFrom(networkStream);
                 var reply = new MongoReplyMessage <TDocument>(this);
                 reply.ReadFrom(buffer);
                 return(reply);
             }
         } catch (Exception ex) {
             HandleException(ex);
             throw;
         }
     }
 }