2024-11-04 23:30:52 +08:00
|
|
|
|
using Serein.Library;
|
|
|
|
|
|
using Serein.Library.Api;
|
|
|
|
|
|
using Serein.Library.Utils;
|
|
|
|
|
|
using Serein.Library.Utils.SereinExpression;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Dynamic;
|
|
|
|
|
|
using System.Linq;
|
2024-12-09 22:57:06 +08:00
|
|
|
|
using System.Text;
|
2024-11-04 23:30:52 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Serein.Library
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 基础功能
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
[DynamicFlow(Name ="[基础功能]")]
|
|
|
|
|
|
public class SereinBaseFunction
|
|
|
|
|
|
{
|
2025-05-30 11:53:33 +08:00
|
|
|
|
|
2024-11-04 23:30:52 +08:00
|
|
|
|
[NodeAction(NodeType.Action, "键值对组装")]
|
2025-05-30 11:53:33 +08:00
|
|
|
|
private Dictionary<string, object> SereinKvDataCollectionNode(string argName,
|
2024-11-04 23:30:52 +08:00
|
|
|
|
params object[] value)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var names = argName.Split(';');
|
|
|
|
|
|
var count = Math.Min(value.Length, names.Length);
|
|
|
|
|
|
var dict = new Dictionary<string, object>();
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
dict[names[i]] = value[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
return dict;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[NodeAction(NodeType.Action, "数组组装")]
|
|
|
|
|
|
private object[] SereinListDataCollectionNode(params object[] value)
|
|
|
|
|
|
{
|
|
|
|
|
|
return value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[NodeAction(NodeType.Action, "输出")]
|
|
|
|
|
|
private object[] SereinConsoleNode(params object[] value)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in value)
|
|
|
|
|
|
{
|
2024-11-08 17:30:51 +08:00
|
|
|
|
SereinEnv.WriteLine(InfoType.INFO, item.ToString());
|
2024-11-04 23:30:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
return value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-18 00:05:42 +08:00
|
|
|
|
[NodeAction(NodeType.Action, "逻辑分支")]
|
2025-05-30 11:53:33 +08:00
|
|
|
|
private object SereinLogicalBranch([NodeParam(IsExplicit = false)]bool @bool,
|
|
|
|
|
|
object t_value,
|
|
|
|
|
|
object f_value)
|
2024-12-18 00:05:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
return @bool ? t_value : f_value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-09 22:57:06 +08:00
|
|
|
|
[NodeAction(NodeType.Action, "文本拼接")]
|
|
|
|
|
|
private string SereinTextJoin(params object[] value)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
foreach (var item in value)
|
|
|
|
|
|
{
|
|
|
|
|
|
var tmp = item.ToString();
|
|
|
|
|
|
if (tmp == "\\n")
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.Append(Environment.NewLine);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (tmp == "\\t")
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.Append('\t');
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sb.Append(tmp);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NodeAction(NodeType.Action, "键值对动态构建对象")]
|
|
|
|
|
|
private object SereinKvDataToObject(Dictionary<string, object> dict,
|
|
|
|
|
|
string classTypeName = "newClass_dynamic",
|
|
|
|
|
|
bool IsPrint = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!DynamicObjectHelper.TryResolve(dict, classTypeName, out var result))
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("赋值过程中有错误,请检查属性名和类型!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsPrint)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("创建完成,正在打印结果");
|
|
|
|
|
|
DynamicObjectHelper.PrintObjectProperties(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NodeAction(NodeType.Action, "设置/更新全局数据")]
|
2025-05-30 11:53:33 +08:00
|
|
|
|
private object SereinAddOrUpdateFlowGlobalData(string name, object data)
|
2024-12-09 22:57:06 +08:00
|
|
|
|
{
|
2024-12-12 20:31:50 +08:00
|
|
|
|
SereinEnv.AddOrUpdateFlowGlobalData(name, data);
|
2024-12-09 22:57:06 +08:00
|
|
|
|
return data;
|
|
|
|
|
|
}
|
2024-11-04 23:30:52 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|