Пример #1
0
 /// <summary>
 /// Adds the options to the list.
 /// </summary>
 public void AddToOptionList(OptionList options)
 {
     options.Clear();
     options["TcpPort"]        = TcpPort.ToString();
     options["ClientLifetime"] = ClientLifetime.ToString();
     options["Behavior"]       = Behavior.ToString();
     options["ConnectionMode"] = ConnectionMode.ToString();
     options["DeviceMapping"]  = DeviceMapping.ToString();
 }
Пример #2
0
        public async Task <IActionResult> UpdateTokenLifetime([FromBody] ClientLifetime clientLifetime)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ApiResult()
                {
                    Data = null, Error_Code = 400, Msg = ModelState.Keys.FirstOrDefault() + "错误", Request = "Post /api/client/lifetime"
                }));
            }

            var client = await _clientStore.FindEnabledClientByIdAsync(clientLifetime.Client);

            if (client == null)
            {
                return(BadRequest(new ApiResult()
                {
                    Data = null, Error_Code = 400, Msg = $"{clientLifetime.Client}不存在或不可用", Request = "Post /api/client/lifetime"
                }));
            }

            if (clientLifetime.Lifetime == client.AccessTokenLifetime)
            {
                return(Ok(new ApiResult()
                {
                    Data = null, Error_Code = 0, Msg = $"{clientLifetime.Client}的 Token 过期时间已改为{clientLifetime.Lifetime}", Request = "Post /api/cleint/lifetime"
                }));
            }

            client.AccessTokenLifetime = clientLifetime.Lifetime;

            try
            {
                _configurationDbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.InnerException.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(Ok(new ApiResult()
            {
                Data = null, Error_Code = 0, Msg = $"{clientLifetime.Client}的 Token 过期时间已改为{clientLifetime.Lifetime}", Request = "Post /api/cleint/lifetime"
            }));
        }