Inheritance: System.IDisposable, System.Runtime.Serialization.ISerializable
Example #1
0
        public static byte[] GetExportCookie(Transaction transaction, byte[] whereabouts)
        {
            if (null == transaction)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            if (null == whereabouts)
            {
                throw new ArgumentNullException(nameof(whereabouts));
            }

            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(SR.TraceSourceDistributed, "TransactionInterop.GetExportCookie");
            }

            // Copy the whereabouts so that it cannot be modified later.
            var whereaboutsCopy = new byte[whereabouts.Length];
            Buffer.BlockCopy(whereabouts, 0, whereaboutsCopy, 0, whereabouts.Length);

            DistributedTransaction dTx = ConvertToDistributedTransaction(transaction);
            byte[] cookie = dTx.GetExportCookie(whereaboutsCopy);

            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(SR.TraceSourceDistributed, "TransactionInterop.GetExportCookie");
            }

            return cookie;
        }
        /// <summary>
        /// Instantiate an opened connection enlisted to the Transaction
        /// if promotable is false, the Transaction wraps a local 
        /// transaction inside and can never be promoted
        /// </summary>
        /// <param name="dbResourceAllocator"></param>
        /// <param name="transaction"></param>
        /// <param name="wantPromotable"></param>
        internal SharedConnectionInfo(
            DbResourceAllocator dbResourceAllocator,
            Transaction transaction,
            bool wantPromotable,
            ManualResetEvent handle)
        {
            Debug.Assert((transaction != null), "Null Transaction!");

            if (null == handle)
                throw new ArgumentNullException("handle");

            this.handle = handle;

            if (wantPromotable)
            {
                // Enlist a newly opened connection to this regular Transaction
                this.connection = dbResourceAllocator.OpenNewConnection();
                this.connection.EnlistTransaction(transaction);
            }
            else
            {
                // Make this transaction no longer promotable by attaching our 
                // IPromotableSinglePhaseNotification implementation (LocalTranscaction)
                // and track the DbConnection and DbTransaction associated with the LocalTranscaction
                LocalTransaction localTransaction = new LocalTransaction(dbResourceAllocator, handle);
                transaction.EnlistPromotableSinglePhase(localTransaction);
                this.connection = localTransaction.Connection;
                this.localTransaction = localTransaction.Transaction;
            }
        }
 public static Driver GetDriverInTransaction(Transaction transaction)
 {
     lock (driversInUse.SyncRoot)
     {
         return (Driver) driversInUse[transaction.GetHashCode()];
     }
 }
