2024-09-06 09:13:13 +08:00
|
|
|
|
|
2024-09-12 20:32:54 +08:00
|
|
|
|
using Serein.Library.Api;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
using Serein.Library.Entity;
|
2024-09-12 20:32:54 +08:00
|
|
|
|
using Serein.Library.Enums;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
using Serein.NodeFlow.Base;
|
2024-09-16 19:53:36 +08:00
|
|
|
|
using Serein.NodeFlow.Tool.SereinExpression;
|
2024-08-06 16:09:46 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Serein.NodeFlow.Model
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 条件节点(用于条件控件)
|
|
|
|
|
|
/// </summary>
|
2024-09-15 12:15:32 +08:00
|
|
|
|
public class SingleConditionNode : NodeModelBase
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否为自定义参数
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsCustomData { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 自定义参数值
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public object? CustomData { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 条件表达式
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
public string Expression { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-12 20:32:54 +08:00
|
|
|
|
public override object? Execute(IDynamicContext context)
|
2024-08-06 16:09:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// 接收上一节点参数or自定义参数内容
|
|
|
|
|
|
object? result;
|
|
|
|
|
|
if (IsCustomData)
|
|
|
|
|
|
{
|
|
|
|
|
|
result = CustomData;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
result = PreviousNode?.FlowData;
|
|
|
|
|
|
}
|
2024-09-09 16:42:01 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-09-16 19:53:36 +08:00
|
|
|
|
var isPass = SereinConditionParser.To(result, Expression);
|
2024-09-15 22:07:10 +08:00
|
|
|
|
NextOrientation = isPass ? ConnectionType.IsSucceed : ConnectionType.IsFail;
|
2024-09-09 16:42:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2024-09-15 22:07:10 +08:00
|
|
|
|
NextOrientation = ConnectionType.IsError;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
RuningException = ex;
|
2024-09-09 16:42:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-15 22:07:10 +08:00
|
|
|
|
Console.WriteLine($"{result} {Expression} -> " + NextOrientation);
|
2024-08-06 16:09:46 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-17 14:20:27 +08:00
|
|
|
|
internal override Parameterdata[] GetParameterdatas()
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
2024-09-17 14:20:27 +08:00
|
|
|
|
var value = CustomData switch
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
2024-09-17 14:20:27 +08:00
|
|
|
|
Type when CustomData.GetType() == typeof(int)
|
|
|
|
|
|
&& CustomData.GetType() == typeof(double)
|
|
|
|
|
|
&& CustomData.GetType() == typeof(float)
|
|
|
|
|
|
=> ((double)CustomData).ToString(),
|
|
|
|
|
|
Type when CustomData.GetType() == typeof(bool) => ((bool)CustomData).ToString(),
|
|
|
|
|
|
_ => CustomData?.ToString()!,
|
|
|
|
|
|
};
|
|
|
|
|
|
return [new Parameterdata
|
2024-09-15 12:15:32 +08:00
|
|
|
|
{
|
2024-09-17 14:20:27 +08:00
|
|
|
|
State = IsCustomData,
|
|
|
|
|
|
Expression = Expression,
|
|
|
|
|
|
Value = value,
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal override NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
var node = this;
|
|
|
|
|
|
if (node != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
node.Guid = nodeInfo.Guid;
|
|
|
|
|
|
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Parameterdata? pd = nodeInfo.ParameterData[i];
|
|
|
|
|
|
node.IsCustomData = pd.State;
|
|
|
|
|
|
node.CustomData = pd.Value;
|
|
|
|
|
|
node.Expression = pd.Expression;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-09-15 12:15:32 +08:00
|
|
|
|
}
|
2024-09-17 14:20:27 +08:00
|
|
|
|
return this;
|
2024-09-15 12:15:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-06 16:09:46 +08:00
|
|
|
|
//public override void Execute(DynamicContext context)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// CurrentState = Judge(context, base.MethodDetails);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//private bool Judge(DynamicContext context, MethodDetails md)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// try
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (DelegateCache.GlobalDicDelegates.TryGetValue(md.MethodName, out Delegate del))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// object[] parameters = GetParameters(context, md);
|
|
|
|
|
|
// var temp = del.DynamicInvoke(parameters);
|
|
|
|
|
|
// //context.GetData(GetDyPreviousKey());
|
|
|
|
|
|
// return (bool)temp;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// Debug.Write(ex.Message);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|