コード例 #1
0
        private static void Main(string[] args)
        {
            Database.SetInitializer(new SagaDatabaseInitializer());
            var sessionFactory = new DbContextSessionFactory();
            var persister = new DbSagaPersister(sessionFactory);
            var saga = new SimpleSagaData
                           {
                               Id = Guid.NewGuid(),
                               BusinessId = 1
                           };
            persister.Save(saga);

            var action = new Action(() =>
                                        {
                                            while (true)
                                            {
                                                try
                                                {
                                                    persister.Update(saga);
                                                }
                                                catch (DbUpdateConcurrencyException exc)
                                                {
                                                    Console.WriteLine("Optimistic concurrency check failed.");
                                                }
                                            }
                                        });

            var task1 = new Task(action);
            var task2 = new Task(action);
            task1.Start();
            task2.Start();

            Console.WriteLine("Processing...");
            Console.ReadLine();
        }
コード例 #2
0
        private static void Main(string[] args)
        {
            Database.SetInitializer(new SagaDatabaseInitializer());
            var sessionFactory = new DbContextSessionFactory();
            var persister      = new DbSagaPersister(sessionFactory);
            var saga           = new SimpleSagaData
            {
                Id         = Guid.NewGuid(),
                BusinessId = 1
            };

            persister.Save(saga);

            var action = new Action(() =>
            {
                while (true)
                {
                    try
                    {
                        persister.Update(saga);
                    }
                    catch (DbUpdateConcurrencyException exc)
                    {
                        Console.WriteLine("Optimistic concurrency check failed.");
                    }
                }
            });

            var task1 = new Task(action);
            var task2 = new Task(action);

            task1.Start();
            task2.Start();

            Console.WriteLine("Processing...");
            Console.ReadLine();
        }
コード例 #3
0
        public void CanSaveSaga()
        {
            uow.Begin();
            persister.Save(saga);
            uow.End();

            using (var context = new SagaContext())
            {
                var sagaData = context.SagaData.FirstOrDefault(s => s.Id == saga.Id);
                context.SagaData.Remove(sagaData);
                context.SaveChanges();

                Assert.IsNotNull(sagaData);
                Assert.IsNotNull(sagaData.Data);
                Assert.IsNotNull(sagaData.UniqueProperty);
                Assert.AreEqual(1, sagaData.Version);
            }
        }