示例#1
0
        private System.Data.IsolationLevel GetSystemDataIsolationLevel(SQLiteConnection connection, System.Transactions.Transaction transaction, System.Data.IsolationLevel defaultIsolationLevel, bool throwOnUnavailable, bool throwOnUnsupported)
        {
            if (transaction == null)
            {
                if (connection != null)
                {
                    return(connection.GetDefaultIsolationLevel());
                }
                if (throwOnUnavailable)
                {
                    throw new InvalidOperationException("isolation level is unavailable");
                }
                return(defaultIsolationLevel);
            }
            System.Transactions.IsolationLevel isolationLevel = transaction.IsolationLevel;
            switch (isolationLevel)
            {
            case System.Transactions.IsolationLevel.Serializable:
            {
                return(System.Data.IsolationLevel.Serializable);
            }

            case System.Transactions.IsolationLevel.RepeatableRead:
            {
                return(System.Data.IsolationLevel.RepeatableRead);
            }

            case System.Transactions.IsolationLevel.ReadCommitted:
            {
                return(System.Data.IsolationLevel.ReadCommitted);
            }

            case System.Transactions.IsolationLevel.ReadUncommitted:
            {
                return(System.Data.IsolationLevel.ReadUncommitted);
            }

            case System.Transactions.IsolationLevel.Snapshot:
            {
                return(System.Data.IsolationLevel.Snapshot);
            }

            case System.Transactions.IsolationLevel.Chaos:
            {
                return(System.Data.IsolationLevel.Chaos);
            }

            case System.Transactions.IsolationLevel.Unspecified:
            {
                return(System.Data.IsolationLevel.Unspecified);
            }
            }
            if (throwOnUnsupported)
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                object[]    objArray       = new object[] { isolationLevel };
                throw new InvalidOperationException(HelperMethods.StringFormat(currentCulture, "unsupported isolation level {0}", objArray));
            }
            return(defaultIsolationLevel);
        }
示例#2
0
 public AppUnitOfWork(bool isTransactional           = false,
                      IsolationLevel isolationLevel  = IsolationLevel.ReadCommitted,
                      int transactionTimeoutInSecond = 300,
                      TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required)
     : base(isTransactional, isolationLevel, transactionTimeoutInSecond, transactionScopeOption)
 {
 }
        private bool _active;                                   // Is the transaction active?

        internal SqlDelegatedTransaction(SqlInternalConnection connection, SysTx.Transaction tx)
        {
            Debug.Assert(null != connection, "null connection?");
            _connection        = connection;
            _atomicTransaction = tx;
            _active            = false;
            SysTx.IsolationLevel systxIsolationLevel = tx.IsolationLevel;

            // We need to map the System.Transactions IsolationLevel to the one
            // that System.Data uses and communicates to SqlServer.  We could
            // arguably do that in Initialize when the transaction is delegated,
            // however it is better to do this before we actually begin the process
            // of delegation, in case System.Transactions adds another isolation
            // level we don't know about -- we can throw the exception at a better
            // place.
            switch (systxIsolationLevel)
            {
            case SysTx.IsolationLevel.ReadCommitted:    _isolationLevel = IsolationLevel.ReadCommitted;     break;

            case SysTx.IsolationLevel.ReadUncommitted:  _isolationLevel = IsolationLevel.ReadUncommitted;   break;

            case SysTx.IsolationLevel.RepeatableRead:   _isolationLevel = IsolationLevel.RepeatableRead;    break;

            case SysTx.IsolationLevel.Serializable:     _isolationLevel = IsolationLevel.Serializable;      break;

            case SysTx.IsolationLevel.Snapshot:         _isolationLevel = IsolationLevel.Snapshot;          break;

            default:
                throw SQL.UnknownSysTxIsolationLevel(systxIsolationLevel);
            }
        }
        internal SqlDelegatedTransaction(SqlInternalConnection connection, System.Transactions.Transaction tx)
        {
            this._connection        = connection;
            this._atomicTransaction = tx;
            this._active            = false;
            System.Transactions.IsolationLevel isolationLevel = tx.IsolationLevel;
            switch (isolationLevel)
            {
            case System.Transactions.IsolationLevel.Serializable:
                this._isolationLevel = System.Data.IsolationLevel.Serializable;
                return;

            case System.Transactions.IsolationLevel.RepeatableRead:
                this._isolationLevel = System.Data.IsolationLevel.RepeatableRead;
                return;

            case System.Transactions.IsolationLevel.ReadCommitted:
                this._isolationLevel = System.Data.IsolationLevel.ReadCommitted;
                return;

            case System.Transactions.IsolationLevel.ReadUncommitted:
                this._isolationLevel = System.Data.IsolationLevel.ReadUncommitted;
                return;

            case System.Transactions.IsolationLevel.Snapshot:
                this._isolationLevel = System.Data.IsolationLevel.Snapshot;
                return;
            }
            throw SQL.UnknownSysTxIsolationLevel(isolationLevel);
        }
