重新优化了NodeModel类;从硬编码类型改为“注册/获取”的方式,为下一步解耦Workbench与节点UI做准备。

新增了“全局数据节点”;保存项目文件时,不同节点可以使用自定义数据保存自身独特的数据,不再借用“方法参数”。
重新设计了运行时的环境输出;增量式生成器现在可以选择在属性变更的前后时间点插入自定义代码;重写了加载项目、保存项目的方法。
This commit is contained in:
fengjiayi
2024-12-12 20:31:50 +08:00
parent dbbaa10cc0
commit 49603bb58f
40 changed files with 999 additions and 681 deletions

View File

@@ -104,7 +104,7 @@ namespace Serein.Workbench.Node.View
cancellationTokenSource = new CancellationTokenSource();
Task.Run(async () =>
{
await Task.Delay(500);
await Task.Delay(380);
}, cancellationTokenSource.Token).ContinueWith((t) =>
{

View File

@@ -22,11 +22,11 @@ namespace Serein.Workbench.Node.View
public NodeControlViewModelBase ViewModel { get; set; }
protected NodeControlBase()
{
this.Background = Brushes.Transparent;
}
protected NodeControlBase(NodeControlViewModelBase viewModelBase)
{
ViewModel = viewModelBase;

View File

@@ -13,10 +13,10 @@
</UserControl.Resources>
<Grid>
<Grid.ToolTip>
<Grid Background="#FEFAF4">
<!--<Grid.ToolTip>
<ToolTip Background="LightYellow" Foreground="Black" Content="{Binding NodeModel.MethodDetails.MethodAnotherName, UpdateSourceTrigger=PropertyChanged}" />
</Grid.ToolTip>
</Grid.ToolTip>-->
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
@@ -37,31 +37,43 @@
<local:ExecuteJunctionControl Grid.Column="0" MyNode="{Binding NodeModel}" x:Name="ExecuteJunctionControl" HorizontalAlignment="Left" Grid.RowSpan="2"/>
<Border Grid.Column="1" BorderThickness="1" HorizontalAlignment="Stretch">
<TextBlock Text="全局数据" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Text="全局数据节点" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<local:NextStepJunctionControl Grid.Column="2" MyNode="{Binding NodeModel}" x:Name="NextStepJunctionControl" HorizontalAlignment="Right" Grid.RowSpan="2"/>
</Grid>
<Grid Grid.Row="1" Background="#FEFAF4" HorizontalAlignment="Stretch">
<Grid Grid.Row="1" HorizontalAlignment="Stretch" Margin="4">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="名称" Margin="2" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
<TextBox Grid.Row="0" Grid.Column="1" MinWidth="50" Margin="2" Text="{Binding NodeModel.CustomData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Stretch" VerticalAlignment="Center">
</TextBox>
<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="设置数据源" Margin="2" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
<local:ResultJunctionControl Grid.Column="2" MyNode="{Binding NodelModel}" x:Name="ResultJunctionControl" HorizontalAlignment="Right"/>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
<TextBlock Text="全局数据名称" Margin="2" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
<TextBox MinWidth="50" Margin="2" Text="{Binding NodeModel.KeyName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Stretch" VerticalAlignment="Center">
</TextBox>
<Button Content="EXP" Command="{Binding CommandCopyDataExp}" Height="17.2"></Button>
<!--<Button Content="刷新 " Command="{Binding CommandCopyDataExp}" Height="17.2" Margin="2,0,0,0"></Button>-->
</StackPanel>
<StackPanel x:Name="GlobalDataPanel"
Grid.Row="1"
Grid.ColumnSpan="2"
Orientation="Horizontal"
HorizontalAlignment="Center"
>
</StackPanel>
<!--<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Left">
<local:ResultJunctionControl Grid.Column="2" MyNode="{Binding NodelModel}" x:Name="ResultJunctionControl" HorizontalAlignment="Right"/>
<TextBlock Text="设置数据源" Margin="2" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</StackPanel>-->
</Grid>

View File

@@ -22,21 +22,36 @@ namespace Serein.Workbench.Node.View
/// </summary>
public partial class GlobalDataControl : NodeControlBase, INodeJunction
{
//private new GlobalDataNodeControlViewModel ViewModel => ViewModel;
public GlobalDataControl() : base()
{
// 窗体初始化需要
ViewModel = new GlobalDataNodeControlViewModel(new SingleGlobalDataNode(null));
base.ViewModel = new GlobalDataNodeControlViewModel(new SingleGlobalDataNode(null));
DataContext = ViewModel;
InitializeComponent();
}
public GlobalDataControl(ConditionNodeControlViewModel viewModel) : base(viewModel)
public GlobalDataControl(GlobalDataNodeControlViewModel viewModel) : base(viewModel)
{
DataContext = viewModel;
InitializeComponent();
}
/// <summary>
/// 设置数据节点
/// </summary>
/// <param name="nodeControl"></param>
public void SetDataNodeControl(NodeControlBase nodeControl)
{
((GlobalDataNodeControlViewModel)ViewModel).SetDataNode(nodeControl.ViewModel.NodeModel);
GlobalDataPanel.Children.Clear();
GlobalDataPanel.Children.Add(nodeControl);
}
/// <summary>
/// 入参控制点(可能有,可能没)
/// </summary>
@@ -50,13 +65,13 @@ namespace Serein.Workbench.Node.View
/// <summary>
/// 返回值控制点(可能有,可能没)
/// </summary>
JunctionControlBase INodeJunction.ReturnDataJunction => this.ResultJunctionControl;
JunctionControlBase INodeJunction.ReturnDataJunction => throw new NotImplementedException();
/// <summary>
/// 方法入参控制点(可能有,可能没)
/// </summary>
JunctionControlBase[] INodeJunction.ArgDataJunction => throw new NotImplementedException();
}
}

View File

@@ -1,18 +1,61 @@
using Serein.NodeFlow.Model;
using Serein.Library;
using Serein.NodeFlow.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace Serein.Workbench.Node.ViewModel
{
public class GlobalDataNodeControlViewModel : NodeControlViewModelBase
{
public new SingleGlobalDataNode NodelModel { get; }
private SingleGlobalDataNode NodeModel => (SingleGlobalDataNode)base.NodeModel;
/// <summary>
/// 复制全局数据表达式
/// </summary>
public ICommand CommandCopyDataExp { get; }
/// <summary>
/// 刷新数据
/// </summary>
public ICommand CommandRefreshData { get; }
public GlobalDataNodeControlViewModel(SingleGlobalDataNode node) : base(node)
{
this.NodelModel = node;
CommandCopyDataExp = new RelayCommand( o =>
{
string exp = NodeModel.KeyName;
string copyValue = "@Data " + exp;
Clipboard.SetDataObject(copyValue);
});
}
/// <summary>
/// 自定义参数值
/// </summary>
public string? KeyName
{
get => NodeModel?.KeyName;
set { NodeModel.KeyName = value; OnPropertyChanged(); }
}
/// <summary>
/// 设置数据节点
/// </summary>
/// <param name="dataNode"></param>
public void SetDataNode(NodeModelBase dataNode)
{
NodeModel.SetDataNode(dataNode);
}
}
}