Beispiel #1
0
        /// <summary>
        /// 引数に指定したSIDのレコードを対象にDT_ALMILOG_ANALYSIS_RESULTテーブルのIS_ALARM_JUDGEDをTRUEに更新する
        /// </summary>
        /// <param name="sidList">更新対象レコードのSID</param>
        /// <returns>更新レコード数</returns>
        public int UpdateIsAlarmJudgedTrue(IEnumerable <long> sidList)
        {
            try
            {
                _logger.EnterJson("{0}", new { sidList });

                int result = 0;

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var targets = (from r in db.DtAlmilogAnalysisResult where sidList.Contains(r.Sid) select r).ToList();

                        foreach (var target in targets)
                        {
                            target.IsAlarmJudged = true;
                        }

                        result = db.SaveChanges();
                    }
                });

                return(result);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALMILOG_ANALYSIS_RESULTテーブルのUpdateに失敗しました。", e);
            }
            finally
            {
                _logger.Leave();
            }
        }
Beispiel #2
0
        /// <summary>
        /// DT_ALARMテーブルに条件に一致するDtAlarmが存在するか確認する
        /// </summary>
        /// <param name="messageId">メッセージID</param>
        /// <returns>存在する場合trueを、存在しない場合falseを返す</returns>
        public bool ExistDtAlarm(string messageId)
        {
            bool result = false;

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

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        result = db.DtAlarm.Any(x => x.MessageId == messageId);
                    }
                });

                return(result);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARMテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", result);
            }
        }
Beispiel #3
0
        /// <summary>
        /// DT_ALMILOG_ANALYSIS_RESULTテーブルに条件に一致するDtAlmilogAnalysisResultが存在するか確認する
        /// </summary>
        /// <param name="logFileName">ログファイル名</param>
        /// <returns>存在する場合trueを、存在しない場合falseを返す</returns>
        public bool ExistDtAlmilogAnalysisResult(string logFileName)
        {
            bool result = false;

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

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        result = db.DtAlmilogAnalysisResult.Any(x => x.LogFileName == logFileName);
                    }
                });

                return(result);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALMILOG_ANALYSIS_RESULTテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", result);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 指定日時より作成日が古いデータを削除する
        /// </summary>
        /// <param name="comparisonSourceDatetime">比較対象日時</param>
        /// <returns>削除数</returns>
        public int DeleteExceedsMonthsAllData(DateTime comparisonSourceDatetime)
        {
            int result = 0;

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

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // 作成日時から指定月数超過しているデータを抽出し、削除する
                        var targets = db.DtAlarm.Where(x => x.CreateDatetime < comparisonSourceDatetime);
                        db.DtAlarm.RemoveRange(targets);
                        result = db.SaveChanges();
                    }
                });

                return(result);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARMテーブルのDeleteに失敗しました。", e);
            }
            finally
            {
                _logger.Leave();
            }
        }
