Upgrade Nuget
大石头 authored at 2024-11-20 14:03:58
1.87 KiB
NewLife.Remoting
using System.ComponentModel;
using NewLife;
using NewLife.Configuration;
using NewLife.Remoting.Extensions.Models;
using NewLife.Security;
using XCode.Configuration;

namespace IoTZero;

/// <summary>配置</summary>
[Config("IoTZero")]
public class IoTSetting : Config<IoTSetting>, ITokenSetting
{
    #region 静态
    static IoTSetting() => Provider = new DbConfigProvider { UserId = 0, Category = "IoTServer" };
    #endregion

    #region 设备管理
    /// <summary>令牌密钥。用于生成JWT令牌的算法和密钥,如HS256:ABCD1234</summary>
    [Description("令牌密钥。用于生成JWT令牌的算法和密钥,如HS256:ABCD1234")]
    [Category("设备管理")]
    public String TokenSecret { get; set; }

    /// <summary>令牌有效期。默认2*3600秒</summary>
    [Description("令牌有效期。默认2*3600秒")]
    [Category("设备管理")]
    public Int32 TokenExpire { get; set; } = 2 * 3600;

    /// <summary>会话超时。默认600秒</summary>
    [Description("会话超时。默认600秒")]
    [Category("设备管理")]
    public Int32 SessionTimeout { get; set; } = 600;

    /// <summary>自动注册。允许客户端自动注册,默认true</summary>
    [Description("自动注册。允许客户端自动注册,默认true")]
    [Category("设备管理")]
    public Boolean AutoRegister { get; set; } = true;
    #endregion

    #region 数据存储
    /// <summary>历史数据保留时间。默认30天</summary>
    [Description("历史数据保留时间。默认30天")]
    [Category("数据存储")]
    public Int32 DataRetention { get; set; } = 30;
    #endregion

    #region 方法
    /// <summary>加载时触发</summary>
    protected override void OnLoaded()
    {
        if (TokenSecret.IsNullOrEmpty() || TokenSecret.Split(':').Length != 2) TokenSecret = $"HS256:{Rand.NextString(16)}";

        base.OnLoaded();
    }
    #endregion
}