28 lines
1.3 KiB
C#
28 lines
1.3 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
|
|
namespace Common.Tools
|
|
{
|
|
/// <summary>
|
|
/// 步骤运行时上下文桥接器(命令库与宿主之间的依赖倒置通道)。
|
|
/// <para>
|
|
/// 命令库(Command 项目)不引用宿主类型,无法直接访问步骤管理器的数据;
|
|
/// 宿主(StepRunning)在执行测试步骤前,将当前作用域的步骤耗时查询委托写入
|
|
/// <see cref="StepTimeQuery"/>;命令库中的耗时统计命令在执行时读取该委托完成查询。
|
|
/// </para>
|
|
/// <para>
|
|
/// 使用 <see cref="AsyncLocal{T}"/> 承载:委托随异步执行流(ExecutionContext)流动,
|
|
/// 多台架并发运行时各自持有自己作用域的查询器,天然隔离互不串扰。
|
|
/// </para>
|
|
/// </summary>
|
|
public static class StepRuntimeContext
|
|
{
|
|
/// <summary>
|
|
/// 当前异步执行流的步骤耗时查询委托:(起始序号, 结束序号) → 该范围内步骤运行时间之和(毫秒)。
|
|
/// 由宿主(StepRunning)在每次执行测试步骤方法前设置;未设置时命令侧按未注入处理。
|
|
/// </summary>
|
|
[Browsable(false)]
|
|
public static readonly AsyncLocal<Func<int, int, double>?> StepTimeQuery = new();
|
|
}
|
|
}
|