Beispiel #5
0
        /// <summary>
        /// MT_INSTALL_RESULT_STATUSテーブルからMtInstallResultStatusを取得する
        /// </summary>
        /// <param name="code">取得するデータのCode</param>
        /// <returns>取得したデータ</returns>
        public MtInstallResultStatus ReadMtInstallResultStatus(string code)
        {
            MtInstallResultStatus model = null;

            try
            {
                _logger.Enter($"{nameof(code)}={code}");

                DBAccessor.Models.MtInstallResultStatus entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.MtInstallResultStatus.FirstOrDefault(x => x.Code.Equals(code));
                    }
                });

                if (entity != null)
                {
                    model = entity.ToModel();
                }

                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("MT_INSTALL_RESULT_STATUSテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
        /// <summary>
        /// DT_SMART_ANALYSIS_RESULTテーブルからDtSmartAnalysisResultを取得する
        /// </summary>
        /// <param name="diskDrive">ディスクドライブ</param>
        /// <returns>取得したデータ</returns>
        public DtSmartAnalysisResult ReadDtSmartAnalysisResult(DiskDrive diskDrive)
        {
            DtSmartAnalysisResult model = null;

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

                DBAccessor.Models.DtSmartAnalysisResult entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.DtSmartAnalysisResult.FirstOrDefault(x => x.EquipmentUid == diskDrive.SourceEquipmentUid && x.DiskSerialNumber == diskDrive.SerialNo);
                    }
                });

                if (entity != null)
                {
                    model = entity.ToModel();
                }

                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_SMART_ANALYSIS_RESULTテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
        /// <summary>
        /// 引数に指定したDtSoftVersionをDT_SOFT_VERSIONテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <param name="equipmentModelCode">機器型式コード</param>
        /// <returns>追加したデータ。エラーが発生した場合には例外を投げるためnullを返さない</returns>
        public DtSoftVersion CreateDtSoftVersionIfAlreadyMessageThrowEx(DtSoftVersion inData, string equipmentModelCode)
        {
            DtSoftVersion model = null;

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

                _dbPolly.Execute(() =>
                {
                    // メッセージIDがなければ追加
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // マスタテーブルから機器型式SIDを取得
                        var equipmentModel = db.MtEquipmentModel.FirstOrDefault(x => x.Code == equipmentModelCode);
                        if (equipmentModel == null || equipmentModel.Sid == 0)
                        {
                            throw new RmsException(string.Format("機器型式コード[{0}]がマスタテーブルに存在しません。", equipmentModelCode));
                        }

                        var addedAlready = db.DtSoftVersion.FirstOrDefault(x => x.MessageId == inData.MessageId);
                        if (addedAlready != null)
                        {
                            throw new RmsAlreadyExistException(string.Format("MessageId [{0}] はすでに追加済みです。", inData.MessageId));
                        }

                        // 機器型式SIDを設定
                        inData.EquipmentModelSid = equipmentModel.Sid;

                        Rms.Server.Core.DBAccessor.Models.DtSoftVersion entity = new Rms.Server.Core.DBAccessor.Models.DtSoftVersion(inData);

                        var dbdata = db.DtSoftVersion.Add(entity).Entity;
                        db.SaveChanges(_timePrivder);
                        model = dbdata.ToModel();
                    }
                });

                return(model);
            }
            catch (RmsAlreadyExistException)
            {
                throw;
            }
            catch (RmsException)
            {
                throw;
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_SOFT_VERSIONテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #8
0
        /// <summary>
        /// DT_DELIVERY_GROUPテーブルからDtDeliveryGroupを取得する
        /// </summary>
        /// <param name="sid">取得するデータのSID</param>
        /// <returns>取得したデータ</returns>
        public DtDeliveryGroup ReadDtDeliveryGroup(long sid)
        {
            DtDeliveryGroup model = null;

            try
            {
                _logger.Enter($"{nameof(sid)}={sid}");

                DBAccessor.Models.DtDeliveryGroup entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.DtDeliveryGroup.Include(x => x.DtDeliveryResult).FirstOrDefault(x => x.Sid == sid);
                    }
                });

                if (entity != null)
                {
                    model = entity.ToModel();
                }

                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DELIVERY_GROUPテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #9
0
        /// <summary>
        /// DT_ALARMテーブルからメール送信済みの最新DtAlarmを取得する
        /// </summary>
        /// <param name="alarmDefId">アラーム定義ID</param>
        /// <returns>取得したデータ</returns>
        public DtAlarm ReadLatestMailSentDtAlarm(string alarmDefId)
        {
            DtAlarm model = null;

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

                DBAccessor.Models.DtAlarm entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.DtAlarm.Where(x => x.AlarmDefId == alarmDefId && x.HasMail == true).OrderByDescending(x => x.CreateDatetime).FirstOrDefault();
                    }
                });

                model = entity?.ToModelExcludedDtEquipment();
                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARMテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #10
0
        /// <summary>
        /// DT_ALARM_SMART_PREMONITORテーブルからDtAlarmSmartPremonitorを取得する
        /// </summary>
        /// <param name="smartAttributeInfoId">取得するデータのSMART項目ID</param>
        /// <returns>取得したデータ</returns>
        public DtAlarmSmartPremonitor ReadDtAlarmSmartPremonitor(string smartAttributeInfoId)
        {
            DtAlarmSmartPremonitor model = null;

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

                DBAccessor.Models.DtAlarmSmartPremonitor entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // 取得できるアラーム定義は1つのみという前提
                        entity = db.DtAlarmSmartPremonitor.FirstOrDefault(x => x.SmartId == smartAttributeInfoId);
                    }
                });

                if (entity != null)
                {
                    model = entity.ToModel();
                }

                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARM_SMART_PREMONITORテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #11
