2023-04-07 22:10:35 +08:00
|
|
|
using Demo.Models;
|
|
|
|
|
|
|
|
namespace Demo.Features;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 抽象功能类
|
|
|
|
/// </summary>
|
2023-04-08 08:35:57 +08:00
|
|
|
public abstract class Feature
|
2023-04-07 22:10:35 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 执行顺序
|
|
|
|
/// </summary>
|
|
|
|
public int Order { get; init; }
|
|
|
|
|
|
|
|
public bool Finished { get; protected set; }
|
|
|
|
|
|
|
|
public string Name { get; init; } = String.Empty;
|
|
|
|
|
2023-04-08 08:35:57 +08:00
|
|
|
public abstract void Execute(IMetadata metadata);
|
2023-04-07 22:10:35 +08:00
|
|
|
|
2023-04-08 08:35:57 +08:00
|
|
|
public virtual ValueTask ExecuteAsync(IMetadata metadata)
|
2023-04-07 22:10:35 +08:00
|
|
|
{
|
|
|
|
Execute(metadata);
|
|
|
|
return ValueTask.CompletedTask;
|
|
|
|
}
|
|
|
|
|
2023-04-08 08:35:57 +08:00
|
|
|
public virtual void OnException(FeatureExceptionContext context)
|
2023-04-07 22:10:35 +08:00
|
|
|
{
|
|
|
|
throw context.Exception;
|
|
|
|
}
|
|
|
|
|
2023-04-08 08:35:57 +08:00
|
|
|
public virtual ValueTask OnExceptionAsync(FeatureExceptionContext context)
|
2023-04-07 22:10:35 +08:00
|
|
|
{
|
|
|
|
throw context.Exception;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-08 08:35:57 +08:00
|
|
|
public delegate void FeatureFunction(Feature feature, IMetadata metadata);
|
2023-04-07 22:10:35 +08:00
|
|
|
|
2023-04-08 08:35:57 +08:00
|
|
|
public delegate ValueTask FeatureFunctionAsync(Feature feature, IMetadata metadata);
|