using TDA.FileIO;
using TDA.StandardTestData;
namespace Ex301.UseRecordReader
{
public static class Ex30101_BasicWorkflow
{
public static void Execute()
{
string? filePath = TDAFileDialog.SelectFile(FileType.stdf);
if (filePath is null || !RecordReader.IsValidStdFile(filePath))
{
Console.WriteLine("不是有效的 STDF 文件,程序退出。");
return;
}
Console.WriteLine($"1. 初始化读取器 (文件: {Path.GetFileName(filePath)})");
using var reader = new RecordReader(filePath);
Console.WriteLine("2. 读取文件头 (FAR):");
if (reader.ReadNext(out Record header) && header is FAR far)
{
Console.WriteLine($" CPU_TYPE = {far.CPU_TYPE}, STDF_VER = {far.STDF_VER}");
}
Console.WriteLine("3. 迭代读取记录:");
int count = 0;
while (reader.ReadNext(out Record record))
{
Console.WriteLine($" [{++count,3}] {record.GetRecordTypeName()} (REC_LEN={record.REC_LEN})");
}
Console.WriteLine($"4. 自动释放资源 (using 语句),共读取 {count} 条记录\n");
}
}
}