/// <summary> /// </summary> /// <param name="sessionWrapper"></param> protected AbstractDao(SessionWrapper sessionWrapper) { if (sessionWrapper == null) throw new ArgumentNullException("sessionWrapper"); _managerBySelf = true; _wrapper = sessionWrapper; }
/// <summary> /// Binds the model by using the specified controller context and binding context. /// </summary> /// <returns> /// The bound object. /// </returns> /// <param name="controllerContext"> /// The context within which the controller operates. The context information includes the /// controller, HTTP content, request context, and route data. /// </param> /// <param name="bindingContext"> /// The context within which the model is bound. The context includes information such as the /// model object, model name, model type, property filter, and value provider. /// </param> /// <exception cref="T:System.ArgumentNullException"> /// The <paramref name="bindingContext " />parameter is null. /// </exception> public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var context = bindingContext as NHModelBindingContext; ModelBindingContext realContext = context == null ? bindingContext : context.Context; if (TypeUtility.IsBasicType(realContext.ModelType)) { return base.BindModel(controllerContext, realContext); } _wrapper = context == null ? Initilize(controllerContext) : context.Wrapper; if (_wrapper == null) { object result = base.BindModel(controllerContext, bindingContext); return result; } bool addSuccess = SetWrapper(controllerContext, _wrapper); try { return base.BindModel(controllerContext, realContext); } finally { if (addSuccess) { RemoveWrapper(controllerContext); } } }
/// <summary> /// </summary> /// <param name="result"></param> /// <param name="sessionWrapper"></param> /// <exception cref="ArgumentNullException"></exception> public NHValueProviderResult(ValueProviderResult result, SessionWrapper sessionWrapper) { _result = result; _sessionWrapper = sessionWrapper; AttemptedValue = result.AttemptedValue; Culture = result.Culture; RawValue = result.RawValue; }
/// <summary> /// /// </summary> /// <param name="actionContext"></param> public override void OnActionExecuting(HttpActionContext actionContext) { if (Enable) { _wrapper = SessionManager.GetSessionWrapper(SessionFactoryName); if (Transaction) { _tras = _setIsolative ? _wrapper.CurrentSession.BeginTransaction(IsolationLevel) : _wrapper.CurrentSession.BeginTransaction(); } } base.OnActionExecuting(actionContext); }
/// <summary> /// </summary> /// <param name="sessionWrapper"></param> protected SqlDaobase(SessionWrapper sessionWrapper) : base(sessionWrapper) { }
/// <summary> /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { if (Enable) { _wrapper = SessionManager.GetSessionWrapper(); if (Transaction) { _tras = _setIsoloatve ? _wrapper.CurrentSession.BeginTransaction(IsolationLevel) : _wrapper.CurrentSession.BeginTransaction(); } } }
/// <summary> /// </summary> /// <param name="customAttributes"></param> /// <param name="wrapper"></param> /// <returns></returns> private bool TryEnableSession(object[] customAttributes, out SessionWrapper wrapper) { wrapper = null; if (customAttributes.Length != 0) { var custommAttr = (SessionAttribute) customAttributes[0]; if (custommAttr.Enable) { wrapper = SessionManager.GetSessionWrapper(custommAttr.SessionFactoryName); return true; } } return false; }
/// <summary> /// </summary> /// <param name="controllerContext"></param> /// <param name="wrapper"></param> internal static bool SetWrapper(ControllerContext controllerContext, SessionWrapper wrapper) { IDictionary items = controllerContext.RequestContext.HttpContext.Items; if (!items.Contains(SessionWrapperContainer)) { items.Add(SessionWrapperContainer, wrapper); return true; } return false; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void context_BeginRequest(object sender, EventArgs e) { _wrapper = SessionManager.GetSessionWrapper(); }