예제 #1
0
        /// <summary>
        /// アラーム情報を作成しQueueStorageへ登録する
        /// </summary>
        /// <param name="directoryUsage">ディレクトリ使用量</param>
        /// <param name="messageId">メッセージID</param>
        /// <param name="alarmDef">アラーム定義</param>
        /// <returns>成功した場合true、失敗した場合falseを返す</returns>
        public bool CreateAndEnqueueAlarmInfo(DirectoryUsage directoryUsage, string messageId, IEnumerable <DtAlarmDefDirectoryUsageMonitor> alarmDef)
        {
            bool result = true;

            _logger.EnterJson("{0}", new { directoryUsage, messageId, alarmDef });

            int index      = 1;
            int alarmCount = alarmDef.Count();

            foreach (var alarm in alarmDef)
            {
                string message = null;
                try
                {
                    string alarmDescription = alarm.AlarmDescription;
                    if (!string.IsNullOrEmpty(alarmDescription))
                    {
                        alarmDescription = string.Format(alarmDescription, alarm.DirectoryPath, alarm.Size, alarm.DirectoryUsage);
                    }

                    // Sq1.1.3: アラームキューを生成する
                    var alarmInfo = new AlarmInfo
                    {
                        SourceEquipmentUid = directoryUsage.SourceEquipmentUid,
                        TypeCode           = directoryUsage.TypeCode,
                        ErrorCode          = alarm.AnalysisResultErrorCode,
                        AlarmLevel         = alarm.AlarmLevel,
                        AlarmTitle         = alarm.AlarmTitle,
                        AlarmDescription   = alarmDescription,
                        AlarmDatetime      = _timeProvider.UtcNow.ToString(Utility.Const.AlarmQueueDateTimeFormat),
                        EventDatetime      = directoryUsage.CollectDt,
                        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_DUM_DUM_005) : nameof(Resources.UT_DUM_DUM_006), new object[] { messageId });
                    result = false;
                }
            }

            _logger.Leave();
            return(result);
        }
예제 #2
0
        /// <summary>
        /// アラーム定義を取得する
        /// </summary>
        /// <param name="directoryUsage">ディレクトリ使用量</param>
        /// <param name="messageId">メッセージID</param>
        /// <param name="models">DBから取得したパラメータ</param>
        /// <returns>成功した場合true、失敗した場合falseを返す</returns>
        public bool ReadAlarmDefinition(DirectoryUsage directoryUsage, string messageId, out IEnumerable <DtAlarmDefDirectoryUsageMonitor> models)
        {
            models = null;

            try
            {
                _logger.EnterJson("{0}", new { directoryUsage, messageId });

                // Sq1.1.1: ディレクトリ通信監視アラーム定義を取得
                models = _dtAlarmDefDirectoryUsageMonitorRepository.ReadDtAlarmDefDirectoryUsageMonitor(directoryUsage);

                return(true);
            }
            catch (RmsException e)
            {
                // DBにアクセスできない(基本設計書 5.1.2.4 エラー処理)
                _logger.Error(e, nameof(Resources.UT_DUM_DUM_003), new object[] { messageId });
                return(false);
            }
            finally
            {
                _logger.LeaveJson("{0}", new { models });
            }
        }
        /// <summary>
        /// DT_ALARM_DEF_DIRECTORY_USAGE_MONITORテーブルからDtAlarmDefDirectoryUsageMonitorを取得する
        /// </summary>
        /// <param name="directoryUsage">ディレクトリ使用量</param>
        /// <returns>取得したデータ</returns>
        public IEnumerable <DtAlarmDefDirectoryUsageMonitor> ReadDtAlarmDefDirectoryUsageMonitor(DirectoryUsage directoryUsage)
        {
            var models = new List <DtAlarmDefDirectoryUsageMonitor>();

            try
            {
                _logger.EnterJson("{0}", directoryUsage);

                List <DBAccessor.Models.DtAlarmDefDirectoryUsageMonitor> entities = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var query = db.DtAlarmDefDirectoryUsageMonitor
                                    .Where(x => string.IsNullOrEmpty(x.TypeCode) || x.TypeCode == directoryUsage.TypeCode);

                        foreach (var detailInfo in directoryUsage.DetailInfo)
                        {
                            query = query.Where(x => string.IsNullOrEmpty(x.DirectoryPath) || x.DirectoryPath == detailInfo.FullPath)
                                    .Where(x => x.Size < detailInfo.Size);
                        }

                        entities = query.ToList();

                        // 検索されたレコードと検索条件の紐づけ(アラーム説明の文字列置換で必要となるため)
                        foreach (var detailInfo in directoryUsage.DetailInfo)
                        {
                            var filteredEntities = entities.Where(x => string.IsNullOrEmpty(x.DirectoryPath) || x.DirectoryPath == detailInfo.FullPath)
                                                   .Where(x => x.Size < detailInfo.Size);

                            // 同一条件で複数検索された場合を考慮(アラーム定義のミスだがそのまま処理してアラーム情報を複数作成する仕様)
                            foreach (var entity in filteredEntities)
                            {
                                DtAlarmDefDirectoryUsageMonitor model = entity.ToModel();
                                model.DirectoryUsage = detailInfo.Size;
                                models.Add(model);
                            }
                        }
                    }
                });

                return(models);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARM_DEF_CALIBRATION_PREMONITORテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", models);
            }
        }