/// <summary>
		/// Gets the local or distributed transaction id.
		/// </summary>
		/// <param name="transactionInformation">The transaction information.</param>
		/// <returns></returns>
		public static Guid GetLocalOrDistributedTransactionId(TransactionInformation transactionInformation)
		{
			if (transactionInformation.DistributedIdentifier != Guid.Empty)
				return transactionInformation.DistributedIdentifier;
			var first = transactionInformation.LocalIdentifier.Split(':').First();
			return new Guid(first);
		}
示例#2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="RavenClientEnlistment"/> class.
		/// </summary>
		public RavenClientEnlistment(ITransactionalDocumentSession session, Action onTxComplete)
		{
			transaction = Transaction.Current.TransactionInformation;
			this.session = session;
			this.onTxComplete = onTxComplete;
			TransactionRecoveryInformationFileName = Guid.NewGuid() + ".recovery-information";
		}
示例#3
0
        public static void Main()
        {
            // Picks up configuration from the config file.
            BehaviorServiceClient wcfClient = new BehaviorServiceClient("NetTcpBinding_IBehaviorService");

            // Create a transaction to flow
            TransactionOptions transactionOptions = new TransactionOptions();

            transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted;
            using (TransactionScope tx = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOptions))
            {
                try
                {
                    // Making calls.
                    Console.Write("Enter to send some work: ");
                    Console.ReadLine();
                    Console.WriteLine("The service responded: " + wcfClient.TxWork("Hello from the client."));
                    // Write the tx information.
                    System.Transactions.TransactionInformation info = System.Transactions.Transaction.Current.TransactionInformation;
                    Console.WriteLine("The distributed tx ID: {0}.", info.DistributedIdentifier);
                    Console.WriteLine("The tx status: {0}.", info.Status);
                    Console.WriteLine("Committing transaction");
                    tx.Complete();
                    Console.WriteLine("Done!");
                    Console.Read();
                }
                catch (TimeoutException)
                {
                    Console.WriteLine("The call failed to complete within the timeout period.");
                }
                catch (TransactionException txException)
                {
                    if (txException.InnerException is TimeoutException)
                    {
                        Console.WriteLine("The transaction scope timeout period was exceeded before it was able to commit.");
                    }
                    else
                    {
                        Console.WriteLine("A transaction problem has occurred: {0}", txException.Message);
                    }
                }
                // Note: Catch sub classes of CommunicationException, such as
                // UnknownFaultException or FaultException<DetailType>, prior
                // to catching CommunicationException.
                catch (FaultException unknown)
                {
                    Console.WriteLine("Unknown fault exception.");
                    Console.WriteLine(unknown.Message);
                    Console.WriteLine(unknown.StackTrace);
                    wcfClient.Abort();
                }
                catch (CommunicationException commProblem)
                {
                    Console.WriteLine("Something went wrong during communication: {0}", commProblem.Message);
                    Console.Read();
                    wcfClient.Abort();
                }
            }
        }
示例#4
0
		internal Transaction (Transaction other)
		{
			level = other.level;
			info = other.info;
			dependents = other.dependents;
			volatiles = other.Volatiles;
			durables = other.Durables;
		}
示例#5
0
 internal Transaction(Transaction other)
 {
     this.level = other.level;
     this.info = other.info;
     this.dependents = other.dependents;
     this.volatiles = other.Volatiles;
     this.durables = other.Durables;
     this.pspe = other.Pspe;
 }
示例#6
0
		/// <summary>
		/// Initializes a new instance of the <see cref="RavenClientEnlistment"/> class.
		/// </summary>
		public RavenClientEnlistment(DocumentStoreBase documentStore,ITransactionalDocumentSession session, Action onTxComplete)
		{
			transaction = Transaction.Current.TransactionInformation;
			this.documentStore = documentStore;
			this.session = session;
			this.onTxComplete = onTxComplete;
			TransactionRecoveryInformationFileName = Guid.NewGuid() + ".recovery-information";

			ctx = documentStore.TransactionRecoveryStorage.Create();
		}
		/// <summary>
		/// Gets the local or distributed transaction id.
		/// </summary>
		/// <param name="transactionInformation">The transaction information.</param>
		/// <returns></returns>
		public static Guid GetLocalOrDistributedTransactionId(TransactionInformation transactionInformation)
		{
			if (transactionInformation.DistributedIdentifier != Guid.Empty)
				return transactionInformation.DistributedIdentifier;
			string[] parts = transactionInformation.LocalIdentifier.Split(':');
			if(parts.Length != 2)
				throw new InvalidOperationException("Could not parse TransactionInformation.LocalIdentifier: " + transactionInformation.LocalIdentifier);
			
			var localOrDistributedTransactionId = new Guid(parts[0]);
			var num = BitConverter.GetBytes(int.Parse(parts[1]));
			byte[] txId = localOrDistributedTransactionId.ToByteArray();
			for (int i = 0; i < num.Length; i++)
			{
				txId[txId.Length - 1 - i] ^= num[i];
			}
			var transactionId = new Guid(txId);
			return transactionId;
		}
示例#8
0
		internal Transaction ()
		{
			info = new TransactionInformation ();
			level = IsolationLevel.Serializable;
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="PromotableRavenClientEnlistment"/> class.
		/// </summary>
		public PromotableRavenClientEnlistment(ITransactionalDocumentSession session, Action onTxComplete)
		{
			transaction = Transaction.Current.TransactionInformation;
			this.session = session;
			this.onTxComplete = onTxComplete;
		}
		internal Transaction (Transaction other)
		{
			level = other.level;
			info = other.info;
			dependents = other.dependents;
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="PromotableRavenClientEnlistment"/> class.
		/// </summary>
		/// <param name="session">The session.</param>
		public PromotableRavenClientEnlistment(ITransactionalDocumentSession session)
		{
			transaction = Transaction.Current.TransactionInformation;
			this.session = session;
		}
示例#12
0
文件: Transaction.cs 项目: xllj/mono
 internal Transaction()
 {
     info  = new TransactionInformation();
     level = IsolationLevel.Serializable;
 }