mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-05 15:56:33 +08:00
将流程事件接口与流程运行环境解耦。
This commit is contained in:
92
NodeFlow/Model/Operation/OperationBase.cs
Normal file
92
NodeFlow/Model/Operation/OperationBase.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Model.Operation
|
||||
{
|
||||
|
||||
class Test {
|
||||
|
||||
/// <summary>
|
||||
/// 撤销栈
|
||||
/// </summary>
|
||||
private Stack<IOperation> undoStack = [];
|
||||
/// <summary>
|
||||
/// 重做栈
|
||||
/// </summary>
|
||||
private Stack<IOperation> redoStack = [];
|
||||
|
||||
|
||||
/*
|
||||
// 执行新命令时,将命令推入撤销栈,并清空重做栈
|
||||
undoStack.Push(operation);
|
||||
redoStack.Clear();
|
||||
*/
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 撤销
|
||||
/// </summary>
|
||||
public void Undo()
|
||||
{
|
||||
if (undoStack.Count > 0)
|
||||
{
|
||||
var command = undoStack.Pop();
|
||||
command.Undo(); // 执行撤销
|
||||
redoStack.Push(command); // 将撤销的命令推入重做栈
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重做
|
||||
/// </summary>
|
||||
public void Redo()
|
||||
{
|
||||
if (redoStack.Count > 0)
|
||||
{
|
||||
var command = redoStack.Pop();
|
||||
command.Execute();
|
||||
undoStack.Push(command); // 将重做的命令推入撤销栈
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
internal class OperationInfo
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal abstract class OperationBase : IOperation
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作的主题
|
||||
/// </summary>
|
||||
public required string Theme { get; set; }
|
||||
|
||||
public abstract void Execute();
|
||||
public abstract void Undo();
|
||||
public abstract void ToInfo();
|
||||
|
||||
protected OperationBase()
|
||||
{
|
||||
|
||||
}
|
||||
protected OperationBase(OperationInfo info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal interface IOperation
|
||||
{
|
||||
void Execute(); // 执行操作
|
||||
void Undo(); // 撤销操作
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -227,12 +227,12 @@ namespace Serein.NodeFlow.Model
|
||||
};
|
||||
|
||||
var envEvent = (IFlowEnvironmentEvent)context.Env;
|
||||
envEvent.OnFlowRunComplete += onFlowStop; // 防止运行后台流程
|
||||
envEvent.FlowRunComplete += onFlowStop; // 防止运行后台流程
|
||||
|
||||
if (token.IsCancellationRequested) return null;
|
||||
|
||||
var result = await ScriptInterpreter.InterpretAsync(scriptContext, mainNode); // 从入口节点执行
|
||||
envEvent.OnFlowRunComplete -= onFlowStop;
|
||||
envEvent.FlowRunComplete -= onFlowStop;
|
||||
return new FlowResult(this, context, result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user