예제 #1
0
        static void TransactionScope()
        {
            using (var scope = new TransactionScope())
            {
                Transaction.Current.TransactionCompleted +=
                    OnTransactionCompleted;

                Utilities.DisplayTransactionInformation("Ambient TX created",
                                                        Transaction.Current.TransactionInformation);

                var s1 = new Student
                {
                    FirstName = "Ingo",
                    LastName  = "Rammer",
                    Company   = "thinktecture"
                };
                var db = new StudentData();
                db.AddStudent(s1);

                if (!Utilities.AbortTx())
                {
                    scope.Complete();
                }
                else
                {
                    Console.WriteLine("transaction will be aborted");
                }
            } // scope.Dispose()
        }
예제 #2
0
        static void CommittableTransaction()
        {
            var tx = new CommittableTransaction();

            Utilities.DisplayTransactionInformation("TX created",
                                                    tx.TransactionInformation);

            try
            {
                var s1 = new Student
                {
                    FirstName = "Neno",
                    LastName  = "Loye",
                    Company   = "thinktecture"
                };
                var db = new StudentData();
                db.AddStudent(s1, tx);

                if (Utilities.AbortTx())
                {
                    throw new ApplicationException("transaction abort");
                }

                tx.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                tx.Rollback();
            }

            Utilities.DisplayTransactionInformation("TX completed",
                                                    tx.TransactionInformation);
        }
예제 #3
0
        static void TransactionPromotion()
        {
            var tx = new CommittableTransaction();

            Utilities.DisplayTransactionInformation("TX created",
                                                    tx.TransactionInformation);

            try
            {
                var s1 = new Student
                {
                    FirstName = "Jörg",
                    LastName  = "Neumann",
                    Company   = "thinktecture"
                };
                var db = new StudentData();
                db.AddStudent(s1, tx);

                Student s2 = new Student
                {
                    FirstName = "Richard",
                    LastName  = "Blewett",
                    Company   = "thintkecture"
                };
                db.AddStudent(s2, tx);

                Utilities.DisplayTransactionInformation("2nd connection enlisted",
                                                        tx.TransactionInformation);

                if (Utilities.AbortTx())
                {
                    throw new ApplicationException("transaction abort");
                }

                tx.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                tx.Rollback();
            }

            Utilities.DisplayTransactionInformation("TX finished",
                                                    tx.TransactionInformation);
        }
예제 #4
0
파일: Program.cs 프로젝트: zilo312/aa
        static void Main()
        {
            CommittableTransaction tx = new CommittableTransaction();

            Utilities.DisplayTransactionInformation("TX created", tx.TransactionInformation);

            try
            {
                Student s1 = new Student();
                s1.FirstName = "Neno";
                s1.LastName  = "Loye";
                s1.Company   = "thinktecture";
                StudentData db = new StudentData();
                db.AddStudent(s1, tx);


                Student s2 = new Student();
                s2.FirstName = "Dominick";
                s2.LastName  = "Baier";
                s2.Company   = "thinktecture";
                db.AddStudent(s2, tx);

                Utilities.DisplayTransactionInformation("2nd connection enlisted", tx.TransactionInformation);



                if (Utilities.AbortTx())
                {
                    throw new ApplicationException("transaction abort");
                }

                tx.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                tx.Rollback();
            }

            Utilities.DisplayTransactionInformation("TX completed", tx.TransactionInformation);
        }