コード例 #1
0
        private static TxProvider BuildProvider(string userId, string pwd)
        {
            //登录
            String logErrorReason        = null;
            UserLoginSessionInfo session = null;

            if (UserLogin(userId, pwd, out session, out logErrorReason))
            {
                var p   = new TxProvider(session.token);
                var key = $"TxProvider_{userId}";
                if (Common.MemcachedHelper.Instance.Get(key) == null)
                {
                    Common.MemcachedHelper.Instance.Add(key, session);
                }
                else
                {
                    Common.MemcachedHelper.Instance.Remove(key);
                    Common.MemcachedHelper.Instance.Add(key, session);
                }

                return(p);
            }
            else
            {
                throw new BusinessException($"{userId}登录消息系统失败。(原因:{logErrorReason})");
            }
        }
コード例 #2
0
        private static bool TryGetTxProvider(string userId, out TxProvider p)
        {
            p = null;

            var key     = $"TxProvider_{userId}";
            var session = Common.MemcachedHelper.Instance.Get <UserLoginSessionInfo>(key);

            if (session == null)
            {
                return(false);
            }
            else
            {
                if (DateTime.Now > FaceHand.Common.Util.DateTimeExt.FromUnixTimestamp(session.expiry).AddMinutes(-10))
                {
                    return(false);
                }
                else
                {
                    p = new TxProvider(session.token);
                    return(true);
                }
            }
        }