mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-06 08:06:33 +08:00
取消使用流程上下文自定义的字典数据;更改流程环境接口的输出方式
This commit is contained in:
@@ -34,31 +34,31 @@ namespace Serein.Library.Utils
|
||||
foreach (var prop in objType.GetProperties())
|
||||
{
|
||||
var value = prop.GetValue(obj);
|
||||
Console.WriteLine($"{indent}{prop.Name} (Type: {prop.PropertyType.Name}): {value}");
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"{indent}{prop.Name} (Type: {prop.PropertyType.Name}): {value}");
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
if (prop.PropertyType.IsArray) // 处理数组类型
|
||||
{
|
||||
var array = (Array)value;
|
||||
Console.WriteLine($"{indent}{prop.Name} is an array with {array.Length} elements:");
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"{indent}{prop.Name} is an array with {array.Length} elements:");
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
var element = array.GetValue(i);
|
||||
if (element != null && element.GetType().IsClass && !(element is string))
|
||||
{
|
||||
Console.WriteLine($"{indent}\tArray[{i}] (Type: {element.GetType().Name}) contains a nested object:");
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"{indent}\tArray[{i}] (Type: {element.GetType().Name}) contains a nested object:");
|
||||
PrintObjectProperties(element, indent + "\t\t");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{indent}\tArray[{i}] (Type: {element?.GetType().Name}): {element}");
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"{indent}\tArray[{i}] (Type: {element?.GetType().Name}): {element}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (value.GetType().IsClass && !(value is string)) // 处理嵌套对象
|
||||
{
|
||||
Console.WriteLine($"{indent}{prop.Name} contains a nested object:");
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"{indent}{prop.Name} contains a nested object:");
|
||||
PrintObjectProperties(value, indent + "\t");
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ namespace Serein.Library.Utils
|
||||
if (propInfo == null)
|
||||
{
|
||||
// 属性不存在,打印警告并标记失败
|
||||
Console.WriteLine($"Warning: 属性 '{propName}' 不存在于类型 '{objType.Name}' 中,跳过赋值。");
|
||||
SereinEnv.WriteLine(InfoType.WARN, $"属性 '{propName}' 不存在于类型 '{objType.Name}' 中,跳过赋值。");
|
||||
allSuccessful = false;
|
||||
continue;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ namespace Serein.Library.Utils
|
||||
if (!IsCompatibleType(targetType, propValue))
|
||||
{
|
||||
// 如果类型不兼容,打印错误并标记失败
|
||||
Console.WriteLine($"Error: 无法将类型 '{propValue?.GetType().Name}' 赋值给属性 '{propName}' (Type: {targetType.Name}),跳过赋值。");
|
||||
SereinEnv.WriteLine(InfoType.ERROR, $"无法将类型 '{propValue?.GetType().Name}' 赋值给属性 '{propName}' (Type: {targetType.Name}),跳过赋值。");
|
||||
allSuccessful = false;
|
||||
continue;
|
||||
}
|
||||
@@ -257,7 +257,7 @@ namespace Serein.Library.Utils
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: 为属性 '{propName}' 赋值时发生异常:{ex.Message}");
|
||||
SereinEnv.WriteLine(InfoType.ERROR, $"为属性 '{propName}' 赋值时发生异常:{ex.Message}");
|
||||
allSuccessful = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Serein.Library.Utils
|
||||
public async Task<bool> ConnectAsync()
|
||||
{
|
||||
// 第2种,WebSocket连接到远程环境,实时接收远程环境的响应?
|
||||
Console.WriteLine($"准备连接:{Config.Addres}:{Config.Port},{Config.Token}");
|
||||
SereinEnv.WriteLine(InfoType.INFO, $"准备连接:{Config.Addres}:{Config.Port},{Config.Token}");
|
||||
bool success = false;
|
||||
try
|
||||
{
|
||||
@@ -97,7 +97,7 @@ namespace Serein.Library.Utils
|
||||
}
|
||||
if (!success)
|
||||
{
|
||||
Console.WriteLine($"无法连通远程端口 {Config.Addres}:{Config.Port}");
|
||||
SereinEnv.WriteLine(InfoType.ERROR, $"无法连通远程端口 {Config.Addres}:{Config.Port}");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -150,7 +150,6 @@ namespace Serein.Library.Utils
|
||||
};
|
||||
}
|
||||
var msg = jsonData.ToString();
|
||||
//Console.WriteLine($"[{msgId}] => {theme}");
|
||||
await EnvClient.SendAsync(msg);
|
||||
}
|
||||
|
||||
|
||||
27
Library/Utils/SereinEnv.cs
Normal file
27
Library/Utils/SereinEnv.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Serein.Library.Api;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Utils
|
||||
{
|
||||
public static class SereinEnv
|
||||
{
|
||||
private static IFlowEnvironment environment;
|
||||
public static void SetEnv(IFlowEnvironment environment)
|
||||
{
|
||||
if (environment != null)
|
||||
{
|
||||
SereinEnv.environment = environment;
|
||||
}
|
||||
}
|
||||
public static void WriteLine(InfoType type, string message, InfoClass @class = InfoClass.Trivial)
|
||||
{
|
||||
SereinEnv.environment.WriteLine(type,message,@class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace Serein.Library.Utils.SereinExpression
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
SereinEnv.WriteLine(InfoType.ERROR, ex.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Serein.Library.Utils
|
||||
{
|
||||
@@ -130,7 +131,7 @@ namespace Serein.Library.Utils
|
||||
var instance = Get(type.FullName);
|
||||
if(instance is null)
|
||||
{
|
||||
Console.WriteLine("类型没有注册:" + type.FullName);
|
||||
SereinEnv.WriteLine(InfoType.INFO, "类型没有注册:" + type.FullName);
|
||||
}
|
||||
|
||||
return Get(type.FullName);
|
||||
@@ -254,8 +255,8 @@ namespace Serein.Library.Utils
|
||||
private ConstructorInfo[] GetConstructor(Type type)
|
||||
{
|
||||
return type.GetConstructors()
|
||||
.OrderByDescending(c => c.GetParameters().Length)
|
||||
.OrderBy(ctor => ctor.GetParameters().Length).ToArray();
|
||||
//.OrderByDescending(c => c.GetParameters().Length)
|
||||
.OrderByDescending(ctor => ctor.GetParameters().Length).ToArray();
|
||||
}
|
||||
|
||||
// 生成顺序
|
||||
@@ -315,11 +316,13 @@ namespace Serein.Library.Utils
|
||||
var tmpList = indegree.Where(kv => kv.Value > 0).Select(kv => kv.Key).ToList();
|
||||
if (tmpList.Count > 0)
|
||||
{
|
||||
Console.WriteLine("以下类型可能产生循环依赖,请避免循环依赖,如果确实需要循环引用,请使用 [AutoInjection] 特性注入属性");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("以下类型可能产生循环依赖,请避免循环依赖,如果确实需要循环引用,请使用 [AutoInjection] 特性注入属性");
|
||||
foreach (var kv in tmpList)
|
||||
{
|
||||
Console.WriteLine($"Class Name : {kv}");
|
||||
sb.AppendLine($"Class Name : {kv}");
|
||||
}
|
||||
SereinEnv.WriteLine(InfoType.ERROR, sb.ToString());
|
||||
}
|
||||
|
||||
return creationOrder;
|
||||
@@ -369,7 +372,7 @@ namespace Serein.Library.Utils
|
||||
argObj = CreateInstance(fullName);
|
||||
if (argObj is null)
|
||||
{
|
||||
Console.WriteLine("构造参数创建失败"); //
|
||||
SereinEnv.WriteLine(InfoType.WARN, "构造参数创建失败");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user