protected override void PerformActionProcess(Controller controller) { ARDataBinder binder = new ARDataBinder(); object instance = binder.BindObject(Model.Type, "", controller.Params); SessionScope scope = new SessionScope(); try { CommonOperationUtils.SaveInstance(instance, controller, errors, prop2Validation); scope.Dispose(); controller.Redirect(controller.AreaName, controller.Name, "list" + Model.Type.Name); } catch (Exception ex) { errors.Add("Could not save " + Model.Type.Name + ". " + ex.Message); scope.Dispose(true); } if (errors.Count != 0) { controller.Context.Flash["errors"] = errors; controller.Redirect(controller.AreaName, controller.Name, "new" + Model.Type.Name); } }
public void TearDown() { if (session != null) { session.Dispose(); } }
public void should_commit_and_dispose() { //act UnitOfWork.Do(uow => { }); //assert A.CallTo(() => SessionScope.Commit()).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => SessionScope.Dispose()).MustHaveHappened(Repeated.Exactly.Once); }
/// <summary> /// Called when the request ends, dipose of the scope /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private static void OnEndRequest(object sender, EventArgs e) { SessionScope session = (SessionScope)HttpContext.Current.Items[SessionKey]; if (session != null) { session.Dispose(); } }
private void OnEndRequest(object sender, EventArgs e) { SessionScope sessionScope = (SessionScope)HttpContext.Current.Items[sessionKey]; if (sessionScope != null) { sessionScope.Flush();//事务提交 if (sessionScope.WantsToCreateTheSession == false) { sessionScope.Dispose(); } } }
protected override void PerformActionProcess(Controller controller) { ARDataBinder binder = new ARDataBinder(); object idVal = CommonOperationUtils.ReadPkFromParams(controller, ObtainPKProperty()); SessionScope scope = new SessionScope(); try { object instance = SupportingUtils.FindByPK(Model.Type, idVal); binder.BindObjectInstance(instance, String.Empty, controller.Params, null, null); CommonOperationUtils.SaveInstance(instance, controller, errors, prop2Validation); scope.Dispose(); controller.Redirect(controller.AreaName, controller.Name, "list" + Model.Type.Name); } catch (Exception ex) { errors.Add("Could not save " + Model.Type.Name + ". " + ex.Message); scope.Dispose(true); } if (errors.Count != 0) { controller.Context.Flash["errors"] = errors; NameValueCollection parameters = new NameValueCollection(); parameters["id"] = idVal.ToString(); controller.Redirect(controller.AreaName, controller.Name, "edit" + Model.Type.Name, parameters); } }
public void OnEndRequest(object sender, EventArgs e) { try { SessionScope scope = HttpContext.Current.Items["ar.sessionscope"] as SessionScope; if (scope != null) { scope.Dispose(); } } catch (Exception ex) { HttpContext.Current.Trace.Warn("Error", "EndRequest:" + ex.Message, ex); } }
protected void Application_EndRequest(Object sender, EventArgs e) { try { SessionScope scope = HttpContext.Current.Items ["ar.sessionscope"] as SessionScope; if (scope != null) { scope.Dispose(); } } catch (Exception ex) { HttpContext.Current.Trace.Warn("Error", "EndRequest: " + ex.Message, ex); } HttpContext.Current.Items.Remove("CurrentUser"); }
protected override void OnPreRender(EventArgs e) { // Only visible if some threshold has been reached... deleteQuestion.Visible = Operator.Current != null && (Operator.Current.CanDeleteQuestion || Operator.Current.ID == _question.CreatedBy.ID); editQuestionBtn.Visible = Operator.Current != null && (Operator.Current.CanEditQuestion || Operator.Current.ID == _question.CreatedBy.ID); answerQuestion.Visible = Operator.Current != null; quoteQuestion.Visible = Operator.Current != null; changeOrdering.Visible = _question.Children.Count > 1; base.OnPreRender(e); _session.Dispose(); }
public void OnEndRequest(object sender, EventArgs e) { SessionScope scope = (SessionScope)HttpContext.Current.Items["nh.sessionscope"]; try { if (scope != null) { scope.Dispose(); } } catch (Exception ex) { HttpContext.Current.Trace.Warn("Error", "Problems with the session:" + ex.Message, ex); } }
public void should_close_unit_of_work() { //arrange A.CallTo(() => SessionScope.Commit()).Throws <Exception>(); //act try { UnitOfWork.Do(uow => { }); } catch (Exception) { //assert A.CallTo(() => SessionScope.Dispose()).MustHaveHappened(); UnitOfWork.Current.IsNone.Should().BeTrue(); } }
public void DicardingChanges() { Post.DeleteAll(); Blog.DeleteAll(); SessionScope scope = new SessionScope(); Blog.FindAll(); // side effects only BlogService service = (BlogService)container[typeof(BlogService)]; Blog blog = service.Create("name", "author"); Assert.AreEqual(1, Blog.FindAll().Length); blog.Name = "joe developer"; scope.Dispose(true); Assert.AreEqual("name", Blog.FindAll()[0].Name); }
public void should_not_try_to_commit_or_rollback_and_should_close_unit_of_work() { //act try { UnitOfWork.Do(uow => { throw new Exception(); }); } catch (Exception) { //assert A.CallTo(() => SessionScope.Rollback()).MustNotHaveHappened(); A.CallTo(() => SessionScope.Commit()).MustNotHaveHappened(); A.CallTo(() => SessionScope.Dispose()).MustHaveHappened(); UnitOfWork.Current.IsNone.Should().BeTrue(); } }
public void DicardingChanges() { Post.DeleteAll(); Blog.DeleteAll(); SessionScope scope = new SessionScope(FlushAction.Never); Blog.FindAll(); // side effects only BlogService service = container.Resolve <BlogService>(); Blog blog = service.Create("name", "author"); Assert.AreEqual(1, Blog.FindAll().Length); blog.Name = "joe developer"; scope.Dispose(); Assert.AreEqual("name", Blog.FindAll()[0].Name); }
/// <summary> /// ends the current AR sessionscope, from vr session /// </summary> private void CloseARSession() { SessionScope scope = RoSession.Instance["nh.sessionscope"] as SessionScope; try { if (scope != null) { string message = "nh.sessionscope " + RoSession.Instance["nh.sessionscope"].GetHashCode() + " closing, took " + (DateTime.Now.Subtract(now).Seconds) + " seconds."; RoLog.Instance.WriteToLog(message); Console.WriteLine(message); RoLog.Instance.WriteToLog(""); Console.WriteLine(""); scope.Flush(); scope.Dispose(); RoSession.Instance["nh.sessionscope"] = null; } } catch (Exception ex) { RoLog.Instance.WriteToLog("Problems with the session:" + ex.Message + "/r/n" + ex, TracedAttribute.ERROR); } }
protected override void OnExit(ExitEventArgs e) { sessionScope.Dispose(); base.OnExit(e); }
public void TearDown() { scope.Dispose(); session.Dispose(); }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); _session.Dispose(); }
private void CloseUnitOfWork() { SessionScope.Dispose(); _current = null; }
/// <summary> /// Libera um <see cref="ISessionScope"/> do <c>ActiveRecord</c>. /// É chamado toda vez que uma requisição é finalizada, no evento /// <see cref="HttpApplication.EndRequest"/>. /// </summary> protected virtual void DisposeActiveRecordSessionScope(SessionScope scope) { scope.Dispose(); }