Example #4
0
        //Releases the transaction lock and allows the next pending transaction to quire it.
        public void Unlock()
        {
            Debug.Assert(Locked);

             OwningTransaction = null;

             LinkedListNode<KeyValuePair<Transaction,ManualResetEvent>> node = null;

             lock(this)
             {
            if(m_PendingTransactions.Count > 0)
            {
               node = m_PendingTransactions.First;
               m_PendingTransactions.RemoveFirst();
            }
             }
             if(node != null)
             {
            Transaction transaction = node.Value.Key;
            ManualResetEvent manualEvent = node.Value.Value;
            Lock(transaction);
            lock(manualEvent)//To deal with race condition of the handle closed between the check and the set
            {
               if(manualEvent.SafeWaitHandle.IsClosed == false)
               {
                  manualEvent.Set();
               }
            }
             }
        }
    ///////////////////////////////////////////////////////////////////////////////////////////////

    private /* protected virtual */ void Dispose(bool disposing)
    {
        if (!disposed)
        {
            if (disposing)
            {
                ////////////////////////////////////
                // dispose managed resources here...
                ////////////////////////////////////

                if (_transaction != null)
                {
                    _transaction.Dispose();
                    _transaction = null;
                }

                if (_scope != null)
                {
                    // _scope.Dispose(); // NOTE: Not "owned" by us.
                    _scope = null;
                }
            }

            //////////////////////////////////////
            // release unmanaged resources here...
            //////////////////////////////////////

            disposed = true;
        }
    }
 internal void Commit(Transaction transaction)
 {
     lock (this.mutex)
     {
         this._pendingWorkCollection.Commit(transaction);
     }
 }
 public static void RemoveDriverInTransaction(Transaction transaction)
 {
     lock (driversInUse.SyncRoot)
     {
         driversInUse.Remove(transaction.GetHashCode());
     }
 }
 internal PersistenceDBAccessor(DbResourceAllocator dbResourceAllocator, Transaction transaction, WorkflowCommitWorkBatchService transactionService)
 {
     this.dbResourceAllocator = dbResourceAllocator;
     this.localTransaction = DbResourceAllocator.GetLocalTransaction(transactionService, transaction);
     this.connection = this.dbResourceAllocator.GetEnlistedConnection(transactionService, transaction, out this.needToCloseConnection);
     this.dbRetry = new DbRetry(false);
 }
        public DbConnection UseConnection(IConnectionUser user) {
            if (user == null) {
                throw Error.ArgumentNull("user");
            }
            if (this.connection.State == ConnectionState.Closed) {
                this.connection.Open();
                this.autoClose = true;
                this.AddInfoMessageHandler();
                if (System.Transactions.Transaction.Current != null) {
                    System.Transactions.Transaction.Current.TransactionCompleted += this.OnTransactionCompleted;
                }
            }
            if (this.transaction == null && System.Transactions.Transaction.Current != null &&
                        System.Transactions.Transaction.Current != systemTransaction) {
                this.ClearConnection();
                systemTransaction = System.Transactions.Transaction.Current;
                this.connection.EnlistTransaction(System.Transactions.Transaction.Current);
            }

            if (this.users.Count == this.maxUsers) {
                this.BootUser(this.users[0]);
            }
            this.users.Add(user);
            return this.connection;
        }
