Exemplo n.º 1
0
        /// <summary>
        /// 获取登录session
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        public static bool GetAdminSession(ref int userId, ref object adminInfo)
        {
            bool result = true;

            //Session共享缓存
            if (IsRedisSession)
            {
                RedisSession redisSession = new RedisSession(System.Web.HttpContext.Current, true);
                var          session      = redisSession[AdminId];
                result = GetAdminInfo(session, ref userId);
                if (result && userId > 0)
                {
                    adminInfo = redisSession[AdminInfo];
                }
            }
            else if (System.Web.HttpContext.Current.Session != null)
            {
                result = GetAdminInfo(System.Web.HttpContext.Current.Session[AdminId], ref userId);
                if (result && userId > 0)
                {
                    adminInfo = System.Web.HttpContext.Current.Session[AdminInfo];
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 存储用户信息
        /// </summary>
        public static void SetSession(SessionModel model)
        {
            var _sessionid = model.Uid.ToString() + Guid.NewGuid();  //每次登陆唯一标识解决不同客户端登陆登出互相影响问题

            CookieInfo.SetLoginCookie(_sessionid);
            RedisSession.Set <SessionModel>(_sessionid, model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 构造器
        /// </summary>
        protected RedisRepositoryProvider()
        {
            this._redisSession = RedisSession.Current;

            this._redisWriteTypedClient = this._redisSession.RedisWriteClient.As <T>();
            this._redisReadTypedClient  = this._redisSession.RedisReadClient.As <T>();
        }
Exemplo n.º 4
0
        public void PushJob(bool useQuery, string sql, bool allowSaveOld, bool allowSaveNew
                            , bool bIsTest, int typeCrawler, int numberJob
                            , DataTable tblOut = null, string queueName = "crawler_product_company_wait", int iTimeReset = 10)
        {
            try
            {
                RedisSession redisSession = new RedisSession();


                SqlDb     sqlDb = new SqlDb(QT.Entities.Server.ConnectionStringCrawler);
                DataTable tbl   = (!useQuery) ? sqlDb.GetTblData(sql, CommandType.Text, null) : tblOut;
                foreach (DataRow row in tbl.Rows)
                {
                    long companyID = Convert.ToInt64(row["ID"]);
                    int  iWait     = redisSession.CheckRunning(companyID, typeCrawler, sqlDb.GetCurrent(), iTimeReset);
                    if (iWait <= 0)
                    {
                        string url = QT.Entities.Common.Obj2String(row["Website"]);

                        //Xóa Cache dữ liệu liên quan session.
                        QueueWaitRedis queueWait = new QueueWaitRedis(companyID, typeCrawler);
                        queueWait.Clean();
                        SetAddedQueueRedis setAddedQueu = new SetAddedQueueRedis(companyID, typeCrawler);
                        setAddedQueu.Clean();

                        var a = Websosanh.Core.Common.BAL.ProtobufTool.Serialize(new QT.Entities.CrawlerProduct.MQCompanyWaitCrawler
                        {
                            CompanyID      = companyID,
                            IsTest         = bIsTest,
                            TypeCrawler    = typeCrawler,
                            datePush       = DateTime.Now,
                            ExtractionLink = (typeCrawler != 1)
                        });

                        QueueWaitRedis queueWaitRedis = new QueueWaitRedis(companyID, typeCrawler);
                        queueWaitRedis.PushJob(new Job()
                        {
                            deep = 0,
                            url  = url
                        });

                        redisSession.InitSession(companyID, typeCrawler);
                        this.WriteLog(string.Format("Pushed job Company:{0}. TypeCrawler:{1}", companyID, typeCrawler));
                    }
                    else
                    {
                        this.WriteLog(string.Format("Skip company running company:{0}. TypeCrawler:{1}. Wait: {2}", companyID, typeCrawler, iWait));
                    }
                }
            }
            catch (Exception ex)
            {
                this.WriteLog("EXCEPTION POST JOB:" + ex.Message);
            }
            finally
            {
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据Key给Session续期
        /// </summary>
        /// <param name="key">sessionID</param>
        /// <returns></returns>
        public static bool PostponeKey()
        {
            var _sessionid = GetSessionID();

            if (!string.IsNullOrEmpty(_sessionid))
            {
                return(RedisSession.Postpone(GetSessionID()));
            }
            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 根据SessionID清除Session信息
        /// </summary>
        /// <param name="key">sessionID</param>
        public static void ClareSessionKey()
        {
            var _sessionid = GetSessionID();

            if (string.IsNullOrEmpty(_sessionid))
            {
                return;
            }
            RedisSession.ClearKey(_sessionid);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取Redis中的Session信息
        /// </summary>
        /// <returns></returns>
        private static SessionModel GetSessionKey()
        {
            string useriD = GetSessionID();

            if (string.IsNullOrEmpty(useriD))
            {
                return(null);
            }
            var model = RedisSession.Get <SessionModel>(useriD);

            return(model);
        }
Exemplo n.º 8
0
 /// <summary>
 /// 退出登录
 /// </summary>
 public static void RemoveMember()
 {
     Tools.Utility.CookieHelper.Del("Remember");
     Tools.Utility.CookieHelper.Del("Auth");
     System.Web.HttpContext.Current.Session.Remove("MB_MemberId");
     //Session共享缓存
     if (Tools.Special.Common.GetIsRedisSession())
     {
         RedisSession redisSession = new RedisSession(System.Web.HttpContext.Current, true, 120);
         redisSession.Remove("MB_MemberId");
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// 退出登录
        /// </summary>
        public static void Remove()
        {
            //Session共享缓存
            if (IsRedisSession)
            {
                RedisSession redisSession = new RedisSession(System.Web.HttpContext.Current, true, 120);
                redisSession.Remove(AdminId);
                redisSession.Remove(AdminInfo);
            }

            System.Web.HttpContext.Current.Session.Remove(AdminId);
            System.Web.HttpContext.Current.Session.Remove(AdminInfo);
            System.Web.HttpContext.Current.Session.Clear();
            System.Web.HttpContext.Current.Session.Abandon();
        }
Exemplo n.º 10
0
        /// <summary>
        ///  设置登录SESSION
        /// </summary>
        /// <param name="memberId"></param>
        public static void SetMemberSession(int memberId, string userName)
        {
            var sessionValue = memberId + "|" + userName;

            //Session共享缓存
            if (Tools.Special.Common.GetIsRedisSession())
            {
                RedisSession redisSession = new RedisSession(System.Web.HttpContext.Current, true);
                redisSession["MB_Member"] = sessionValue;
            }
            else
            {
                System.Web.HttpContext.Current.Session["MB_Member"] = sessionValue;
                System.Web.HttpContext.Current.Session.Timeout      = 120;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 获取登录session
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        public static bool GetMemberSession(ref int userId, ref string userName)
        {
            //Session共享缓存
            if (Tools.Special.Common.GetIsRedisSession())
            {
                RedisSession redisSession = new RedisSession(System.Web.HttpContext.Current, true);
                var          session      = redisSession["MB_Member"];
                return(GetMemberInfo(session, ref userId, ref userName));
            }
            else if (System.Web.HttpContext.Current.Session != null)
            {
                return(GetMemberInfo(System.Web.HttpContext.Current.Session["MB_Member"], ref userId, ref userName));
            }

            return(true);
        }
Exemplo n.º 12
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            RedisSession redisSession = new RedisSession(HttpContext.Current);
            var          user         = redisSession.Get <Administrator>("ADMINUSER");

            if (user != null)
            {
                if (Code != null)
                {
                    var  adminService = Container.Instance.Resolve <IAdministratorService>();
                    bool pass         = adminService.IsAuthorizePass(user.RoleId, Code);
                    return(pass);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 获取用户Id
        /// </summary>
        /// <returns></returns>
        public static int GetAdminId()
        {
            bool result = true;
            int  userId = 0;

            //Session共享缓存
            if (IsRedisSession)
            {
                RedisSession redisSession = new RedisSession(System.Web.HttpContext.Current, true);
                var          session      = redisSession[AdminId];
                result = GetAdminInfo(session, ref userId);
            }
            else if (System.Web.HttpContext.Current.Session != null)
            {
                result = GetAdminInfo(System.Web.HttpContext.Current.Session[AdminId], ref userId);
            }
            return(userId);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Action方法执行之前执行此方法
        /// </summary>
        /// <param name="filterContext"></param>

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (IsCheck)
            {
                //获取客户端
                var cookie = ExtractClient(filterContext, out var user);
                //验证用户真实性
                if (VerifyUser(filterContext, user))
                {
                    return;
                }
                //验证客户是否有权限访问当前URL
                if (VerifyPermission(filterContext, user))
                {
                    return;
                }
                //延长客户有效在线时间
                RedisSession.Postpone(cookie);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 处理用户请求的具体方法,该方法是必须的
        /// </summary>
        /// <param name="c">OwinContext对象</param>
        /// <returns></returns>
        public override Task Invoke(IOwinContext context)
        {
            if (_next != null && context.Request == null) { return _next.Invoke(context); }

            #region request
            var sessionID = context.Request.Cookies["Redis_SessionId"];
            RedisSession redisSession = new RedisSession(context, true, 300);
            string sessionStr = "未登录";
            if (!string.IsNullOrEmpty(sessionID))
            {
                if (redisSession[sessionID] != null)
                {

                    var userStr = redisSession[sessionID];
                    var user = JsonConvert.DeserializeObject<User>(userStr.ToString());
                    sessionStr = user.Name + " 已登录";
                }
                else
                {
                    redisSession.Add(sessionID, JsonConvert.SerializeObject(new User() { ID = 1, Name = "张三" }));
                }
            }
            else
            {
                //sessionID = redisSession.SessionID;
                redisSession.Add(sessionID, JsonConvert.SerializeObject(new User() { ID = 1, Name = "张三" }));
            }

            #endregion

            #region response
            context.Response.ContentType = "text/html; charset=utf-8";
            context.Response.Cookies.Append("Redis_SessionId", sessionID);

            string outString = "<html><head><title>Jexus Owin Web Server</title></head><body>Jexus Owin Server!<br /><h2>" + sessionStr + "</h2>\r\n</body></html>";
            var outBytes = Encoding.UTF8.GetBytes(outString);
            context.Response.Write(outBytes, 0, outBytes.Length);
            #endregion

            return Task.FromResult<int>(0);
        }
Exemplo n.º 16
0
 /// <summary>
 ///  设置登录SESSION
 /// </summary>
 /// <param name="memberId"></param>
 public static void SetSession(int adminId, object adminInfo = null)
 {
     //Session共享缓存
     if (IsRedisSession)
     {
         RedisSession redisSession = new RedisSession(System.Web.HttpContext.Current, true, 120);
         redisSession[AdminId] = adminId;
         if (adminInfo != null)
         {
             redisSession[AdminInfo] = adminInfo;
         }
     }
     else
     {
         System.Web.HttpContext.Current.Session.Timeout  = 120;
         System.Web.HttpContext.Current.Session[AdminId] = adminId;
         if (adminInfo != null)
         {
             System.Web.HttpContext.Current.Session[AdminInfo] = adminInfo;
         }
     }
 }
Exemplo n.º 17
0
        private void Button_Redis_New(object sender, RoutedEventArgs e)
        {
            var redission = new RedisSession();

            redission.Create();
        }