using System;
using XP.Common.License.Enums;
namespace XP.Common.License.Implementations
{
///
/// 授权检查结果(不可变)| License check result (immutable)
///
public sealed class LicenseCheckResult
{
///
/// 消息最大长度 | Maximum message length
///
private const int MaxMessageLength = 512;
///
/// 是否授权成功 | Whether authorization is successful
///
public bool IsAuthorized { get; }
///
/// 结果消息(最大512字符)| Result message (maximum 512 characters)
///
public string Message { get; }
///
/// 授权模式 | License mode
///
public LicenseMode LicenseMode { get; }
///
/// 模块ID | Module ID
///
public ushort ModuleId { get; }
///
/// 授权到期日期 | License expiration date
///
public DateTime? ExpirationDate { get; }
///
/// SMA到期日期 | SMA expiration date
///
public DateTime? SmaDate { get; }
///
/// 浮动许可IP地址 | Floating license IP address
///
public string? FloatingLicenseIp { get; }
///
/// 浮动许可端口 | Floating license port
///
public string? FloatingLicensePort { get; }
///
/// 构造函数 | Constructor
///
/// 是否授权成功 | Whether authorization is successful
/// 结果消息 | Result message
/// 授权模式 | License mode
/// 模块ID | Module ID
/// 授权到期日期 | License expiration date
/// SMA到期日期 | SMA expiration date
/// 浮动许可IP地址 | Floating license IP address
/// 浮动许可端口 | Floating license port
public LicenseCheckResult(
bool isAuthorized,
string message,
LicenseMode licenseMode,
ushort moduleId,
DateTime? expirationDate,
DateTime? smaDate,
string? floatingLicenseIp,
string? floatingLicensePort)
{
IsAuthorized = isAuthorized;
Message = string.IsNullOrEmpty(message)
? string.Empty
: message.Length > MaxMessageLength
? message[..MaxMessageLength]
: message;
LicenseMode = licenseMode;
ModuleId = moduleId;
ExpirationDate = expirationDate;
SmaDate = smaDate;
FloatingLicenseIp = floatingLicenseIp;
FloatingLicensePort = floatingLicensePort;
}
}
}