0
        /// <summary>
        /// DT_ALMILOG_ANALYSIS_RESULTテーブルからアラーム判定の対象データを取得する
        /// 機器UIDとDetector名称単位で判定済みデータを連続NG数-1件、未判定データを全件取得する
        /// 取得したアラーム判定対象データは次の順番でListに格納する(連続した1次元のデータとして格納)
        ///   機器UID1、Detector名称1、判定済みデータ1、判定済みデータ2...、未判定データ1、未判定データ2...
        ///   機器UID1、Detector名称2、判定済みデータ1、...
        ///   機器UID2、Detector名称1、...
        /// </summary>
        /// <param name="alarmCountThreshold">アラーム通知閾値</param>
        /// <returns>取得したデータ</returns>
        public IEnumerable <DtAlmilogAnalysisResult> ReadAlarmJudgementTarget(int alarmCountThreshold)
        {
            IEnumerable <DtAlmilogAnalysisResult> models = null;

            try
            {
                _logger.Enter();

                List <DBAccessor.Models.DtAlmilogAnalysisResult> entities = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // アラーム判定フラグが未判定の情報を取得する
                        var alarmJudgementTarget = db.DtAlmilogAnalysisResult.Where(x => x.IsAlarmJudged == false);

                        if (alarmCountThreshold >= 2)
                        {
                            // アラーム判定フラグが判定済みの最新情報を機器UID、Detector名称単位で連続NG数-1件取得する
                            var confirmedAnalysisResult =
                                db.DtAlmilogAnalysisResult
                                .GroupBy(x => new { x.EquipmentUid, x.DetectorName })
                                .SelectMany(x => x
                                            .Where(y => y.IsAlarmJudged == true)
                                            .OrderByDescending(y => y.AlmilogMonth)
                                            .ThenByDescending(y => y.FileNameNo)
                                            .Take(alarmCountThreshold - 1));

                            alarmJudgementTarget = alarmJudgementTarget.Concat(confirmedAnalysisResult);
                        }

                        alarmJudgementTarget =
                            alarmJudgementTarget
                            .OrderBy(x => x.EquipmentUid)
                            .ThenBy(x => x.DetectorName)
                            .ThenByDescending(x => x.IsAlarmJudged)
                            .ThenBy(x => x.AlmilogMonth)
                            .ThenBy(x => x.FileNameNo);

                        entities = alarmJudgementTarget.ToList();
                    }
                });

                if (entities.Any())
                {
                    models = entities.Select(x => x.ToModel());
                }

                return(models);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALMILOG_ANALYSIS_RESULTテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", models);
            }
        }
Beispiel #12
0
        /// <summary>
        /// 配信用に親・子エンティティデータをIncludeしたデータを取得する
        /// </summary>
        /// <param name="sid">配信グループSID</param>
        /// <returns>配信用に親・子エンティティデータをIncludeしたデータ</returns>
        public DtDeliveryGroup ReadDeliveryIncludedDtDeliveryGroup(long sid)
        {
            DtDeliveryGroup includedModel = null;

            try
            {
                _logger.Enter($"{nameof(sid)}: {sid}");

                _dbPolly.Execute(
                    () =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // 配信用に親・子エンティティを一括Includeする
                        var includedEntitiy = db.DtDeliveryGroup
                                              .Where(x => x.Sid == sid)
                                              //// 端末
                                              .Include(group => group.DtDeliveryResult)
                                              .ThenInclude(results => results.DeviceS)
                                              .ThenInclude(device => device.ConnectStatusS)
                                              //// 最上位端末
                                              .Include(group => group.DtDeliveryResult)
                                              .ThenInclude(results => results.GwDeviceS)
                                              .ThenInclude(device => device.ConnectStatusS)
                                              //// 配信ファイル種別
                                              .Include(group => group.DeliveryFileS)
                                              .ThenInclude(file => file.DeliveryFileTypeS)
                                              //// インストールタイプ
                                              .Include(group => group.DeliveryFileS)
                                              .ThenInclude(file => file.InstallTypeS)
                                              //// 機器型式
                                              .Include(group => group.DeliveryFileS)
                                              .ThenInclude(file => file.DtDeliveryModel)
                                              .ThenInclude(models => models.EquipmentModelS)
                                              .FirstOrDefault();

                        if (includedEntitiy != null)
                        {
                            includedModel = includedEntitiy.ToModel();
                        }
                    }
                });
                return(includedModel);
            }
            catch (RmsException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DELIVERY_GROUPテーブルのReadに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", includedModel);
            }
        }
