2025-05-30 01:02:25 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
using Serein.Library;
|
2025-03-14 16:04:06 +08:00
|
|
|
|
using Serein.Library.Api;
|
2025-07-04 11:35:34 +08:00
|
|
|
|
using Serein.NodeFlow.Model;
|
2025-03-14 16:04:06 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Serein.Workbench.Node.ViewModel
|
|
|
|
|
|
{
|
2025-05-30 01:02:25 +08:00
|
|
|
|
public partial class UINodeControlViewModel : NodeControlViewModelBase
|
2025-03-14 16:04:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
private SingleUINode NodeModel => (SingleUINode)base.NodeModel;
|
|
|
|
|
|
//public IEmbeddedContent Adapter => NodeModel.Adapter;
|
|
|
|
|
|
|
2025-05-30 01:02:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 节点UI的对应内容
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private UserControl _nodeUIContent;
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-31 12:15:01 +08:00
|
|
|
|
public UINodeControlViewModel(IFlowNode nodeModel) : base(nodeModel)
|
2025-03-14 16:04:06 +08:00
|
|
|
|
{
|
2025-05-30 01:02:25 +08:00
|
|
|
|
|
2025-03-14 16:04:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-30 01:02:25 +08:00
|
|
|
|
public void InitAdapter()
|
2025-03-14 16:04:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
Task.Factory.StartNew(async () =>
|
|
|
|
|
|
{
|
2025-07-23 16:20:41 +08:00
|
|
|
|
var context = new FlowContext(NodeModel.Env);
|
2025-03-20 22:54:10 +08:00
|
|
|
|
var cts = new CancellationTokenSource();
|
2025-03-21 18:26:01 +08:00
|
|
|
|
var result = await NodeModel.ExecutingAsync(context, cts.Token);
|
2025-03-20 22:54:10 +08:00
|
|
|
|
cts?.Dispose();
|
2025-03-14 16:04:06 +08:00
|
|
|
|
if (context.NextOrientation == ConnectionInvokeType.IsSucceed
|
|
|
|
|
|
&& NodeModel.Adapter.GetUserControl() is UserControl userControl)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeModel.Env.UIContextOperation.Invoke(() =>
|
2025-05-30 01:02:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
NodeUIContent = userControl;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void InitAdapter(Action<UserControl> setUIDisplayHandle)
|
|
|
|
|
|
{
|
|
|
|
|
|
Task.Factory.StartNew(async () =>
|
|
|
|
|
|
{
|
2025-07-23 16:20:41 +08:00
|
|
|
|
var context = new FlowContext(NodeModel.Env);
|
2025-05-30 01:02:25 +08:00
|
|
|
|
var cts = new CancellationTokenSource();
|
|
|
|
|
|
var result = await NodeModel.ExecutingAsync(context, cts.Token);
|
|
|
|
|
|
cts?.Dispose();
|
|
|
|
|
|
if (context.NextOrientation == ConnectionInvokeType.IsSucceed
|
|
|
|
|
|
&& NodeModel.Adapter.GetUserControl() is UserControl userControl)
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeModel.Env.UIContextOperation.Invoke(() =>
|
2025-03-14 16:04:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
setUIDisplayHandle.Invoke(userControl);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-05-30 01:02:25 +08:00
|
|
|
|
|
2025-03-14 16:04:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|