private void LoadAlarmsFromXml(IEnumerable level1Node)
        {
            #region alarms

            foreach (XmlNode level2Node in level1Node)
            {
                // level2 --  "alarm"
                if (level2Node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }

                var level2Item = (XmlElement)level2Node;

                if (!string.Equals(level2Item.Name.ToLower(), "alarm",
                                   StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                var almDef = AlarmDefinition.CreateFromConfig(level2Node, this);

                almDef.LoadFromConfig(level2Node);

                if (!AlarmDefinitions.ContainsKey(almDef.AlarmID)) //add by David 20170621,检测是否有重复报警
                {
                    AlarmDefinitions.Add(almDef.AlarmID, almDef);  //增加到数据源集合
                }
                else
                {
                    throw new Exception($"添加重复的报警项:{almDef.AlarmID}");
                }
            }

            #endregion
        }
        public static Alarm New(AlarmDefinition AlmDef)
        {
            Alarm _newAlarm = new Alarm();

            _newAlarm._model.AlarmId = AlmDef.AlarmID;
            _newAlarm._model.Message = AlmDef.Message;
            _newAlarm._model.Group   = AlmDef.Group;

            _newAlarm.Trig();

            return(_newAlarm);
        }
        /// <summary>
        /// 改变alarm状态Trigged,添加。
        /// </summary>
        /// <param name="AlarmDef"></param>
        /// <param name="status"></param>
        public void ChangeAlarmStatus(AlarmDefinition AlarmDef, AlarmSignalStatus status)
        {
            if (status == AlarmSignalStatus.Trigged)
            {                                              // 处于报警状态
                if (!_liveAlarms.Keys.Contains(AlarmDef.AlarmID))
                {                                          //原来不存在此报警
                    Alarm new_alarm = Alarm.New(AlarmDef); //新增一条报警
                    _liveAlarms.Add(AlarmDef.AlarmID, new_alarm);
                }
                //2017年7月17日10:27:01  夏 注释
                //else
                //{//原来存在此报警
                //    Alarm alarm = _liveAlarms[AlarmDef.AlarmID];
                //    if (alarm.Status != MachineAlarmModel.StatusType.Triggered)
                //    {
                //        alarm.Trig();  //触发一条报警
                //    }
                //}
            }
            else if (status == AlarmSignalStatus.Untrigged)
            {     // 不处于报警状态
                if (_liveAlarms.Keys.Contains(AlarmDef.AlarmID))
                { //原来存在此报警
                 //2017年7月17日10:27:01  夏 注释
                 //Alarm alarm = _liveAlarms[AlarmDef.AlarmID];
                 //if (alarm.Status == MachineAlarmModel.StatusType.Triggered || alarm.Status == MachineAlarmModel.StatusType.Confirmed)
                 //{
                 //    alarm.Reset(); //复位一条报警
                 //}

                    //if (alarm.Status == MachineAlarmModel.StatusType.Nottriggered) //原来报警已复位
                    //{
                    _liveAlarms.Remove(AlarmDef.AlarmID);     //删除一条报警
                    //}
                }
            }
            //else if (status == AlarmModel.StatusType.Confirmed)
            //{
            //    if (_liveAlarms.Keys.Contains(AlarmDef.AlarmID))
            //    {
            //        Alarm alarm = _liveAlarms[AlarmDef.AlarmID];
            //        alarm.Confirm();

            //        if (alarm.Status == AlarmModel.StatusType.Nottriggered)
            //            _liveAlarms.Remove(AlarmDef.AlarmID);
            //    }
            //}
        }