Beispiel #13
0
        /// <summary>
        /// 引数に指定したDtDeviceをDT_DEVICEテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>処理結果</returns>
        public DtDevice CreateDtDevice(DtDevice inData)
        {
            DtDevice model = null;

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

                DBAccessor.Models.DtDevice entity = new DBAccessor.Models.DtDevice(inData);

                // 初期値GUIDはIDを割り振る
                if (entity.EdgeId == Guid.Empty)
                {
                    entity.EdgeId = Guid.NewGuid();
                }

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // 接続ステータスが「unconnected」のデータを取得する
                        var unconnectedData = db.MtConnectStatus
                                              .Where(x => x.Code.Equals(Const.ConnectStatus.Unconnected))
                                              .FirstOrDefault();
                        if (unconnectedData == null)
                        {
                            // データ設定せずに返却
                            return;
                        }

                        // 接続ステータス設定
                        entity.ConnectStatusSid = unconnectedData.Sid;

                        var dbdata = db.DtDevice.Add(entity).Entity;
                        db.SaveChanges(_timePrivder);
                        model = dbdata.ToModel();
                    }
                });

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DEVICEテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #14
0
        /// <summary>
        /// データの更新(配信ステータスを指定SIDのものにする)
        /// 実際の更新処理を行う
        /// </summary>
        /// <param name="sid">更新する配信グループデータのSID</param>
        /// <returns>更新されたDB内容</returns>
        private DtDeliveryGroup UpdateStatusStarted(long sid)
        {
            using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
            {
                try
                {
                    // 指定した配信グループSIDと一致する情報を取得する
                    var entity = db.DtDeliveryGroup.Include(x => x.DeliveryGroupStatusS).FirstOrDefault(x => x.Sid == sid);
                    if (entity == null)
                    {
                        // 値を設定せずにリターン
                        return(null);
                    }

                    // 指定した配信グループが未配信状態であるかチェックする
                    var isNotStart = entity.DeliveryGroupStatusS.Code.Equals(Utility.Const.DeliveryGroupStatus.NotStarted);
                    if (!isNotStart)
                    {
                        throw new RmsCannotChangeDeliveredFileException(string.Format("配信前状態ではないDT_DELIVERY_GROUPテーブルのレコードをUpdateしようとしました。(DT_DELIVERY_GROUP.SID = {0})", sid));
                    }

                    // 「開始済」の配信グループステータスSIDを取得する
                    var startedData = db.MtDeliveryGroupStatus.Where(x => x.Code.Equals(Utility.Const.DeliveryGroupStatus.Started)).FirstOrDefault();
                    if (startedData == null)
                    {
                        // 値を設定せずにリターン
                        return(null);
                    }

                    // 情報の更新
                    entity.DeliveryGroupStatusSid = startedData.Sid;

                    var p = db.DtDeliveryGroup.Update(entity);
                    db.SaveChanges(_timePrivder);

                    return(p.Entity.ToModel());
                }
                catch (ValidationException e)
                {
                    throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
                }
                catch (DbUpdateConcurrencyException e)
                {
                    // RowVersion衝突が起きた
                    throw new RmsConflictException("DT_DELIVERY_GROUPテーブルのUpdateで競合が発生しました。", e);
                }
                catch
                {
                    // SqlExceptionであれば再試行される
                    throw;
                }
            }
        }
        /// <summary>
        /// DT_ALMILOG_PREMONITORテーブルからDtAlmilogPremonitorを取得する
        /// </summary>
        /// <param name="almilogAnalysisResult">アルミスロープログ解析結果</param>
        /// <param name="allowNotExist">取得件数が0件である場合を正常系とする場合はtrueを、異常系とする場合はfalseを指定する</param>
        /// <param name="allowMultiple">取得件数が2件以上である場合を正常系とする場合はtrueを、異常系とする場合はfalseを指定する</param>
        /// <returns>取得したデータ</returns>
        public IEnumerable <DtAlmilogPremonitor> ReadDtAlmilogPremonitor(DtAlmilogAnalysisResult almilogAnalysisResult, bool allowNotExist = true, bool allowMultiple = true)
        {
            IEnumerable <DtAlmilogPremonitor> models = null;

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

                List <DBAccessor.Models.DtAlmilogPremonitor> entities = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entities = db.DtAlmilogPremonitor
                                   .Where(x => x.DetectorName == almilogAnalysisResult.DetectorName)
                                   .Where(x => x.JudgeResult == almilogAnalysisResult.AnalysisResult)
                                   .ToList();
                    }
                });

                if (!allowNotExist && (entities == null || entities.Count <= 0))
                {
                    var info = new { Sid = almilogAnalysisResult?.Sid, AnalysisResult = almilogAnalysisResult?.AnalysisResult, DetectorName = almilogAnalysisResult?.DetectorName };
                    throw new RmsException(string.Format("DT_ALMILOG_PREMONITORテーブルに該当レコードが存在しません。(アルミスロープログ解析結果: {0})", JsonConvert.SerializeObject(info)));
                }

                if (!allowMultiple && entities.Count > 1)
                {
                    var info = new { Sid = almilogAnalysisResult?.Sid, AnalysisResult = almilogAnalysisResult?.AnalysisResult, DetectorName = almilogAnalysisResult?.DetectorName };
                    throw new RmsException(string.Format("DT_ALMILOG_PREMONITORテーブルに該当レコードが複数あります。(アルミスロープログ解析結果: {0})", JsonConvert.SerializeObject(info)));
                }

                if (entities != null)
                {
                    models = entities.Select(x => x.ToModel());
                }

                return(models);
            }
            catch (RmsException)
            {
                throw;
            }
            catch (Exception e)
            {
                var info = new { Sid = almilogAnalysisResult?.Sid, AnalysisResult = almilogAnalysisResult?.AnalysisResult, DetectorName = almilogAnalysisResult?.DetectorName };
                throw new RmsException(string.Format("DT_ALMILOG_PREMONITORテーブルのSelectに失敗しました。(アルミスロープログ解析結果: {0})", JsonConvert.SerializeObject(info)), e);
            }
            finally
            {
                _logger.LeaveJson("{0}", 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);
            }
        }
