重构了运行逻辑。上下文使用对象池封装,节点方法调用时间传递CancellationTokenSource用来中止任务

This commit is contained in:
fengjiayi
2025-03-20 22:54:10 +08:00
parent 2168c5ec66
commit 9941f24c5d
27 changed files with 830 additions and 621 deletions

View File

@@ -3,8 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Serein.Workbench"
xmlns:view="clr-namespace:Serein.Workbench.Views"
StartupUri="Views/FlowWorkbenchView.xaml"
StartupUri="MainWindow.xaml"
Startup="Application_Startup">
<!--StartupUri="Views/FlowWorkbenchView.xaml"-->
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

View File

@@ -90,17 +90,19 @@ namespace Serein.Workbench
public App()
{
_ = Task.Run(async () =>
{
await Task.Delay(500);
await this.LoadLocalProjectAsync();
});
return;
var collection = new ServiceCollection();
collection.AddWorkbenchServices();
collection.AddFlowServices();
collection.AddViewModelServices();
var services = collection.BuildServiceProvider(); // 绑定并返回获取实例的服务接口
App.ServiceProvider = services;
_ = Task.Run(async () =>
{
await Task.Delay(500);
await this.LoadLocalProjectAsync();
});
}
@@ -115,14 +117,14 @@ namespace Serein.Workbench
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\net8.0\PLCproject.dnf";
filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\Release\banyunqi\project.dnf";
filePath = @"F:\临时\project\project.dnf";
filePath = @"F:\临时\flow\qrcode\project.dnf";
filePath = @"F:\TempFile\flow\qrcode\project.dnf";
//filePath = @"C:\Users\Az\source\repos\CLBanyunqiState\CLBanyunqiState\bin\debug\net8.0\test.dnf";
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
App.FlowProjectData = JsonConvert.DeserializeObject<SereinProjectData>(content);
App.FileDataPath = System.IO.Path.GetDirectoryName(filePath)!; // filePath;//
var dir = Path.GetDirectoryName(filePath);
App.GetService<IFlowEnvironment>().LoadProject(new FlowEnvInfo { Project = App.FlowProjectData },App.FileDataPath);
//App.GetService<IFlowEnvironment>().LoadProject(new FlowEnvInfo { Project = App.FlowProjectData },App.FileDataPath);
}
#endif
}

View File

@@ -29,7 +29,9 @@ namespace Serein.Workbench.Node.ViewModel
{
try
{
var result = await NodeModel.ExecutingAsync(new Library.DynamicContext(nodeModel.Env));
var cts = new CancellationTokenSource();
var result = await NodeModel.ExecutingAsync(new Library.DynamicContext(nodeModel.Env), cts.Token);
cts.Cancel();
SereinEnv.WriteLine(InfoType.INFO, result?.ToString());
}
catch (Exception ex)

View File

@@ -25,7 +25,9 @@ namespace Serein.Workbench.Node.ViewModel
Task.Factory.StartNew(async () =>
{
var context = new DynamicContext(NodeModel.Env);
await NodeModel.ExecutingAsync(context);
var cts = new CancellationTokenSource();
await NodeModel.ExecutingAsync(context, cts.Token);
cts?.Dispose();
if (context.NextOrientation == ConnectionInvokeType.IsSucceed
&& NodeModel.Adapter.GetUserControl() is UserControl userControl)
{