Beispiel #1
0
            protected async Task <bool> LoadFromEnumerator(CancellationToken cancellationToken)
            {
                if (await enumerator.MoveNext(cancellationToken)
                    .ConfigureAwait(false))
                {
                    current = enumerator.Current;
                    return(true);
                }

                enumerator?.Dispose();
                enumerator = null;

                return(false);
            }
Beispiel #2
0
 protected override void Cleanup()
 {
     try
     {
         m_chunkIterator?.Dispose();
     }
     finally
     {
         m_chunkIterator         = null;
         m_chunk                 = null;
         m_outOfChunks           = true;
         m_currentOffsetInChunk  = 0;
         m_itemsRemainingInChunk = 0;
     }
 }
Beispiel #3
0
            protected override async Task <bool> MoveNextCore(CancellationToken cancellationToken)
            {
                switch (state)
                {
                case AsyncIteratorState.Allocated:
                    queue = new Queue <IAsyncEnumerable <TSource> >();
                    queue.Enqueue(source);

                    state = AsyncIteratorState.Iterating;
                    goto case AsyncIteratorState.Iterating;

                case AsyncIteratorState.Iterating:
                    while (true)
                    {
                        if (enumerator == null)
                        {
                            if (queue.Count > 0)
                            {
                                var src = queue.Dequeue();

                                enumerator?.Dispose();
                                enumerator = src.GetEnumerator();

                                continue;     // loop
                            }

                            break;     // while
                        }

                        if (await enumerator.MoveNext(cancellationToken)
                            .ConfigureAwait(false))
                        {
                            var item = enumerator.Current;
                            var next = selector(item);
                            queue.Enqueue(next);
                            current = item;
                            return(true);
                        }
                        enumerator.Dispose();
                        enumerator = null;
                    }

                    break;     // case
                }

                Dispose();
                return(false);
            }
Beispiel #4
0
            protected override async Task <bool> MoveNextCore(CancellationToken cancellationToken)
            {
                switch (state)
                {
                case AsyncIteratorState.Allocated:
                    sourceEnumerator = source.GetEnumerator();
                    mode             = State_Source;
                    state            = AsyncIteratorState.Iterating;
                    goto case AsyncIteratorState.Iterating;

                case AsyncIteratorState.Iterating:
                    switch (mode)
                    {
                    case State_Source:
                        if (await sourceEnumerator.MoveNext(cancellationToken)
                            .ConfigureAwait(false))
                        {
                            resultEnumerator?.Dispose();
                            resultEnumerator = selector(sourceEnumerator.Current)
                                               .GetEnumerator();

                            mode = State_Result;
                            goto case State_Result;
                        }
                        break;

                    case State_Result:
                        if (await resultEnumerator.MoveNext(cancellationToken)
                            .ConfigureAwait(false))
                        {
                            current = resultEnumerator.Current;
                            return(true);
                        }

                        mode = State_Source;
                        goto case State_Source;         // loop
                    }

                    break;
                }

                Dispose();
                return(false);
            }
Beispiel #5
0
            protected override async Task <bool> MoveNextCore(CancellationToken cancellationToken)
            {
                switch (state)
                {
                case AsyncIteratorState.Allocated:
                    _outerEnumerator = _source.GetEnumerator();
                    _mode            = State_OuterNext;
                    state            = AsyncIteratorState.Iterating;
                    goto case AsyncIteratorState.Iterating;

                case AsyncIteratorState.Iterating:
                    switch (_mode)
                    {
                    case State_OuterNext:
                        if (_outerEnumerator.MoveNext())
                        {
                            // make sure we dispose the previous one if we're about to replace it
                            _currentEnumerator?.Dispose();
                            _currentEnumerator = _outerEnumerator.Current.GetEnumerator();

                            _mode = State_While;
                            goto case State_While;
                        }

                        break;

                    case State_While:
                        if (await _currentEnumerator.MoveNext(cancellationToken)
                            .ConfigureAwait(false))
                        {
                            current = _currentEnumerator.Current;
                            return(true);
                        }

                        // No more on the inner enumerator, move to the next outer
                        goto case State_OuterNext;
                    }

                    Dispose();
                    break;
                }

                return(false);
            }
Beispiel #6
0
        internal static IAsyncEnumerator <T> GetEnumerator([NotNull] FdbAsyncSequenceQuery <T> sequence, AsyncIterationHint mode)
        {
            var generator = sequence.CompileSequence(sequence.Expression);

            if (sequence.Transaction != null)
            {
                var source = generator(sequence.Transaction);
                Contract.Assert(source != null);
                return(source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(sequence.Transaction.Cancellation, mode) : source.GetAsyncEnumerator());
            }

            //BUGBUG: how do we get a CancellationToken without a transaction?
            var ct = CancellationToken.None;

            IFdbTransaction      trans    = null;
            IAsyncEnumerator <T> iterator = null;
            bool success = true;

            try
            {
                trans = sequence.Database.BeginTransaction(ct);
                var source = generator(trans);
                Contract.Assert(source != null);
                iterator = source is IConfigurableAsyncEnumerable <T> configurable?configurable.GetAsyncEnumerator(ct, mode) : source.GetAsyncEnumerator();

                return(new TransactionIterator(trans, iterator));
            }
            catch (Exception)
            {
                success = false;
                throw;
            }
            finally
            {
                if (!success)
                {
                    iterator?.Dispose();
                    trans?.Dispose();
                }
            }
        }
 public void Dispose()
 {
     source.Dispose();
 }
 public void Dispose() => _innerEnumerator.Dispose();
