|
|
@@ -133,22 +133,19 @@ namespace YSAI.Core.data
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- if (RegisterEvent())
|
|
|
+ //类的唯一标识符
|
|
|
+ string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
+ //方法的唯一标识符
|
|
|
+ string MethodSN = "[Produce]";
|
|
|
+ //执行转发方法
|
|
|
+ OperateResult operateResult = reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { PacketType.Message.ToString(), addressValue.ToJson().JsonFormatting() }) as OperateResult;
|
|
|
+ //状态判断
|
|
|
+ if (!operateResult.State)
|
|
|
{
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //方法的唯一标识符
|
|
|
- string MethodSN = "[Produce]";
|
|
|
- //执行转发方法
|
|
|
- OperateResult operateResult = reflectionOperate.ExecuteMethod($"{ClassSN}{MethodSN}", new object[] { PacketType.Message.ToString(), addressValue.ToJson().JsonFormatting() }) as OperateResult;
|
|
|
- //状态判断
|
|
|
- if (!operateResult.State)
|
|
|
- {
|
|
|
- DynamicObj.Value = addressValue;
|
|
|
- DynamicObj.State = operateResult.State;
|
|
|
- DynamicObj.Exception = operateResult.Message;
|
|
|
- LogHelper.Error(DynamicObj.ToJson(), logName);
|
|
|
- }
|
|
|
+ DynamicObj.Value = addressValue;
|
|
|
+ DynamicObj.State = operateResult.State;
|
|
|
+ DynamicObj.Exception = operateResult.Message;
|
|
|
+ LogHelper.Error(DynamicObj.ToJson(), logName);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
@@ -158,52 +155,25 @@ namespace YSAI.Core.data
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 注册事件状态
|
|
|
- /// </summary>
|
|
|
- private static bool RegisterEventState = false;
|
|
|
- /// <summary>
|
|
|
- /// 执行注册事件
|
|
|
+ /// 转发事件外部注册
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
- private static bool RegisterEvent()
|
|
|
+ public static bool RelayEventRegister(Action<object, object> action)
|
|
|
{
|
|
|
- if (!RegisterEventState)
|
|
|
+ //类的唯一标识符
|
|
|
+ string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
+ //事件的唯一标识符
|
|
|
+ string EventSN = "[OnEvent]";
|
|
|
+ //注册事件
|
|
|
+ OperateResult operateResult = reflectionOperate.RegisterEvent($"{ClassSN}{EventSN}", true, P2: action);
|
|
|
+ if (!operateResult.State)
|
|
|
{
|
|
|
- //类的唯一标识符
|
|
|
- string ClassSN = "YSAI.RelayManage.RelayManageOperate[Instance]";
|
|
|
- //事件的唯一标识符
|
|
|
- string EventSN = "[OnEvent]";
|
|
|
- //注册事件
|
|
|
- OperateResult operateResult = reflectionOperate.RegisterEvent($"{ClassSN}{EventSN}", true, P2: RelayManageOperate_OnEvent);
|
|
|
- if (!operateResult.State)
|
|
|
- {
|
|
|
- throw new Exception($"注册事件失败:{operateResult.Message}");
|
|
|
- }
|
|
|
- RegisterEventState = operateResult.State;
|
|
|
- return operateResult.State;
|
|
|
+ throw new Exception($"注册事件失败:{operateResult.Message}");
|
|
|
}
|
|
|
- return true;
|
|
|
+ return operateResult.State;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 转发的事件注册
|
|
|
- /// </summary>
|
|
|
- /// <param name="sender"></param>
|
|
|
- /// <param name="e"></param>
|
|
|
- /// <exception cref="NotImplementedException"></exception>
|
|
|
- private static void RelayManageOperate_OnEvent(object? sender, object e)
|
|
|
- {
|
|
|
- //日志文件名称
|
|
|
- string logName = "RelayEvent.log";
|
|
|
- EventResult eventResult = e as EventResult;
|
|
|
- if (eventResult != null)
|
|
|
- {
|
|
|
- if (!eventResult.State)
|
|
|
- {
|
|
|
- LogHelper.Error(eventResult.ToJson().JsonFormatting(), logName);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|