Beispiel #17
0
        /// <summary>
        /// 引数に指定したDtDeviceでDT_DEVICEテーブルを更新する
        /// </summary>
        /// <param name="inData">更新するデータ</param>
        /// <returns>更新したデータ</returns>
        public DtDevice UpdateDtDevice(DtDevice inData)
        {
            DtDevice model = null;

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

                DBAccessor.Models.DtDevice entity = new DBAccessor.Models.DtDevice(inData);

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // 指定SIDのデータがDBになければnullリターン
                        if (db.DtDevice.AsNoTracking().FirstOrDefault(x => x.Sid == inData.Sid) == null)
                        {
                            return;
                        }

                        db.DtDevice.Attach(entity);

                        // 全フィールドを更新する
                        //     特定フィールドだけUpdateする場合は下記のように記述してください
                        //     db.Entry(entity).Property(x => x.UpdateDatetime).IsModified = true;
                        db.Entry(entity).Property(x => x.InstallTypeSid).IsModified    = true;
                        db.Entry(entity).Property(x => x.EquipmentModelSid).IsModified = true;

                        if (db.SaveChanges(_timePrivder) > 0)
                        {
                            // 呼び出し側に更新済みデータを返却する
                            model = db.DtDevice.AsNoTracking().FirstOrDefault(x => x.Sid == inData.Sid)?.ToModel();
                        }
                    }
                });

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DEVICEテーブルのUpdateに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #18
0
        /// <summary>
        /// データの更新(配信ステータスが「配信前」の時のみ)
        /// 実際の更新処理を行う
        /// </summary>
        /// <param name="inData">更新データ</param>
        /// <returns>更新されたDB内容</returns>
        private DtDeliveryGroup UpdateIfNotStart(DtDeliveryGroup inData)
        {
            using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
            {
                try
                {
                    // 指定した配信グループSIDと一致する情報を取得する
                    var entity = db.DtDeliveryGroup
                                 .Include(x => x.DeliveryGroupStatusS)
                                 .FirstOrDefault(x => x.Sid == inData.Sid);
                    if (entity == null)
                    {
                        return(null);
                    }

                    // 指定した配信ステータスSIDを検索し、未配信状態であるかチェックする
                    var isNotStart = entity.DeliveryGroupStatusS.Code.Equals(Utility.Const.DeliveryGroupStatus.NotStarted);
                    if (!isNotStart)
                    {
                        throw new RmsCannotChangeDeliveredFileException(string.Format("配信前状態ではないDT_DELIVERY_GROUPテーブルのレコードをUpdateしようとしました。(DT_DELIVERY_GROUP.SID = {0})", inData.Sid));
                    }

                    // 情報の更新
                    entity.Name              = inData.Name;
                    entity.StartDatetime     = inData.StartDatetime;
                    entity.DownloadDelayTime = inData.DownloadDelayTime;

                    // コンテキスト管理のRowVersionを投入値に置き換えて、DBデータと比較させる(Attatch処理以外では必要)
                    db.Entry(entity).Property(e => e.RowVersion).OriginalValue = inData.RowVersion;

                    var p = db.DtDeliveryGroup.Update(entity);
                    db.SaveChanges(_timePrivder);

                    return(p.Entity.ToModel());
                }
                catch (ValidationException e)
                {
                    throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
                }
                catch (DbUpdateConcurrencyException e)
                {
                    // RowVersion衝突が起きた
                    throw new RmsConflictException("DT_DELIVERY_GROUPテーブルのUpdateで競合が発生しました。", e);
                }
                catch
                {
                    // SqlExceptionであれば再試行される
                    throw;
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// デバイスツイン更新イベントを受信して端末テーブルの「リモート接続UID」と「RMSソフトバージョン」を更新する
        /// </summary>
        /// <param name="sid">端末SID</param>
        /// <param name="data">更新データ</param>
        /// <returns>更新したデータ。テーブルが更新されなかった場合にはnullを返す</returns>
        public DtDevice UpdateDeviceInfoByTwinChanged(long sid, DtTwinChanged data)
        {
            DtDevice model = null;

            try
            {
                _logger.EnterJson("{0}", sid);
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        string remoteConnectionUid = data.RemoteConnectionUid;
                        string rmsSoftVersion      = data.SoftVersion;

                        // リモート接続UIDとRMSソフトバージョンを更新する
                        DtDevice inData = new DtDevice()
                        {
                            Sid = sid, RemoteConnectUid = remoteConnectionUid, RmsSoftVersion = rmsSoftVersion
                        };
                        DBAccessor.Models.DtDevice entity = new DBAccessor.Models.DtDevice(inData);

                        db.DtDevice.Attach(entity);

                        // リモート接続UIDとRMSソフトバージョンを更新する
                        db.Entry(entity).Property(x => x.RemoteConnectUid).IsModified = true;
                        db.Entry(entity).Property(x => x.RmsSoftVersion).IsModified   = true;

                        if (db.SaveChanges(_timePrivder) > 0)
                        {
                            model = entity.ToModel();
                        }
                    }
                });
                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DEVICEテーブルのUpdateに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
        /// <summary>
        /// 引数に指定したDtSmartAnalysisResultでDT_SMART_ANALYSIS_RESULTテーブルを更新する
        /// </summary>
        /// <param name="inData">更新するデータ</param>
        /// <returns>更新したデータ</returns>
        public DtSmartAnalysisResult UpdateDtSmartAnalysisResult(DtSmartAnalysisResult inData)
        {
            DtSmartAnalysisResult model = null;

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

                DBAccessor.Models.DtSmartAnalysisResult entity = new DBAccessor.Models.DtSmartAnalysisResult(inData);

                // バリデーション
                Validator.ValidateObject(entity, new ValidationContext(entity, null, null));

                _dbPolly.Execute(() =>
                {
                    entity.UpdateDatetime = _timePrivder.UtcNow;

                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        db.DtSmartAnalysisResult.Attach(entity);

                        // 全フィールドを更新する
                        //     特定フィールドだけUpdateする場合は下記のように記述してください
                        //     db.Entry(entity).Property(x => x.UpdateDatetime).IsModified = true;
                        db.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;

                        if (db.SaveChanges() > 0)
                        {
                            model = entity.ToModel();
                        }
                    }
                });

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_SMART_ANALYSIS_RESULTテーブルのUpdateに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #21
0
        /// <summary>
        /// 引数に指定したDtInventoryをDT_INVENTORYテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>追加したデータ。エラーが発生した場合には例外を投げるためnullを返さない</returns>
        public DtInventory CreateDtInventoryIfAlreadyMessageThrowEx(DtInventory inData)
        {
            DtInventory model = null;

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

                DBAccessor.Models.DtInventory entity = new DBAccessor.Models.DtInventory(inData);

                _dbPolly.Execute(() =>
                {
                    // メッセージIDがなければ追加
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var addedAlready = db.DtInventory.FirstOrDefault(x => x.MessageId == inData.MessageId);
                        if (addedAlready != null)
                        {
                            throw new RmsAlreadyExistException(string.Format("MessageId [{0}] はすでに追加済みです。", inData.MessageId));
                        }

                        var dbdata = db.DtInventory.Add(entity).Entity;
                        db.SaveChanges(_timePrivder);
                        model = dbdata.ToModel();
                    }
                });

                return(model);
            }
            catch (RmsAlreadyExistException)
            {
                throw;
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_INVENTORYテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #22
0
        /// <summary>
        /// DT_DEVICEテーブルからオンラインなゲートウェイ機器のDtDeviceを取得する
        /// </summary>
        /// <param name="groupData">配信グループ</param>
        /// <returns>オンラインなゲートウェイ機器のDtDeviceデータリスト</returns>
        public IEnumerable <DtDevice> ReadDtDeviceOnlineGateway(DtDeliveryGroup groupData)
        {
            Assert.IfNull(groupData);
            Assert.IfNull(groupData.DtDeliveryResult);

            IEnumerable <DtDevice> models = new List <DtDevice>();

            try
            {
                _logger.EnterJson($"{nameof(groupData)}={0}", groupData);

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // ゲートウェイ機器でオンラインなデータを取得する
                        var gwSids = groupData.DtDeliveryResult
                                     .Where(x => x.GwDeviceSid == x.DeviceSid)
                                     .Select(x => x.GwDeviceSid);
                        var entities = db.DtDevice.Include(x => x.ConnectStatusS)
                                       .Where(x => gwSids.Contains(x.Sid))
                                       .Where(x => x.ConnectStatusS.Code.Equals(Utility.Const.ConnectStatus.Connected));

                        if (entities != null)
                        {
                            models = entities.Select(x => x.ToModel()).ToList();
                        }
                    }
                });

                return(models);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DEVICEテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", models);
            }
        }
