You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
218 lines
6.9 KiB
218 lines
6.9 KiB
using CellularManagement.Domain.Abstractions;
|
|
|
|
namespace CellularManagement.Domain.Entities.Terminal;
|
|
|
|
/// <summary>
|
|
/// ADB操作实体
|
|
/// </summary>
|
|
public class AdbOperation : AuditableEntity
|
|
{
|
|
/// <summary>
|
|
/// 执行的ADB命令
|
|
/// </summary>
|
|
public string Command { get; private set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// ADB操作的描述
|
|
/// </summary>
|
|
public string Description { get; private set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// 命令执行时所依赖的路径(绝对路径或相对路径)
|
|
/// </summary>
|
|
public string Path { get; private set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// 是否启用绝对路径,默认值为false
|
|
/// </summary>
|
|
public bool UseAbsolutePath { get; private set; } = false;
|
|
|
|
/// <summary>
|
|
/// 是否启用,默认值为true
|
|
/// </summary>
|
|
public bool IsEnabled { get; private set; } = true;
|
|
|
|
/// <summary>
|
|
/// 执行命令完需要等待的时间(毫秒),默认值为0
|
|
/// </summary>
|
|
public int WaitTimeMs { get; private set; } = 0;
|
|
|
|
/// <summary>
|
|
/// 操作截图数据(字节数组)
|
|
/// </summary>
|
|
public byte[]? ScreenshotData { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 设备ID
|
|
/// </summary>
|
|
public string DeviceId { get; private set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// 私有构造函数,确保通过工厂方法创建实例
|
|
/// </summary>
|
|
private AdbOperation() { }
|
|
|
|
/// <summary>
|
|
/// 创建ADB操作
|
|
/// </summary>
|
|
/// <param name="command">执行的ADB命令</param>
|
|
/// <param name="description">ADB操作的描述</param>
|
|
/// <param name="path">命令执行时所依赖的路径</param>
|
|
/// <param name="useAbsolutePath">是否启用绝对路径</param>
|
|
/// <param name="createdBy">创建人</param>
|
|
/// <param name="deviceId">设备ID</param>
|
|
/// <param name="isEnabled">是否启用,默认true</param>
|
|
/// <param name="waitTimeMs">执行命令完需要等待的时间(毫秒),默认0</param>
|
|
/// <param name="screenshotData">操作截图数据,可选</param>
|
|
/// <returns>ADB操作实例</returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新ADB操作
|
|
/// </summary>
|
|
/// <param name="command">执行的ADB命令</param>
|
|
/// <param name="description">ADB操作的描述</param>
|
|
/// <param name="path">命令执行时所依赖的路径</param>
|
|
/// <param name="useAbsolutePath">是否启用绝对路径</param>
|
|
/// <param name="isEnabled">是否启用</param>
|
|
/// <param name="waitTimeMs">执行命令完需要等待的时间(毫秒)</param>
|
|
/// <param name="updatedBy">更新人</param>
|
|
/// <param name="screenshotData">操作截图数据,可选</param>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换绝对路径设置
|
|
/// </summary>
|
|
/// <param name="updatedBy">更新人</param>
|
|
public void ToggleAbsolutePath(string updatedBy)
|
|
{
|
|
UseAbsolutePath = !UseAbsolutePath;
|
|
SetUpdated(updatedBy);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启用ADB操作
|
|
/// </summary>
|
|
/// <param name="updatedBy">更新人</param>
|
|
public void Enable(string updatedBy)
|
|
{
|
|
IsEnabled = true;
|
|
SetUpdated(updatedBy);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 禁用ADB操作
|
|
/// </summary>
|
|
/// <param name="updatedBy">更新人</param>
|
|
public void Disable(string updatedBy)
|
|
{
|
|
IsEnabled = false;
|
|
SetUpdated(updatedBy);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置等待时间
|
|
/// </summary>
|
|
/// <param name="waitTimeMs">等待时间(毫秒)</param>
|
|
/// <param name="updatedBy">更新人</param>
|
|
public void SetWaitTime(int waitTimeMs, string updatedBy)
|
|
{
|
|
if (waitTimeMs < 0)
|
|
throw new ArgumentException("等待时间不能为负数", nameof(waitTimeMs));
|
|
|
|
WaitTimeMs = waitTimeMs;
|
|
SetUpdated(updatedBy);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置截图数据
|
|
/// </summary>
|
|
/// <param name="screenshotData">截图数据</param>
|
|
/// <param name="updatedBy">更新人</param>
|
|
public void SetScreenshotData(byte[]? screenshotData, string updatedBy)
|
|
{
|
|
ScreenshotData = screenshotData;
|
|
SetUpdated(updatedBy);
|
|
}
|
|
|
|
}
|
|
|