Files
serein-flow/Workbench/ViewModels/FlowLibrarysViewModel.cs
fengjiayi 88de5a21f5 优化了SereinEnv.WriteLine(Exception, InfoClass)输出,可以通过更改InfoClass控制是否输出异常堆栈信息。
优化了批量加载节点时,脚本节点类型分析异常的问题。
2025-07-17 22:46:40 +08:00

72 lines
2.3 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using Serein.Library;
using Serein.Library.Api;
using Serein.NodeFlow.Env;
using Serein.Workbench.Api;
using Serein.Workbench.Models;
using Serein.Workbench.Services;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serein.Workbench.ViewModels
{
internal partial class FlowLibrarysViewModel : ObservableObject
{
private readonly IFlowEEForwardingService flowEEForwardingService;
private readonly IFlowEnvironment flowEnvironment;
[ObservableProperty]
private ObservableCollection<FlowLibraryInfo> flowLibraryInfos;
public FlowLibrarysViewModel(IFlowEEForwardingService flowEEForwardingService,IFlowEnvironment flowEnvironment)
{
this.flowEEForwardingService = flowEEForwardingService;
this.flowEnvironment = flowEnvironment;
FlowLibraryInfos = new ObservableCollection<FlowLibraryInfo>();
flowEEForwardingService.DllLoad += FlowEEForwardingService_OnDllLoad;
}
/// <summary>
/// 加载文件依赖
/// </summary>
/// <param name="filePath"></param>
public void LoadFileLibrary(string filePath)
{
try
{
flowEnvironment.LoadLibrary(filePath);
}
catch (Exception ex)
{
SereinEnv.WriteLine(ex);
return;
}
}
private void FlowEEForwardingService_OnDllLoad(Library.Api.LoadDllEventArgs eventArgs)
{
if (!eventArgs.IsSucceed) return;
List<MethodDetailsInfo> mds = eventArgs.MethodDetailss;
NodeLibraryInfo libraryInfo = eventArgs.NodeLibraryInfo;
var methodInfo = new ObservableCollection<MethodDetailsInfo>();
foreach (var md in mds)
{
methodInfo.Add(md);
}
var flInfo = new FlowLibraryInfo
{
LibraryName = libraryInfo.AssemblyName,
FilePath = libraryInfo.FilePath,
MethodInfo = methodInfo
};
FlowLibraryInfos.Add(flInfo);
}
}
}