Example #10
0
 /// <summary>
 /// Make the transacted changes permanent.
 /// </summary>
 void IEnlistmentNotification.Commit(Enlistment enlistment)
 {
     _value = new StringBuilder(_temporaryValue.ToString());
     _temporaryValue = null;
     _enlistedTransaction = null;
     enlistment.Done();
 }
        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);
        }
        /// <summary>
        /// Construct a new <see cref="AdoPersistenceResourceAccessor" /> with the
        /// specified <see cref="IAdoResourceProvider" />, 
        /// <see cref="IPersistenceNameResolver" /> and <see cref="IAdoValueReader" /> 
        /// All work should be performed in the specified <see cref="Transaction" />.
        /// </summary>
        /// <param name="resourceProvider">
        /// An <see cref="IAdoResourceProvider" /> used to provide resources for
        /// accessing the tracking store.
        /// </param>
        /// <param name="nameResolver">
        /// An <see cref="IPersistenceNameResolver" /> that resolves names
        /// of commands and parameters for the relevant tracking store.
        /// </param>
        /// <param name="valueReader">
        /// An <see cref="IAdoValueReader" /> that reads values from
        /// <see cref="IDbCommand" /> and <see cref="IDataReader" /> implementations.
        /// </param>
        /// <param name="transaction">
        /// An <see cref="Transaction" /> in which to perform the work.
        /// </param>
        public AdoPersistenceResourceAccessor(IAdoResourceProvider resourceProvider,
            IPersistenceNameResolver nameResolver, IAdoValueReader valueReader,
            Transaction transaction)
        {
            if (resourceProvider == null)
                throw new ArgumentNullException("resourceProvider");

            if (nameResolver == null)
                throw new ArgumentNullException("nameResolver");

            if (valueReader == null)
                throw new ArgumentNullException("valueReader");

            this.resourceProvider = resourceProvider;
            this.nameResolver = nameResolver;
            this.valueReader = valueReader;

            if (transaction == null)
            {
                this.isConnectionOwner = true;
                this.dbConnection = resourceProvider.CreateConnection();
                this.dbConnection.Open();
            }
            else
                this.dbConnection = resourceProvider.CreateEnlistedConnection(transaction, out this.isConnectionOwner);
        }
        /// <summary>
        /// Given a provider name locate the necessary 
        /// <see cref="AdoTrackingResourceAccessor" /> in the configuration file.
        /// </summary>
        /// <returns>
        /// An <see cref="AdoTrackingResourceAccessor" />.
        /// </returns>
        public static AdoTrackingResourceAccessor Create(
            IAdoResourceProvider resourceProvider, ITrackingNameResolver nameResolver,
            IAdoValueReader valueReader, Transaction transaction, IStateProvider stateProvider)
        {
            // locate any mappings for the specified provider
            ProviderNameTypeMapping mapping = TrackingAdoProviderSettings.Get()
                    .ResourceAccessors.FindByProviderName(resourceProvider.ProviderName);

            AdoTrackingResourceAccessor resourceAccessor;
            if (mapping != null)
            {
                resourceAccessor =
                    TypeUtilities.CreateInstance<AdoTrackingResourceAccessor>(
                        mapping.Type, new object[]
                            {
                                resourceProvider, nameResolver, valueReader,
                                transaction, stateProvider
                            });
            }
            else
            {
                return new AdoTrackingResourceAccessor(
                    resourceProvider, nameResolver, valueReader,
                    transaction, stateProvider);
            }

            return resourceAccessor;
        }
        private void Enlist(Transaction transaction)
        {
            if (transaction == null)
            {
                // no enlistment as we are not in a TransactionScope
                return;
            }

            // try to enlist as a PSPE
            if (!transaction.EnlistPromotableSinglePhase(this))
            {
                // our enlistmente fail so we need to enlist ourselves as durable.

                // we create a transaction directly instead of using BeginTransaction that GraphClient
                // doesn't store it in its stack of scopes.
                 var localTransaction = new Neo4jTransaction(_client);
                localTransaction.ForceKeepAlive();
                _transactionId = localTransaction.Id;
                var resourceManager = GetResourceManager();
                var propagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
                var transactionExecutionEnvironment = new TransactionExecutionEnvironment(_client.ExecutionConfiguration)
                {
                    TransactionId =  localTransaction.Id,
                    TransactionBaseEndpoint = _client.TransactionEndpoint
                };
                resourceManager.Enlist(transactionExecutionEnvironment, propagationToken);
                localTransaction.Cancel();
            }

            _enlistedInTransactions.Add(transaction);
        }
 internal void AddReference(ref MessageRpc rpc, Transaction tx, bool updateCallCount)
 {
     lock (this.mutex)
     {
         if (this.pending == null)
         {
             this.pending = new Dictionary<Transaction, RemoveReferenceRM>();
         }
         if (tx != null)
         {
             RemoveReferenceRM erm;
             if (this.pending == null)
             {
                 this.pending = new Dictionary<Transaction, RemoveReferenceRM>();
             }
             if (!this.pending.TryGetValue(tx, out erm))
             {
                 RemoveReferenceRM erm2 = new RemoveReferenceRM(this.instanceContext, tx, rpc.Operation.Name) {
                     CallCount = 1L
                 };
                 this.pending.Add(tx, erm2);
             }
             else if (updateCallCount)
             {
                 erm.CallCount += 1L;
             }
         }
     }
 }
 public TryLoadRunnableWorkflowAsyncResult(InstancePersistenceContext context, InstancePersistenceCommand command, SqlWorkflowInstanceStore store, SqlWorkflowInstanceStoreLock storeLock, Transaction currentTransaction, TimeSpan timeout, AsyncCallback callback, object state) : base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
 {
     if (base.Store.WorkflowHostType == Guid.Empty)
     {
         throw FxTrace.Exception.AsError(new InstancePersistenceCommandException(command.Name, System.Activities.DurableInstancing.SR.TryLoadRequiresWorkflowType, null));
     }
 }
