示例#1
0
 public static void AddOrUpdate(ISqlFactory sqlFactory, string key, string token, DateTime expirationTime)
 {
     try
     {
         TokenReplayCache_Ex replayRecord = new TokenReplayCache_Ex()
         {
             _Id             = Guid.NewGuid(),
             _ExpirationTime = expirationTime,
             _SecurityToken  = Encoding.UTF8.GetBytes(token),
             _TokenKey       = key
         };
         replayRecord.SqlFactory = sqlFactory;
         replayRecord.Insert();
     }
     catch (Exception)
     {
         //failed, probably dublicate key, try to update
         try
         {
             var existingToken = new TokenReplayCache_Ex();
             existingToken.SqlFactory      = sqlFactory;
             existingToken._TokenKey       = key;
             existingToken._SecurityToken  = Encoding.UTF8.GetBytes(token);
             existingToken._ExpirationTime = expirationTime;
             existingToken.Update(" SecurityToken = @SecurityToken, ExpirationTime = @ExpirationTime ", " TokenKey = @TokenKey ");
         }
         catch (Exception)
         {
             //log this
         }
     }
 }
示例#2
0
        public static void RemoveAllExpired(ISqlFactory sqlFactory)
        {
            var token = new TokenReplayCache_Ex();

            token.SqlFactory      = sqlFactory;
            token._ExpirationTime = DateTime.Now;
            token.Delete(" ExpirationTime < @ExpirationTime ");
        }
示例#3
0
        public static void Remove(ISqlFactory sqlFactory, string key)
        {
            var token = new TokenReplayCache_Ex();

            token.SqlFactory = sqlFactory;
            token._TokenKey  = key;
            token.Delete(" TokenKey = @TokenKey ");
        }
示例#4
0
        public static List <TokenReplayCache_Ex> FindAll(PersistentLib.ISqlFactory sf)
        {
            TokenReplayCache_Ex item = new TokenReplayCache_Ex();

            item.SqlFactory = sf;
            List <TokenReplayCache_Ex> data = item.SelectList <TokenReplayCache_Ex>(SelectAll, item.BuildParams_, ReadReader_ALL);

            return(data);
        }
示例#5
0
        public static TokenReplayCache_Ex FindByKey(PersistentLib.ISqlFactory sf, string tokenkey)
        {
            TokenReplayCache_Ex item = new TokenReplayCache_Ex();

            item.SqlFactory = sf;
            item._TokenKey  = tokenkey;
            TokenReplayCache_Ex data = item.SelectSingleRow <TokenReplayCache_Ex>(SelectBy_TokenKey, item.BuildParams__TokenKey, ReadReader_ALL);

            return(data);
        }
示例#6
0
        public static string Get(ISqlFactory sqlFactory, string key, out DateTime expirationTime)
        {
            expirationTime = DateTime.Now;

            var token = TokenReplayCache_Ex.FindByKey(sqlFactory, key);

            if (token != null)
            {
                expirationTime = token._ExpirationTime.Value;
                return(Encoding.UTF8.GetString(token._SecurityToken));
            }
            return(null);
        }
示例#7
0
 public static bool Contains(ISqlFactory sqlFactory, string key)
 {
     return(TokenReplayCache_Ex.FindByKey(sqlFactory, key) != null);
 }