public static JsonReturn RunTransactionScope(Func <JsonReturn> method, TransactionScopeOption scopeOption, TimeSpan scopeTimeout) { JsonReturn cr; //开启事务,执行操作(注意,这里一定要开启分布式事务,以便应用多业务 using (TransactionScope scope = new TransactionScope(scopeOption, scopeTimeout)) { try { if (method != null) { cr = method(); } else { cr = JsonReturn.RunFail("未执行实际数据操作方法"); } } catch (Exception ex) { cr = JsonReturn.RunFail(ex.Message, ex); } if (cr.IsSuccess) { scope.Complete(); } }; return(cr); }
public static JsonReturn RunTransactionScope(Action method, TransactionScopeOption scopeOption, TimeSpan scopeTimeout) { JsonReturn jr; //开启事务,执行操作(注意,这里一定要开启分布式事务,以便应用多业务 using (TransactionScope scope = new TransactionScope(scopeOption, scopeTimeout)) { try { if (method != null) { method(); } jr = JsonReturn.RunSuccess(true); } catch (Exception ex) { jr = JsonReturn.RunFail(ex.Message); } if (jr.IsSuccess) { scope.Complete(); } }; return(jr); }
/// <summary> /// 保存Cookie信息,并得到ID /// 注意,这里不能使用事务锁 /// </summary> /// <param name="session"></param> /// <returns></returns> public JsonReturn SaveCookie(Guid CookieID, string CookieName, string CookieValue, DateTime ExpireTime) { DateTime today = DateTime.Now; if (ExpireTime < today) { return(JsonReturn.RunFail("无法存储Cookie信息:该Cookie已失效")); } //先检测是否存在该CookieID if (CookieID != Guid.Empty) //当前该Cookie还保存,可能是存放的另外一个 { //删除现有保存的Cookie db.ExecuteCommand(string.Format("delete from TSys_LoginUserCookie where CookieID='{0}'", CookieID)); } else { CookieID = Guid.NewGuid();//创建一个新的CookieID,用于标识该Cookie } try { DynamicObj Cookie = new DynamicObj(); Cookie.Set("CookieID", CookieID); Cookie.Set("UserInfoEntity", CookieValue); Cookie.Set("Expires", ExpireTime); Cookie.Set("CookieName", CookieName); Cookie.Set("ReadTime", DateTime.Now); //仅为单表,暂不进行事务处理 if (db.SaveNewObject(Cookie, "TSys_LoginUserCookie")) { return(JsonReturn.RunSuccess(CookieID)); } else { return(JsonReturn.RunFail("无法存储Cookie信息")); } } catch { return(JsonReturn.RunFail("存储Cookie信息时出现异常")); } }