private async Task <bool> ExistsAsync(bool retryOnNotExists, CancellationToken cancellationToken)
        {
            var retryCount = 0;

            while (true)
            {
                try
                {
                    await _connection.OpenAsync(cancellationToken);

                    _connection.Close();
                    return(true);
                }
                catch (SqlException e)
                {
                    if (!retryOnNotExists &&
                        IsDoesNotExist(e))
                    {
                        return(false);
                    }

                    if (!RetryOnExistsFailure(e, ref retryCount))
                    {
                        throw;
                    }
                }
            }
        }
        private Task <bool> ExistsAsync(bool retryOnNotExists, CancellationToken cancellationToken)
        {
            return(ExecutionStrategyFactory.Create().ExecuteAsync(
                       async(giveUp, ct) =>
            {
                var retryCount = 0;
                while (true)
                {
                    try
                    {
                        await _connection.OpenAsync(ct);

                        _connection.Close();
                        return true;
                    }
                    catch (SqlException e)
                    {
                        if (!retryOnNotExists &&
                            IsDoesNotExist(e))
                        {
                            return false;
                        }

                        if (DateTime.UtcNow > giveUp ||
                            !RetryOnExistsFailure(e, ref retryCount))
                        {
                            throw;
                        }

                        await Task.Delay(100, ct);
                    }
                }
            }, DateTime.UtcNow + TimeSpan.FromMinutes(1), cancellationToken));
        }
Beispiel #3
0
        private Task <bool> ExistsAsync(bool retryOnNotExists, CancellationToken cancellationToken)
        => Dependencies.ExecutionStrategyFactory.Create().ExecuteAsync(
            DateTime.UtcNow + RetryTimeout, async(giveUp, ct) =>
        {
            while (true)
            {
                try
                {
                    using (new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled))
                    {
                        await _connection.OpenAsync(ct, errorsExpected: true);

                        await _connection.CloseAsync();
                    }

                    return(true);
                }
                catch (SqlException e)
                {
                    if (!retryOnNotExists &&
                        IsDoesNotExist(e))
                    {
                        return(false);
                    }

                    if (DateTime.UtcNow > giveUp ||
                        !RetryOnExistsFailure(e))
                    {
                        throw;
                    }

                    await Task.Delay(RetryDelay, ct);
                }
            }
        }, cancellationToken);
Beispiel #4
0
        private Task <bool> ExistsAsync(bool retryOnNotExists, CancellationToken cancellationToken)
        => Dependencies.ExecutionStrategyFactory.Create().ExecuteAsync(
            async(giveUp, ct) =>
        {
            while (true)
            {
                try
                {
                    await _connection.OpenAsync(ct);

                    _connection.Close();
                    return(true);
                }
                catch (SqlException e)
                {
                    if (!retryOnNotExists &&
                        IsDoesNotExist(e))
                    {
                        return(false);
                    }

                    if (DateTime.UtcNow > giveUp ||
                        !RetryOnExistsFailure(e))
                    {
                        throw;
                    }

                    await Task.Delay(RetryDelay, ct);
                }
            }
        }, DateTime.UtcNow + RetryTimeout, cancellationToken);
        public virtual Task OpenAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            PreOpen();

            return(_realConnection.OpenAsync(cancellationToken));
        }