Exemplo n.º 1
0
 protected virtual int SaveChanges(
     [NotNull] IReadOnlyList <InternalEntityEntry> entriesToSave)
 {
     try
     {
         _concurrencyDetector.EnterCriticalSection();
         return(_database.SaveChanges(entriesToSave));
     }
     finally
     {
         _concurrencyDetector.ExitCriticalSection();
     }
 }
Exemplo n.º 2
0
            public bool MoveNext()
            {
                try
                {
                    _concurrencyDetector?.EnterCriticalSection();

                    try
                    {
                        if (!_hasExecuted)
                        {
                            if (!_readItemEnumerable.TryGetResourceId(out var resourceId))
                            {
                                throw new InvalidOperationException(CosmosStrings.ResourceIdMissing);
                            }

                            if (!_readItemEnumerable.TryGetPartitionId(out var partitionKey))
                            {
                                throw new InvalidOperationException(CosmosStrings.PartitionKeyMissing);
                            }

                            EntityFrameworkEventSource.Log.QueryExecuting();

                            _item = _cosmosQueryContext.CosmosClient.ExecuteReadItem(
                                _readItemExpression.Container,
                                partitionKey,
                                resourceId);

                            return(ShapeResult());
                        }

                        return(false);
                    }
                    finally
                    {
                        _concurrencyDetector?.ExitCriticalSection();
                    }
                }
                catch (Exception exception)
                {
                    if (_exceptionDetector.IsCancellation(exception))
                    {
                        _queryLogger.QueryCanceled(_contextType);
                    }
                    else
                    {
                        _queryLogger.QueryIterationFailed(_contextType, exception);
                    }

                    throw;
                }
            }
            public async ValueTask <bool> MoveNextAsync()
            {
                try
                {
                    _concurrencyDetector?.EnterCriticalSection();

                    try
                    {
                        if (_enumerator == null)
                        {
                            var sqlQuery = _queryingEnumerable.GenerateQuery();

                            EntityFrameworkEventSource.Log.QueryExecuting();

                            _enumerator = _cosmosQueryContext.CosmosClient
                                          .ExecuteSqlQueryAsync(
                                _selectExpression.Container,
                                _partitionKey,
                                sqlQuery)
                                          .GetAsyncEnumerator(_cancellationToken);
                            _cosmosQueryContext.InitializeStateManager(_standAloneStateManager);
                        }

                        var hasNext = await _enumerator.MoveNextAsync().ConfigureAwait(false);

                        Current
                            = hasNext
                                ? _shaper(_cosmosQueryContext, _enumerator.Current)
                                : default;

                        return(hasNext);
                    }
                    finally
                    {
                        _concurrencyDetector?.ExitCriticalSection();
                    }
                }
                catch (Exception exception)
                {
                    if (_exceptionDetector.IsCancellation(exception, _cancellationToken))
                    {
                        _queryLogger.QueryCanceled(_contextType);
                    }
                    else
                    {
                        _queryLogger.QueryIterationFailed(_contextType, exception);
                    }

                    throw;
                }
            }
Exemplo n.º 4
0
            public bool MoveNext()
            {
                try
                {
                    _concurrencyDetector?.EnterCriticalSection();

                    try
                    {
                        if (_enumerator == null)
                        {
                            var sqlQuery = _queryingEnumerable.GenerateQuery();

                            EntityFrameworkEventSource.Log.QueryExecuting();

                            _enumerator = _cosmosQueryContext.CosmosClient
                                          .ExecuteSqlQuery(
                                _selectExpression.Container,
                                _partitionKey,
                                sqlQuery)
                                          .GetEnumerator();
                            _cosmosQueryContext.InitializeStateManager(_standAloneStateManager);
                        }

                        var hasNext = _enumerator.MoveNext();

                        Current
                            = hasNext
                                ? _shaper(_cosmosQueryContext, _enumerator.Current)
                                : default;

                        return(hasNext);
                    }
                    finally
                    {
                        _concurrencyDetector?.ExitCriticalSection();
                    }
                }
                catch (Exception exception)
                {
                    _queryLogger.QueryIterationFailed(_contextType, exception);

                    throw;
                }
            }
Exemplo n.º 5
0
 /// <inheritdoc />
 public void Dispose()
 => _concurrencyDetector.ExitCriticalSection();