Files
serein-flow/NodeFlow/Model/Operation/CreateCanvasOperation.cs
2025-06-22 21:53:37 +08:00

52 lines
1.5 KiB
C#

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.Operation
{
internal class CreateCanvasOperation : OperationBase
{
public override string Theme => nameof(CreateCanvasOperation);
public override bool IsCanUndo => false;
public required FlowCanvasDetailsInfo CanvasInfo { get; set; }
private FlowCanvasDetails? flowCanvasDetails;
public override bool ValidationParameter()
{
if (CanvasInfo is null)
return false; // 没有必须的参数
if (string.IsNullOrEmpty(CanvasInfo.Guid))
return false; // 不能没有Guid
if(flowModelService.ContainsCanvasModel(CanvasInfo.Guid))
return false; // 画布已存在
return true;
}
public override bool Execute()
{
if(!ValidationParameter()) return false;
var cavasnModel = new FlowCanvasDetails(flowEnvironment);
cavasnModel.LoadInfo(CanvasInfo);
flowModelService.AddCanvasModel(cavasnModel);
this.flowCanvasDetails = cavasnModel; ;
flowEnvironmentEvent.OnCanvasCreated(new CanvasCreateEventArgs(cavasnModel));
return true;
}
public override void ToInfo()
{
throw new NotImplementedException();
}
}
}