/// <summary> /// アラーム情報を作成しQueueStorageへ登録する /// </summary> /// <param name="tubeDeteriorationPredictiveResutLog">管球劣化予兆結果ログ</param> /// <param name="messageId">メッセージID</param> /// <param name="alarmDef">アラーム定義</param> /// <returns>成功した場合true、失敗した場合falseを返す</returns> public bool CreateAndEnqueueAlarmInfo(TubeDeteriorationPredictiveResutLog tubeDeteriorationPredictiveResutLog, string messageId, IEnumerable <DtAlarmDefTubeDeteriorationPremonitor> alarmDef) { bool result = true; _logger.EnterJson("{0}", new { tubeDeteriorationPredictiveResutLog, messageId, alarmDef }); int index = 1; int alarmCount = alarmDef.Count(); foreach (var alarm in alarmDef) { string message = null; try { // Sq1.1.3: アラームキューを生成する var alarmInfo = new AlarmInfo { SourceEquipmentUid = tubeDeteriorationPredictiveResutLog.SourceEquipmentUid, TypeCode = tubeDeteriorationPredictiveResutLog.TypeCode, ErrorCode = tubeDeteriorationPredictiveResutLog.ErrorCode, AlarmLevel = alarm.AlarmLevel, AlarmTitle = alarm.AlarmTitle, AlarmDescription = alarm.AlarmDescription, AlarmDatetime = _timeProvider.UtcNow.ToString(Utility.Const.AlarmQueueDateTimeFormat), EventDatetime = tubeDeteriorationPredictiveResutLog.EventDt, AlarmDefId = $"{_settings.SystemName}_{_settings.SubSystemName}_{alarm.Sid.ToString()}", MessageId = alarmCount <= 1 ? messageId : $"{messageId}_{index}" }; index++; message = JsonConvert.SerializeObject(alarmInfo); // Sq1.1.4: キューを登録する _queueRepository.SendMessageToAlarmQueue(message); } catch (Exception e) { // アラーム生成エラー or アラームキューにアラーム情報を送信できない(基本設計書 5.1.2.4 エラー処理) _logger.Error(e, string.IsNullOrEmpty(message) ? nameof(Resources.UT_TDP_TDP_005) : nameof(Resources.UT_TDP_TDP_006), new object[] { messageId }); result = false; } } _logger.Leave(); return(result); }
/// <summary> /// アラーム定義を取得する /// </summary> /// <param name="tubeDeteriorationPredictiveResutLog">管球劣化予兆結果ログ</param> /// <param name="messageId">メッセージID</param> /// <param name="models">DBから取得したパラメータ</param> /// <returns>成功した場合true、失敗した場合falseを返す</returns> public bool ReadAlarmDefinition(TubeDeteriorationPredictiveResutLog tubeDeteriorationPredictiveResutLog, string messageId, out IEnumerable <DtAlarmDefTubeDeteriorationPremonitor> models) { models = null; try { _logger.EnterJson("{0}", new { tubeDeteriorationPredictiveResutLog, messageId }); // Sq1.1.1: 管球劣化予兆監視アラーム定義を取得 models = _dtAlarmDefTubeDeteriorationPremonitorRepository.ReadDtAlarmDefTubeDeteriorationPremonitor(tubeDeteriorationPredictiveResutLog); return(true); } catch (RmsException e) { // DBにアクセスできない(基本設計書 5.1.2.4 エラー処理) _logger.Error(e, nameof(Resources.UT_TDP_TDP_003), new object[] { messageId }); return(false); } finally { _logger.LeaveJson("{0}", new { models }); } }
/// <summary> /// DT_ALARM_DEF_TUBE_DETERIORATION_PREMONITORテーブルからDtAlarmDefTubeDeteriorationPremonitorを取得する /// </summary> /// <param name="tubeDeteriorationPredictiveResutLog">管球劣化予兆結果ログ</param> /// <returns>取得したデータ</returns> public IEnumerable <DtAlarmDefTubeDeteriorationPremonitor> ReadDtAlarmDefTubeDeteriorationPremonitor(TubeDeteriorationPredictiveResutLog tubeDeteriorationPredictiveResutLog) { IEnumerable <DtAlarmDefTubeDeteriorationPremonitor> models = null; try { _logger.EnterJson("{0}", tubeDeteriorationPredictiveResutLog); List <DBAccessor.Models.DtAlarmDefTubeDeteriorationPremonitor> entities = null; _dbPolly.Execute(() => { using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings)) { entities = db.DtAlarmDefTubeDeteriorationPremonitor .Where(x => string.IsNullOrEmpty(x.TypeCode) || x.TypeCode == tubeDeteriorationPredictiveResutLog.TypeCode) .Where(x => string.IsNullOrEmpty(x.ErrorCode) || x.ErrorCode == tubeDeteriorationPredictiveResutLog.ErrorCode) .ToList(); } }); if (entities != null) { models = entities.Select(x => x.ToModel()); } return(models); } catch (Exception e) { throw new RmsException("DT_ALARM_DEF_TUBE_DETERIORATION_PREMONITORテーブルのSelectに失敗しました。", e); } finally { _logger.LeaveJson("{0}", models); } }