|
|
@@ -20,11 +20,6 @@ namespace YSAI.Core.handler
|
|
|
/// 处理异常日志输出文件
|
|
|
/// </summary>
|
|
|
private readonly static string ExecuteDisposeLog = "ExecuteDispose.log";
|
|
|
- /// <summary>
|
|
|
- /// 解析异常日志输出文件
|
|
|
- /// </summary>
|
|
|
- private readonly static string ParseLog = "Parse.log";
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 反射操作
|
|
|
/// </summary>
|
|
|
@@ -45,7 +40,7 @@ namespace YSAI.Core.handler
|
|
|
string originalValue = value;
|
|
|
|
|
|
//解析
|
|
|
- value = Parse(addressDetails, value);
|
|
|
+ value = ParseHandler.Parse(addressDetails, value);
|
|
|
|
|
|
//最终数据组织
|
|
|
AddressValue addressValue = new AddressValue().SET(addressDetails);
|
|
|
@@ -59,7 +54,7 @@ namespace YSAI.Core.handler
|
|
|
if (reflectionOperate.ReflectionState)
|
|
|
{
|
|
|
//转发
|
|
|
- OperateResult operateResult = Produce("Message", addressValue.ToJson().JsonFormatting());
|
|
|
+ OperateResult operateResult = RelayHandler.Produce("Message", addressValue.ToJson().JsonFormatting());
|
|
|
if (!operateResult.State)
|
|
|
{
|
|
|
//转发失败存入本地记录
|
|
|
@@ -76,330 +71,6 @@ namespace YSAI.Core.handler
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 数据解析
|
|
|
- /// </summary>
|
|
|
- /// <param name="addressDetails">地址详情</param>
|
|
|
- /// <param name="value">当前值</param>
|
|
|
- /// <returns></returns>
|
|
|
- public static string Parse(AddressDetails addressDetails, string value)
|
|
|
- {
|
|
|
- //最新值
|
|
|
- string? NewValue = value;
|
|
|
- if (addressDetails.AddressParseParam != null)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- switch (addressDetails.AddressParseParam.ParseType)
|
|
|
- {
|
|
|
- case ParseType.MethodAnalysis:
|
|
|
- NewValue = reflectionOperate.ExecuteMethod(addressDetails.AddressParseParam.ReflectionSN, new object[] { value })?.ToString();
|
|
|
- break;
|
|
|
- case ParseType.ScriptAnalysis:
|
|
|
- using (ScriptOperate scriptOperate = new ScriptOperate(addressDetails.AddressParseParam.Script)) //通过脚本解析
|
|
|
- {
|
|
|
- OperateResult operateResult = scriptOperate.Execute(addressDetails.AddressParseParam.Script.ScriptType, addressDetails.AddressParseParam.Script.ScriptCode, addressDetails.AddressParseParam.Script.ScriptFunction, value);
|
|
|
- if (operateResult.State)
|
|
|
- {
|
|
|
- NewValue = operateResult.RData?.ToString();
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- if (string.IsNullOrEmpty(NewValue))
|
|
|
- {
|
|
|
- NewValue = value;
|
|
|
- }
|
|
|
- return NewValue;
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogHelper.Error("解析异常:" + ex.ToString(), ParseLog);
|
|
|
- }
|
|
|
- }
|
|
|
- return value;
|
|
|
- }
|
|
|
-
|
|
|
- #region 转发库的操作
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 订阅
|
|
|
- /// </summary>
|
|
|
- /// <param name="Topic">主题</param>
|
|
|
- /// <param name="ISn">实例唯一标识符</param>
|
|
|
- /// <returns>统一出参</returns>
|
|
|
- public static OperateResult Subscribe(string Topic, string ISn)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[Subscribe]";
|
|
|
- //执行转发方法
|
|
|
- return reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { Topic, ISn }) as OperateResult;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return new OperateResult(false, $"反射状态 {reflectionOperate.ReflectionState} 不做此操作", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return new OperateResult(false, $"转发事件注册异常:{ex.Message}", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 取消订阅
|
|
|
- /// </summary>
|
|
|
- /// <param name="Topic">主题</param>
|
|
|
- /// <param name="ISn">实例唯一标识符</param>
|
|
|
- /// <returns>统一出参</returns>
|
|
|
- public static OperateResult UnSubscribe(string Topic, string ISn)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[UnSubscribe]";
|
|
|
- //执行转发方法
|
|
|
- return reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { Topic, ISn }) as OperateResult;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return new OperateResult(false, $"反射状态 {reflectionOperate.ReflectionState} 不做此操作", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return new OperateResult(false, $"转发事件注册异常:{ex.Message}", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 生产
|
|
|
- /// </summary>
|
|
|
- /// <param name="Topic">主题</param>
|
|
|
- /// <param name="Content">内容</param>
|
|
|
- /// <param name="ISns">实例唯一标识符集合,空则全部发送</param>
|
|
|
- /// <returns>统一出参</returns>
|
|
|
- public static OperateResult Produce(string Topic, string Content, List<string>? ISns = null)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[Produce]";
|
|
|
- //执行转发方法
|
|
|
- return reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { Topic, Content, ISns }) as OperateResult;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return new OperateResult(false, $"反射状态 {reflectionOperate.ReflectionState} 不做此操作", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return new OperateResult(false, $"转发事件注册异常:{ex.Message}", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 程序集唯一标识符集合
|
|
|
- /// </summary>
|
|
|
- public static List<string>? TypeSns()
|
|
|
- {
|
|
|
- if (reflectionOperate != null)
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[TypeSns]";
|
|
|
- //执行转发方法
|
|
|
- return reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", null) as List<string>;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 实例唯一标识符集合
|
|
|
- /// </summary>
|
|
|
- public static List<string>? InstanceSns()
|
|
|
- {
|
|
|
- if (reflectionOperate != null)
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[InstanceSns]";
|
|
|
- //执行转发方法
|
|
|
- return reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", null) as List<string>;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 释放指定实例
|
|
|
- /// </summary>
|
|
|
- /// <param name="ISn">实例唯一标识符</param>
|
|
|
- /// <returns>统一出参</returns>
|
|
|
- public static OperateResult DisposeISn(string ISn)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[DisposeISn]";
|
|
|
- //执行转发方法
|
|
|
- return reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { ISn }) as OperateResult;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return new OperateResult(false, $"反射状态 {reflectionOperate.ReflectionState} 不做此操作", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return new OperateResult(false, $"转发事件注册异常:{ex.Message}", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 移除指定实例
|
|
|
- /// </summary>
|
|
|
- /// <param name="ISn">实例唯一标识符</param>
|
|
|
- /// <returns>统一出参</returns>
|
|
|
- public static OperateResult RemoveISn(string ISn)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[RemoveISn]";
|
|
|
- //执行转发方法
|
|
|
- return reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { ISn }) as OperateResult;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return new OperateResult(false, $"反射状态 {reflectionOperate.ReflectionState} 不做此操作", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return new OperateResult(false, $"转发事件注册异常:{ex.Message}", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 打开
|
|
|
- /// </summary>
|
|
|
- /// <param name="ISn">实例唯一标识符</param>
|
|
|
- /// <returns>统一出参</returns>
|
|
|
- public static OperateResult On(string ISn)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[On]";
|
|
|
- //执行转发方法
|
|
|
- return reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { ISn }) as OperateResult;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return new OperateResult(false, $"反射状态 {reflectionOperate.ReflectionState} 不做此操作", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return new OperateResult(false, $"转发事件注册异常:{ex.Message}", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 关闭
|
|
|
- /// </summary>
|
|
|
- /// <param name="ISn">实例唯一标识符</param>
|
|
|
- /// <returns>统一出参</returns>
|
|
|
- public static OperateResult Off(string ISn)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[Off]";
|
|
|
- //执行转发方法
|
|
|
- return reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { ISn }) as OperateResult;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return new OperateResult(false, $"反射状态 {reflectionOperate.ReflectionState} 不做此操作", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return new OperateResult(false, $"转发事件注册异常:{ex.Message}", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 转发事件注册
|
|
|
- /// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- public static OperateResult RelayEventRegister(Action<object, object> action, bool Register = true)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- //反射状态为true才进行操作
|
|
|
- if (reflectionOperate.ReflectionState)
|
|
|
- {
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //事件的唯一标识符
|
|
|
- string EventSN = "[OnEvent]";
|
|
|
- //注册事件
|
|
|
- return reflectionOperate.RegisterEvent($"{ClassSN}{EventSN}", Register, P2: action);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return new OperateResult(false, $"反射状态 {reflectionOperate.ReflectionState} 不做此操作", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return new OperateResult(false, $"转发事件注册异常:{ex.Message}", 0.1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- #endregion
|
|
|
+
|
|
|
}
|
|
|
}
|