Beispiel #23
0
        /// <summary>
        /// DT_ALARM_DEF_CONNECTION_MONITORテーブルからDtAlarmDefConnectionMonitorを取得する
        /// </summary>
        /// <param name="typeCode">機種コード</param>
        /// <param name="targets">監視対象</param>
        /// <returns>取得したデータ</returns>
        public IEnumerable <DtAlarmDefConnectionMonitor> ReadDtAlarmDefConnectionMonitor(string typeCode, IEnumerable <string> targets)
        {
            IEnumerable <DtAlarmDefConnectionMonitor> models = null;

            try
            {
                _logger.EnterJson("{0}", new { typeCode, targets });

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

                        foreach (var target in targets)
                        {
                            query = query.Where(x => string.IsNullOrEmpty(x.Target) || x.Target == target);
                        }

                        entities = query.ToList();
                    }
                });

                if (entities != null)
                {
                    models = entities.Select(x => x.ToModel());
                }

                return(models);
            }
            catch (RmsException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARM_DEF_CONNECTION_MONITORテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", models);
            }
        }
        /// <summary>
        /// 引数に指定したDtDeliveryFileをDT_DELIVERY_FILEテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>処理結果</returns>
        public DtDeliveryFile CreateDtDeliveryFile(DtDeliveryFile inData)
        {
            DtDeliveryFile model = null;

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

                DBAccessor.Models.DtDeliveryFile entity = new DBAccessor.Models.DtDeliveryFile(inData);

                _dbPolly.Execute(() =>
                {
                    DateTime createdAt = _timePrivder.UtcNow;

                    entity.CreateDatetime = createdAt;
                    entity.UpdateDatetime = createdAt;
                    foreach (DBAccessor.Models.DtDeliveryModel child in entity.DtDeliveryModel)
                    {
                        child.CreateDatetime = createdAt;
                    }

                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var dbdata = db.DtDeliveryFile.Add(entity).Entity;
                        db.SaveChanges();
                        model = dbdata.ToModel();
                    }
                });

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DELIVERY_FILEテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #25
0
        /// <summary>
        /// 引数に指定したパスに、ファイルパスが先頭一致するDtDeviceFileを取得する
        /// </summary>
        /// <param name="containerName">コンテナ名</param>
        /// <param name="path">パス。指定したパスに先頭一致するDtDeviceFileを取得する。</param>
        /// <param name="endDateTime">期間(終了)。指定した日時より過去のDtDeviceFileを取得する。</param>
        /// <returns>DtDeviceFileのリスト</returns>
        public IEnumerable <DtDeviceFile> FindByFilePathStartingWithAndUpdateDatetimeLessThan(string containerName, string path, DateTime endDateTime)
        {
            IEnumerable <DtDeviceFile> model = null;

            try
            {
                _logger.EnterJson("{0}", new { containerName, path, endDateTime });

                List <DBAccessor.Models.DtDeviceFile> entities = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        IQueryable <DBAccessor.Models.DtDeviceFile> query = db.DtDeviceFile;

                        // フィルター時にコンテナ名の大文字小文字は区別しない
                        query = query.Where(x => x.Container.Equals(containerName, StringComparison.OrdinalIgnoreCase));
                        if (!string.IsNullOrEmpty(path))
                        {
                            // パスの大文字小文字は区別しない
                            query = query.Where(x => x.FilePath.StartsWith(path, StringComparison.OrdinalIgnoreCase));
                        }

                        query    = query.Where(x => x.UpdateDatetime != null && x.UpdateDatetime < endDateTime);
                        entities = query.ToList();
                    }
                });

                if (entities != null && entities.Count > 0)
                {
                    model = entities.Select(x => x.ToModel());
                }

                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DEVICE_FILEテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Beispiel #26
