Esempio n. 1
0
        /// <summary>
        /// 移除超时 Token.
        /// </summary>
        public override void RemoveTimeoutToken()
        {
            try
            {
                using (MyTokenContext context = new MyTokenContext())
                {
                    var timeoutQuery =
                        from data in context.TokenDatas
                        where
                        data.ExpiredTime < DateTime.Now
                        select data;

                    List <TokenData> removeList = timeoutQuery.ToList();

                    foreach (var item in removeList)
                    {
                        context.TokenDatas.Remove(item);
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // 日志.
                logger.Error(ex.Message, ex);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 保存访问日志.
 /// </summary>
 /// <param name="log"></param>
 protected override void SaveTokenAccessLog(TokenAccessLog log)
 {
     using (MyTokenContext context = new MyTokenContext())
     {
         context.TokenAccessLogs.Add(log);
         context.SaveChanges();
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 保存令牌数据.
        /// </summary>
        /// <param name="data"></param>
        protected override void SaveTokenData(TokenData data)
        {
            using (MyTokenContext context = new MyTokenContext())
            {
                // 获取数据库数据.
                TokenData dbData = context.TokenDatas.Find(data.TokenID);

                if (dbData == null)
                {
                    // 新增.
                    context.TokenDatas.Add(data);
                }
                else
                {
                    // 编辑.

                    // 更新次数.
                    dbData.AccessCount = data.AccessCount;
                }


                context.SaveChanges();
            }
        }