示例#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;
                }
            }
        }
示例#2
0
        /// <summary>
        /// 获取告警短信内容
        /// </summary>
        public static String GetShowMessage(
            String substation,
            String deviceName,
            Int32 alarmMode,
            Int32 alarmType,
            Int32 alarmLevel,
            Single temperature,
            DateTime time)
        {
            String msg = String.Format("变电站:{0}\n", substation);

            msg += String.Format("设备:{0}\n", deviceName);

            AlarmMode mode = (AlarmMode)alarmMode;

            if (mode == AlarmMode.Selection)
            {
                SelectionAlarmType type = (SelectionAlarmType)alarmType;
                switch (type)
                {
                case SelectionAlarmType.MaxTemp:
                    msg += "监控类型:最高温度\n";
                    break;

                case SelectionAlarmType.MinTemp:
                    msg += "监控类型:最低温度\n";
                    break;

                case SelectionAlarmType.AvgTemp:
                    msg += "监控类型:平均温度\n";
                    break;
                }
                msg += String.Format("温度值:{0:F2}℃\n", temperature);
            }
            else if (mode == AlarmMode.GroupSelection)
            {
                GroupAlarmType type = (GroupAlarmType)alarmType;
                switch (type)
                {
                case GroupAlarmType.MaxTemperature:
                    msg += "监控类型:最高温度(组)\n";
                    break;

                case GroupAlarmType.MaxTempDif:
                    msg += "监控类型:最大温差(组)\n";
                    break;

                case GroupAlarmType.MaxTempRise:
                    msg += "监控类型:最大温升(组)\n";
                    break;

                case GroupAlarmType.RelativeTempDif:
                    msg += "监控类型:相对温差(组)\n";
                    break;
                }

                if (type == GroupAlarmType.RelativeTempDif)
                {
                    msg += String.Format("百分比:{0:F2}%\n", temperature);
                }
                else
                {
                    msg += String.Format("温度值:{0:F2}℃\n", temperature);
                }
            }

            AlarmLevel level = (AlarmLevel)alarmLevel;

            switch (level)
            {
            case AlarmLevel.General:
                msg += "告警等级:一般\n";
                break;

            case AlarmLevel.Serious:
                msg += "告警等级:严重\n";
                break;

            case AlarmLevel.Critical:
                msg += "告警等级:危急\n";
                break;
            }

            msg += String.Format("时间:{0}", DateTime.Now.ToString("HH:mm:ss"));

            return(msg);
        }