2026-07-03 10:47:27 +08:00
|
|
|
namespace WCTDataMiner.Core.Parsers;
|
2026-07-02 18:13:56 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通用解析器接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
public interface IParser<TRecord>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断是否可以解析该行
|
|
|
|
|
/// </summary>
|
|
|
|
|
bool CanParse(string line);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 解析日志行
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="line">日志行内容</param>
|
|
|
|
|
/// <param name="scenarioId">关联的测试场景ID</param>
|
|
|
|
|
ParseResult<TRecord> Parse(string line, Guid scenarioId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 解析结果
|
|
|
|
|
/// </summary>
|
|
|
|
|
public record ParseResult<TRecord>
|
|
|
|
|
{
|
|
|
|
|
public bool IsSuccess { get; init; }
|
|
|
|
|
public TRecord? Record { get; init; }
|
|
|
|
|
public string? ErrorType { get; init; }
|
|
|
|
|
public string? ErrorMessage { get; init; }
|
|
|
|
|
|
|
|
|
|
public static ParseResult<TRecord> Success(TRecord record) =>
|
|
|
|
|
new() { IsSuccess = true, Record = record };
|
|
|
|
|
|
|
|
|
|
public static ParseResult<TRecord> Failure(string errorType, string errorMessage) =>
|
|
|
|
|
new() { IsSuccess = false, ErrorType = errorType, ErrorMessage = errorMessage };
|
|
|
|
|
}
|