示例#1
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);
        }
示例#2
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()
        }
示例#3
0
        static async Task TransactionScopeAsync()
        {
            using (var scope = new TransactionScope())
            {
                Transaction.Current.TransactionCompleted += OnTransactionCompleted;

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

                var s1 = new Student
                {
                    FirstName = "Angela",
                    LastName  = "Nagel",
                    Company   = "Kantine M101"
                };
                var db = new StudentData();
                await db.AddStudentAsync(s1);

                if (!Utilities.AbortTx())
                {
                    scope.Complete();
                }
                else
                {
                    Console.WriteLine("transaction will be aborted");
                }
            } // scope.Dispose()
        }
示例#4
0
        static async Task CommittableTransactionAsync()
        {
            var tx = new CommittableTransaction();

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

            try
            {
                var s1 = new Student
                {
                    FirstName = "Stephanie",
                    LastName  = "Nagel",
                    Company   = "CN innovation"
                };
                var db = new StudentData();
                await db.AddStudentAsync(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);
        }
示例#5
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);
        }
示例#6
0
        static async Task TransactionPromotionAsync()
        {
            var tx = new CommittableTransaction();

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

            try
            {
                var s1 = new Student
                {
                    FirstName = "Matthias",
                    LastName  = "Nagel",
                    Company   = "CN innovation"
                };
                var db = new StudentData();
                await db.AddStudentAsync(s1, tx);

                var s2 = new Student
                {
                    FirstName = "Stephanie",
                    LastName  = "Nagel",
                    Company   = "CN innovation"
                };
                await db.AddStudentAsync(s2, tx);

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

                if (TransactionUtilities.AbortTransaction())
                {
                    throw new ApplicationException("transaction abort");
                }

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

            TransactionUtilities.DisplayTransactionInformation("TX finished",
                                                               tx.TransactionInformation);
        }
示例#7
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);
        }