Example #17
0
        public DeveelDbEnlistment(DeveelDbConnection connection, Transaction scope)
        {
            transaction = connection.BeginTransaction();

            Scope = scope;
            Scope.EnlistVolatile(this, EnlistmentOptions.None);
        }
 public void TransmitSucceeded(Transaction sendTransaction)
 {
     if (sendTransaction == null)
     {
         this.sent = true;
     }
 }
Example #19
0
        internal static SafeTransactionHandle Create(Transaction managedTransaction)
        {
            if (managedTransaction == null)
            {
                throw new InvalidOperationException(RegistryProviderStrings.InvalidOperation_NeedTransaction);
            }

            // MSDTC is not available on WinPE machine.
            // CommitableTransaction will use DTC APIs under the covers to get KTM transaction manager interface. 
            // KTM is kernel Transaction Manager to handle file, registry etc and MSDTC provides an integration support 
            // with KTM to handle transaction across kernel resources and MSDTC resources like SQL, MSMQ etc. 
            // We need KTMRM service as well. WinPE doesn’t have these services installed 
            if (Utils.IsWinPEHost() || PsUtils.IsRunningOnProcessorArchitectureARM())
            {
                throw new NotSupportedException(RegistryProviderStrings.NotSupported_KernelTransactions);
            }

            IDtcTransaction dtcTransaction = TransactionInterop.GetDtcTransaction(managedTransaction);
            IKernelTransaction ktmInterface = dtcTransaction as IKernelTransaction;
            if (null == ktmInterface)
            {
                throw new NotSupportedException(RegistryProviderStrings.NotSupported_KernelTransactions);
            }

            IntPtr ktmTxHandle;
            int hr = ktmInterface.GetHandle(out ktmTxHandle);
            HandleError(hr);

            return new SafeTransactionHandle(ktmTxHandle);
        }
 public void Commit(Guid guid)
 {
     try
     {
         if (this.committableTx == null)
         {
             Marshal.ThrowExceptionForHR(-2147418113);
         }
         else if (this.owned)
         {
             if (guid == this.ownerGuid)
             {
                 this.committableTx.Commit();
             }
             else
             {
                 Marshal.ThrowExceptionForHR(-2147418113);
             }
         }
         else
         {
             this.committableTx.Commit();
         }
     }
     catch (TransactionException exception)
     {
         this.MapTxExceptionToHR(exception, true);
     }
     finally
     {
         this.committableTx.Dispose();
         this.committableTx = null;
         this.systemTx = null;
     }
 }
 public static IDtcTransaction GetDtcTransaction(Transaction transaction)
 {
     if (!TransactionManager._platformValidated)
     {
         TransactionManager.ValidatePlatform();
     }
     if (null == transaction)
     {
         throw new ArgumentNullException("transaction");
     }
     if (DiagnosticTrace.Verbose)
     {
         MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "TransactionInterop.GetDtcTransaction");
     }
     IDtcTransaction transactionNative = null;
     OletxTransaction transaction2 = ConvertToOletxTransaction(transaction);
     try
     {
         transaction2.realOletxTransaction.TransactionShim.GetITransactionNative(out transactionNative);
     }
     catch (COMException exception)
     {
         OletxTransactionManager.ProxyException(exception);
         throw;
     }
     if (DiagnosticTrace.Verbose)
     {
         MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceOletx"), "TransactionInterop.GetDtcTransaction");
     }
     return transactionNative;
 }
