Esempio n. 1
0
        public void ExecuteTransaction(
            System.Data.IsolationLevel isolationLevel,
            Action<Danny> transactionPayload,
            int maximumAttempts = 30)
        {
            if (_transaction != null)
            {
                throw new InvalidOperationException("Cannot create non-nested transactions per connection");
            }

            var attempt = 0;
            var exceptions = new List<Exception>();
            var random = new Random();

            while (true)
            {
                attempt++;
                try
                {
                    var connection = _connectionFactory();

                    connection.DisallowDispose();

                    var transaction = connection.Connection.BeginTransaction(isolationLevel);
                    var danny = new Danny(transaction, () => connection, null);

                    transactionPayload(danny);

                    break;
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);

                    if (attempt == maximumAttempts)
                    {
                        throw new AggregateException(
                            $"Maximum number of attempts reached ({maximumAttempts}) when executing transaction payload",
                            exceptions);
                    }

                    Thread.Sleep(random.Next(200, 500));
                }
            }
        }
Esempio n. 2
0
 public Session(string connectionString)
 {
     _danny = new Danny(connectionString);
 }
Esempio n. 3
0
 private Session(Danny danny)
 {
     _danny = danny;
 }
Esempio n. 4
0
 public Query(Danny danny, string query)
 {
     _danny = danny;
     _query = query;
 }