2024-12-26 22:24:44 +08:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
using Serein.Library.Utils;
|
|
|
|
|
|
using System;
|
2024-09-20 10:50:32 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
2024-09-22 17:37:32 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2024-09-20 10:50:32 +08:00
|
|
|
|
|
2024-10-20 12:10:57 +08:00
|
|
|
|
namespace Serein.Library
|
2024-09-20 10:50:32 +08:00
|
|
|
|
{
|
2024-10-11 19:31:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 节点调试设置,用于中断节点的运行
|
|
|
|
|
|
/// </summary>
|
2024-10-22 00:13:13 +08:00
|
|
|
|
[NodeProperty(ValuePath = NodeValuePath.DebugSetting)]
|
2024-10-20 21:59:42 +08:00
|
|
|
|
public partial class NodeDebugSetting
|
2024-09-20 10:50:32 +08:00
|
|
|
|
{
|
2024-10-20 21:59:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建属于某个节点的调试设置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="nodeModel"></param>
|
|
|
|
|
|
public NodeDebugSetting(NodeModelBase nodeModel)
|
|
|
|
|
|
{
|
2024-10-23 19:22:27 +08:00
|
|
|
|
NodeModel = nodeModel;
|
2024-10-20 21:59:42 +08:00
|
|
|
|
}
|
2024-10-28 15:21:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 对应的节点
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[PropertyInfo(IsProtection = true)]
|
|
|
|
|
|
private NodeModelBase _nodeModel;
|
|
|
|
|
|
|
2024-09-20 10:50:32 +08:00
|
|
|
|
/// <summary>
|
2024-10-20 12:10:57 +08:00
|
|
|
|
/// 是否使能
|
2024-09-20 10:50:32 +08:00
|
|
|
|
/// </summary>
|
2024-10-20 21:59:42 +08:00
|
|
|
|
[PropertyInfo(IsNotification = true)]
|
|
|
|
|
|
private bool _isEnable = true;
|
2024-09-20 10:50:32 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-12-26 22:24:44 +08:00
|
|
|
|
/// 是否中断节点。
|
2024-09-20 10:50:32 +08:00
|
|
|
|
/// </summary>
|
2024-12-26 22:24:44 +08:00
|
|
|
|
[PropertyInfo(IsNotification = true, CustomCodeAtEnd = "ChangeInterruptState(value);")] // CustomCode = "NodeModel?.Env?.SetNodeInterruptAsync(NodeModel?.Guid, value);"
|
2024-10-22 00:13:13 +08:00
|
|
|
|
private bool _isInterrupt = false;
|
|
|
|
|
|
|
2024-12-26 22:24:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 节点中断
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class NodeDebugSetting
|
|
|
|
|
|
{
|
2024-09-22 17:37:32 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 取消中断的回调函数
|
|
|
|
|
|
/// </summary>
|
2024-12-26 22:24:44 +08:00
|
|
|
|
private Action _cancelInterrupt { get; set; }
|
2024-09-22 17:37:32 +08:00
|
|
|
|
/// <summary>
|
2024-12-26 22:24:44 +08:00
|
|
|
|
/// 取消中断
|
2024-09-22 17:37:32 +08:00
|
|
|
|
/// </summary>
|
2024-12-26 22:24:44 +08:00
|
|
|
|
public Action CancelInterrupt => _cancelInterrupt;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 中断节点
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Func<Task> _getInterruptTask;
|
2024-09-20 10:50:32 +08:00
|
|
|
|
|
2024-12-26 22:24:44 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取中断的Task
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Func<Task> GetInterruptTask => _getInterruptTask;
|
2024-10-11 19:31:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-09-20 10:50:32 +08:00
|
|
|
|
/// <summary>
|
2024-12-26 22:24:44 +08:00
|
|
|
|
/// 改变中断状态
|
2024-09-20 10:50:32 +08:00
|
|
|
|
/// </summary>
|
2024-12-26 22:24:44 +08:00
|
|
|
|
public void ChangeInterruptState(bool state)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (state && _getInterruptTask is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 设置获取中断的委托
|
|
|
|
|
|
_getInterruptTask = () => NodeModel.Env.IOC.Get<FlowInterruptTool>().WaitTriggerAsync(NodeModel.Guid);
|
2025-03-17 10:14:18 +08:00
|
|
|
|
|
2024-12-26 22:24:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (!state)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_getInterruptTask is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 设置解除中断的委托
|
|
|
|
|
|
_cancelInterrupt = () => NodeModel.Env.IOC.Get<FlowInterruptTool>().InvokeTrigger(NodeModel.Guid);
|
|
|
|
|
|
_cancelInterrupt.Invoke();
|
|
|
|
|
|
_getInterruptTask = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-20 10:50:32 +08:00
|
|
|
|
}
|
2024-12-26 22:24:44 +08:00
|
|
|
|
}
|
2024-10-20 21:59:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|