mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-03 23:06:34 +08:00
流程返回值改为FlowResult,记录节点信息、上下文信息,为以后的流程调用回溯做准备
This commit is contained in:
97
Library/FlowNode/FlowResult.cs
Normal file
97
Library/FlowNode/FlowResult.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Serein.Library.Api;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library
|
||||
{
|
||||
/// <summary>
|
||||
/// 表示空数据
|
||||
/// </summary>
|
||||
/*public readonly struct Unit : IEquatable<Unit>
|
||||
{
|
||||
public static readonly Unit Default = default;
|
||||
public bool Equals(Unit _) => true;
|
||||
public override bool Equals(object obj) => obj is Unit;
|
||||
public override int GetHashCode() => 0;
|
||||
}*/
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 流程返回值的包装
|
||||
/// </summary>
|
||||
public class FlowResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化返回值
|
||||
/// </summary>
|
||||
/// <param name="nodeModel"></param>
|
||||
/// <param name="context"></param>
|
||||
public FlowResult(NodeModelBase nodeModel, IDynamicContext context, object value)
|
||||
{
|
||||
this.NodeGuid = nodeModel.Guid;
|
||||
this.ContextGuid = context.Guid;
|
||||
this.Value = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 空返回值
|
||||
/// </summary>
|
||||
/// <param name="nodeModel"></param>
|
||||
/// <param name="context"></param>
|
||||
public FlowResult(NodeModelBase nodeModel, IDynamicContext context)
|
||||
{
|
||||
this.NodeGuid = nodeModel.Guid;
|
||||
this.ContextGuid = context.Guid;
|
||||
this.Value = Unit.Default;
|
||||
}
|
||||
/// <summary>
|
||||
/// 尝试获取值
|
||||
/// </summary>
|
||||
/// <param name="targetType">目标类型</param>
|
||||
/// <param name="value">返回值</param>
|
||||
/// <returns>指示是否获取成功</returns>
|
||||
/// <exception cref="ArgumentNullException">无法转为对应类型</exception>
|
||||
public bool TryGetValue(Type targetType, out object value)
|
||||
{
|
||||
if (targetType is null)
|
||||
throw new ArgumentNullException(nameof(targetType));
|
||||
|
||||
if (targetType.IsInstanceOfType(Value))
|
||||
{
|
||||
value = Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
value = Unit.Default;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 来源节点Guid
|
||||
/// </summary>
|
||||
public string NodeGuid { get; }
|
||||
/// <summary>
|
||||
/// 来源上下文Guid
|
||||
/// </summary>
|
||||
public string ContextGuid { get; }
|
||||
/// <summary>
|
||||
/// 数据值
|
||||
/// </summary>
|
||||
public object Value { get; private set; }
|
||||
/// <summary>
|
||||
/// 生成时间
|
||||
/// </summary>
|
||||
public DateTime ResultTime { get; } = DateTime.MinValue;
|
||||
|
||||
/// <summary>
|
||||
/// 是否自动回收
|
||||
/// </summary>
|
||||
public bool IsAutoRecovery { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user