Example #1
0
        /// <summary>
        /// 根据指定会话ID获取会话信息,如果指定会话不在,则返回空
        /// </summary>
        /// <param name="SessionID"></param>
        /// <returns></returns>
        public string GetCookieValue(Guid CookieID)
        {
            string json = "";

            RemoveExpiresCookie();

            DynamicObj rec = db.GetDynamicObj(string.Format("select * from TSys_LoginUserCookie with(nolock) where CookieID='{0}'", CookieID));

            if (rec != null)
            {
                json = rec.Get <string>("UserInfoEntity");

                DateTime readTime = rec.Get <DateTime>("ReadTime");
                DateTime Expires  = rec.Get <DateTime>("Expires");

                //取到两者之前间隔,则可知道Cookie保存长度
                TimeSpan ts = Expires - readTime;

                Expires.AddTicks(ts.Ticks);

                //再次更新
                db.ExecuteCommand(string.Format("update TSys_LoginUserCookie set ReadTime={0},Expires={1} where CookieID='{2}'", db.Function.DateTimeValue(DateTime.Now), db.Function.DateTimeValue(Expires), CookieID));
            }
            return(json);
        }
Example #2
0
        /// <summary>
        /// 获取保存在当前库
        /// </summary>
        /// <returns></returns>
        public IUserSession <T> GetUserSession(AppSession <T> appSession)
        {
            string CookieValue = GetCookies(Options.SessionCookieName);

            if (CookieValue.IsWhiteSpace()) //找不到Cookie,则表示过期了
            {
                return(null);
            }



            DynamicObj cookie    = LibHelper.JSON.DeserializeDynamicObj(CookieValue.Decrypt());
            Guid       SessionID = cookie.Get <Guid>("SessionID");

            //再次从会话Session中查找,找到,就直接返回,没找到,则从Cookie中加载
            IUserSession <T> u = appSession.GetUserSession(SessionID);

            if (u != null)
            {
                return(u);
            }
            string User;

            if (Options.IsSqlSaveCookie)
            {
                User = App.GetAppService <ICookieService>().GetCookieValue(SessionID).Decrypt();
            }
            else
            {
                User = cookie.Get <string>("User");
            }
            try
            {
                u = LibHelper.JSON.Deserialize <UserSession <T> >(User);
                if (u != null)
                {
                    Func <string, IAppUser> parseUser = Options.ParseUser;
                    if (parseUser != null && u.ExtendInfo.IsNotWhiteSpace()) //还原真实的用户信息
                    {
                        IAppUser au = parseUser(u.ExtendInfo);
                        if (au != null)
                        {
                            u.User = au;
                        }
                        else
                        {
                            u.User = null;//则当前操作者并没有用户信息,视为游客
                        }
                        u.ExtendInfo = "";
                    }
                }
            }
            catch (Exception ex)
            {
                Loger.Error("读取Cookie用户信息出错误" + ex.Message);
            }
            return(u);
        }
Example #3
0
        public IUserSession <T> GetUserSession(string Id)
        {
            string key = $"{Options.SessionCookieName}_{Id}";

            if (Options.IsSqlSaveCookie)  //Session是采用分布式保存,则会话直接按系统Session控制,这种多用于多应用服务器
            {
                return(WebHelper.Current.Session.Get <UserSession <T> >(key));
            }
            else//这种只适合单应用服务器
            {
                return(UserSessions.Get <UserSession <T> >(key));
            }
        }
Example #4
0
        public virtual void Init(DynamicObj dataParam)
        {
            if (_isInit)
            {
                return;
            }

            InitRelations();

            DefaultItemTypeId = dataParam.Get("DEFAULTLAYOUT", 0);

            BuildDefaultQueries();
            PrepareComputeOrderSeq();

            _isInit = true;
        }
        protected override void BuildDataRowActions(DataListContext context, DynamicObj row)
        {
            var rowId   = row.Get(ViewConstant.RowId, 0);
            var actions = new List <ActionInfo>();

            if (context.Context.UserInfo.HasAccess(context.SourceEntityId, AccessType.Update))
            {
                var actionContext = new ActionContext(null, ActionType.Edit, "BTN_EDIT");
                actionContext.Query          = new RequestQueryString();
                actionContext.Query.EntityId = context.SourceEntityId;
                actionContext.Query.ItemId   = rowId;

                var ac = PageActionCreator.Create(actionContext);
                ac.LinkTarget = "POPUP";

                actions.Add(ac);
            }

            row.Add("_RowActions", actions);
        }
Example #6
0
        public static T CreateObject <T>(DbDataReader dr, DynamicObj ps, Dictionary <string, string> FieldMap2Property) where T : new()
        {
            T entity = new T();

            for (int i = 0; i < dr.FieldCount; i++)
            {
                string fn = dr.GetName(i);
                if (FieldMap2Property.ContainsKey(fn))
                {
                    fn = FieldMap2Property[fn];
                }

                PropertyInfo p = ps.Get(fn) as PropertyInfo;
                if (p != null && p.CanWrite)
                {
                    object v = dr.GetValue(i);
                    p.SetValue(entity, v.GetObjectValue(p.PropertyType), null);
                }
            }
            return(entity);
        }
Example #7
0
        internal static T CreateObjectRec <T>(DbDataReader dr, DynamicObj ps, Action <DbDataReader> OtherSetMethod) where T : new()
        {
            T entity = new T();

            for (int i = 0; i < dr.FieldCount; i++)
            {
                string fn = dr.GetName(i);

                PropertyInfo p = ps.Get(fn) as PropertyInfo;
                if (p != null && p.CanWrite)
                {
                    object v = dr.GetValue(i);
                    p.SetValue(entity, v.GetObjectValue(p.PropertyType), null);
                }

                if (OtherSetMethod != null)
                {
                    OtherSetMethod(dr);
                }
            }
            return(entity);
        }
 private void SetEntityOpenLink(DataListContext context, DataListDefinition defn, DynamicObj row, IDisplayWidget widget)
 {
     if (!String.IsNullOrEmpty(defn.ItemViewField) && widget.WidgetId.ToLower() == defn.ItemViewField.ToLower())
     {
         widget.SetAdditionalValue(ViewConstant.ViewLink, StackErp.Model.AppLinkProvider.GetDetailPageLink(defn.DataSource.Entity, row.Get(ViewConstant.RowId, 0)).Url);
     }
 }
Example #9
0
        /// <summary>
        /// 传递后取到参数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static T GetUrlParams <T>(string Key)
        {
            DynamicObj curParams = UrlGetSession[Current.Session.Id];

            return(curParams.Get <T>(Key));
        }