コード例 #1
0
        private static async Task InterceptAsync(Task task, IDbContext dbContext)
        {
            try
            {
                await task.ConfigureAwait(false);

                dbContext.CommitTransaction();
            }
            catch (Exception)
            {
                dbContext.RollbackTransaction();
                throw;
            }
        }
コード例 #2
0
            /// <summary>
            /// Use/Override the render function so that rendering takes place at the right time
            /// </summary>
            /// <param name="output"></param>
            protected override void Render(System.Web.UI.HtmlTextWriter output)
            {
                DataPersister persister = new DataPersister();
                IDbContext    dbcontext = persister.getDBContext();

                dbcontext.BeginTransaction();
                try
                {
                    output.Write(ParentControl.RenderToString(ControlDefnToRender, LangToRenderFor));
                    dbcontext.CommitTransaction();
                }
                catch
                {
                    dbcontext.RollbackTransaction();
                    throw;
                }
            }
コード例 #3
0
        private static async Task <T> InterceptWithResultAsync <T>(Task <T> task, IDbContext dbContext)
        {
            try
            {
                var result = await task.ConfigureAwait(false);

                if (result is Result returnValue && returnValue.Failed)
                {
                    dbContext.RollbackTransaction();
                }
                else
                {
                    dbContext.CommitTransaction();
                }

                return(result);
            }
コード例 #4
0
    // not-atomic example
    public bool RecordUserActivity(UserModel user, IEnumerable <UserActivity> activities)
    {
        try {
            _dbContext.BeginTransaction();

            // messy example
            _dbContext.UserLogins
            .Add(activities.Where(x => x.ActivityType == ActivityTypes.Logins));
            _dbContext.UserEdits
            .Add(activities.Where(x => x.ActivityType == ActivityTypes.Edits));
            //
            _dbContext.CommitTransaction();
            return(true);
        } catch (Exception ex) {
            // log your exceptions!
            _dbContext.RollbackTransaction();
        }
        return(false);
    }
コード例 #5
0
        public void SetUp()
        {
            mocks       = new MockRepository();
            gameService = mocks.DynamicMock <IGameService>();
            repository  = mocks.DynamicMock <IRepository <Game> >();
            dbContext   = mocks.DynamicMock <IDbContext>();
            service     = new RecalcGameStateService(1, repository, gameService);

            game = new Game
            {
                GameState   = GameStates.Started,
                GameDate    = new DateTime(2010, 1, 1, 21, 0, 0),
                TotalTime   = 540,
                TimePerTask = 90,
                TimePerTip  = 30
            };

            task1     = new Task();
            task1Tip0 = new Tip {
                SuspendTime = 0, Task = task1
            };
            task1Tip1 = new Tip {
                SuspendTime = 30, Task = task1
            };
            task1Tip2 = new Tip {
                SuspendTime = 60, Task = task1
            };
            task1.Tips.Add(task1Tip0);
            task1.Tips.Add(task1Tip1);
            task1.Tips.Add(task1Tip2);
            task1.Codes.Add(new Code {
                Name = "1", Task = task1
            });

            game.Tasks.Add(task1);

            Expect.Call(repository.DbContext).Return(dbContext).Repeat.Any();
            Expect.Call(dbContext.BeginTransaction()).Repeat.Any();
            Expect.Call(() => dbContext.CommitTransaction()).Repeat.Any();
        }
コード例 #6
0
ファイル: UnitOfWork.cs プロジェクト: mkeeton/ISS
 public void CommitWork()
 {
     DbContext.CommitTransaction();
 }
コード例 #7
0
 public void Commit()
 {
     ctx.CommitTransaction();
 }
コード例 #8
0
 public void CommitTransaction()
 {
     _dbContext.CommitTransaction();
 }
コード例 #9
0
        public void SetUp()
        {
            mocks = new MockRepository();
            gameService = mocks.DynamicMock<IGameService>();
            repository = mocks.DynamicMock<IRepository<Game>>();
            dbContext = mocks.DynamicMock<IDbContext>();
            service = new RecalcGameStateService(1, repository, gameService);

            game = new Game
            {
                GameState = GameStates.Started,
                GameDate = new DateTime(2010, 1, 1, 21, 0, 0),
                TotalTime = 540,
                TimePerTask = 90,
                TimePerTip = 30
            };

            task1 = new Task();
            task1Tip0 = new Tip { SuspendTime = 0, Task = task1 };
            task1Tip1 = new Tip { SuspendTime = 30, Task = task1 };
            task1Tip2 = new Tip { SuspendTime = 60, Task = task1 };
            task1.Tips.Add(task1Tip0);
            task1.Tips.Add(task1Tip1);
            task1.Tips.Add(task1Tip2);
            task1.Codes.Add(new Code { Name = "1", Task = task1 });

            game.Tasks.Add(task1);

            Expect.Call(repository.DbContext).Return(dbContext).Repeat.Any();
            Expect.Call(dbContext.BeginTransaction()).Repeat.Any();
            Expect.Call(() => dbContext.CommitTransaction()).Repeat.Any();
        }