Exemplo n.º 1
0
        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 Neo4jRestTransaction(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);
        }
Exemplo n.º 2
0
        public byte[] Promote()
        {
            // we have been promoted to MSTDC, so we have to clean the local resources
            if (transaction == null)
            {
                transaction = new Neo4jRestTransaction(client);
            }

            // do a keep alive in case the promotion takes too long or in case we don't have an ID
            transaction.ForceKeepAlive();
            transactionId = transaction.Id;
            transaction.Cancel();
            transaction = null;

            if (transactionId == 0)
            {
                throw new InvalidOperationException("For some reason we don't have a TransactionContext ID");
            }

            var resourceManager = GetResourceManager();

            return(resourceManager.Promote(new TransactionExecutionEnvironment(client.ExecutionConfiguration)
            {
                TransactionId = transactionId,
                TransactionBaseEndpoint = client.TransactionEndpoint
            }));
        }
Exemplo n.º 3
0
        public byte[] Promote()
        {
            // we have been promoted to MSTDC, so we have to clean the local resources
            if (transaction == null)
            {
                transaction = new Neo4jRestTransaction(client);
            }

            // do a keep alive in case the promotion takes too long or in case we don't have an ID
            transaction.ForceKeepAlive();
            transactionId = transaction.Id;
            transaction.Cancel();
            transaction = null;

            if (transactionId == 0)
            {
                throw new InvalidOperationException("For some reason we don't have a TransactionContext ID");
            }

            // BUG: .NET 4.7.1 introduced a bug where the current transaction wouldn't get restored
            // after a call which crosses AppDomain boundaries. We have to restore it ourselves.
            // Ref https://github.com/Microsoft/dotnet-framework-early-access/issues/7
            var tx = Transaction.Current;
            var resourceManager = GetResourceManager();
            var res             = resourceManager.Promote(new TransactionExecutionEnvironment(client.ExecutionConfiguration)
            {
                TransactionId           = transactionId,
                TransactionBaseEndpoint = client.TransactionEndpoint
            });

            // Only restore if the bug exists to avoid any potentially side-effects
            // of setting the transaction
            if (Transaction.Current == null)
            {
                Transaction.Current = tx;
            }
            return(res);
        }