Example #1
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
        }
Example #2
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;
        }