尝试将节点流导出为c#代码文件

This commit is contained in:
fengjiayi
2025-07-06 14:34:49 +08:00
parent 162dc7bcf8
commit b25fd9c83c
45 changed files with 1625 additions and 361 deletions

View File

@@ -9,9 +9,11 @@ using Serein.Workbench.Services;
using Serein.Workbench.ViewModels;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using static System.Net.Mime.MediaTypeNames;
namespace Serein.Workbench
{
@@ -20,7 +22,7 @@ namespace Serein.Workbench
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App : System.Windows.Application
{
private static IServiceProvider? ServiceProvider;
@@ -28,12 +30,12 @@ namespace Serein.Workbench
/// UI线程
/// </summary>
public static UIContextOperation UIContextOperation => App.GetService<UIContextOperation>() ?? throw new NullReferenceException();
public static T GetService<T>() where T : class
{
return ServiceProvider?.GetService<T>() ?? throw new NullReferenceException();
}
public App()
{
var collection = new ServiceCollection();

View File

@@ -75,7 +75,7 @@
<ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.3.0.90" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

View File

@@ -63,10 +63,12 @@ namespace Serein.Workbench
getSyncContext = () => uiContext;
}
});
UIContextOperation? uIContextOperation = null;
uIContextOperation = new UIContextOperation(getSyncContext); // 封装一个调用UI线程的工具类
var flowEnvironment = new FlowEnvironment();
UIContextOperation? uIContextOperation = new (getSyncContext); // 封装一个调用UI线程的工具类
IFlowEnvironment flowEnvironment = new FlowEnvironment();
flowEnvironment.SetUIContextOperation(uIContextOperation);
collection.AddSingleton<UIContextOperation>(uIContextOperation); // 注册UI线程操作上下文
collection.AddSingleton<IFlowEnvironment>(flowEnvironment); // 注册运行环境
collection.AddSingleton<IFlowEnvironmentEvent>(flowEnvironment.Event); // 注册运行环境事件

View File

