using Serein.Library.Api; using Serein.Library.Utils; using Serein.NodeFlow.Env; using System.ComponentModel; using System.Windows; namespace Serein.Workbench { /// /// 工作台数据视图 /// /// public class MainWindowViewModel: INotifyPropertyChanged { private readonly MainWindow window ; /// /// 运行环境 /// public IFlowEnvironment FlowEnvironment { get; set; } /// /// 工作台数据视图 /// /// public MainWindowViewModel(MainWindow window) { UIContextOperation? uIContextOperation = null; Application.Current.Dispatcher.Invoke(() => { SynchronizationContext? uiContext = SynchronizationContext.Current; // 在UI线程上获取UI线程上下文信息 if (uiContext != null) { uIContextOperation = new UIContextOperation(uiContext); // 封装一个调用UI线程的工具类 } }); if (uIContextOperation is null) { throw new Exception("无法封装 UIContextOperation "); } else { FlowEnvironment = new FlowEnvironmentDecorator(uIContextOperation); //_ = FlowEnvironment.StartRemoteServerAsync(); this.window = window; } } private bool _isConnectionInvokeNode = false; /// /// 是否正在连接节点的方法调用关系 /// public bool IsConnectionInvokeNode { get => _isConnectionInvokeNode; set { if (_isConnectionInvokeNode != value) { SetProperty(ref _isConnectionInvokeNode, value); } } } private bool _isConnectionArgSouceNode = false; /// /// 是否正在连接节点的参数传递关系 /// public bool IsConnectionArgSourceNode { get => _isConnectionArgSouceNode; set { if (_isConnectionArgSouceNode != value) { SetProperty(ref _isConnectionArgSouceNode, value); } } } /// /// 略 /// 此事件为自动生成 /// public event PropertyChangedEventHandler? PropertyChanged; /// /// 通知属性变更 /// /// 类型 /// 绑定的变量 /// 新的数据 /// protected void SetProperty(ref T storage, T value, [System.Runtime.CompilerServices.CallerMemberName] string propertyName = null) { if (Equals(storage, value)) { return; } storage = value; PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); } } }