0
        /// <summary>
        /// 指定日時より作成日が古い非最新データを削除する
        /// </summary>
        /// <param name="comparisonSourceDatetime">比較対象日時</param>
        /// <returns>削除数</returns>
        public int DeleteExceedsMonthsAllData(DateTime comparisonSourceDatetime)
        {
            int result = 0;

            try
            {
                _logger.Enter($"{nameof(comparisonSourceDatetime)}={comparisonSourceDatetime}");

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var CollectDatetime = new SqlParameter("CollectDatetime", comparisonSourceDatetime);

                        // 収集日時から指定月数超過しているデータを抽出し、削除する
                        var targets = db.DtSoftVersion
                                      .FromSql(
                            @"
                            Select
                                *
                            From
                                core.DT_SOFT_VERSION tbl1
                            Where
                                tbl1.COLLECT_DATETIME < @CollectDatetime
                                and
                                tbl1.COLLECT_DATETIME <> (SELECT MAX(tbl2.COLLECT_DATETIME) FROM core.DT_SOFT_VERSION tbl2 Where tbl1.DEVICE_SID = tbl2.DEVICE_SID)",
                            CollectDatetime);

                        db.DtSoftVersion.RemoveRange(targets);
                        result = db.SaveChanges();
                    }
                });

                return(result);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_SOFT_VERSIONテーブルのDeleteに失敗しました。", e);
            }
            finally
            {
                _logger.Leave($"{nameof(result)}={result}");
            }
        }
