예제 #1
0
        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);
            }
        }
예제 #2
0
        private void CommStateChecker_DataValidityChanged(object sender, DataValidityChangedEventArgs <string> e)
        {
            try
            {
                if (this.PublishCommStateChanged)
                {
                    var tmpData    = e.Data.ToUInt32Array(10);
                    var localCode  = tmpData[0];
                    var remoteCode = tmpData[1];

                    var remoteType = this.GetRemoteType(remoteCode);

                    var args = new CommStateChangedEventArgs(e.Avaliable, this.LocalType, localCode, remoteType, remoteCode);
                    GlobalMessageBus.PublishCommStateChanged(args);

                    if (this.CommStateChanged != null)
                    {
                        this.CommStateChanged(this, args);
                    }
                }
            }
            catch (Exception /*ex*/)
            {
            }
        }