Exemple #1
0
        public override IAsyncCursor <TResult> Aggregate <TResult>(IClientSessionHandle session, PipelineDefinition <NoPipelineInput, TResult> pipeline, AggregateOptions options, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(session, nameof(session));
            var renderedPipeline = Ensure.IsNotNull(pipeline, nameof(pipeline)).Render(NoPipelineInputSerializer.Instance, _settings.SerializerRegistry, _linqProvider);

            options = options ?? new AggregateOptions();

            var lastStage     = renderedPipeline.Documents.LastOrDefault();
            var lastStageName = lastStage?.GetElement(0).Name;

            if (lastStage != null && (lastStageName == "$out" || lastStageName == "$merge"))
            {
                var aggregateOperation = CreateAggregateToCollectionOperation(renderedPipeline, options);
                ExecuteWriteOperation(session, aggregateOperation, cancellationToken);

                // we want to delay execution of the find because the user may
                // not want to iterate the results at all...
                var findOperation  = CreateAggregateToCollectionFindOperation(lastStage, renderedPipeline.OutputSerializer, options);
                var forkedSession  = session.Fork();
                var deferredCursor = new DeferredAsyncCursor <TResult>(
                    () => forkedSession.Dispose(),
                    ct => ExecuteReadOperation(forkedSession, findOperation, ReadPreference.Primary, ct),
                    ct => ExecuteReadOperationAsync(forkedSession, findOperation, ReadPreference.Primary, ct));
                return(deferredCursor);
            }
            else
            {
                var aggregateOperation = CreateAggregateOperation(renderedPipeline, options);
                return(ExecuteReadOperation(session, aggregateOperation, cancellationToken));
            }
        }
Exemple #2
0
        public static ICoreSessionHandle ToCoreSession(this IClientSessionHandle clientSession)
        {
            var coreSession = new ClientSessionWrappingCoreSession(clientSession.Fork());

            return(new CoreSessionHandle(coreSession));
        }
Exemple #3
0
 public IClientSessionHandle Fork()
 {
     return(_sessionHandle.Fork());
 }