@@ -14,6 +14,7 @@ using Serein.Library.Utils;
using Serein.Workbench.Avalonia.Api;
using Serein.Workbench.Api;
using System.Diagnostics;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace Serein.Workbench.Services
{
@@ -184,10 +185,11 @@ namespace Serein.Workbench.Services
/// <param name="value"></param>
private void FlowEnvironment_OnEnvOutEvent(InfoType type, string value)
{
uiContextOperation.Invoke(() =>
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
EnvOutput?.Invoke(type, value);
});
}));
}
/// <summary>
@@ -197,7 +199,10 @@ namespace Serein.Workbench.Services
/// <exception cref="NotImplementedException"></exception>
private void FlowEnvironment_OnProjectSaving(ProjectSavingEventArgs eventArgs)
{
ProjectSaving?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
ProjectSaving?.Invoke(eventArgs);
}));
}
/// <summary>
@@ -206,7 +211,10 @@ namespace Serein.Workbench.Services
/// <param name="eventArgs"></param>
private void FlowEnvironment_OnProjectLoaded(ProjectLoadedEventArgs eventArgs)
{
ProjectLoaded?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
ProjectLoaded?.Invoke(eventArgs);
}));
}
/// <summary>
@@ -216,8 +224,11 @@ namespace Serein.Workbench.Services
/// <exception cref="NotImplementedException"></exception>
private void FlowEnvironment_OnFlowRunCompleteEvent(FlowEventArgs eventArgs)
{
SereinEnv.WriteLine(InfoType.INFO, "-------运行完成---------\r\n");
FlowRunComplete?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
SereinEnv.WriteLine(InfoType.INFO, "-------运行完成---------\r\n");
FlowRunComplete?.Invoke(eventArgs);
}));
}
/// <summary>
@@ -225,7 +236,10 @@ namespace Serein.Workbench.Services
/// </summary>
private void FlowEnvironment_DllLoadEvent(LoadDllEventArgs eventArgs)
{
DllLoad?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
DllLoad?.Invoke(eventArgs);
}));
}
/// <summary>
@@ -234,11 +248,10 @@ namespace Serein.Workbench.Services
/// <param name="eventArgs"></param>
private void FlowEnvironment_NodeConnectChangeEvemt(NodeConnectChangeEventArgs eventArgs)
{
uiContextOperation.Invoke(() =>
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
Debug.WriteLine(DateTime.Now, $"Node Connect Changed");
NodeConnectChanged?.Invoke(eventArgs);
});
}));
}
@@ -249,10 +262,10 @@ namespace Serein.Workbench.Services
/// <exception cref="NotImplementedException"></exception>
private void FlowEnvironmentEvent_OnCanvasCreate(CanvasCreateEventArgs eventArgs)
{
uiContextOperation?.Invoke(() =>
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
CanvasCreated?.Invoke(eventArgs);
});
}));
}
/// <summary>
@@ -262,7 +275,10 @@ namespace Serein.Workbench.Services
/// <exception cref="NotImplementedException"></exception>
private void FlowEnvironmentEvent_OnCanvasRemove(CanvasRemoveEventArgs eventArgs)
{
CanvasRemoved?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
CanvasRemoved?.Invoke(eventArgs);
}));
}
@@ -272,7 +288,10 @@ namespace Serein.Workbench.Services
/// <param name="eventArgs"></param>
private void FlowEnvironment_NodeRemoveEvent(NodeRemoveEventArgs eventArgs)
{
NodeRemoved?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
NodeRemoved?.Invoke(eventArgs);
}));
}
/// <summary>
@@ -282,11 +301,11 @@ namespace Serein.Workbench.Services
/// <exception cref="NotImplementedException"></exception>
private void FlowEnvironment_NodeCreateEvent(NodeCreateEventArgs eventArgs)
{
uiContextOperation.Invoke(() =>
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
Debug.WriteLine(DateTime.Now, $"Create Node {eventArgs.NodeModel.Guid}");
NodeCreated?.Invoke(eventArgs);
});
}));
}
/// <summary>
@@ -296,7 +315,10 @@ namespace Serein.Workbench.Services
/// <exception cref="NotImplementedException"></exception>
private void FlowEnvironment_OnNodePlaceEvent(NodePlaceEventArgs eventArgs)
{
NodePlace?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
NodePlace?.Invoke(eventArgs);
}));
}
/// <summary>
@@ -305,19 +327,23 @@ namespace Serein.Workbench.Services
/// <param name="eventArgs"></param>
private void FlowEnvironment_OnNodeTakeOutEvent(NodeTakeOutEventArgs eventArgs)
{
NodeTakeOut?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
NodeTakeOut?.Invoke(eventArgs);
}));
}
/// <summary>
/// 设置了流程起始控件
/// </summary>
/// <param name="oldNodeGuid"></param>
/// <param name="newNodeGuid"></param>
/// <param name="eventArgs"></param>
private void FlowEnvironment_StartNodeChangeEvent(StartNodeChangeEventArgs eventArgs)
{
StartNodeChanged?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
StartNodeChanged?.Invoke(eventArgs);
}));
}
/// <summary>
@@ -326,7 +352,10 @@ namespace Serein.Workbench.Services
/// <param name="eventArgs"></param>
private void FlowEnvironment_OnMonitorObjectChangeEvent(MonitorObjectEventArgs eventArgs)
{
MonitorObjectChanged?.Invoke(eventArgs);
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
MonitorObjectChanged?.Invoke(eventArgs);
}));
}
/// <summary>

View File

@@ -15,8 +15,6 @@ namespace Serein.Workbench.Services
{
private readonly IFlowEnvironment flowEnvironment;
public SereinProjectData? FlowProjectData { get; set; }
public string FileDataPath { get; set; }
public FlowProjectService(IFlowEnvironment flowEnvironment)
{
@@ -32,15 +30,13 @@ namespace Serein.Workbench.Services
{
if (File.Exists(filePath))
{
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
this.FlowProjectData = JsonConvert.DeserializeObject<SereinProjectData>(content);
this.FileDataPath = System.IO.Path.GetDirectoryName(filePath)!; // filePath;//
/*
var dir = Path.GetDirectoryName(filePath);
var flowEnvInfo = new FlowEnvInfo
{
Project = FlowProjectData,
};
flowEnvironment.LoadProject(flowEnvInfo, FileDataPath);
};*/
flowEnvironment.LoadProject(filePath);
}
}