Files
serein-flow/NodeFlow/Model/Nodes/SingleUINode.cs

64 lines
2.1 KiB
C#
Raw Normal View History

2025-03-14 16:04:06 +08:00
using Serein.Library;
using Serein.Library.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serein.NodeFlow.Model.Nodes
2025-03-14 16:04:06 +08:00
{
/// <summary>
/// 单个UI节点适用于需要在流程中嵌入用户自定义控件的场景。
/// </summary>
2025-03-14 16:04:06 +08:00
public class SingleUINode : NodeModelBase
{
/// <summary>
/// 适配的UI控件必须实现IEmbeddedContent接口。
/// </summary>
public IEmbeddedContent? Adapter { get; private set; }
/// <summary>
/// 单个UI节点构造函数初始化流程环境。
/// </summary>
/// <param name="environment"></param>
2025-03-14 16:04:06 +08:00
public SingleUINode(IFlowEnvironment environment) : base(environment)
{
}
/// <summary>
/// 执行节点逻辑适用于嵌入式UI控件的流程节点。
/// </summary>
/// <param name="context"></param>
/// <param name="token"></param>
/// <returns></returns>
public override async Task<FlowResult> ExecutingAsync(IFlowContext context, CancellationToken token)
2025-03-14 16:04:06 +08:00
{
if (token.IsCancellationRequested) return FlowResult.Fail(this.Guid, context, "流程已通过token取消");
2025-03-14 16:04:06 +08:00
if(Adapter is null)
{
var result = await base.ExecutingAsync(context, token);
if (result.Value is IEmbeddedContent adapter)
2025-03-14 16:04:06 +08:00
{
Adapter = adapter;
2025-03-14 16:04:06 +08:00
context.NextOrientation = ConnectionInvokeType.IsSucceed;
}
else
{
context.NextOrientation = ConnectionInvokeType.IsError;
}
}
else
{
var p = context.GetPreviousNode(this.Guid);
var data = context.GetFlowData(p).Value;
var iflowContorl = Adapter.GetFlowControl();
iflowContorl.OnExecuting(data);
2025-03-14 16:04:06 +08:00
}
return FlowResult.OK(this.Guid, context, null);
2025-03-14 16:04:06 +08:00
}
}
}