39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Workflow.Application.BuildFlow.Common.Services;
|
|
|
|
namespace BuildFlow.Workflow.Tests.Performance;
|
|
|
|
/// <summary>在导出写入阶段触发取消或指定异常,并记录实际输出路径。</summary>
|
|
public sealed class CancellingExportExcelService(
|
|
CancellationTokenSource? cancellation = null,
|
|
Exception? exception = null) : IFormSchemaExcelService
|
|
{
|
|
/// <summary>handler 传入的临时文件路径。</summary>
|
|
public string? OutputPath { get; private set; }
|
|
|
|
public byte[] BuildTemplate(string schemaJson, string formName) => [];
|
|
|
|
public IEnumerable<ExcelParsedRow> Parse(
|
|
string schemaJson,
|
|
Stream xlsxStream,
|
|
int maxRows,
|
|
int maxCellTextLength) => [];
|
|
|
|
/// <summary>记录路径后触发测试指定的失败。</summary>
|
|
public Task WriteExportAsync(
|
|
string schemaJson,
|
|
string formName,
|
|
IAsyncEnumerable<string> dataJsonRows,
|
|
Stream output,
|
|
CancellationToken ct)
|
|
{
|
|
OutputPath = (output as FileStream)?.Name;
|
|
if (cancellation is not null)
|
|
{
|
|
cancellation.Cancel();
|
|
ct.ThrowIfCancellationRequested();
|
|
}
|
|
|
|
throw exception ?? new InvalidOperationException("测试导出写入失败");
|
|
}
|
|
}
|