refactor(temp) : 修复了一些命名和构造函数入参类型

This commit is contained in:
fengjiayi
2026-01-27 17:36:16 +08:00
parent 0e2e5e6a68
commit 2d136a6b2c
10 changed files with 98 additions and 41 deletions

View File

@@ -64,6 +64,11 @@ namespace Serein.Library.Utils
TaskHasResult, TaskHasResult,
} }
static Task<object> ConvertTaskResult<T>(Task<T> task) where T : class
{
return task.ContinueWith(t => (object)t.Result);
}
/// <summary> /// <summary>
/// 判断一个类型是否为泛型 Task&lt;T&gt; 或 Task并返回泛型参数类型如果有的话 /// 判断一个类型是否为泛型 Task&lt;T&gt; 或 Task并返回泛型参数类型如果有的话
/// </summary> /// </summary>
@@ -100,11 +105,6 @@ namespace Serein.Library.Utils
/// <param name="methodInfo"></param> /// <param name="methodInfo"></param>
/// <param name="delegate"></param> /// <param name="delegate"></param>
/// <returns></returns> /// <returns></returns>
/// <summary>
/// 根据方法信息创建动态调用的委托,返回方法类型,以及传出一个委托
/// </summary>
/// <param name="methodInfo"></param>
/// <param name="delegate"></param>
/// <returns></returns> /// <returns></returns>
public static EmitMethodInfo CreateMethod(MethodInfo methodInfo, out Delegate @delegate) public static EmitMethodInfo CreateMethod(MethodInfo methodInfo, out Delegate @delegate)
{ {
@@ -205,6 +205,17 @@ namespace Serein.Library.Utils
// ============================== // ==============================
il.Emit(isStatic ? OpCodes.Call : OpCodes.Callvirt, methodInfo); il.Emit(isStatic ? OpCodes.Call : OpCodes.Callvirt, methodInfo);
// 如果是泛型Task
if (isTaskGeneric && taskResultType is not null)
{
var convertMethod = typeof(EmitHelper)
.GetMethod(nameof(ConvertTaskResult),
BindingFlags.Static | BindingFlags.NonPublic)!
.MakeGenericMethod(taskResultType);
il.Emit(OpCodes.Call, convertMethod);
}
// ============================== // ==============================
// 6. 回写 ref / out 参数 // 6. 回写 ref / out 参数
// ============================== // ==============================
@@ -237,6 +248,8 @@ namespace Serein.Library.Utils
il.Emit(OpCodes.Box, methodInfo.ReturnType); il.Emit(OpCodes.Box, methodInfo.ReturnType);
} }
il.Emit(OpCodes.Ret); il.Emit(OpCodes.Ret);
// ============================== // ==============================

View File

