Exemple #1
0
        /// <summary>
        /// Start a transaction.
        /// </summary>
        /// <param name="timeout">
        /// Time before transaction timeouts if has not already finished.
        /// Unit is seconds.
        /// </param>
        public void StartTransaction(Int32 timeout)
        {
            Boolean abortTransaction = false;
            WebServiceDataServer transactionDatabase = null;
            Thread transactionThread;

            _transactionTimeout = timeout;
            lock (_transactionInformation)
            {
                if (IsInTransaction())
                {
                    // StartTransaction should only be called once
                    // to start the transaction.
                    abortTransaction = true;

                    // Undo transaction.
                    if (_transactionInformation.ContainsKey(TransactionKey))
                    {
                        transactionDatabase = (WebServiceDataServer)(_transactionInformation[TransactionKey]);
                        _transactionInformation.Remove(TransactionKey);
                    }
                    if (_transactionInformation.ContainsKey(TransactionIdKey))
                    {
                        _transactionInformation.Remove(TransactionIdKey);
                    }
                }
                else
                {
                    // Start transaction.
                    transactionDatabase = WebServiceData.DatabaseManager.GetDatabase(this);
                    transactionDatabase.CommandTimeout = _transactionTimeout;
                    transactionDatabase.BeginTransaction();
                    _transactionInformation.Add(TransactionKey, transactionDatabase);
                    _transactionInformation.Add(TransactionIdKey, RequestId);
                }
            }

            if (abortTransaction)
            {
                if (transactionDatabase.IsNotNull())
                {
                    lock (transactionDatabase)
                    {
                        transactionDatabase.RollbackTransaction();
                        transactionDatabase.Disconnect();
                    }
                }
                throw new ApplicationException("Transaction has already been started!");
            }

            // Start thread that control time out of transaction.
            transactionThread          = new Thread(CheckTransactionTimeOut);
            transactionThread.Priority = ThreadPriority.Highest;
            transactionThread.Start();
        }
 private WebServiceDataServer GetDatabase(Boolean refresh)
 {
     if (_database.IsNull() || refresh)
     {
         if (_database.IsNotNull())
         {
             _database.Dispose();
         }
         _database = new TaxonServer();
         _database.BeginTransaction();
     }
     return(_database);
 }