mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-17 13:26:34 +08:00
优化了节点连接
This commit is contained in:
@@ -63,13 +63,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <para>表示是否正在控制远程</para>
|
||||
/// <para>Local control remote env</para>
|
||||
/// </summary>
|
||||
public bool IsLcR { get; set; }
|
||||
/// <summary>
|
||||
/// <para>表示是否受到远程控制</para>
|
||||
/// <para>Remote control local env</para>
|
||||
/// </summary>
|
||||
public bool IsRcL { get; set; }
|
||||
|
||||
public bool IsControlRemoteEnv { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -81,6 +75,7 @@ namespace Serein.NodeFlow.Env
|
||||
if (clientMsgManage is null)
|
||||
{
|
||||
clientMsgManage = new MsgControllerOfServer(this);
|
||||
//clientMsgManage = new MsgControllerOfServer(this,"123456");
|
||||
}
|
||||
_ = clientMsgManage.StartRemoteServerAsync(port);
|
||||
}
|
||||
@@ -657,7 +652,7 @@ namespace Serein.NodeFlow.Env
|
||||
&& NodeModels.TryGetValue(pd.ArgDataSourceNodeGuid, out var fromNode))
|
||||
{
|
||||
|
||||
ConnectGerResultOfNode(fromNode, toNode, pd.ArgDataSourceType, pd.Index);
|
||||
await ConnectArgSourceOfNodeAsync(fromNode, toNode, pd.ArgDataSourceType, pd.Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -678,7 +673,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <param name="token">密码</param>
|
||||
public async Task<(bool, RemoteMsgUtil)> ConnectRemoteEnv(string addres, int port, string token)
|
||||
{
|
||||
if (IsLcR)
|
||||
if (IsControlRemoteEnv)
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"当前已经连接远程环境");
|
||||
return (false, null);
|
||||
@@ -702,7 +697,7 @@ namespace Serein.NodeFlow.Env
|
||||
return (false, null);
|
||||
}
|
||||
await Console.Out.WriteLineAsync("连接成功,开始验证Token");
|
||||
IsLcR = true;
|
||||
IsControlRemoteEnv = true;
|
||||
return (true, remoteMsgUtil);
|
||||
}
|
||||
|
||||
@@ -711,7 +706,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// </summary>
|
||||
public void ExitRemoteEnv()
|
||||
{
|
||||
IsLcR = false;
|
||||
IsControlRemoteEnv = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -916,7 +911,7 @@ namespace Serein.NodeFlow.Env
|
||||
var fromNode = GuidToModel(fromNodeGuid);
|
||||
var toNode = GuidToModel(toNodeGuid);
|
||||
if (fromNode is null || toNode is null) return false;
|
||||
(var type,var state) = CheckConnect(fromNode, toNode, fromNodeJunctionType, toNodeJunctionType);
|
||||
(var type, var state) = CheckConnect(fromNode, toNode, fromNodeJunctionType, toNodeJunctionType);
|
||||
if (!state)
|
||||
{
|
||||
Console.WriteLine("出现非预期的连接行为");
|
||||
@@ -977,7 +972,7 @@ namespace Serein.NodeFlow.Env
|
||||
}
|
||||
|
||||
// 确定方法入参关系
|
||||
state = ConnectGerResultOfNode(fromNode, toNode, connectionArgSourceType, argIndex); // 本地环境进行连接
|
||||
state = await ConnectArgSourceOfNodeAsync(fromNode, toNode, connectionArgSourceType, argIndex); // 本地环境进行连接
|
||||
}
|
||||
return state;
|
||||
|
||||
@@ -1291,21 +1286,36 @@ namespace Serein.NodeFlow.Env
|
||||
{
|
||||
var nodeModel = GuidToModel(nodeGuid);
|
||||
if (nodeModel is null) return;
|
||||
if (NodeValueChangeLogger.Remove((nodeGuid, path, value)))
|
||||
{
|
||||
// 说明存在过重复的修改
|
||||
return;
|
||||
}
|
||||
NodeValueChangeLogger.Add((nodeGuid, path, value));
|
||||
var setExp = $"@Set .{path} = {value}"; // 生成 set 表达式
|
||||
//var getExp = $"@Get .{path}";
|
||||
SerinExpressionEvaluator.Evaluate(setExp, nodeModel, out _); // 更改对应的数据
|
||||
//var getResult = SerinExpressionEvaluator.Evaluate(getExp, nodeModel, out _);
|
||||
//Console.WriteLine($"Set表达式:{setExp},result : {getResult}");
|
||||
|
||||
SerinExpressionEvaluator.Evaluate($"@Set .{path} = {value}", nodeModel, out _); // 更改对应的数据
|
||||
|
||||
//if (NodeValueChangeLogger.Remove((nodeGuid, path, value)))
|
||||
//{
|
||||
// // 说明存在过重复的修改
|
||||
// return;
|
||||
//}
|
||||
//NodeValueChangeLogger.Add((nodeGuid, path, value));
|
||||
|
||||
//lock (NodeValueChangeLogger)
|
||||
//{
|
||||
|
||||
// Interlocked.Add(ref i, 1);
|
||||
// Console.WriteLine(i);
|
||||
// var getExp = $"@Get .{path}";
|
||||
// var setExp = $"@Set .{path} = {value}"; // 生成 set 表达式
|
||||
// var oldValue = SerinExpressionEvaluator.Evaluate(getExp, nodeModel, out _);
|
||||
// if(oldValue != value)
|
||||
// {
|
||||
// Console.WriteLine($"旧值:{getExp},result : {oldValue}");
|
||||
// SerinExpressionEvaluator.Evaluate(setExp, nodeModel, out _); // 更改对应的数据
|
||||
// Console.WriteLine($"新值:{getExp},result : {SerinExpressionEvaluator.Evaluate(getExp, nodeModel, out _)}");
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1487,7 +1497,7 @@ namespace Serein.NodeFlow.Env
|
||||
Console.WriteLine($"无法加载方法信息:{assemblyName}-{type}-{method}");
|
||||
continue;
|
||||
}
|
||||
md.MethodTips = flowName + md.MethodTips;
|
||||
md.MethodAnotherName = flowName + md.MethodAnotherName;
|
||||
if (MethodDelegates.TryAdd(md.MethodName, del))
|
||||
{
|
||||
methodDetails.Add(md);
|
||||
@@ -1702,14 +1712,23 @@ namespace Serein.NodeFlow.Env
|
||||
/// <param name="connectionArgSourceType"></param>
|
||||
/// <param name="argIndex"></param>
|
||||
/// <returns></returns>
|
||||
private bool ConnectGerResultOfNode(NodeModelBase fromNode,
|
||||
private async Task<bool> ConnectArgSourceOfNodeAsync(NodeModelBase fromNode,
|
||||
NodeModelBase toNode,
|
||||
ConnectionArgSourceType connectionArgSourceType,
|
||||
int argIndex)
|
||||
{
|
||||
|
||||
if (!string.IsNullOrEmpty(toNode.MethodDetails.ParameterDetailss[argIndex].ArgDataSourceNodeGuid))
|
||||
{
|
||||
//if(toNode.MethodDetails.ParameterDetailss[argIndex].ArgDataSourceType == connectionArgSourceType)
|
||||
//{
|
||||
// return ;
|
||||
//}
|
||||
await RemoteConnectAsync(fromNode,toNode,argIndex); // 已经存在连接,将其移除
|
||||
}
|
||||
toNode.MethodDetails.ParameterDetailss[argIndex].ArgDataSourceNodeGuid = fromNode.Guid;
|
||||
toNode.MethodDetails.ParameterDetailss[argIndex].ArgDataSourceType = connectionArgSourceType;
|
||||
UIContextOperation?.Invoke(() =>
|
||||
await UIContextOperation.InvokeAsync(() =>
|
||||
OnNodeConnectChange?.Invoke(
|
||||
new NodeConnectChangeEventArgs(
|
||||
fromNode.Guid, // 从哪个节点开始
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace Serein.NodeFlow.Env
|
||||
private IFlowEnvironment currentFlowEnvironment;
|
||||
|
||||
|
||||
|
||||
private int _loadingProjectFlag = 0; // 使用原子自增代替锁
|
||||
/// <summary>
|
||||
/// 传入false时,将停止数据通知。传入true时,
|
||||
@@ -68,9 +69,8 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
public bool IsGlobalInterrupt => currentFlowEnvironment.IsGlobalInterrupt;
|
||||
|
||||
public bool IsLcR => currentFlowEnvironment.IsLcR;
|
||||
public bool IsControlRemoteEnv => currentFlowEnvironment.IsControlRemoteEnv;
|
||||
|
||||
public bool IsRcL => currentFlowEnvironment.IsRcL;
|
||||
|
||||
public RunState FlowState { get => currentFlowEnvironment.FlowState; set => currentFlowEnvironment.FlowState = value; }
|
||||
public RunState FlipFlopState { get => currentFlowEnvironment.FlipFlopState; set => currentFlowEnvironment.FlipFlopState = value; }
|
||||
@@ -404,14 +404,23 @@ namespace Serein.NodeFlow.Env
|
||||
currentFlowEnvironment.WriteLineObjToJson(obj);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// (用于远程)通知节点属性变更
|
||||
/// </summary>
|
||||
/// <param name="nodeGuid">节点Guid</param>
|
||||
/// <param name="path">属性路径</param>
|
||||
/// <param name="value">属性值</param>
|
||||
/// <returns></returns>
|
||||
public async Task NotificationNodeValueChangeAsync(string nodeGuid, string path, object value)
|
||||
{
|
||||
if (!IsLoadingProject())
|
||||
{
|
||||
return;
|
||||
}
|
||||
await currentFlowEnvironment.NotificationNodeValueChangeAsync(nodeGuid, path, value);
|
||||
if (currentFlowEnvironment.IsControlRemoteEnv)
|
||||
{
|
||||
await currentFlowEnvironment.NotificationNodeValueChangeAsync(nodeGuid, path, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Serein.NodeFlow.Env
|
||||
methodDetails = new MethodDetails();
|
||||
}
|
||||
var md = methodDetails.CloneOfNode(nodeModel.Env, nodeModel);
|
||||
nodeModel.DisplayName = md.MethodTips;
|
||||
nodeModel.DisplayName = md.MethodAnotherName;
|
||||
nodeModel.MethodDetails = md;
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ namespace Serein.NodeFlow.Env
|
||||
/// <summary>
|
||||
/// 启动带token验证的远程服务
|
||||
/// </summary>
|
||||
/// <param name="environment"></param>
|
||||
/// <param name="token"></param>
|
||||
public MsgControllerOfServer(IFlowEnvironment environment, string token)
|
||||
{
|
||||
@@ -567,6 +568,7 @@ namespace Serein.NodeFlow.Env
|
||||
environment.SetMonitorObjState(key, isMonitor);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 节点数据更改
|
||||
/// </summary>
|
||||
@@ -576,6 +578,7 @@ namespace Serein.NodeFlow.Env
|
||||
[AutoSocketHandle(ThemeValue = EnvMsgTheme.ValueNotification)]
|
||||
public async Task ValueNotification(string nodeGuid, string path, string value)
|
||||
{
|
||||
|
||||
await environment.NotificationNodeValueChangeAsync(nodeGuid, path, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,9 +64,8 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
public bool IsGlobalInterrupt => false;
|
||||
|
||||
public bool IsLcR => true;
|
||||
public bool IsControlRemoteEnv => true;
|
||||
|
||||
public bool IsRcL => false;
|
||||
|
||||
public RunState FlowState { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public RunState FlipFlopState { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
@@ -78,6 +77,10 @@ namespace Serein.NodeFlow.Env
|
||||
/// 标示是否正在加载项目
|
||||
/// </summary>
|
||||
private bool IsLoadingProject = false;
|
||||
/// <summary>
|
||||
/// 表示是否正在加载节点
|
||||
/// </summary>
|
||||
private bool IsLoadingNode = false;
|
||||
|
||||
public void SetConsoleOut()
|
||||
{
|
||||
@@ -666,13 +669,14 @@ namespace Serein.NodeFlow.Env
|
||||
/// <param name="methodDetailsInfo">节点绑定的方法说明</param>
|
||||
public async Task<NodeInfo> CreateNodeAsync(NodeControlType nodeControlType, PositionOfUI position, MethodDetailsInfo methodDetailsInfo = null)
|
||||
{
|
||||
IsLoadingNode = true;
|
||||
var nodeInfo = await msgClient.SendAndWaitDataAsync<NodeInfo>(EnvMsgTheme.CreateNode, new
|
||||
{
|
||||
nodeType = nodeControlType.ToString(),
|
||||
position = position,
|
||||
mdInfo = methodDetailsInfo,
|
||||
});
|
||||
|
||||
|
||||
MethodDetails? methodDetails = null;
|
||||
if (!string.IsNullOrEmpty(nodeInfo.MethodName))
|
||||
{
|
||||
@@ -683,6 +687,7 @@ namespace Serein.NodeFlow.Env
|
||||
var nodeModel = FlowFunc.CreateNode(this, nodeControlType, methodDetails); // 远程环境下加载节点
|
||||
nodeModel.LoadInfo(nodeInfo);
|
||||
TryAddNode(nodeModel);
|
||||
IsLoadingNode = false;
|
||||
|
||||
// 通知UI更改
|
||||
UIContextOperation.Invoke(() =>
|
||||
@@ -816,14 +821,18 @@ namespace Serein.NodeFlow.Env
|
||||
|
||||
public async Task NotificationNodeValueChangeAsync(string nodeGuid, string path, object value)
|
||||
{
|
||||
//Console.WriteLine($"通知远程环境修改节点数据:{nodeGuid},name:{path},value:{value}");
|
||||
if(IsLoadingProject || IsLoadingNode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Console.WriteLine($"通知远程环境修改节点数据:{nodeGuid},name:{path},value:{value}");
|
||||
|
||||
//_ = msgClient.SendAsync(EnvMsgTheme.ValueNotification, new
|
||||
//{
|
||||
// nodeGuid = nodeGuid,
|
||||
// path = path,
|
||||
// value = value.ToString(),
|
||||
//});
|
||||
_ = msgClient.SendAsync(EnvMsgTheme.ValueNotification, new
|
||||
{
|
||||
nodeGuid = nodeGuid,
|
||||
path = path,
|
||||
value = value.ToString(),
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Serein.NodeFlow.Model
|
||||
{
|
||||
Guid = Guid,
|
||||
MethodName = MethodDetails?.MethodName,
|
||||
Label = DisplayName ?? "",
|
||||
Label = MethodDetails?.MethodAnotherName,
|
||||
Type = this.GetType().ToString(),
|
||||
TrueNodes = trueNodes.ToArray(),
|
||||
FalseNodes = falseNodes.ToArray(),
|
||||
|
||||
@@ -83,14 +83,14 @@ public static class NodeMethodDetailsHelper
|
||||
returnType = method.ReturnType;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(attribute.MethodTips)){
|
||||
attribute.MethodTips = method.Name;
|
||||
if (string.IsNullOrEmpty(attribute.AnotherName)){
|
||||
attribute.AnotherName = method.Name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var asyncPrefix = "[异步]"; // IsGenericTask(returnType) ? "[async]" : ;
|
||||
var methodTips = isTask ? asyncPrefix + attribute.MethodTips : attribute.MethodTips;
|
||||
var methodMethodAnotherName = isTask ? asyncPrefix + attribute.AnotherName : attribute.AnotherName;
|
||||
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public static class NodeMethodDetailsHelper
|
||||
MethodName = dllTypeMethodName,
|
||||
MethodDynamicType = attribute.MethodDynamicType,
|
||||
MethodLockName = attribute.LockName,
|
||||
MethodTips = methodTips,
|
||||
MethodAnotherName = methodMethodAnotherName,
|
||||
ParameterDetailss = explicitDataOfParameters,
|
||||
ReturnType = returnType,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user