Beispiel #9
0
 public void Dispose()
 {
     first.Dispose();
     second.Dispose();
 }
Beispiel #10
0
 public override void Dispose() => _enumerator.Dispose();
 public void Dispose()
 {
     asyncEnumerator.Dispose();
 }
 public void Dispose()
 {
     _enumerator.Dispose();
 }
Beispiel #13
0
 public void Dispose()
 {
     _sourceEnumerator?.Dispose();
     _groupJoinAsyncEnumerable._innerGroupJoinInclude?.Dispose();
     _groupJoinAsyncEnumerable._outerGroupJoinInclude?.Dispose();
 }
Beispiel #14
0
 public void Dispose() => m_inner.Dispose();
Beispiel #15
0
 public void Dispose() => _sourceEnumerator?.Dispose();
Beispiel #16
0
 public void Dispose()
 {
     _outer.Dispose();
 }
 public void Dispose()
 {
     _enumerator.Dispose();
     _transaction?.Dispose();
 }
 public void Dispose()
 {
     _relatedValuesIterator.Dispose();
     _enumerator.Dispose();
 }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual async Task IncludeCollectionAsync(
            int includeId,
            INavigation navigation,
            INavigation inverseNavigation,
            IEntityType targetEntityType,
            IClrCollectionAccessor clrCollectionAccessor,
            IClrPropertySetter inverseClrPropertySetter,
            bool tracking,
            object entity,
            Func <IAsyncEnumerable <object> > relatedEntitiesFactory,
            CancellationToken cancellationToken)
        {
            IDisposable untypedAsyncEnumerator        = null;
            IAsyncEnumerator <object> asyncEnumerator = null;

            if (includeId == -1 ||
                !_includedCollections.TryGetValue(includeId, out untypedAsyncEnumerator))
            {
                asyncEnumerator = relatedEntitiesFactory().GetEnumerator();

                if (!await asyncEnumerator.MoveNext(cancellationToken))
                {
                    asyncEnumerator.Dispose();
                    asyncEnumerator = null;
                }

                if (includeId != -1)
                {
                    _includedCollections.Add(includeId, asyncEnumerator);
                }
            }

            if (asyncEnumerator == null)
            {
                if (untypedAsyncEnumerator == null)
                {
                    clrCollectionAccessor.GetOrCreate(entity);

                    return;
                }

                asyncEnumerator = (IAsyncEnumerator <object>)untypedAsyncEnumerator;
            }

            var relatedEntities = new List <object>();

            // TODO: This should be done at query compile time and not require a VB unless there are shadow props
            var keyComparer = CreateIncludeKeyComparer(entity, navigation);

            while (true)
            {
                bool shouldInclude;

                if (_valueBuffers.TryGetValue(asyncEnumerator.Current, out var relatedValueBuffer))
                {
                    shouldInclude = keyComparer.ShouldInclude((ValueBuffer)relatedValueBuffer);
                }
                else
                {
                    var entry = _dependencies.StateManager.TryGetEntry(asyncEnumerator.Current);

                    Debug.Assert(entry != null);

                    shouldInclude = keyComparer.ShouldInclude(entry);
                }

                if (shouldInclude)
                {
                    relatedEntities.Add(asyncEnumerator.Current);

                    if (tracking)
                    {
                        StartTracking(asyncEnumerator.Current, targetEntityType);
                    }

                    if (inverseNavigation != null)
                    {
                        Debug.Assert(inverseClrPropertySetter != null);

                        inverseClrPropertySetter.SetClrValue(asyncEnumerator.Current, entity);

                        if (tracking)
                        {
                            var internalEntityEntry = _dependencies.StateManager.TryGetEntry(asyncEnumerator.Current);

                            Debug.Assert(internalEntityEntry != null);

                            internalEntityEntry.SetRelationshipSnapshotValue(inverseNavigation, entity);
                        }
                    }

                    if (!await asyncEnumerator.MoveNext(cancellationToken))
                    {
                        asyncEnumerator.Dispose();

                        _includedCollections[includeId] = null;

                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            clrCollectionAccessor.AddRange(entity, relatedEntities);

            if (tracking)
            {
                var internalEntityEntry = _dependencies.StateManager.TryGetEntry(entity);

                Debug.Assert(internalEntityEntry != null);

                internalEntityEntry.AddRangeToCollectionSnapshot(navigation, relatedEntities);
                internalEntityEntry.SetIsLoaded(navigation);
            }
        }
Beispiel #20
0
 public void Dispose()
 {
     enum1.Dispose();
 }
Beispiel #21
0
 public virtual void Dispose()
 {
     _relatedValuesEnumerator.Dispose();
 }
Beispiel #22
0
 public static ValueTask DisposeAsync <T>(this IAsyncEnumerator <T> enumerator)
 {
     enumerator.Dispose();
     return(default);
 public void Dispose()
 {
     _innerEnumerator?.Dispose();
     _exceptionInterceptor._queryContext.Dispose();
 }
 public override void Dispose()
 {
     _asyncEnumerator.Dispose();
 }
Beispiel #25
0
 public void Dispose() => _enumerator.Dispose();
 public void Dispose() => _asyncEnumerator.Dispose();
Beispiel #27
0
 public void Dispose()
 {
     _inner.Dispose();
 }
        protected override void Dispose(bool disposing)
        {
            source.Dispose();

            source = null;
        }
Beispiel #29
0
 public void Dispose()
 {
     _sourceEnumerator?.Dispose();
     _innerGroupJoinIncludeContext?.Dispose();
     _outerGroupJoinIncludeContext?.Dispose();
 }
 public void Dispose() => _underlyingStream.Dispose();