@@ -17,7 +17,10 @@ namespace Serein.Library
/// </summary> /// </summary>
public static class SereinEnv public static class SereinEnv
{ {
private static IFlowEnvironment environment; /// <summary>
/// 运行环境
/// </summary>
public static IFlowEnvironment Environment { get;private set; }
#region 使 #region 使
/// <summary> /// <summary>
@@ -112,7 +115,7 @@ namespace Serein.Library
{ {
if (environment != null) if (environment != null)
{ {
SereinEnv.environment = environment; SereinEnv.Environment = environment;
} }
} }
@@ -126,7 +129,7 @@ namespace Serein.Library
{ {
Debug.WriteLine($"{type} : {message}"); Debug.WriteLine($"{type} : {message}");
Console.WriteLine($"{type} : {message}"); Console.WriteLine($"{type} : {message}");
SereinEnv.environment?.WriteLine(type,message,@class); SereinEnv.Environment?.WriteLine(type,message,@class);
} }
/// <summary> /// <summary>
@@ -139,12 +142,12 @@ namespace Serein.Library
if(@class == InfoClass.Debug) if(@class == InfoClass.Debug)
{ {
SereinEnv.environment.WriteLine(InfoType.ERROR, ex.ToString(), @class); SereinEnv.Environment.WriteLine(InfoType.ERROR, ex.ToString(), @class);
} }
else else
{ {
SereinEnv.environment.WriteLine(InfoType.ERROR, ex.Message, @class); SereinEnv.Environment.WriteLine(InfoType.ERROR, ex.Message, @class);
} }
} }
@@ -157,13 +160,13 @@ namespace Serein.Library
/// <returns></returns> /// <returns></returns>
public async static Task TriggerEvent(Action action) public async static Task TriggerEvent(Action action)
{ {
if (environment is null) if (Environment is null)
{ {
action?.Invoke(); action?.Invoke();
} }
else else
{ {
var uco = environment.UIContextOperation; var uco = Environment.UIContextOperation;
if (uco is null) if (uco is null)
{ {
action?.Invoke(); action?.Invoke();

View File

@@ -510,13 +510,15 @@ namespace Serein.Library.Utils
{ {
return null; return null;
} }
else else
{ {
// 没有显示指定构造函数入参,选择参数最多的构造函数 // 没有显示指定构造函数入参,选择参数最多的构造函数
//var constructor = GetConstructorWithMostParameters(type); //var constructor = GetConstructorWithMostParameters(type);
var constructors = GetConstructor(type); // 获取构造函数 var constructors = GetConstructor(type); // 获取构造函数
if(constructors.Length == 0)
{
return null;
}
foreach(var constructor in constructors) foreach(var constructor in constructors)
{ {
var parameters = constructor.GetParameters(); var parameters = constructor.GetParameters();
@@ -535,7 +537,9 @@ namespace Serein.Library.Utils
if (argObj is null) if (argObj is null)
{ {
SereinEnv.WriteLine(InfoType.WARN, "构造参数创建失败"); SereinEnv.WriteLine(InfoType.WARN, "构造参数创建失败");
continue;
argObj = CreateInstance(fullName);
throw new Exception("构造参数创建失败");
} }
} }
args[i] = argObj; args[i] = argObj;
@@ -545,7 +549,7 @@ namespace Serein.Library.Utils
instance = Activator.CreateInstance(type, args); instance = Activator.CreateInstance(type, args);
if(instance != null) if(instance != null)
{ {
break; break; // 构建完成退出
} }
} }
catch (Exception) catch (Exception)
@@ -553,10 +557,7 @@ namespace Serein.Library.Utils
continue; continue;
} }
} }
} }
InjectDependencies(instance); // 完成创建后注入实例需要的特性依赖项 InjectDependencies(instance); // 完成创建后注入实例需要的特性依赖项
_dependencies[typeName] = instance; _dependencies[typeName] = instance;
return instance; return instance;
@@ -662,7 +663,7 @@ namespace Serein.Library.Utils
/// </summary> /// </summary>
/// <param name="instance">实例</param> /// <param name="instance">实例</param>
/// <param name="isRecord">未完成依赖项注入时是否记录</param> /// <param name="isRecord">未完成依赖项注入时是否记录</param>
private bool InjectDependencies(object instance,bool isRecord = true) private bool InjectDependencies(object instance, bool isRecord = true)
{ {
var properties = instance.GetType() var properties = instance.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public).ToArray() .GetProperties(BindingFlags.Instance | BindingFlags.Public).ToArray()

View File

@@ -29,9 +29,10 @@ namespace Serein.NodeFlow.Env
/// </summary> /// </summary>
public LocalFlowEnvironment(IFlowEnvironment flowEnvironment, public LocalFlowEnvironment(IFlowEnvironment flowEnvironment,
IFlowEnvironmentEvent flowEnvironmentEvent, IFlowEnvironmentEvent flowEnvironmentEvent,
FlowLibraryService flowLibraryManagement, IFlowLibraryService flowLibraryManagement,
FlowOperationService flowOperationService, FlowOperationService flowOperationService,
FlowModelService flowModelService, FlowModelService flowModelService,
UIContextOperation uIContextOperation,
IFlowControl flowControl, IFlowControl flowControl,
IFlowEdit flowEdit, IFlowEdit flowEdit,
ISereinIOC sereinIOC, ISereinIOC sereinIOC,
@@ -42,7 +43,8 @@ namespace Serein.NodeFlow.Env
FlowEdit = flowEdit; FlowEdit = flowEdit;
IOC = sereinIOC; IOC = sereinIOC;
FlowControl = flowControl; FlowControl = flowControl;
_flowLibraryService = flowLibraryManagement; FlowLibraryService = flowLibraryManagement;
UIContextOperation = uIContextOperation;
_flowModelService = flowModelService; _flowModelService = flowModelService;
_flowOperationService = flowOperationService; _flowOperationService = flowOperationService;
_IsGlobalInterrupt = false; _IsGlobalInterrupt = false;
@@ -114,6 +116,11 @@ namespace Serein.NodeFlow.Env
/// </summary> /// </summary>
public IFlowControl FlowControl { get; set; } public IFlowControl FlowControl { get; set; }
/// <summary>
/// 通过程序集名称管理动态加载的程序集用于节点创建提供方法描述流程运行时提供Emit委托
/// </summary>
public IFlowLibraryService FlowLibraryService { get; set; }
/// <summary> /// <summary>
/// UI线程操作类 /// UI线程操作类
/// </summary> /// </summary>
@@ -184,10 +191,7 @@ namespace Serein.NodeFlow.Env
/// </summary> /// </summary>
private ISereinIOC _flowEnvIOC; private ISereinIOC _flowEnvIOC;
/// <summary>
/// 通过程序集名称管理动态加载的程序集用于节点创建提供方法描述流程运行时提供Emit委托
/// </summary>
private readonly FlowLibraryService _flowLibraryService;
/// <summary> /// <summary>
/// 流程节点操作服务 /// 流程节点操作服务
@@ -302,9 +306,9 @@ namespace Serein.NodeFlow.Env
} }
var projectData = flowProjectData ?? throw new ArgumentNullException(nameof(flowProjectData)); var projectData = flowProjectData ?? throw new ArgumentNullException(nameof(flowProjectData));
if (!_flowLibraryService.IsLoadedBaseLibrary) if (!FlowLibraryService.IsLoadedBaseLibrary)
{ {
var baseLibrary = _flowLibraryService.LoadBaseLibrary(); var baseLibrary = FlowLibraryService.LoadBaseLibrary();
if (baseLibrary.MethodInfos.Count > 0 && UIContextOperation is not null) if (baseLibrary.MethodInfos.Count > 0 && UIContextOperation is not null)
{ {
await UIContextOperation.InvokeAsync(() => Event.OnDllLoad(new LoadDllEventArgs(baseLibrary))); // 通知UI创建dll面板显示 await UIContextOperation.InvokeAsync(() => Event.OnDllLoad(new LoadDllEventArgs(baseLibrary))); // 通知UI创建dll面板显示
@@ -360,7 +364,7 @@ namespace Serein.NodeFlow.Env
{ {
var projectData = new SereinProjectData() var projectData = new SereinProjectData()
{ {
Librarys = this._flowLibraryService.GetAllLibraryInfo().ToArray(), Librarys = this.FlowLibraryService.GetAllLibraryInfo().ToArray(),
Nodes = _flowModelService.GetAllNodeModel() Nodes = _flowModelService.GetAllNodeModel()
.Select(node => node.ToInfo()) .Select(node => node.ToInfo())
.Where(info => info is not null) .Where(info => info is not null)
@@ -384,7 +388,8 @@ namespace Serein.NodeFlow.Env
{ {
try try
{ {
var libraryInfo = _flowLibraryService.LoadFlowLibrary(dllPath);
var libraryInfo = FlowLibraryService.LoadFlowLibrary(dllPath);
if (libraryInfo is not null && libraryInfo.MethodInfos.Count > 0) if (libraryInfo is not null && libraryInfo.MethodInfos.Count > 0)
{ {
UIContextOperation?.Invoke(() => Event.OnDllLoad(new LoadDllEventArgs(libraryInfo))); // 通知UI创建dll面板显示 UIContextOperation?.Invoke(() => Event.OnDllLoad(new LoadDllEventArgs(libraryInfo))); // 通知UI创建dll面板显示
@@ -407,7 +412,7 @@ namespace Serein.NodeFlow.Env
var groupedNodes = _flowModelService.GetAllNodeModel().Where(node => !string.IsNullOrWhiteSpace(node.MethodDetails.AssemblyName) && node.MethodDetails.AssemblyName.Equals(assemblyName)).ToArray(); var groupedNodes = _flowModelService.GetAllNodeModel().Where(node => !string.IsNullOrWhiteSpace(node.MethodDetails.AssemblyName) && node.MethodDetails.AssemblyName.Equals(assemblyName)).ToArray();
if (groupedNodes.Length == 0) if (groupedNodes.Length == 0)
{ {
var isPass = _flowLibraryService.UnloadLibrary(assemblyName); var isPass = FlowLibraryService.UnloadLibrary(assemblyName);
return isPass; return isPass;
} }
else else
@@ -508,7 +513,7 @@ namespace Serein.NodeFlow.Env
public bool TryGetMethodDetailsInfo(string assemblyName, string methodName, out MethodDetailsInfo? mdInfo) public bool TryGetMethodDetailsInfo(string assemblyName, string methodName, out MethodDetailsInfo? mdInfo)
{ {
var isPass = _flowLibraryService.TryGetMethodDetails(assemblyName, methodName, out var md); var isPass = FlowLibraryService.TryGetMethodDetails(assemblyName, methodName, out var md);
if (!isPass || md is null) if (!isPass || md is null)
{ {
mdInfo = null; mdInfo = null;
@@ -534,7 +539,7 @@ namespace Serein.NodeFlow.Env
/// <returns></returns> /// <returns></returns>
public bool TryGetDelegateDetails(string assemblyName, string methodName, out DelegateDetails? delegateDetails) public bool TryGetDelegateDetails(string assemblyName, string methodName, out DelegateDetails? delegateDetails)
{ {
return _flowLibraryService.TryGetDelegateDetails(assemblyName, methodName, out delegateDetails); return FlowLibraryService.TryGetDelegateDetails(assemblyName, methodName, out delegateDetails);
} }
/// <summary> /// <summary>
@@ -662,7 +667,6 @@ namespace Serein.NodeFlow.Env
/// <returns></returns> /// <returns></returns>
public bool LoadNativeLibraryOfRuning(string file) public bool LoadNativeLibraryOfRuning(string file)
{ {
return NativeDllHelper.LoadDll(file); return NativeDllHelper.LoadDll(file);
} }
@@ -685,6 +689,11 @@ namespace Serein.NodeFlow.Env
{ {
} }
Task IFlowEnvironment.StartRemoteServerAsync(int port)
{
throw new NotImplementedException();
}
} }

View File

@@ -251,7 +251,7 @@ namespace Serein.NodeFlow.Model.Nodes
var index = node.MethodDetails.MethodName.IndexOf('('); var index = node.MethodDetails.MethodName.IndexOf('(');
var methodName = tempName[..(index - 1)]; var methodName = tempName[..(index - 1)];
return GetApiInvokeName(node, methodName);*/ return GetApiInvokeName(node, methodName);*/
FlowLibraryService service = node.Env.IOC.Get<FlowLibraryService>(); IFlowLibraryService service = node.Env.IOC.Get<IFlowLibraryService>();
if (service.TryGetMethodInfo(md.AssemblyName, md.MethodName, out var methodInfo)) if (service.TryGetMethodInfo(md.AssemblyName, md.MethodName, out var methodInfo))
{ {

View File

@@ -196,7 +196,7 @@ namespace Serein.NodeFlow.Model.Nodes
string returnTypeName = nodeInfo.CustomData?.ReturnTypeName ?? typeof(object); string returnTypeName = nodeInfo.CustomData?.ReturnTypeName ?? typeof(object);
var flowLibService = Env.IOC.Get<FlowLibraryService>(); var flowLibService = Env.IOC.Get<IFlowLibraryService>();
Type?[] argType = array.Select(info => string.IsNullOrWhiteSpace(info.ArgType) ? typeof(Unit) Type?[] argType = array.Select(info => string.IsNullOrWhiteSpace(info.ArgType) ? typeof(Unit)
: Type.GetType(info.ArgType) : Type.GetType(info.ArgType)

View File

@@ -56,7 +56,7 @@ namespace Serein.NodeFlow.Model.Operations
/// 流程依赖服务 /// 流程依赖服务
/// </summary> /// </summary>
[AutoInjection] [AutoInjection]
protected FlowLibraryService flowLibraryManagement; protected IFlowLibraryService flowLibraryManagement;
/// <summary> /// <summary>
/// 流程事件服务 /// 流程事件服务

View File

@@ -79,7 +79,8 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Serein.Extend.NewtonsoftJson\Serein.Extend.NewtonsoftJson.csproj" /> <ProjectReference Include="..\Serein.Extend.NewtonsoftJson\Serein.Extend.NewtonsoftJson.csproj" />
<ProjectReference Include="..\Serein.Library.MyGenerator\Serein.Library.NodeGenerator.csproj" OutputItemType="Analyzer" /> <ProjectReference Include="..\Serein.Library.NodeGenerator\Serein.Library.NodeGenerator.csproj" OutputItemType="Analyzer"/>
<ProjectReference Include="..\Library\Serein.Library.csproj" /> <ProjectReference Include="..\Library\Serein.Library.csproj" />

View File

@@ -2,6 +2,7 @@
using Serein.Library; using Serein.Library;
using Serein.Library.Api; using Serein.Library.Api;
using Serein.NodeFlow.Env; using Serein.NodeFlow.Env;
using Serein.NodeFlow.Services;
using Serein.Workbench.Api; using Serein.Workbench.Api;
using Serein.Workbench.Models; using Serein.Workbench.Models;
using Serein.Workbench.Services; using Serein.Workbench.Services;
@@ -27,6 +28,9 @@ namespace Serein.Workbench.ViewModels
this.flowEnvironment = flowEnvironment; this.flowEnvironment = flowEnvironment;
FlowLibraryInfos = new ObservableCollection<Models.FlowLibraryInfo>(); FlowLibraryInfos = new ObservableCollection<Models.FlowLibraryInfo>();
flowEEForwardingService.DllLoad += FlowEEForwardingService_OnDllLoad; flowEEForwardingService.DllLoad += FlowEEForwardingService_OnDllLoad;
//var baseLibrary = App.GetService<IFlowLibraryService>().LoadBaseLibrary();
} }
/// <summary> /// <summary>
/// 加载文件依赖 /// 加载文件依赖

View File

@@ -6,6 +6,7 @@
xmlns:local="clr-namespace:Serein.Workbench.Views" xmlns:local="clr-namespace:Serein.Workbench.Views"
xmlns:vm="clr-namespace:Serein.Workbench.ViewModels" xmlns:vm="clr-namespace:Serein.Workbench.ViewModels"
xmlns:converter="clr-namespace:Serein.Workbench.Converters" xmlns:converter="clr-namespace:Serein.Workbench.Converters"
xmlns:template="clr-namespace:CXLims.Software.WPFTemplate"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="300" d:DesignHeight="600" d:DesignWidth="300"
d:DataContext="{d:DesignInstance vm:ViewCanvasInfoViewModel}"> d:DataContext="{d:DesignInstance vm:ViewCanvasInfoViewModel}">
@@ -118,6 +119,31 @@
<TextBox Text="{Binding Model.ScaleY, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource InfoValueTextBox}"/> <TextBox Text="{Binding Model.ScaleY, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource InfoValueTextBox}"/>
</StackPanel> </StackPanel>
<StackPanel x:Name="TestBtn"
Height="100"
DataContext="{Binding}"
template:XScript.TriggerType="Event"
Background="AliceBlue"
template:XScript.TriggerName="MouseLeave"
template:XScript.Return="{Binding Tag, RelativeSource={RelativeSource Self}}"
template:XScript.ParamName1="canvasModel"
template:XScript.ParamData1="{Binding Model}"
>
<template:XScript.XamlScript>
<template:XamlScript>
<![CDATA[
debug(vm);
return canvasModel.Guid;
]]>
</template:XamlScript>
</template:XScript.XamlScript>
</StackPanel>
<TextBlock Text="{Binding ElementName=TestBtn, Path=Tag}"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</Border> </Border>