示例#1
0
 /// <summary>
 /// Notifies an enlisted object that a transaction is being prepared for commitment.
 /// </summary>
 /// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     onTxComplete();
     session.StoreRecoveryInformation(session.ResourceManagerId, PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction),
                                      preparingEnlistment.RecoveryInformation());
     preparingEnlistment.Prepared();
 }
示例#2
0
 /// <summary>
 /// Notifies an enlisted object that a transaction is being prepared for commitment.
 /// </summary>
 /// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     onTxComplete();
     try
     {
         using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
         {
             var name = TransactionRecoveryInformationFileName;
             using (var file = machineStoreForApplication.CreateFile(name + ".temp"))
                 using (var writer = new BinaryWriter(file))
                 {
                     writer.Write(session.ResourceManagerId.ToString());
                     writer.Write(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction).ToString());
                     writer.Write(session.DatabaseName ?? "");
                     writer.Write(preparingEnlistment.RecoveryInformation());
                     file.Flush(true);
                 }
             machineStoreForApplication.MoveFile(name + ".temp", name);
         }
     }
     catch (Exception e)
     {
         logger.ErrorException("Could not prepare distributed transaction", e);
         preparingEnlistment.ForceRollback(e);
         return;
     }
     preparingEnlistment.Prepared();
 }
示例#3
0
        private void TryEnlistInAmbientTransaction()
        {
#if !SILVERLIGHT
            if (documentStore.EnlistInDistributedTransactions == false)
            {
                return;
            }

            if (hasEnlisted || Transaction.Current == null)
            {
                return;
            }

            HashSet <string> registered;
            var localIdentifier = Transaction.Current.TransactionInformation.LocalIdentifier;
            if (RegisteredStoresInTransaction.TryGetValue(localIdentifier, out registered) == false)
            {
                RegisteredStoresInTransaction[localIdentifier] =
                    registered = new HashSet <string>();
            }

            if (registered.Add(StoreIdentifier))
            {
                var transactionalSession = (ITransactionalDocumentSession)this;
                if (documentStore.DatabaseCommands.SupportsPromotableTransactions == false)
                {
                    Transaction.Current.EnlistDurable(
                        ResourceManagerId,
                        new RavenClientEnlistment(transactionalSession, () => RegisteredStoresInTransaction.Remove(localIdentifier)),
                        EnlistmentOptions.None);
                }
                else
                {
                    var promotableSinglePhaseNotification = new PromotableRavenClientEnlistment(transactionalSession,
                                                                                                () =>
                                                                                                RegisteredStoresInTransaction.
                                                                                                Remove(localIdentifier));
                    var registeredSinglePhaseNotification =
                        Transaction.Current.EnlistPromotableSinglePhase(promotableSinglePhaseNotification);

                    if (registeredSinglePhaseNotification == false)
                    {
                        Transaction.Current.EnlistDurable(
                            ResourceManagerId,
                            new RavenClientEnlistment(transactionalSession, () => RegisteredStoresInTransaction.Remove(localIdentifier)),
                            EnlistmentOptions.None);
                    }
                }
            }
            hasEnlisted = true;
#endif
        }
示例#4
0
 /// <summary>
 /// Notifies an enlisted object that the status of a transaction is in doubt.
 /// </summary>
 /// <param name="enlistment">An <see cref="T:System.Transactions.Enlistment"/> object used to send a response to the transaction manager.</param>
 public void InDoubt(Enlistment enlistment)
 {
     onTxComplete();
     try
     {
         session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
     }
     catch (Exception e)
     {
         logger.ErrorException("Could not mark distriubted transaction as in doubt", e);
     }
     enlistment.Done();             // what else can we do?
 }
示例#5
0
 /// <summary>
 /// Notifies an enlisted object that a transaction is being rolled back (aborted).
 /// </summary>
 /// <param name="enlistment">A <see cref="T:System.Transactions.Enlistment"/> object used to send a response to the transaction manager.</param>
 public void Rollback(Enlistment enlistment)
 {
     onTxComplete();
     try
     {
         session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
     }
     catch (Exception e)
     {
         logger.ErrorException("Could not rollback distributed transaction", e);
     }
     enlistment.Done();             // will happen anyway, tx will be rolled back after timeout
 }
示例#6
0
 /// <summary>
 /// Notifies an enlisted object that a transaction is being committed.
 /// </summary>
 /// <param name="enlistment">An <see cref="T:System.Transactions.Enlistment"/> object used to send a response to the transaction manager.</param>
 public void Commit(Enlistment enlistment)
 {
     onTxComplete();
     try
     {
         session.Commit(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
     }
     catch (Exception e)
     {
         logger.ErrorException("Could not commit distributed transaction", e);
         return;                 // nothing to do, DTC will mark tx as hang
     }
     enlistment.Done();
 }
示例#7
0
 /// <summary>
 /// Rollbacks the specified single phase enlistment.
 /// </summary>
 /// <param name="singlePhaseEnlistment">The single phase enlistment.</param>
 public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     onTxComplete();
     try
     {
         session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
     }
     catch (Exception e)
     {
         logger.ErrorException("Could not rollback distributed transaction", e);
         singlePhaseEnlistment.InDoubt(e);
         return;
     }
     singlePhaseEnlistment.Aborted();
 }
示例#8
0
 /// <summary>
 /// Notifies an enlisted object that a transaction is being prepared for commitment.
 /// </summary>
 /// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     onTxComplete();
     try
     {
         session.StoreRecoveryInformation(session.ResourceManagerId, PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction),
                                          preparingEnlistment.RecoveryInformation());
     }
     catch (Exception e)
     {
         logger.ErrorException("Could not prepare distributed transaction", e);
         preparingEnlistment.ForceRollback(e);
         return;
     }
     preparingEnlistment.Prepared();
 }