Example #22
0
        public static byte[] GetExportCookie(Transaction transaction, byte[] whereabouts)
        {
            if (null == transaction)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            if (null == whereabouts)
            {
                throw new ArgumentNullException(nameof(whereabouts));
            }

            TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;
            if (etwLog.IsEnabled())
            {
                etwLog.MethodEnter(TraceSourceType.TraceSourceDistributed, "TransactionInterop.GetExportCookie");
            }

            // Copy the whereabouts so that it cannot be modified later.
            var whereaboutsCopy = new byte[whereabouts.Length];
            Buffer.BlockCopy(whereabouts, 0, whereaboutsCopy, 0, whereabouts.Length);

            DistributedTransaction dTx = ConvertToDistributedTransaction(transaction);
            byte[] cookie = dTx.GetExportCookie(whereaboutsCopy);

            if (etwLog.IsEnabled())
            {
                etwLog.MethodExit(TraceSourceType.TraceSourceDistributed, "TransactionInterop.GetExportCookie");
            }

            return cookie;
        }
    internal SQLiteEnlistment(SQLiteConnection cnn, Transaction scope)
    {
      _transaction = cnn.BeginTransaction();
      _scope = scope;

      _scope.EnlistVolatile(this, System.Transactions.EnlistmentOptions.None);
    }
        internal PersistenceContextEnlistment(PersistenceContext context, Transaction transaction)
        {
            this.transaction = transaction;

            this.enlistedContexts = new List<PersistenceContext>();
            this.enlistedContexts.Add(context);
        }
 /// <summary>
 /// Initializes a new instance of the TransactionScope class 
 /// with the specified timeout value, and sets the specified 
 /// transaction as the ambient transaction, so that transactional 
 /// work done inside the scope uses this transDoFactory. 
 /// </summary>
 /// <param name="transactionToUse">Represents a transaction.</param>
 /// <param name="scopeTimeout">The TimeSpan after which the transaction scope times out and aborts the transaction.</param>
 public TransactionDecorator(Transaction transactionToUse, TimeSpan scopeTimeout)
 {
     _transactionToUse = transactionToUse;
     _scopeTimeout = scopeTimeout;
     if (_dataProvider != "System.Data.OleDb")
         _scope = new TransactionScope(_transactionToUse, _scopeTimeout);
 }
Example #26
0
 void IEnlistmentNotification.Commit(Enlistment enlistment)
 {
     this.m_Value = new StringBuilder(this.m_TemporaryValue.ToString());
     this.m_TemporaryValue = null;
     this.enlistedTransaction = null;
     enlistment.Done();
 }
Example #27
0
 public MySqlTransactionScope(MySqlConnection con, Transaction trans,
     MySqlTransaction simpleTransaction)
 {
   connection = con;
   baseTransaction = trans;
   this.simpleTransaction = simpleTransaction;
 }
Example #28
0
        /// <summary>
        /// Called just after a transaction is created for this workbatch.
        /// </summary>
        /// <param name="transaction">
        /// The transaction that was created.
        /// </param>
        protected override void TransactionCreated(Transaction transaction)
        {
            TraceHelper.Trace();

            if (!connectionsByTransaction.ContainsKey(transaction))
                connectionsByTransaction.Add(transaction, new Dictionary<String, DbConnection>());
        }
 public SaveWorkflowAsyncResult(InstancePersistenceContext context, InstancePersistenceCommand command, SqlWorkflowInstanceStore store, SqlWorkflowInstanceStoreLock storeLock, Transaction currentTransaction, TimeSpan timeout, AsyncCallback callback, object state) : base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
 {
     if (((SaveWorkflowCommand) command).InstanceKeyMetadataChanges.Count > 0)
     {
         throw FxTrace.Exception.AsError(new InstancePersistenceCommandException(System.Activities.DurableInstancing.SR.InstanceKeyMetadataChangesNotSupported));
     }
 }
        public FbEnlistmentNotification(FbConnectionInternal connection, Transaction systemTransaction)
        {            
            this.connection         = connection;
            this.transaction        = connection.BeginTransaction(systemTransaction.IsolationLevel);
            this.systemTransaction  = systemTransaction;

            this.systemTransaction.EnlistVolatile(this, System.Transactions.EnlistmentOptions.None);
        }