Files
serein-flow/Workbench/ViewModels/FlowLibrarysViewModel.cs

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.OnDllLoad += FlowEEForwardingService_OnDllLoad;
}
/// <summary>
/// 加载文件依赖
/// </summary>
/// <param name="filePath"></param>
public void LoadFileLibrary(string filePath)
{
try
{
flowEnvironment.LoadLibrary(filePath);
}
catch (Exception ex)
{
flowEnvironment.WriteLine(Library.InfoType.ERROR, ex.ToString());
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);
}
}
}