using CellularManagement.Domain.Abstractions; namespace CellularManagement.Domain.Entities.Terminal; /// /// ADB操作实体 /// public class AdbOperation : AuditableEntity { /// /// 执行的ADB命令 /// public string Command { get; private set; } = string.Empty; /// /// ADB操作的描述 /// public string Description { get; private set; } = string.Empty; /// /// 命令执行时所依赖的路径(绝对路径或相对路径) /// public string Path { get; private set; } = string.Empty; /// /// 是否启用绝对路径,默认值为false /// public bool UseAbsolutePath { get; private set; } = false; /// /// 是否启用,默认值为true /// public bool IsEnabled { get; private set; } = true; /// /// 执行命令完需要等待的时间(毫秒),默认值为0 /// public int WaitTimeMs { get; private set; } = 0; /// /// 操作截图数据(字节数组) /// public byte[]? ScreenshotData { get; private set; } /// /// 设备ID /// public string DeviceId { get; private set; } = string.Empty; /// /// 私有构造函数,确保通过工厂方法创建实例 /// private AdbOperation() { } /// /// 创建ADB操作 /// /// 执行的ADB命令 /// ADB操作的描述 /// 命令执行时所依赖的路径 /// 是否启用绝对路径 /// 创建人 /// 设备ID /// 是否启用,默认true /// 执行命令完需要等待的时间(毫秒),默认0 /// 操作截图数据,可选 /// ADB操作实例 public static AdbOperation Create( string command, string description, string path, bool useAbsolutePath, string createdBy, string deviceId, bool isEnabled = true, int waitTimeMs = 0, byte[]? screenshotData = null) { if (string.IsNullOrWhiteSpace(command)) throw new ArgumentException("ADB命令不能为空", nameof(command)); if (string.IsNullOrWhiteSpace(description)) throw new ArgumentException("操作描述不能为空", nameof(description)); if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("路径不能为空", nameof(path)); if (string.IsNullOrWhiteSpace(createdBy)) throw new ArgumentException("创建人不能为空", nameof(createdBy)); if (string.IsNullOrWhiteSpace(deviceId)) throw new ArgumentException("设备ID不能为空", nameof(deviceId)); if (waitTimeMs < 0) throw new ArgumentException("等待时间不能为负数", nameof(waitTimeMs)); var adbOperation = new AdbOperation { Command = command.Trim(), Description = description.Trim(), Path = path.Trim(), UseAbsolutePath = useAbsolutePath, IsEnabled = isEnabled, WaitTimeMs = waitTimeMs, ScreenshotData = screenshotData, DeviceId = deviceId.Trim() }; // 设置审计信息 adbOperation.SetCreated(createdBy); return adbOperation; } /// /// 更新ADB操作 /// /// 执行的ADB命令 /// ADB操作的描述 /// 命令执行时所依赖的路径 /// 是否启用绝对路径 /// 是否启用 /// 执行命令完需要等待的时间(毫秒) /// 更新人 /// 操作截图数据,可选 public void Update( string command, string description, string path, bool useAbsolutePath, bool isEnabled, int waitTimeMs, string updatedBy, byte[]? screenshotData = null) { if (string.IsNullOrWhiteSpace(command)) throw new ArgumentException("ADB命令不能为空", nameof(command)); if (string.IsNullOrWhiteSpace(description)) throw new ArgumentException("操作描述不能为空", nameof(description)); if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("路径不能为空", nameof(path)); if (string.IsNullOrWhiteSpace(updatedBy)) throw new ArgumentException("更新人不能为空", nameof(updatedBy)); if (waitTimeMs < 0) throw new ArgumentException("等待时间不能为负数", nameof(waitTimeMs)); Command = command.Trim(); Description = description.Trim(); Path = path.Trim(); UseAbsolutePath = useAbsolutePath; IsEnabled = isEnabled; WaitTimeMs = waitTimeMs; ScreenshotData = screenshotData; // 设置审计信息 SetUpdated(updatedBy); } /// /// 切换绝对路径设置 /// /// 更新人 public void ToggleAbsolutePath(string updatedBy) { UseAbsolutePath = !UseAbsolutePath; SetUpdated(updatedBy); } /// /// 启用ADB操作 /// /// 更新人 public void Enable(string updatedBy) { IsEnabled = true; SetUpdated(updatedBy); } /// /// 禁用ADB操作 /// /// 更新人 public void Disable(string updatedBy) { IsEnabled = false; SetUpdated(updatedBy); } /// /// 设置等待时间 /// /// 等待时间(毫秒) /// 更新人 public void SetWaitTime(int waitTimeMs, string updatedBy) { if (waitTimeMs < 0) throw new ArgumentException("等待时间不能为负数", nameof(waitTimeMs)); WaitTimeMs = waitTimeMs; SetUpdated(updatedBy); } /// /// 设置截图数据 /// /// 截图数据 /// 更新人 public void SetScreenshotData(byte[]? screenshotData, string updatedBy) { ScreenshotData = screenshotData; SetUpdated(updatedBy); } }