private void OnCommStateChanged(object sender, CommStateChangedEventArgs args) { try { var remoteNode = GlobalServices.Repository.Where <SystemNode>(p => p.Code == args.RemoteNodeCode).FirstOrDefault(); // 产生事件。 var eventLog = new SysEventLog(); eventLog.TypeCode = args.CommState.GetValueOrDefault() ? EventType.CommRecovery : EventType.CommInterruption; eventLog.Level = GlobalServices.SEM.GetEventLevel(eventLog.TypeCode); var nodeName = remoteNode == null?string.Format("{0}", args.RemoteNodeCode) : string.Format("{0}_{1}", args.RemoteNodeCode, remoteNode.Name); if (args.CommState.GetValueOrDefault()) { eventLog.Description = string.Format("本节点与远程节点({0})通信恢复。", nodeName); } else { eventLog.Description = string.Format("本节点与远程节点({0})通信中断。", nodeName); } // 发布事件 GlobalMessageBus.PublishNewSystemEventGenerated(new NewSystemEventArgs(eventLog)); } catch (System.Exception ex) { LogUtility.Error(ex); } }
private void btnGenerateSysEvent_Click(object sender, EventArgs e) { try { // 模拟产生一个系统日志;系统将显示此日志并进行持久化。 var log = new SysEventLog(EventType.CommRecovery, EventLevel.First, "节点 A 与节点 B 通信恢复。"); GlobalMessageBus.PublishNewSystemEventGenerated(new NewSystemEventArgs(log)); // 模拟产生一个系统日志;系统将显示此日志并进行持久化。 log = new SysEventLog(EventType.CommInterruption, EventLevel.Third, "节点 A 与节点 B 通信中断。"); GlobalMessageBus.PublishNewSystemEventGenerated(new NewSystemEventArgs(log)); // 模拟产生一个通信中断消息;系统将显示此消息并自动产生一个系统日志;然后持久化。 var args = new CommStateChangedEventArgs(false, NodeType.Node1, 16, NodeType.Node2, 18); GlobalMessageBus.PublishCommStateChanged(args); // 查询 log = GlobalServices.Repository.Where <SysEventLog>(p => p.Code == log.Code).FirstOrDefault(); LogUtility.Info("{0}", log); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void confirmAllToolStripMenuItem_Click(object sender, EventArgs e) { try { var timeNow = DateTime.Now; var rows = dataGridView.Rows; for (var i = 0; i < rows.Count; i++) { var theLog = rows[i].Tag as SysEventLog; var confirmEnabled = GlobalServices.SEM.GetConfirmEnabled(theLog.TypeCode); if (confirmEnabled && !theLog.IsConfirmed) { theLog.ConfirmTime = timeNow; GlobalMessageBus.PublishNewSystemEventGenerated(new NewSystemEventArgs(theLog)); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }