mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-16 04:46:34 +08:00
重新优化了NodeModel类;从硬编码类型改为“注册/获取”的方式,为下一步解耦Workbench与节点UI做准备。
新增了“全局数据节点”;保存项目文件时,不同节点可以使用自定义数据保存自身独特的数据,不再借用“方法参数”。 重新设计了运行时的环境输出;增量式生成器现在可以选择在属性变更的前后时间点插入自定义代码;重写了加载项目、保存项目的方法。
This commit is contained in:
@@ -22,6 +22,14 @@ namespace Serein.Library.Api
|
||||
/// </summary>
|
||||
public delegate void ProjectLoadedHandler(ProjectLoadedEventArgs eventArgs);
|
||||
|
||||
/// <summary>
|
||||
/// 项目准备保存
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
public delegate void ProjectSavingHandler(ProjectSavingEventArgs eventArgs);
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载项目文件时成功加载了DLL文件
|
||||
/// </summary>
|
||||
@@ -136,6 +144,13 @@ namespace Serein.Library.Api
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ProjectSavingEventArgs : FlowEventArgs
|
||||
{
|
||||
public ProjectSavingEventArgs()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class LoadDllEventArgs : FlowEventArgs
|
||||
{
|
||||
@@ -259,11 +274,23 @@ namespace Serein.Library.Api
|
||||
|
||||
public class NodeCreateEventArgs : FlowEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 节点添加事件参数
|
||||
/// </summary>
|
||||
/// <param name="nodeModel">节点对象</param>
|
||||
/// <param name="position">位置</param>
|
||||
public NodeCreateEventArgs(object nodeModel, PositionOfUI position)
|
||||
{
|
||||
this.NodeModel = nodeModel;
|
||||
this.Position = position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 区域子项节点添加事件参数
|
||||
/// </summary>
|
||||
/// <param name="nodeModel">节点对象</param>
|
||||
/// <param name="isAddInRegion">是否添加在区域中</param>
|
||||
/// <param name="regeionGuid">区域Guid</param>
|
||||
public NodeCreateEventArgs(object nodeModel, bool isAddInRegion, string regeionGuid)
|
||||
{
|
||||
this.NodeModel = nodeModel;
|
||||
@@ -564,6 +591,11 @@ namespace Serein.Library.Api
|
||||
/// </summary>
|
||||
event ProjectLoadedHandler OnProjectLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// 项目准备保存
|
||||
/// </summary>
|
||||
event ProjectSavingHandler OnProjectSaving;
|
||||
|
||||
/// <summary>
|
||||
/// 节点连接属性改变事件
|
||||
/// </summary>
|
||||
@@ -656,18 +688,24 @@ namespace Serein.Library.Api
|
||||
/// </summary>
|
||||
void StopRemoteServer();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存当前项目
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<SereinProjectData> GetProjectInfoAsync();
|
||||
/// <summary>
|
||||
/// 加载项目文件
|
||||
/// </summary>
|
||||
/// <param name="flowEnvInfo">包含项目信息的远程环境</param>
|
||||
/// <param name="filePath"></param>
|
||||
void LoadProject(FlowEnvInfo flowEnvInfo, string filePath);
|
||||
|
||||
/// <summary>
|
||||
/// 保存项目
|
||||
/// </summary>
|
||||
void SaveProject();
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前项目信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<SereinProjectData> GetProjectInfoAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 加载远程环境
|
||||
/// </summary>
|
||||
|
||||
@@ -93,6 +93,10 @@ namespace Serein.Library
|
||||
/// 条件节点区域
|
||||
/// </summary>
|
||||
ConditionRegion,
|
||||
/// <summary>
|
||||
/// 全局数据
|
||||
/// </summary>
|
||||
GlobalData,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Serein.Library
|
||||
/// <summary>
|
||||
/// 中断级别,暂时停止继续执行后继分支。
|
||||
/// </summary>
|
||||
[PropertyInfo(IsNotification = true, CustomCode = "NodeModel?.Env?.SetNodeInterruptAsync(NodeModel?.Guid, value);")] // CustomCode = "NodeModel?.Env?.SetNodeInterruptAsync(NodeModel?.Guid, value);"
|
||||
[PropertyInfo(IsNotification = true, CustomCodeAtEnd = "NodeModel?.Env?.SetNodeInterruptAsync(NodeModel?.Guid, value);")] // CustomCode = "NodeModel?.Env?.SetNodeInterruptAsync(NodeModel?.Guid, value);"
|
||||
private bool _isInterrupt = false;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -72,7 +72,10 @@ namespace Serein.Library
|
||||
/// <summary>
|
||||
/// 实体节点创建完成后调用的方法,调用时间早于 LoadInfo() 方法
|
||||
/// </summary>
|
||||
public abstract void OnCreating();
|
||||
public virtual void OnCreating()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public NodeModelBase(IFlowEnvironment environment)
|
||||
{
|
||||
|
||||
@@ -28,13 +28,55 @@ namespace Serein.Library
|
||||
/// </summary>
|
||||
public abstract partial class NodeModelBase : IDynamicFlowNode
|
||||
{
|
||||
#region 节点移除相关
|
||||
/// <summary>
|
||||
/// 移除该节点
|
||||
/// </summary>
|
||||
public virtual void Remove()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 导出/导入项目文件节点信息
|
||||
|
||||
/// <summary>
|
||||
/// 获取节点参数
|
||||
/// 输出方法参数信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract ParameterData[] GetParameterdatas();
|
||||
public virtual ParameterData[] SaveParameterInfo()
|
||||
{
|
||||
if(MethodDetails.ParameterDetailss == null)
|
||||
{
|
||||
return new ParameterData[0];
|
||||
}
|
||||
if (MethodDetails.ParameterDetailss.Length > 0)
|
||||
{
|
||||
return MethodDetails.ParameterDetailss
|
||||
.Select(it => new ParameterData
|
||||
{
|
||||
SourceNodeGuid = it.ArgDataSourceNodeGuid,
|
||||
SourceType = it.ArgDataSourceType.ToString(),
|
||||
State = it.IsExplicitData,
|
||||
Value = it.DataValue,
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ParameterData[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存自定义信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual NodeInfo SaveCustomData(NodeInfo nodeInfo)
|
||||
{
|
||||
return nodeInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出为节点信息
|
||||
@@ -43,16 +85,15 @@ namespace Serein.Library
|
||||
public virtual NodeInfo ToInfo()
|
||||
{
|
||||
// if (MethodDetails == null) return null;
|
||||
|
||||
|
||||
var trueNodes = SuccessorNodes[ConnectionInvokeType.IsSucceed].Select(item => item.Guid); // 真分支
|
||||
var falseNodes = SuccessorNodes[ConnectionInvokeType.IsFail].Select(item => item.Guid);// 假分支
|
||||
var errorNodes = SuccessorNodes[ConnectionInvokeType.IsError].Select(item => item.Guid);// 异常分支
|
||||
var upstreamNodes = SuccessorNodes[ConnectionInvokeType.Upstream].Select(item => item.Guid);// 上游分支
|
||||
|
||||
// 生成参数列表
|
||||
ParameterData[] parameterData = GetParameterdatas();
|
||||
ParameterData[] parameterData = SaveParameterInfo();
|
||||
|
||||
return new NodeInfo
|
||||
NodeInfo nodeInfo = new NodeInfo
|
||||
{
|
||||
Guid = Guid,
|
||||
AssemblyName = MethodDetails.AssemblyName,
|
||||
@@ -66,6 +107,17 @@ namespace Serein.Library
|
||||
ErrorNodes = errorNodes.ToArray(),
|
||||
Position = Position,
|
||||
};
|
||||
nodeInfo = SaveCustomData(nodeInfo);
|
||||
return nodeInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载自定义数据
|
||||
/// </summary>
|
||||
/// <param name="nodeInfo"></param>
|
||||
public virtual void LoadCustomData(NodeInfo nodeInfo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,78 +125,53 @@ namespace Serein.Library
|
||||
/// </summary>
|
||||
/// <param name="nodeInfo"></param>
|
||||
/// <returns></returns>
|
||||
public virtual NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
public virtual void LoadInfo(NodeInfo nodeInfo)
|
||||
{
|
||||
this.Guid = nodeInfo.Guid;
|
||||
|
||||
if (nodeInfo.Position is null)
|
||||
this.Position = nodeInfo.Position ?? new PositionOfUI(0, 0);// 加载位置信息
|
||||
var md = this.MethodDetails; // 当前节点的方法说明
|
||||
if (md != null)
|
||||
{
|
||||
nodeInfo.Position = new PositionOfUI(0, 0);
|
||||
}
|
||||
this.Position = nodeInfo.Position;// 加载位置信息
|
||||
if (this.MethodDetails != null)
|
||||
{
|
||||
if(this.MethodDetails.ParameterDetailss is null)
|
||||
if(md.ParameterDetailss == null)
|
||||
{
|
||||
this.MethodDetails.ParameterDetailss = new ParameterDetails[nodeInfo.ParameterData.Length];
|
||||
this.MethodDetails.ParameterDetailss = nodeInfo.ParameterData.Select((pd,index) =>
|
||||
{
|
||||
return new ParameterDetails()
|
||||
{
|
||||
Index = index,
|
||||
NodeModel = this,
|
||||
DataType = typeof(object),
|
||||
ExplicitType = typeof(object),
|
||||
Name = string.Empty,
|
||||
ExplicitTypeName = "Value",
|
||||
IsExplicitData = pd.State,
|
||||
DataValue = pd.Value,
|
||||
ArgDataSourceType = EnumHelper.ConvertEnum<ConnectionArgSourceType>(pd.SourceType),
|
||||
ArgDataSourceNodeGuid = pd.SourceNodeGuid,
|
||||
};
|
||||
}).ToArray();
|
||||
md.ParameterDetailss = new ParameterDetails[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
var md = this.MethodDetails; // 当前节点的方法说明
|
||||
var pds = md.ParameterDetailss; // 当前节点的入参描述数组
|
||||
if (nodeInfo.ParameterData.Length > pds.Length && md.HasParamsArg)
|
||||
{
|
||||
// 保存的参数信息项数量大于方法本身的方法入参数量(可能存在可变入参)
|
||||
var length = nodeInfo.ParameterData.Length - pds.Length; // 需要扩容的长度
|
||||
this.MethodDetails.ParameterDetailss = ArrayHelper.Expansion(pds, length); // 扩容入参描述数组
|
||||
pds = this.MethodDetails.ParameterDetailss;
|
||||
var startParmsPd = pds[md.ParamsArgIndex]; // 获取可变入参参数描述
|
||||
for(int i = md.ParamsArgIndex + 1; i <= md.ParamsArgIndex + length; i++)
|
||||
{
|
||||
pds[i] = startParmsPd.CloneOfModel(this);
|
||||
pds[i].Index = pds[i-1].Index + 1;
|
||||
pds[i].IsParams = true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
{
|
||||
if(i >= pds.Length)
|
||||
{
|
||||
Env.WriteLine(InfoType.ERROR, $"保存的参数数量大于方法此时的入参参数数量:[{nodeInfo.Guid}][{nodeInfo.MethodName}]");
|
||||
LoadCustomData(nodeInfo); // 加载自定义数据
|
||||
|
||||
break;
|
||||
}
|
||||
var pd = pds[i];
|
||||
ParameterData pdInfo = nodeInfo.ParameterData[i];
|
||||
pd.IsExplicitData = pdInfo.State;
|
||||
pd.DataValue = pdInfo.Value;
|
||||
pd.ArgDataSourceType = EnumHelper.ConvertEnum<ConnectionArgSourceType>(pdInfo.SourceType);
|
||||
pd.ArgDataSourceNodeGuid = pdInfo.SourceNodeGuid;
|
||||
|
||||
var pds = md.ParameterDetailss; // 当前节点的入参描述数组
|
||||
#region 类库方法型节点加载参数
|
||||
if (nodeInfo.ParameterData.Length > pds.Length && md.HasParamsArg)
|
||||
{
|
||||
// 保存的参数信息项数量大于方法本身的方法入参数量(可能存在可变入参)
|
||||
var length = nodeInfo.ParameterData.Length - pds.Length; // 需要扩容的长度
|
||||
this.MethodDetails.ParameterDetailss = ArrayHelper.Expansion(pds, length); // 扩容入参描述数组
|
||||
pds = md.ParameterDetailss; // 当前节点的入参描述数组
|
||||
var startParmsPd = pds[md.ParamsArgIndex]; // 获取可变入参参数描述
|
||||
for (int i = md.ParamsArgIndex + 1; i <= md.ParamsArgIndex + length; i++)
|
||||
{
|
||||
pds[i] = startParmsPd.CloneOfModel(this);
|
||||
pds[i].Index = pds[i - 1].Index + 1;
|
||||
pds[i].IsParams = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
{
|
||||
if (i >= pds.Length)
|
||||
{
|
||||
Env.WriteLine(InfoType.ERROR, $"保存的参数数量大于方法此时的入参参数数量:[{nodeInfo.Guid}][{nodeInfo.MethodName}]");
|
||||
break;
|
||||
}
|
||||
var pd = pds[i];
|
||||
ParameterData pdInfo = nodeInfo.ParameterData[i];
|
||||
pd.IsExplicitData = pdInfo.State;
|
||||
pd.DataValue = pdInfo.Value;
|
||||
pd.ArgDataSourceType = EnumHelper.ConvertEnum<ConnectionArgSourceType>(pdInfo.SourceType);
|
||||
pd.ArgDataSourceNodeGuid = pdInfo.SourceNodeGuid;
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -617,7 +644,6 @@ namespace Serein.Library
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Serein.Library.Api;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serein.Library.Api;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
@@ -244,6 +245,11 @@ namespace Serein.Library
|
||||
/// 是否选中(暂时无效)
|
||||
/// </summary>
|
||||
public bool IsSelect { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义数据
|
||||
/// </summary>
|
||||
public dynamic CustomData { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace Serein.Library
|
||||
[NodeAction(NodeType.Action, "设置/更新全局数据")]
|
||||
private object SereinAddOrUpdateFlowGlobalData(string name,object data)
|
||||
{
|
||||
SereinEnv.EnvGlobalData.AddOrUpdate(name, data,(k,o)=> data);
|
||||
SereinEnv.AddOrUpdateFlowGlobalData(name, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Serein.Library.Utils
|
||||
return (TResult)data.ToConvert(type);
|
||||
|
||||
}
|
||||
public static object ToConvert(this object data,Type type)
|
||||
public static object ToConvert(this object data, Type type)
|
||||
{
|
||||
if (type.IsValueType)
|
||||
{
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Serein.Library.Utils
|
||||
{
|
||||
@@ -13,14 +15,69 @@ namespace Serein.Library.Utils
|
||||
{
|
||||
private static IFlowEnvironment environment;
|
||||
|
||||
#region 全局数据(暂时使用静态全局变量)
|
||||
/// <summary>
|
||||
/// 记录全局数据
|
||||
/// </summary>
|
||||
public static ConcurrentDictionary<string, object> EnvGlobalData { get; } = new ConcurrentDictionary<string, object>();
|
||||
private static ConcurrentDictionary<string, object> EnvGlobalData { get; } = new ConcurrentDictionary<string, object>();
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新全局数据
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static void AddOrUpdateFlowGlobalData(string name, object data)
|
||||
{
|
||||
SereinEnv.EnvGlobalData.AddOrUpdate(name, data, (k, o) => data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更改某个数据的名称
|
||||
/// </summary>
|
||||
/// <param name="oldName">旧名称</param>
|
||||
/// <param name="newName">新名称</param>
|
||||
/// <returns></returns>
|
||||
public static bool ChangeNameFlowGlobalData(string oldName, string newName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(oldName) || string.IsNullOrEmpty(newName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// 确保存在,然后尝试移除
|
||||
if (SereinEnv.EnvGlobalData.ContainsKey(oldName)
|
||||
&& SereinEnv.EnvGlobalData.TryRemove(oldName, out var data))
|
||||
{
|
||||
SereinEnv.EnvGlobalData.AddOrUpdate(newName, data, (k, o) => data);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全局数据
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public static object GetFlowGlobalData(string name)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(name) && SereinEnv.EnvGlobalData.TryGetValue(name, out var data))
|
||||
{
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 清空全局数据
|
||||
/// </summary>
|
||||
public static void ClearGlobalData()
|
||||
/// <returns></returns>
|
||||
public static void ClearFlowGlobalData()
|
||||
{
|
||||
foreach (var nodeObj in EnvGlobalData.Values)
|
||||
{
|
||||
@@ -37,8 +94,12 @@ namespace Serein.Library.Utils
|
||||
}
|
||||
}
|
||||
EnvGlobalData.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -510,9 +510,7 @@ namespace Serein.Library.Utils.SereinExpression
|
||||
private static object GetGlobleData(object value, string expression)
|
||||
{
|
||||
var keyName = expression;
|
||||
SereinEnv.EnvGlobalData.TryGetValue(keyName, out var data);
|
||||
|
||||
return data;
|
||||
return SereinEnv.GetFlowGlobalData(keyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user