private void HandlerSwitchExecute() { List <CncEventData> tempEventDatas = new List <CncEventData>(m_EventDatas.ToArray()); tempEventDatas.ForEach(item => { string info = ""; switch (item.Kind) { case CncEventEnum.ReadPmc: info = ReadPmcHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadMacro: info = ReadMacroHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadPosition: info = ReadPositionHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadAlarm: info = ReadAlarmHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadNotice: info = ReadNoticeHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadProgramName: info = ReadProgramNameHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadProgramBlock: info = ReadProgramBlockHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadProgramStr: info = ReadProgramStrHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadProgramInfo: info = ReadProgramInfoHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadModalInfo: info = ReadModalInfoHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadCycleTime: info = ReadCycleTimeHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadWorkpartNum: info = ReadWorkpartNumHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadSpindleSpeed: info = ReadSpindleSpeedHandle(ref m_flib, item.Para); break; case CncEventEnum.ReadFeedrate: info = ReadFeedrateHandle(ref m_flib, item.Para); break; default: break; } if (info?.Length >= 1) { ShowErrorLogEvent?.Invoke(info); } }); }
private void HandlerExecute() { List <CncEventData> tempEventDatas = new List <CncEventData>(); foreach (var item in MMKSmartSystemWebCommonConsts.PageCncEventDict) { tempEventDatas.AddRange(item.Value); } List <DyHandlerProxy> dyHandlers = new List <DyHandlerProxy>(); var listGroup = tempEventDatas.GroupBy(d => d.Kind); foreach (var item in listGroup) { Type kindtype = item.Key.GetType(); FieldInfo fd = kindtype.GetField(item.Key.ToString()); var cncCustom = fd.GetCustomAttribute <CncCustomEventAttribute>(); if (cncCustom == null) { ShowErrorLogEvent?.Invoke($"未定义与前端定义的映射模型{item.Key.ToString()} CncCustomEvent"); continue; } var handlerType = Type.GetType(cncCustom.HandlerName); if (handlerType == null) { ShowErrorLogEvent?.Invoke($"未定义{cncCustom.HandlerName} Handler"); continue; } try { var handler = iocManager.Resolve(handlerType); var methodInfo = handlerType.GetMethod("MargePollRequest"); var methodType = methodInfo.GetParameters()[0].ParameterType; var firstParm = typeof(CncEventData).Assembly.CreateInstance(methodType.FullName); foreach (var data in item) { var jsonData = JsonConvert.DeserializeObject(data.Para, methodType); firstParm = methodInfo.Invoke(handler, new object[] { firstParm, jsonData }); } dyHandlers.Add(new DyHandlerProxy() { Handler = handler, Method = handlerType.GetMethod("PollHandle"), Parms = firstParm }); } catch (Exception ex) { ShowErrorLogEvent?.Invoke($"CncCustomEnum:【{item.Key}】{ex.Message}"); } } foreach (var item in dyHandlers) { try { var info = item.Method.Invoke(item.Handler, new object[] { item.Parms }); JObject jObject = JObject.FromObject(info); if (!string.IsNullOrEmpty(jObject["ErrorMessage"]?.ToString())) { string message = jObject["ErrorMessage"]?.ToString(); string error = "\r\n==============Begin【Hander Exception】==============\n"; error += $"Hander:【{item.Handler.ToString()}】 Method:【{item.Method.Name}】\n"; error += $"【HanderError】:{message}\n"; error += "==============End【Hander Exception】==============\r\n"; ShowErrorLogEvent?.Invoke(error); continue; } GetResultEvent(info); } catch (Exception ex) { string error = "\r\n==============Begin【Hander Exception】==============\n"; error += $"Hander:【{item.Handler.ToString()}】 Method:【{item.Method.Name}】\n"; error += $"【Exception】:{ex.Message}\n"; error += $"【InnerException】:{ex.InnerException?.Message}\n"; error += "==============End【Hander Exception】==============\r\n"; ShowErrorLogEvent?.Invoke(error); } } }