using Serein.Library; using Serein.Library.Api; using Serein.Library.Utils; using Serein.NodeFlow.Services; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Serein.NodeFlow.Model.Operations { internal interface IOperation { /// /// 用于判断是否可以撤销 /// bool IsCanUndo { get; } /// /// 执行操作前验证数据 /// /// bool ValidationParameter(); /// /// 执行操作 /// Task ExecuteAsync(); /// /// 撤销操作 /// bool Undo(); } internal abstract class OperationBase : IOperation { /// /// 运行环境 /// [AutoInjection] protected IFlowEnvironment flowEnvironment; /// /// 节点管理服务 /// [AutoInjection] protected FlowModelService flowModelService; /// /// 节点管理服务 /// [AutoInjection] protected UIContextOperation uiContextOperation; /// /// 流程依赖服务 /// [AutoInjection] protected FlowLibraryService flowLibraryManagement; /// /// 流程事件服务 /// [AutoInjection] protected IFlowEnvironmentEvent flowEnvironmentEvent; public abstract string Theme { get;} /// /// 是否支持特效 /// public virtual bool IsCanUndo => true; /// /// 验证参数 /// /// public abstract bool ValidationParameter(); /// /// 执行 /// public abstract Task ExecuteAsync(); /// /// 撤销 /// public virtual bool Undo() { if (!IsCanUndo) { Debug.WriteLine($"该操作暂未提供撤销功能[{Theme}]"); return false; } return true; } /// /// 导出操作信息 /// public abstract void ToInfo(); protected async Task TriggerEvent(Action action) => await SereinEnv.TriggerEvent(action); } internal class OperationInfo { } class Test { } }