Beispiel #27
0
        /// <summary>
        /// DT_BLOCLOG_ANALYSIS_CONFIGテーブルからDtBloclogAnalysisConfigを取得する
        /// </summary>
        /// <param name="isNormalized">規格化フラグ</param>
        /// <param name="allowNotExist">取得件数が0件である場合を正常系とする場合はtrueを、異常系とする場合はfalseを指定する</param>
        /// <returns>取得したデータ</returns>
        public DtBloclogAnalysisConfig ReadDtBloclogAnalysisConfig(bool isNormalized, bool allowNotExist = true)
        {
            DtBloclogAnalysisConfig model = null;

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

                DBAccessor.Models.DtBloclogAnalysisConfig entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.DtBloclogAnalysisConfig.FirstOrDefault(x => x.IsNormalized == isNormalized);
                    }
                });

                if (entity != null)
                {
                    model = entity.ToModel();
                }
                else
                {
                    if (!allowNotExist)
                    {
                        throw new RmsException("DT_BLOCLOG_ANALYSIS_CONFIGテーブルに該当レコードが存在しません。");
                    }
                }

                return(model);
            }
            catch (RmsException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new RmsException("DT_BLOCLOG_ANALYSIS_CONFIGテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
        /// <summary>
        /// DT_STORAGE_CONFIGテーブルから全レコードを取得する
        /// </summary>
        /// <returns>ストレージ設定データリスト</returns>
        /// <remarks>
        /// テーブルからデータを取得できなかった場合にはnuilを返す
        /// </remarks>
        public List <DtStorageConfig> ReadDtStorageConfigs()
        {
            List <DtStorageConfig> models = null;

            try
            {
                _logger.Enter("ReadDtStorageConfigs");

                IQueryable <DBAccessor.Models.DtStorageConfig> entities = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // 全件取得
                        entities = db.DtStorageConfig.Select(x => x);
                    }
                });

                if (entities != null && entities.Count() > 0)
                {
                    models = new List <DtStorageConfig>();
                    foreach (DBAccessor.Models.DtStorageConfig config in entities)
                    {
                        DtStorageConfig model = config.ToModel();
                        models.Add(model);
                    }
                }

                return(models);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_STORAGE_CONFIGテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", models);
            }
        }
Beispiel #29
0
        /// <summary>
        /// 引数に指定したDtDeliveryGroupをDT_DELIVERY_GROUPテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>処理結果</returns>
        public DtDeliveryGroup CreateDtDeliveryGroup(DtDeliveryGroup inData)
        {
            DtDeliveryGroup model = null;

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

                DBAccessor.Models.DtDeliveryGroup entity = new DBAccessor.Models.DtDeliveryGroup(inData);

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var statusNotStart = db.MtDeliveryGroupStatus.FirstOrDefault(x => x.Code.Equals(Const.DeliveryGroupStatus.NotStarted));
                        if (statusNotStart == null)
                        {
                            return;
                        }

                        entity.DeliveryGroupStatusSid = statusNotStart.Sid;
                        var dbdata = db.DtDeliveryGroup.Add(entity).Entity;
                        db.SaveChanges(_timePrivder);
                        model = dbdata.ToModel();
                    }
                });

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DELIVERY_GROUPテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
        /// <summary>
        /// DT_ALARM_DEF_FAILURE_MONITORテーブルからDtAlarmDefFailureMonitorを取得する
        /// </summary>
        /// <param name="errorLog">エラーログ</param>
        /// <returns>取得したデータ</returns>
        public IEnumerable <DtAlarmDefFailureMonitor> ReadDtAlarmDefFailureMonitor(ErrorLog errorLog)
        {
            IEnumerable <DtAlarmDefFailureMonitor> models = null;

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

                List <DBAccessor.Models.DtAlarmDefFailureMonitor> entities = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entities = db.DtAlarmDefFailureMonitor
                                   .Where(x => string.IsNullOrEmpty(x.TypeCode) || x.TypeCode == errorLog.TypeCode)
                                   .Where(x => string.IsNullOrEmpty(x.ErrorCode) || x.ErrorCode == errorLog.ErrorCode)
                                   .ToList();

                        // 同一エラーコードの定義が複数存在した場合
                        if (entities.Count > 1)
                        {
                            entities = entities.Where(x => string.IsNullOrEmpty(x.AnalysisText) || errorLog.ErrorContents.Contains(x.AnalysisText)).ToList();
                        }
                    }
                });

                if (entities != null)
                {
                    models = entities.Select(x => x.ToModel());
                }

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