示例#5
0
        /// <summary>
        /// Starts the new transaction.
        /// </summary>
        /// <param name="isolationLevel">The isolation level.</param>
        /// <returns>
        /// The transaction scope.
        /// </returns>
        public static WeddingCD.Common.Infrastructure.Transaction StartNewTransactionForAsync(System.Data.IsolationLevel isolationLevel = System.Data.IsolationLevel.ReadCommitted)
        {
            System.Transactions.IsolationLevel mappedLevel = IsolationLevel.Unspecified;
            switch (isolationLevel)
            {
            case System.Data.IsolationLevel.Chaos:
                mappedLevel = IsolationLevel.Chaos;
                break;

            case System.Data.IsolationLevel.ReadCommitted:
                mappedLevel = IsolationLevel.ReadCommitted;
                break;

            case System.Data.IsolationLevel.ReadUncommitted:
                mappedLevel = IsolationLevel.ReadUncommitted;
                break;

            case System.Data.IsolationLevel.RepeatableRead:
                mappedLevel = IsolationLevel.RepeatableRead;
                break;

            case System.Data.IsolationLevel.Serializable:
                mappedLevel = IsolationLevel.Serializable;
                break;

            case System.Data.IsolationLevel.Snapshot:
                mappedLevel = IsolationLevel.Snapshot;
                break;
            }

            return(new DatabaseTransaction(true, mappedLevel));
        }
        public FatQueueTransaction(
            IsolationLevel isolationLevel, 
            TimeSpan? timeout,
            Func<IDbConnection> connectionFactory,
            TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required, 
            TransactionScopeAsyncFlowOption transactionScopeAsyncFlowOption = TransactionScopeAsyncFlowOption.Enabled)
        {
            _connectionFactory = connectionFactory;

            var transactionOptions = new TransactionOptions
            {
                IsolationLevel = isolationLevel,
            };

            if (timeout != null)
            {
                transactionOptions.Timeout = timeout.Value;
            }

            if (System.Transactions.Transaction.Current == null || transactionScopeOption == TransactionScopeOption.RequiresNew)
            {
                _transaction = new CommittableTransaction(transactionOptions);
                _transactionScope = new TransactionScope(_transaction, transactionScopeAsyncFlowOption);
            }
        }
