mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-15 05:56:34 +08:00
1. 重新设计了Generate项目及相关特性的命名,避免与其他类型混淆。
2. 补充了部分注释。 3. 修改了删除容器节点时,容器内子节点未正确删除的问题。
This commit is contained in:
82
NodeFlow/Model/Operations/SetStartNodeOperation.cs
Normal file
82
NodeFlow/Model/Operations/SetStartNodeOperation.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Serein.Library;
|
||||
using Serein.Library.Api;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Model.Operations
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置起始节点
|
||||
/// </summary>
|
||||
internal class SetStartNodeOperation : OperationBase
|
||||
{
|
||||
public override string Theme => nameof(SetStartNodeOperation);
|
||||
|
||||
|
||||
public string CanvasGuid { get; set; }
|
||||
public string NewNodeGuid { get; set; }
|
||||
|
||||
|
||||
private FlowCanvasDetails CanvasModel;
|
||||
private IFlowNode NewStartNodeModel;
|
||||
private IFlowNode? OldStartNodeModel;
|
||||
|
||||
|
||||
public override bool ValidationParameter()
|
||||
{
|
||||
if (!flowModelService.TryGetCanvasModel(CanvasGuid, out CanvasModel)
|
||||
|| !flowModelService.TryGetNodeModel(NewNodeGuid, out NewStartNodeModel))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public override async Task<bool> ExecuteAsync()
|
||||
{
|
||||
if (!ValidationParameter()) return false;
|
||||
|
||||
if (CanvasModel.StartNode is not null
|
||||
&& flowModelService.TryGetNodeModel(CanvasModel.StartNode.Guid, out var flowNode))
|
||||
{
|
||||
OldStartNodeModel = flowNode;
|
||||
}
|
||||
|
||||
CanvasModel.StartNode = NewStartNodeModel;
|
||||
|
||||
await TriggerEvent(() =>
|
||||
{
|
||||
flowEnvironmentEvent.OnStartNodeChanged(new StartNodeChangeEventArgs(CanvasModel.Guid, OldStartNodeModel?.Guid, NewStartNodeModel.Guid));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Undo()
|
||||
{
|
||||
if(OldStartNodeModel is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var newStartNode = OldStartNodeModel;
|
||||
var oldStartNode = NewStartNodeModel;
|
||||
|
||||
NewStartNodeModel = newStartNode;
|
||||
OldStartNodeModel = oldStartNode;
|
||||
CanvasModel.StartNode = oldStartNode;
|
||||
|
||||
flowEnvironmentEvent.OnStartNodeChanged(new StartNodeChangeEventArgs(CanvasModel.Guid, oldStartNode?.Guid, newStartNode.Guid));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override void ToInfo()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user