Ejemplo n.º 1
0
        // private methods
        private IAsyncCursor <TDocument> CreateCursor(IChannelSourceHandle channelSource, BsonDocument query, CursorBatch <TDocument> batch)
        {
            var getMoreChannelSource = new ServerChannelSource(channelSource.Server, channelSource.Session.Fork());

            return(new AsyncCursor <TDocument>(
                       getMoreChannelSource,
                       _collectionNamespace,
                       query,
                       batch.Documents,
                       batch.CursorId,
                       _batchSize,
                       _limit < 0 ? Math.Abs(_limit.Value) : _limit,
                       _resultSerializer,
                       _messageEncoderSettings));
        }
        private AsyncCursor <TResult> CreateCursorFromCursorResult(IChannelSourceHandle channelSource, BsonDocument command, AggregateResult result)
        {
            var getMoreChannelSource = new ServerChannelSource(channelSource.Server);

            return(new AsyncCursor <TResult>(
                       getMoreChannelSource,
                       CollectionNamespace,
                       command,
                       result.Results,
                       result.CursorId.GetValueOrDefault(0),
                       _batchSize,
                       null, // limit
                       _resultSerializer,
                       MessageEncoderSettings));
        }
Ejemplo n.º 3
0
        private AsyncCursor <TDocument> CreateCursor(IChannelSourceHandle channelSource, CursorBatch <TDocument> batch, bool slaveOk)
        {
            var getMoreChannelSource = new ServerChannelSource(channelSource.Server);

            return(new AsyncCursor <TDocument>(
                       getMoreChannelSource,
                       _collectionNamespace,
                       _filter ?? new BsonDocument(),
                       batch.Documents,
                       batch.CursorId,
                       _batchSize,
                       _limit < 0 ? Math.Abs(_limit.Value) : _limit,
                       _resultSerializer,
                       _messageEncoderSettings,
                       _cursorType == CursorType.TailableAwait ? _maxAwaitTime : null));
        }
Ejemplo n.º 4
0
        private IAsyncCursor <BsonDocument> CreateCursor(IChannelSourceHandle channelSource, BsonDocument result, BsonDocument command)
        {
            var getMoreChannelSource = new ServerChannelSource(channelSource.Server, channelSource.Session.Fork());
            var cursorDocument       = result["cursor"].AsBsonDocument;
            var cursor = new AsyncCursor <BsonDocument>(
                getMoreChannelSource,
                CollectionNamespace.FromFullName(cursorDocument["ns"].AsString),
                command,
                cursorDocument["firstBatch"].AsBsonArray.OfType <BsonDocument>().ToList(),
                cursorDocument["id"].ToInt64(),
                0,
                0,
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings);

            return(cursor);
        }
        private AsyncCursor <TDocument> CreateCursor(IChannelSourceHandle channelSource, BsonDocument commandResult)
        {
            var getMoreChannelSource = new ServerChannelSource(channelSource.Server, channelSource.Session.Fork());
            var firstBatch           = CreateCursorBatch(commandResult);

            return(new AsyncCursor <TDocument>(
                       getMoreChannelSource,
                       _collectionNamespace,
                       _filter ?? new BsonDocument(),
                       firstBatch.Documents,
                       firstBatch.CursorId,
                       _batchSize,
                       _limit < 0 ? Math.Abs(_limit.Value) : _limit,
                       _resultSerializer,
                       _messageEncoderSettings,
                       _cursorType == CursorType.TailableAwait ? _maxAwaitTime : null));
        }
Ejemplo n.º 6
0
        internal static IChannelSourceHandle CreateGetMoreChannelSource(IChannelSourceHandle channelSource, long cursorId)
        {
            IChannelSource effectiveChannelSource;

            if (IsInLoadBalancedMode(channelSource.ServerDescription) && cursorId != 0)
            {
                var getMoreChannel = channelSource.GetChannel(CancellationToken.None); // no need for cancellation token since we already have channel in the source
                var getMoreSession = channelSource.Session.Fork();

                effectiveChannelSource = new ChannelChannelSource(
                    channelSource.Server,
                    getMoreChannel,
                    getMoreSession);
            }
            else
            {
                effectiveChannelSource = new ServerChannelSource(channelSource.Server, channelSource.Session.Fork());
            }

            return(new ChannelSourceHandle(effectiveChannelSource));
        }
        internal static IChannelSourceHandle CreateGetMoreChannelSource(IChannelSourceHandle channelSource, IChannelHandle channel, long cursorId)
        {
            IChannelSource effectiveChannelSource;

            if (IsInLoadBalancedMode(channelSource.ServerDescription) && cursorId != 0)
            {
                if (channel.Connection is ICheckOutReasonTracker checkOutReasonTracker)
                {
                    checkOutReasonTracker.SetCheckOutReasonIfNotAlreadySet(CheckOutReason.Cursor);
                }

                effectiveChannelSource = new ChannelChannelSource(
                    channelSource.Server,
                    channel.Fork(),
                    channelSource.Session.Fork());
            }
            else
            {
                effectiveChannelSource = new ServerChannelSource(channelSource.Server, channelSource.Session.Fork());
            }

            return(new ChannelSourceHandle(effectiveChannelSource));
        }