示例#7
0
        public virtual void Commit(IsolationLevel isolationLevel     = IsolationLevel.ReadCommitted,
                                   TransactionScopeOption scopOption = TransactionScopeOption.Required)
        {
            try
            {
                void CommitAction()
                {
                    DbContexts.ForEach(dbContext =>
                    {
                        dbContext.SaveChanges();
                        dbContext.ChangeTracker.Entries()
                        .ForEach(e =>
                        {
                            if (e.Entity is AggregateRoot root)
                            {
                                EventBus.Publish(root.GetDomainEvents());
                                root.ClearDomainEvents();
                            }
                        });
                    });
                    BeforeCommitAsync().Wait();
                }

                if (InTransaction)
                {
                    CommitAction();
                }
                else
                {
                    using (var scope = new TransactionScope(scopOption,
                                                            new TransactionOptions {
                        IsolationLevel = isolationLevel
                    },
                                                            TransactionScopeAsyncFlowOption.Enabled))
                    {
                        CommitAction();
                        scope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Rollback();
                if (ex is DbUpdateConcurrencyException)
                {
                    Exception = new DBConcurrencyException(ex.Message, ex);
                    throw Exception;
                }
                else
                {
                    Exception = ex;
                    throw;
                }
            }
            finally
            {
                AfterCommitAsync().Wait();
            }
        }
示例#8
0
        public TransactionScope CreateTransactionScope(System.Transactions.IsolationLevel level = System.Transactions.IsolationLevel.ReadCommitted)
        {
            var transactionOptions = new TransactionOptions();

            transactionOptions.IsolationLevel = level;
            transactionOptions.Timeout        = TransactionManager.MaximumTimeout;
            return(new TransactionScope(TransactionScopeOption.Required, transactionOptions));
        }
示例#9
0
        protected override async Task DoCommitAsync(TransactionScopeOption scopeOption,
                                                    IsolationLevel isolationLevel)
        {
            try
            {
                async Task CommitAction()
                {
                    _dbContexts.ForEach(async context =>
                    {
                        await context.SaveChangesAsync();
                        foreach (var entityEntry in context.ChangeTracker.Entries())
                        {
                            if (!(entityEntry is IAggregateRoot aggregateRoot))
                            {
                                continue;
                            }

                            _eventBus.PrepareEvents(aggregateRoot.GetEvents());
                            aggregateRoot.ClearEvents();
                        }
                    });

                    await BeforeCommitAsync();
                }
                if (InTransaction)
                {
                    await CommitAction();
                }
                else
                {
                    using (var scope = new TransactionScope(scopeOption,
                                                            new TransactionOptions {
                        IsolationLevel = isolationLevel
                    },
                                                            TransactionScopeAsyncFlowOption.Enabled))
                    {
                        await CommitAction();

                        scope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is DbUpdateConcurrencyException)
                {
                    throw new DBConcurrencyException(ex.Message, ex);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                await AfterCommitAsync();
            }
        }
示例#10
0
 public TransactionScope GetTransaction(int?timeoutInSec = null, TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required,
                                        System.Transactions.IsolationLevel isolationLevel = System.Transactions.IsolationLevel.ReadCommitted)
 {
     return(new TransactionScope(transactionScopeOption,
                                 new TransactionOptions()
     {
         IsolationLevel = isolationLevel, Timeout = (timeoutInSec == null) ? TransactionManager.DefaultTimeout : new TimeSpan(0, 0, timeoutInSec.Value)
     }));
 }
        public static TransactionScope CreateTransactionScope(IsolationLevel isolationLevel)
        {
            var transactionOptions = new TransactionOptions
            {
                IsolationLevel = isolationLevel
            };

            return(new TransactionScope(TransactionScopeOption.Required, transactionOptions));
        }
 public PostgreSqlDatabase(
     Func<IDbConnection> connectionFactory,
     IsolationLevel isolationLevel = IsolationLevel.ReadCommitted,
     ITransaction externalTransaction = null)
 {
     _connectionFactory = connectionFactory;
     _isolationLevel = isolationLevel;
     _externalTransaction = externalTransaction;
 }
 public PostgreSqlDbTransaction(IsolationLevel isolationLevel, 
     TimeSpan? timeout, 
     Func<IDbConnection> connectionFactory, 
     TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required, 
     TransactionScopeAsyncFlowOption transactionScopeAsyncFlowOption = TransactionScopeAsyncFlowOption.Enabled) : 
     base(isolationLevel, timeout, connectionFactory, transactionScopeOption, transactionScopeAsyncFlowOption)
 {
     _isolationLevel = isolationLevel;
 }
示例#14
0
        public static TransactionScope CreateTransactionScope(
            TransactionScopeOption option, System.Transactions.IsolationLevel level)
        {
            var transactionOptions = new TransactionOptions();

            transactionOptions.IsolationLevel = level;
            // TODO Set transaction time-out
            return(new TransactionScope(option, transactionOptions));
        }
示例#15
0
        public void BeginTransaction(System.Transactions.IsolationLevel isolationLevel)
        {
            var transactionOptions = new TransactionOptions();

            transactionOptions.IsolationLevel = isolationLevel;
            transactionOptions.Timeout        = TransactionManager.MaximumTimeout;

            scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions);
        }
示例#16
0
        /// <summary>
        /// Creates a new transaction scope associated with the specified connection,
        /// using the specified transaction configuration options.
        /// The scope can be nested inside another scope in which case the underlying
        /// db transaction is only committed once both the outer and inner transaction(s)
        /// have been committed. The returned ITransactionScope implements IDisposable
        /// and should be wrapped in a using statement.
        /// </summary>
        /// <param name="dbConnection">
        /// <para>
        /// The DbConnection instance to manage transactions for. Transaction scopes
        /// created by this instance only apply to a single DbConnection, so if you want
        /// the scope to span additional data access mechanism then they must share the
        /// same connection.
        /// </para>
        /// <para>
        /// You can use the ICofoundryDbConnectionManager to get a reference to the shared
        /// connection directly.
        /// </para>
        /// </param>
        /// <param name="transactionScopeOption">This is defaulted to TransactionScopeOption.Required.</param>
        /// <param name="isolationLevel">This is defaulted to IsolationLevel.ReadCommitted.</param>
        /// <returns>ITransactionScope, which is IDisposable and must be disposed.</returns>
        public ITransactionScope Create(DbConnection dbConnection,
                                        System.Transactions.TransactionScopeOption transactionScopeOption = System.Transactions.TransactionScopeOption.Required,
                                        System.Transactions.IsolationLevel isolationLevel = System.Transactions.IsolationLevel.ReadCommitted
                                        )
        {
            var transactionScopeFactory = CreateScopeFactory(transactionScopeOption, isolationLevel);

            return(Create(dbConnection, transactionScopeFactory));
        }
示例#17
0
 public static TransactionScope GetTransactionScopeAsync(IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
 {
     return(new TransactionScope(TransactionScopeOption.Required,
                                 new TransactionOptions
     {
         IsolationLevel = isolationLevel,
         Timeout = TransactionManager.MaximumTimeout
     }, TransactionScopeAsyncFlowOption.Enabled));
 }
示例#18
0
 private Func <System.Transactions.TransactionScope> CreateScopeFactory(
     System.Transactions.TransactionScopeOption transactionScopeOption = System.Transactions.TransactionScopeOption.Required,
     System.Transactions.IsolationLevel isolationLevel = System.Transactions.IsolationLevel.ReadCommitted
     )
 {
     return(() => _transactionScopeFactory.Create(
                transactionScopeOption,
                isolationLevel
                ));
 }
 public RawSQLEntityFramework(DbContext context, Transactions.IsolationLevel isoLevel = Transactions.IsolationLevel.ReadCommitted, Transactions.TransactionScopeOption scopeOption = Transactions.TransactionScopeOption.RequiresNew)
 {
     ContractUtility.Requires <ArgumentNullException>(context.IsNotNull(), "context instance cannot be null");
     _context = context;
     //_context.Database.CreateIfNotExists();//Alongwith creating the DB(if the DB does not exist),
     // this method also creates the tables even if the tables do not exist - also alters the tables if
     // some changes are there in the structure of domain classes.
     _isoLevel    = isoLevel;
     _scopeOption = scopeOption;
 }
示例#20
0
        public static async Task <T> WithTransaction <T>(Func <TransactionScope, Task <T> > func,
                                                         TimeSpan?timeout = null,
                                                         IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
        {
            using var scope = CreateTransactionScope(timeout, isolationLevel, EnableAsync);
            var result = await func(scope);

            scope.Complete();
            return(result);
        }
示例#21
0
 public static void WithTransaction(Action <TransactionScope> action,
                                    TimeSpan?timeout = null,
                                    IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
 {
     WithTransaction(scope =>
     {
         action(scope);
         return((object)null);
     }, timeout, isolationLevel);
 }
示例#22
0
 public static async Task WithTransaction(Func <TransactionScope, Task> func,
                                          TimeSpan?timeout = null,
                                          IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
 {
     await WithTransaction(async scope =>
     {
         await func(scope);
         return((object)null);
     }, timeout, isolationLevel);
 }
示例#23
0
        public DapperUnitOfWork(System.Transactions.IsolationLevel isolationLevel, IDbConnection connection)
        {
            var transactionScopeOption = new  TransactionScopeOption();

            _transactionScope = new TransactionScope(transactionScopeOption, new TransactionOptions()
            {
                IsolationLevel = isolationLevel
            });
            _connection = connection;
            _connection.Open();
        }
示例#24
0
 /// <summary>
 /// 事务的隔离级别,如果上面已经有了环境事务, 则引用环境事务的隔离级别, 如果没有引用. 可以用自己的隔离级别
 /// </summary>
 /// <param name="isolationLevel"></param>
 /// <returns></returns>
 public static System.Transactions.IsolationLevel isolationLevel(System.Transactions.IsolationLevel isolationLevel)
 {
     if (Transaction.Current == null)
     {
         return(isolationLevel);
     }
     else
     {
         return(Transaction.Current.IsolationLevel);
     }
 }
示例#25
0
 public void DoInTransaction(Action action, IsolationLevel level)
 {
     using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
         IsolationLevel = level
     }))
     {
         CurrentConnection.EnlistTransaction(Transaction.Current);
         action();
         scope.Complete();
     }
 }
示例#26
0
        public TransactionScope CreateTransaction(System.Transactions.IsolationLevel isolationLevel, int timeoutInSeconds)
        {
            var option  = TransactionScopeOption.Required;
            var options = new TransactionOptions()
            {
                IsolationLevel = isolationLevel,
                Timeout        = new TimeSpan(0, 0, timeoutInSeconds)
            };

            return(new TransactionScope(option, options));
        }
        public static TransactionScope CreateLongRunningTransactionScope(
            IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
        {
            var transactionOptions = new TransactionOptions
            {
                IsolationLevel = isolationLevel,
                Timeout        = TransactionManager.MaximumTimeout,
            };

            return(new TransactionScope(TransactionScopeOption.Required, transactionOptions));
        }
示例#28
0
 private void ExecuteTransactionStep(Database database, IsolationLevel isolationLevel, TimeSpan timeout, string changeTable, IStep step)
 {
     using (var transaction = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions {
         IsolationLevel = isolationLevel, Timeout = timeout
     }))
         using (var stepDatabase = database.Clone())
         {
             ExecuteStep(stepDatabase, changeTable, step);
             transaction.Complete();
         }
 }
示例#29
0
 public void BeginTransaction(System.Transactions.IsolationLevel level, TimeSpan timeout)
 {
     base.CheckDisposed();
     if (_transactionScope == null)
     {
         _transactionScope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
         {
             IsolationLevel = level,
             Timeout        = timeout
         });
     }
 }
示例#30
0
        protected TransactionScope CreateTransactionScopeWithIsolationLevel(System.Transactions.IsolationLevel isolationLevel = IsolationLevel.ReadCommitted, TimeSpan?timeout = null)
        {
            var opts = new TransactionOptions();

            opts.IsolationLevel = isolationLevel;
            if (timeout == null)
            {
                timeout = new TimeSpan(0, 1, 30);
            }
            opts.Timeout = timeout.Value;
            return(new TransactionScope(TransactionScopeOption.Required, opts));
        }
        public SQLiteWriteOnlyTransaction(
            IDbConnection connection,
            IsolationLevel? isolationLevel,
            PersistentJobQueueProviderCollection queueProviders)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (queueProviders == null) throw new ArgumentNullException("queueProviders");

            _connection = connection;
            _isolationLevel = isolationLevel;
            _queueProviders = queueProviders;
        }
        private void ReadFrom(XmlDictionaryReader reader)
        {
            try
            {
                reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.CreateCoordinationContext, this.coordinationXmlDictionaryStrings.Namespace);
                if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.Expires, this.coordinationXmlDictionaryStrings.Namespace))
                {
                    int num = reader.ReadElementContentAsInt();
                    if (num < 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
                    }
                    this.expiration     = (uint)num;
                    this.expiresPresent = true;
                }
                if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace))
                {
                    this.CurrentContext = CoordinationContext.ReadFrom(reader, this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace, this.protocolVersion);
                }
                reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.CoordinationType, this.coordinationXmlDictionaryStrings.Namespace);
                if (reader.ReadElementContentAsString().Trim() != this.atomicTransactionStrings.Namespace)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
                }
                if (!reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
                {
                    goto Label_016B;
                }
                this.IsolationLevel = (System.Transactions.IsolationLevel)reader.ReadElementContentAsInt();
                if (((this.IsolationLevel >= System.Transactions.IsolationLevel.Serializable) && (this.IsolationLevel <= System.Transactions.IsolationLevel.Unspecified)) && (this.IsolationLevel != System.Transactions.IsolationLevel.Snapshot))
                {
                    goto Label_016B;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
Label_0165:
                reader.Skip();
Label_016B:
                if (reader.IsStartElement())
                {
                    goto Label_0165;
                }
                reader.ReadEndElement();
            }
            catch (XmlException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
            }
            catch (InvalidCoordinationContextException exception2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception2));
            }
        }
 public CreateCoordinationContext(Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
 {
     this.expiration = 0;
     this.expiresPresent = false;
     this.CurrentContext = null;
     this.IssuedToken = null;
     this.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
     this.protocolVersion = protocolVersion;
     this.coordinationXmlDictionaryStrings = CoordinationXmlDictionaryStrings.Version(protocolVersion);
     this.atomicTransactionXmlDictionaryStrings = AtomicTransactionXmlDictionaryStrings.Version(protocolVersion);
     this.atomicTransactionStrings = AtomicTransactionStrings.Version(protocolVersion);
     this.coordinationStrings = CoordinationStrings.Version(protocolVersion);
 }
 public CreateCoordinationContext(Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
 {
     this.expiration      = 0;
     this.expiresPresent  = false;
     this.CurrentContext  = null;
     this.IssuedToken     = null;
     this.IsolationLevel  = System.Transactions.IsolationLevel.Serializable;
     this.protocolVersion = protocolVersion;
     this.coordinationXmlDictionaryStrings      = CoordinationXmlDictionaryStrings.Version(protocolVersion);
     this.atomicTransactionXmlDictionaryStrings = AtomicTransactionXmlDictionaryStrings.Version(protocolVersion);
     this.atomicTransactionStrings = AtomicTransactionStrings.Version(protocolVersion);
     this.coordinationStrings      = CoordinationStrings.Version(protocolVersion);
 }
示例#35
0
 public static sysTx.TransactionScope Make(
     sysTx.TransactionScopeOption txScopOption = sysTx.TransactionScopeOption.Required,
     sysTx.IsolationLevel isoLevel             = sysTx.IsolationLevel.ReadCommitted,
     double timeOutMinutes = 30d, sysTx.DependentTransaction depTx = null)
 {
     return(depTx != null?
            new sysTx.TransactionScope(depTx):
            new sysTx.TransactionScope(txScopOption,
                                       new sysTx.TransactionOptions {
         IsolationLevel = isoLevel,
         Timeout = TimeSpan.FromMinutes(timeOutMinutes)
     }));
 }
 internal SharedTransactedBatchContext(ChannelHandler handler, ChannelDispatcher dispatcher, int maxConcurrentBatches)
 {
     this.handler = handler;
     this.maxBatchSize = dispatcher.MaxTransactedBatchSize;
     this.maxConcurrentBatches = maxConcurrentBatches;
     this.currentBatchSize = dispatcher.MaxTransactedBatchSize;
     this.currentConcurrentBatches = 0;
     this.currentConcurrentDispatches = 0;
     this.successfullCommits = 0;
     this.isBatching = true;
     this.isolationLevel = dispatcher.TransactionIsolationLevel;
     this.txTimeout = TransactionBehavior.NormalizeTimeout(dispatcher.TransactionTimeout);
     this.BatchingStateChanged(this.isBatching);
 }
示例#37
0
		public SQLiteConnection(
			IDbConnection connection,
			IsolationLevel? isolationLevel,
			PersistentJobQueueProviderCollection queueProviders,
			bool ownsConnection)
		{
			if (connection == null) throw new ArgumentNullException("connection");
			if (queueProviders == null) throw new ArgumentNullException("queueProviders");

			_connection = connection;
			_isolationLevel = isolationLevel;
			_queueProviders = queueProviders;

			OwnsConnection = ownsConnection;
		}
        public FatQueueDatabase(
            Func<IDbConnection> createConnection, 
            TransactionScopeOption? transactionType = null, 
            IsolationLevel isolationLevel = IsolationLevel.ReadCommitted,
            ITransaction externalTransaction = null)
        {
            _createConnection = createConnection;
            _externalTransaction = externalTransaction;

            if (!transactionType.HasValue)
                return;

            var transactionTypeValue = transactionType.Value;

            if (Transaction.Current != null && transactionTypeValue == TransactionScopeOption.Required)
                return;

            var transactionOptions = new TransactionOptions
            {
                IsolationLevel = isolationLevel
            };

            _transactionScope = new TransactionScope(transactionTypeValue, transactionOptions);
        }
示例#39
0
		public SQLiteConnection(
			IDbConnection connection,
			IsolationLevel? isolationLevel,
			PersistentJobQueueProviderCollection queueProviders)
			: this(connection, isolationLevel, queueProviders, true)
		{}
 private TransactionScope CreateTransaction(IsolationLevel? isolationLevel)
 {
     return isolationLevel != null
         ? new TransactionScope(TransactionScopeOption.Required,
             new TransactionOptions { IsolationLevel = isolationLevel.Value })
         : new TransactionScope();
 }
示例#41
0
 /// <summary>
 /// Will mark the block as transactional
 /// </summary>
 /// <param name="level"></param>
 public void StartTransaction(System.Transactions.IsolationLevel level,bool seperatedTransaction)
 {
     _transactionLevel = level;
     _seperatedTransaction = seperatedTransaction;
     IsTransactional = true;
 }
 private void ReadFrom(XmlDictionaryReader reader)
 {
     try
     {
         reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.CreateCoordinationContext, this.coordinationXmlDictionaryStrings.Namespace);
         if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.Expires, this.coordinationXmlDictionaryStrings.Namespace))
         {
             int num = reader.ReadElementContentAsInt();
             if (num < 0)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
             }
             this.expiration = (uint) num;
             this.expiresPresent = true;
         }
         if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace))
         {
             this.CurrentContext = CoordinationContext.ReadFrom(reader, this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace, this.protocolVersion);
         }
         reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.CoordinationType, this.coordinationXmlDictionaryStrings.Namespace);
         if (reader.ReadElementContentAsString().Trim() != this.atomicTransactionStrings.Namespace)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
         }
         if (!reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             goto Label_016B;
         }
         this.IsolationLevel = (System.Transactions.IsolationLevel) reader.ReadElementContentAsInt();
         if (((this.IsolationLevel >= System.Transactions.IsolationLevel.Serializable) && (this.IsolationLevel <= System.Transactions.IsolationLevel.Unspecified)) && (this.IsolationLevel != System.Transactions.IsolationLevel.Snapshot))
         {
             goto Label_016B;
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
     Label_0165:
         reader.Skip();
     Label_016B:
         if (reader.IsStartElement())
         {
             goto Label_0165;
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
     }
     catch (InvalidCoordinationContextException exception2)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception2));
     }
 }