private string AuthExtendTime(TokenApplyPlace apiToken, string token, int _tokenExtendedTime_, AuthStatus authStatus)
        {
            if (AutoTokenExtended && !String.IsNullOrWhiteSpace(token) && authStatus == AuthStatus.Authorized)
            {
                //無cache 及 過期前 (_tokenExtendedTime/10)秒 提早SQL update
                int SlidingExpiration = -1 * (int)Math.Round(_tokenExtendedTime_ / 10.0);
                if (apiToken == null || apiToken.ExpireDateTime.AddSeconds(SlidingExpiration) < DateTime.Now)
                {
                    using (SqlConnection conn = new SqlConnection(_DBconfig)) {
                        string sqlStr = @"UPDATE TOP (1) dbo.Token
                                        SET RefreshDateTime = GETDATE(),
                                            ExpireDateTime = DATEADD(s, @tokenExtendedTime, GETDATE())
                                        OUTPUT INSERTED.RefreshDateTime, INSERTED.ExpireDateTime
                                        WHERE Token = @token";

                        conn.Open();
                        var updateTmp = conn.Query <TokenApplyPlace>(sqlStr, new { token = token, tokenExtendedTime = _tokenExtendedTime_ }).SingleOrDefault();
                        if (updateTmp != null)
                        {
                            _apiToken.RefreshDateTime = updateTmp.RefreshDateTime;
                            _apiToken.ExpireDateTime  = updateTmp.ExpireDateTime;

                            if (_apiToken != null && _apiToken.ExpireDateTime != null)
                            {
                                CacheHelper.CacheInsert(token, apiToken, apiToken.ExpireDateTime);
                            }
                        }
                    }
                }
                return(_apiToken.ExpireDateTime.ToString("yyyy-MM-ddTHH:mm:ssK"));
            }
            return(null);
        }
        private string AuthExtendTime(DevTokenApplyPlace apiToken, string token, int _tokenExtendedTime_, AuthStatus authStatus)
        {
            if (AutoTokenExtended && !String.IsNullOrWhiteSpace(token) && authStatus == AuthStatus.Authorized)
            {
                //無cache 及 過期前 (_tokenExtendedTime/10)秒 提早SQL update
                int SlidingExpiration = -1 * (int)Math.Round(_tokenExtendedTime_ / 10.0);
                if (apiToken == null || apiToken.expire.AddSeconds(SlidingExpiration) < DateTime.Now)
                {
                    using (SqlConnection conn = new SqlConnection(_DBconfig))
                    {
                        string sqlStr = string.Empty;

                        conn.Open();

                        var updateTmp = conn.Query <DevToken>("CheckAPI_Token_UpDate",
                                                              new { token = token, TokenStatus = apiToken.TokenStatus, _tokenExtendedTime_ = _tokenExtendedTime_ },
                                                              commandType: CommandType.StoredProcedure).FirstOrDefault();

                        if (updateTmp != null)
                        {
                            if (string.Equals(apiToken.TokenStatus, "T", StringComparison.OrdinalIgnoreCase))
                            {
                                _apiToken.expire = updateTmp.token_texpire;
                            }
                            if (string.Equals(apiToken.TokenStatus, "F", StringComparison.OrdinalIgnoreCase))
                            {
                                _apiToken.expire = updateTmp.token_fexpire;
                            }
                            CacheHelper.CacheInsert(token, apiToken, apiToken.expire);
                        }
                    }
                }
                return(_apiToken.expire.ToString("yyyy-MM-ddTHH:mm:ssK"));
            }
            return(null);
        }