2023-04-07 22:10:35 +08:00
|
|
|
using System.ComponentModel.Design;
|
|
|
|
using Demo.Models;
|
|
|
|
|
|
|
|
namespace Demo.Features;
|
|
|
|
|
2023-04-09 16:22:54 +08:00
|
|
|
public class FeatureWrapper : IFeatureWrapper
|
2023-04-07 22:10:35 +08:00
|
|
|
{
|
2023-04-09 16:22:54 +08:00
|
|
|
private readonly IMetadata _metadata;
|
2023-04-07 22:10:35 +08:00
|
|
|
|
2023-04-09 16:22:54 +08:00
|
|
|
protected FeatureList Features { get; }
|
2023-04-07 22:10:35 +08:00
|
|
|
|
2023-04-09 16:22:54 +08:00
|
|
|
public FeatureWrapper(IMetadata metadata, FeatureList? features = null)
|
2023-04-07 22:10:35 +08:00
|
|
|
{
|
2023-04-09 16:22:54 +08:00
|
|
|
_metadata = metadata;
|
|
|
|
Features = features ?? new FeatureList();
|
2023-04-07 22:10:35 +08:00
|
|
|
}
|
|
|
|
|
2023-04-08 08:35:57 +08:00
|
|
|
public void ExecuteAll()
|
2023-04-07 22:10:35 +08:00
|
|
|
{
|
|
|
|
foreach (var feature in Features.Values.OrderBy(f => f.Order))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-04-09 16:22:54 +08:00
|
|
|
feature.Execute(_metadata);
|
|
|
|
if (feature.Finished)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2023-04-07 22:10:35 +08:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2023-04-08 08:35:57 +08:00
|
|
|
feature.OnException(new FeatureExceptionContext(feature, new FeatureException(_metadata, feature, ex)));
|
2023-04-09 16:22:54 +08:00
|
|
|
}
|
2023-04-07 22:10:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Execute(string name)
|
|
|
|
{
|
|
|
|
if (Features.TryGetValue(name, out var feature))
|
|
|
|
{
|
|
|
|
feature.Execute(_metadata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new KeyNotFoundException(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|