Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <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信息时出现异常"));
            }
        }