Exemple #1
0
        /// <summary>
        /// 单个告警处理
        /// </summary>
        private void SubProcessSeletionAlarm(SelectionAlarmType alarmType, Selection select)
        {
            AlarmConfigData alarmSet;
            AlarmInfo       info;
            float           temperature;

            switch (alarmType)
            {
            case SelectionAlarmType.MaxTemp:
                alarmSet    = select.mAlarmConfig.mMaxTempConfig;
                temperature = select.mTemperatureData.mMaxTemperature;
                info        = select.mAlarmInfo.mMaxTempAlarmInfo;
                break;

            case SelectionAlarmType.MinTemp:
                alarmSet    = select.mAlarmConfig.mMinTempConfig;
                temperature = select.mTemperatureData.mMinTemperature;
                info        = select.mAlarmInfo.mMinTempAlarmInfo;
                break;

            case SelectionAlarmType.AvgTemp:
                alarmSet    = select.mAlarmConfig.mAvgTempConfig;
                temperature = select.mTemperatureData.mAvgTemperature;
                info        = select.mAlarmInfo.mAvgTempAlarmInfo;
                break;

            default:
                return;
            }

            AlarmStatus lastStatus = info.mAlarmStatus;

            info.mLastAlarmLevel = info.mCurrentAlarmLevel;

            CalcAlarmInfo(alarmSet, temperature, info);
            ProcessAlarmReadyEnd(alarmSet, temperature, info);

            if (info.mAlarmStatus == AlarmStatus.AlarmStart)
            {
                info.mAlarmStatus = AlarmStatus.Alarming;

                // 添加告警
                string selectionData   = select.Serialize();
                string temperatureInfo = JsonUtils.ObjectToJson(select.mTemperatureData);

                // 阈值设置序列化
                string condition = string.Format("{0},{1},{2}", alarmSet.mGeneralThreshold,
                                                 alarmSet.mSeriousThreshold, alarmSet.mCriticalThreshold);

                List <Selection> list = new List <Selection>()
                {
                    select
                };

                // 记录告警开始时间
                info.mBeginTime = DateTime.Now;
                info.mIsTimeout = false;

                // 告警入库
                OnAddAlarmInfo?.Invoke(
                    (int)AlarmMode.Selection,
                    (int)alarmType,
                    (int)alarmSet.mAlarmReason,
                    (int)info.mCurrentAlarmLevel,
                    condition,
                    temperature,
                    select.mSelectionId,
                    select.mSelectionName,
                    selectionData,
                    temperatureInfo,
                    mMaxTemperature,
                    mMinTemperature,
                    list,
                    info);
            }
            else if (info.mAlarmStatus == AlarmStatus.AlarmEnd)
            {
                info.mAlarmStatus = AlarmStatus.Unknown;

                // 结束告警
                string selectionData = select.Serialize();
                OnUpdateAlarmInfo?.Invoke(
                    (int)AlarmMode.Selection,
                    (int)alarmType,
                    select.mSelectionId,
                    selectionData,
                    info);

                // 取消超时
                info.mIsTimeout = true;
            }
            else if (info.mAlarmStatus == AlarmStatus.AlarmingChanged)
            {
                // 结束上一次告警
                string selectionData = select.Serialize();
                OnUpdateAlarmInfo?.Invoke(
                    (int)AlarmMode.Selection,
                    (int)alarmType,
                    select.mSelectionId,
                    selectionData,
                    info);

                string           temperatureInfo = JsonUtils.ObjectToJson(select.mTemperatureData);
                List <Selection> list            = new List <Selection>()
                {
                    select
                };

                // 阈值设置序列化
                string condition = string.Format("{0},{1},{2}", alarmSet.mGeneralThreshold,
                                                 alarmSet.mSeriousThreshold, alarmSet.mCriticalThreshold);

                // 记录告警开始时间
                info.mBeginTime   = DateTime.Now;
                info.mIsTimeout   = false;
                info.mAlarmStatus = AlarmStatus.Alarming;

                OnAddAlarmInfo?.Invoke(
                    (int)AlarmMode.Selection,
                    (int)alarmType,
                    (int)alarmSet.mAlarmReason,
                    (int)info.mCurrentAlarmLevel,
                    condition,
                    temperature,
                    select.mSelectionId,
                    select.mSelectionName,
                    selectionData,
                    temperatureInfo,
                    mMaxTemperature,
                    mMinTemperature,
                    list,
                    info);
            }
            else if (((info.mAlarmStatus == AlarmStatus.Alarming) ||
                      (info.mAlarmStatus == AlarmStatus.AlarmingReadyChanged)) &&
                     (info.mIsTimeout == false))
            {
                DateTime time = DateTime.Now;
                if ((time - info.mBeginTime).TotalMinutes >= mTimeout)
                {
                    string selectionData = select.Serialize();
                    OnAlarmTimeout?.Invoke(
                        (int)AlarmMode.Selection,
                        (int)alarmType,
                        select.mSelectionId,
                        selectionData,
                        info);

                    info.mIsTimeout = true;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 单个告警处理
        /// </summary>
        private void SubProcessGroupAlarm(
            GroupAlarmType alarmType,
            SelectionGroup group)
        {
            AlarmConfigData alarmSet;
            AlarmInfo       info;
            float           temperature;

            switch (alarmType)
            {
            case GroupAlarmType.MaxTemperature:
                alarmSet    = group.mAlarmConfig.mMaxTempConfig;
                temperature = group.mTemperatureData.mMaxTemperature;
                info        = group.mAlarmInfo.mMaxTempAlarm;
                break;

            case GroupAlarmType.MaxTempRise:
                alarmSet    = group.mAlarmConfig.mMaxTempeRiseConfig;
                temperature = group.mTemperatureData.mTemperatureRise;
                info        = group.mAlarmInfo.mMaxTempRiseAlarmInfo;
                break;

            case GroupAlarmType.MaxTempDif:
                alarmSet    = group.mAlarmConfig.mMaxTempDifConfig;
                temperature = group.mTemperatureData.mTemperatureDif;
                info        = group.mAlarmInfo.mMaxTempDifAlarmInfo;
                break;

            case GroupAlarmType.RelativeTempDif:
                alarmSet    = group.mAlarmConfig.mRelativeTempDifConfig;
                temperature = group.mTemperatureData.mRelTemperatureDif;
                info        = group.mAlarmInfo.mRelativeTempDifAlarmInfo;
                break;

            default:
                return;
            }

            AlarmStatus lastStatus = info.mAlarmStatus;

            info.mLastAlarmLevel = info.mCurrentAlarmLevel;

            if ((alarmType == GroupAlarmType.MaxTemperature) || (alarmType == GroupAlarmType.RelativeTempDif))
            {
                CalcAlarmInfo(alarmSet, temperature, info);
            }
            else
            {
                SpecialCalAlarmInfo(alarmSet, temperature, info); // 特殊处理组选区温升/温差
            }
            if (alarmType == GroupAlarmType.MaxTemperature)
            {
                ProcessAlarmReadyEnd(alarmSet, temperature, info);
            }

            if (info.mAlarmStatus == AlarmStatus.AlarmStart)
            {
                info.mAlarmStatus = AlarmStatus.Alarming;

                // 添加告警
                string groupData       = group.Serialize();
                string temperatureInfo = JsonUtils.ObjectToJson(group.mTemperatureData);

                // 阈值设置序列化
                string condition = string.Format("{0},{1},{2}", alarmSet.mGeneralThreshold, alarmSet.mSeriousThreshold, alarmSet.mCriticalThreshold);

                // 记录告警开始时间
                info.mBeginTime = DateTime.Now;
                info.mIsTimeout = false;

                // 告警入库
                OnAddAlarmInfo?.Invoke(
                    (int)AlarmMode.GroupSelection,
                    (int)alarmType,
                    (int)alarmSet.mAlarmReason,
                    (int)info.mCurrentAlarmLevel,
                    condition,
                    temperature,
                    group.mId,
                    group.mGroupName,
                    groupData,
                    temperatureInfo,
                    mMaxTemperature,
                    mMinTemperature,
                    group.mSelections,
                    info);
            }
            else if (info.mAlarmStatus == AlarmStatus.AlarmEnd)
            {
                info.mAlarmStatus = AlarmStatus.Unknown;

                // 结束告警
                string selectionData = group.Serialize();
                OnUpdateAlarmInfo?.Invoke(
                    (int)AlarmMode.GroupSelection,
                    (int)alarmType,
                    group.mId,
                    selectionData,
                    info);

                // 取消超时
                info.mIsTimeout = true;
            }
            else if (info.mAlarmStatus == AlarmStatus.AlarmingChanged)
            {
                // 结束上一次告警
                string selectionData = group.Serialize();
                OnUpdateAlarmInfo?.Invoke(
                    (int)AlarmMode.GroupSelection,
                    (int)alarmType,
                    group.mId,
                    selectionData,
                    info);

                string temperatureInfo = JsonUtils.ObjectToJson(group.mTemperatureData);

                // 阈值设置序列化
                string condition = string.Format("{0},{1},{2}", alarmSet.mGeneralThreshold, alarmSet.mSeriousThreshold, alarmSet.mCriticalThreshold);

                // 记录告警开始时间
                info.mBeginTime   = DateTime.Now;
                info.mIsTimeout   = false;
                info.mAlarmStatus = AlarmStatus.Alarming;

                OnAddAlarmInfo?.Invoke(
                    (int)AlarmMode.GroupSelection,
                    (int)alarmType,
                    (int)alarmSet.mAlarmReason,
                    (int)info.mCurrentAlarmLevel,
                    condition,
                    temperature,
                    group.mId,
                    group.mGroupName,
                    selectionData,
                    temperatureInfo,
                    mMaxTemperature,
                    mMinTemperature,
                    group.mSelections,
                    info);
            }
            else if ((info.mAlarmStatus == AlarmStatus.Alarming ||
                      info.mAlarmStatus == AlarmStatus.AlarmingReadyChanged) &&
                     (info.mIsTimeout == false))
            {
                DateTime time = DateTime.Now;
                if ((time - info.mBeginTime).TotalMinutes >= mTimeout)
                {
                    string selectionData = group.Serialize();
                    OnAlarmTimeout?.Invoke(
                        (int)AlarmMode.GroupSelection,
                        (int)alarmType,
                        group.mId,
                        selectionData,
                        info);

                    info.mIsTimeout = true;
                }
            }
        }