Ejemplo n.º 1
0
        public virtual async Task <int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            var stateManager = Configuration.StateManager;

            // TODO: Allow auto-detect changes to be switched off
            Configuration.Services.ChangeDetector.DetectChanges(stateManager);

            try
            {
                return(await stateManager.SaveChangesAsync(cancellationToken));
            }
            catch (Exception ex)
            {
                if (DataStoreException.ContainsDataStoreException(ex))
                {
                    if (_logger.Value.IsEnabled(TraceType.Error))
                    {
                        _logger.Value.WriteError(Strings.FormatLogDataStoreExceptionRethrow(Strings.LogExceptionDuringSaveChanges), ex);
                    }

                    throw;
                }

                if (_logger.Value.IsEnabled(TraceType.Error))
                {
                    _logger.Value.WriteError(Strings.FormatLogDataStoreExceptionWrap(Strings.LogExceptionDuringSaveChanges), ex);
                }

                throw new DataStoreException(Strings.DataStoreException, this, ex);
            }
        }
                public bool MoveNext()
                {
                    try
                    {
                        return(_inner.MoveNext());
                    }
                    catch (Exception ex)
                    {
                        if (DataStoreException.ContainsDataStoreException(ex))
                        {
                            if (_logger.Value.IsEnabled(TraceType.Error))
                            {
                                _logger.Value.WriteError(Strings.FormatLogDataStoreExceptionRethrow(Strings.LogExceptionDuringQueryIteration), ex);
                            }

                            throw;
                        }

                        if (_logger.Value.IsEnabled(TraceType.Error))
                        {
                            _logger.Value.WriteError(Strings.FormatLogDataStoreExceptionWrap(Strings.LogExceptionDuringQueryIteration), ex);
                        }

                        throw new DataStoreException(Strings.DataStoreException, _context, ex);
                    }
                }
                public async Task <bool> MoveNext(CancellationToken cancellationToken)
                {
                    try
                    {
                        return(await _inner.MoveNext().ConfigureAwait(continueOnCapturedContext: false));
                    }
                    catch (Exception ex)
                    {
                        if (DataStoreException.ContainsDataStoreException(ex))
                        {
                            if (_logger.Value.IsEnabled(TraceType.Error))
                            {
                                _logger.Value.WriteError(Strings.FormatLogDataStoreExceptionRethrow(Strings.LogExceptionDuringQueryIteration), ex);
                            }

                            throw;
                        }

                        if (_logger.Value.IsEnabled(TraceType.Error))
                        {
                            _logger.Value.WriteError(Strings.FormatLogDataStoreExceptionWrap(Strings.LogExceptionDuringQueryIteration), ex);
                        }

                        throw new DataStoreException(Strings.DataStoreException, _context, ex);
                    }
                }
        public virtual IEnumerable <T> ExecuteCollection <T>([NotNull] QueryModel queryModel)
        {
            Check.NotNull(queryModel, "queryModel");

            new SubQueryFlattener().VisitQueryModel(queryModel);

            LogQueryModel(queryModel);

            try
            {
                return(new EnumerableExceptionInterceptor <T>(
                           _context.Configuration.DataStore.Query <T>(queryModel, _context.Configuration.StateManager),
                           _context,
                           _logger));
            }
            catch (Exception ex)
            {
                if (DataStoreException.ContainsDataStoreException(ex))
                {
                    if (_logger.Value.IsEnabled(TraceType.Error))
                    {
                        _logger.Value.WriteError(Strings.FormatLogDataStoreExceptionRethrow(Strings.LogExceptionDuringQueryExecution), ex);
                    }

                    throw;
                }

                if (_logger.Value.IsEnabled(TraceType.Error))
                {
                    _logger.Value.WriteError(Strings.FormatLogDataStoreExceptionWrap(Strings.LogExceptionDuringQueryExecution), ex);
                }

                throw new DataStoreException(Strings.DataStoreException, _context, ex);
            }
        }