示例#9
0
        /// <summary>
        /// Notifies an enlisted object that a transaction is being rolled back (aborted).
        /// </summary>
        /// <param name="enlistment">A <see cref="T:System.Transactions.Enlistment"/> object used to send a response to the transaction manager.</param>
        public void Rollback(Enlistment enlistment)
        {
            onTxComplete();
            try
            {
                session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));

                using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
                {
                    machineStoreForApplication.DeleteFile(TransactionRecoveryInformationFileName);
                }
            }
            catch (Exception e)
            {
                logger.ErrorException("Could not rollback distributed transaction", e);
            }
            enlistment.Done();             // will happen anyway, tx will be rolled back after timeout
        }
示例#10
0
        /// <summary>
        /// Notifies an enlisted object that the status of a transaction is in doubt.
        /// </summary>
        /// <param name="enlistment">An <see cref="T:System.Transactions.Enlistment"/> object used to send a response to the transaction manager.</param>
        public void InDoubt(Enlistment enlistment)
        {
            onTxComplete();
            try
            {
                session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));

                using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
                {
                    machineStoreForApplication.DeleteFile(TransactionRecoveryInformationFileName);
                }
            }
            catch (Exception e)
            {
                logger.ErrorException("Could not mark distriubted transaction as in doubt", e);
            }
            enlistment.Done();             // what else can we do?
        }
示例#11
0
        /// <summary>
        /// Notifies an enlisted object that a transaction is being committed.
        /// </summary>
        /// <param name="enlistment">An <see cref="T:System.Transactions.Enlistment"/> object used to send a response to the transaction manager.</param>
        public void Commit(Enlistment enlistment)
        {
            onTxComplete();
            try
            {
                session.Commit(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));

                using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
                {
                    machineStoreForApplication.DeleteFile(TransactionRecoveryInformationFileName);
                }
            }
            catch (Exception e)
            {
                logger.ErrorException("Could not commit distributed transaction", e);
                return;                 // nothing to do, DTC will mark tx as hang
            }
            enlistment.Done();
        }
示例#12
0
        /// <summary>
        /// Rollbacks the specified single phase enlistment.
        /// </summary>
        /// <param name="singlePhaseEnlistment">The single phase enlistment.</param>
        public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
        {
            onTxComplete();
            try
            {
                session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));

                using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
                {
                    machineStoreForApplication.DeleteFile(TransactionRecoveryInformationFileName);
                }
            }
            catch (Exception e)
            {
                logger.ErrorException("Could not rollback distributed transaction", e);
                singlePhaseEnlistment.InDoubt(e);
                return;
            }
            singlePhaseEnlistment.Aborted();
        }
示例#13
0
 /// <summary>
 /// Rollbacks the specified single phase enlistment.
 /// </summary>
 /// <param name="singlePhaseEnlistment">The single phase enlistment.</param>
 public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     onTxComplete();
     session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
     singlePhaseEnlistment.Aborted();
 }
示例#14
0
 /// <summary>
 /// Notifies an enlisted object that the status of a transaction is in doubt.
 /// </summary>
 /// <param name="enlistment">An <see cref="T:System.Transactions.Enlistment"/> object used to send a response to the transaction manager.</param>
 public void InDoubt(Enlistment enlistment)
 {
     onTxComplete();
     session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
     enlistment.Done();
 }
示例#15
0
        protected virtual void TryEnlistInAmbientTransaction()
        {
            if (hasEnlisted || Transaction.Current == null)
            {
                return;
            }

            HashSet <string> registered;
            var localIdentifier = Transaction.Current.TransactionInformation.LocalIdentifier;

            if (RegisteredStoresInTransaction.TryGetValue(localIdentifier, out registered) == false)
            {
                RegisteredStoresInTransaction[localIdentifier] =
                    registered = new HashSet <string>();
            }

            if (registered.Add(StoreIdentifier))
            {
                var transactionalSession = (ITransactionalDocumentSession)this;
                if (documentStore.DatabaseCommands.SupportsPromotableTransactions == false)
                {
                    Transaction.Current.EnlistDurable(
                        ResourceManagerId,
                        new RavenClientEnlistment(transactionalSession, () =>
                    {
                        RegisteredStoresInTransaction.Remove(localIdentifier);
                        if (documentStore.WasDisposed)
                        {
                            throw new ObjectDisposedException("RavenDB Session");
                        }
                    }),
                        EnlistmentOptions.None);
                }
                else
                {
                    var promotableSinglePhaseNotification = new PromotableRavenClientEnlistment(transactionalSession,
                                                                                                () =>
                    {
                        RegisteredStoresInTransaction.Remove(localIdentifier);
                        if (documentStore.WasDisposed)
                        {
                            throw new ObjectDisposedException("RavenDB Session");
                        }
                    });
                    var registeredSinglePhaseNotification =
                        Transaction.Current.EnlistPromotableSinglePhase(promotableSinglePhaseNotification);

                    if (registeredSinglePhaseNotification == false)
                    {
                        Transaction.Current.EnlistDurable(
                            ResourceManagerId,
                            new RavenClientEnlistment(transactionalSession, () =>
                        {
                            RegisteredStoresInTransaction.Remove(localIdentifier);
                            if (documentStore.WasDisposed)
                            {
                                throw new ObjectDisposedException("RavenDB Session");
                            }
                        }),
                            EnlistmentOptions.None);
                    }
                }
            }
            hasEnlisted = true;
        }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     session.StoreRecoveryInformation(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction), preparingEnlistment.RecoveryInformation());
     preparingEnlistment.Prepared();
 }
 public void Rollback(Enlistment enlistment)
 {
     session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
     enlistment.Done();
 }