2024-09-12 20:32:54 +08:00
|
|
|
|
using Serein.Library.Api;
|
|
|
|
|
|
using Serein.Library.Utils;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Serein.Library.Framework.NodeFlow
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 动态流程上下文
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class DynamicContext : IDynamicContext
|
|
|
|
|
|
{
|
2024-09-16 21:38:34 +08:00
|
|
|
|
public DynamicContext(ISereinIOC sereinIoc, IFlowEnvironment flowEnvironment)
|
2024-09-12 20:32:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
SereinIoc = sereinIoc;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
FlowEnvironment = flowEnvironment;
|
2024-09-12 20:32:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
public NodeRunCts NodeRunCts { get; set; }
|
2024-09-16 21:38:34 +08:00
|
|
|
|
public ISereinIOC SereinIoc { get; }
|
2024-09-15 12:15:32 +08:00
|
|
|
|
public IFlowEnvironment FlowEnvironment { get; }
|
2024-09-12 20:32:54 +08:00
|
|
|
|
public Task CreateTimingTask(Action action, int time = 100, int count = -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(NodeRunCts == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2024-09-17 14:20:27 +08:00
|
|
|
|
NodeRunCts = SereinIoc.GetOrRegisterInstantiate<NodeRunCts>();
|
2024-09-12 20:32:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
return Task.Factory.StartNew(async () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeRunCts.Token.ThrowIfCancellationRequested();
|
|
|
|
|
|
await Task.Delay(time);
|
|
|
|
|
|
action.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|