Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        /// <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);
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 引数に指定したDtAlarmをDT_ALARMテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>処理結果</returns>
        public DtAlarm CreateDtAlarm(DtAlarm inData)
        {
            DtAlarm model = null;

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

                DBAccessor.Models.DtAlarm entity = new DBAccessor.Models.DtAlarm();
                entity.CopyExcludingEquipmentFrom(inData);

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

                _dbPolly.Execute(() =>
                {
                    entity.CreateDatetime = _timeProvider.UtcNow;

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

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARMテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
        /// <summary>
        /// 引数に指定したDtSmartAnalysisResultをDT_SMART_ANALYSIS_RESULTテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>処理結果</returns>
        public DtSmartAnalysisResult CreateDtSmartAnalysisResult(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.CreateDatetime = _timePrivder.UtcNow;
                    entity.UpdateDatetime = _timePrivder.UtcNow;

                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var dbdata = db.DtSmartAnalysisResult.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_SMART_ANALYSIS_RESULTテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 7
0
        /// <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);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 引数に指定したMtInstallResultStatusをMT_INSTALL_RESULT_STATUSテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>処理結果</returns>
        public MtInstallResultStatus CreateMtInstallResultStatus(MtInstallResultStatus inData)
        {
            MtInstallResultStatus model = null;

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

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

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

                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var dbdata = db.MtInstallResultStatus.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("MT_INSTALL_RESULT_STATUSテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 引数に指定したDtDeliveryResultをDT_DELIVERY_RESULTテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>処理結果</returns>
        public DtDeliveryResult CreateDtDeliveryResult(DtDeliveryResult inData)
        {
            DtDeliveryResult model = null;

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

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

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

                    using (Rms.Server.Core.DBAccessor.Models.RmsDbContext db = new Rms.Server.Core.DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var dbdata = db.DtDeliveryResult.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_RESULTテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
0
        /// <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);
            }
        }
        /// <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);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// DT_ALARM_CONFIGテーブルからDtAlarmConfigを取得する
        /// </summary>
        /// <param name="alarmLevel">アラームレベル</param>
        /// <param name="allowNotExist">取得件数が0件である場合を正常系とする場合はtrueを、異常系とする場合はfalseを指定する</param>
        /// <returns>取得したデータ</returns>
        public DtAlarmConfig ReadDtAlarmConfig(byte alarmLevel, bool allowNotExist = true)
        {
            DtAlarmConfig model = null;

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

                DBAccessor.Models.DtAlarmConfig entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.DtAlarmConfig.FirstOrDefault(x => x.AlarmLevelFrom <= alarmLevel && alarmLevel <= x.AlarmLevelTo);
                    }
                });

                if (entity != null)
                {
                    model = entity.ToModel();
                }
                else
                {
                    if (!allowNotExist)
                    {
                        var info = new { AlarmLevelFrom = alarmLevel, AlarmLevelTo = alarmLevel };
                        throw new RmsException(string.Format("DT_ALARM_CONFIGテーブルに該当レコードが存在しません。(検索条件: {0})", JsonConvert.SerializeObject(info)));
                    }
                }

                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARM_CONFIGテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// DT_EQUIPMENTテーブルからDtEquipmentを取得する
        /// </summary>
        /// <param name="equipmentNumber">機器管理番号</param>
        /// <param name="allowNotExist">取得件数が0件である場合を正常系とする場合はtrueを、異常系とする場合はfalseを指定する</param>
        /// <returns>取得したデータ</returns>
        public DtEquipment ReadDtEquipment(string equipmentNumber, bool allowNotExist = true)
        {
            DtEquipment model = null;

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

                DBAccessor.Models.DtEquipment entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.DtEquipment.Include(x => x.InstallBaseS).FirstOrDefault(x => x.EquipmentNumber == equipmentNumber);
                    }
                });

                if (entity != null)
                {
                    model = entity.ToModelIncludedInstallBase();
                }
                else
                {
                    if (!allowNotExist)
                    {
                        var info = new { EquipmentNumber = equipmentNumber };
                        throw new RmsException(string.Format("DT_EQUIPMENTテーブルに該当レコードが存在しません。(検索条件: {0})", JsonConvert.SerializeObject(info)));
                    }
                }

                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_EQUIPMENTテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// DT_ALARM_DEF_INSTALL_RESULT_MONITORテーブルからDtAlarmDefInstallResultMonitorを取得する
        /// </summary>
        /// <param name="installResult">適用結果</param>
        /// <returns>取得したデータ</returns>
        public IEnumerable <DtAlarmDefInstallResultMonitor> ReadDtAlarmDefInstallResultMonitor(InstallResult installResult)
        {
            IEnumerable <DtAlarmDefInstallResultMonitor> models = null;

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

                List <DBAccessor.Models.DtAlarmDefInstallResultMonitor> entities = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entities = db.DtAlarmDefInstallResultMonitor
                                   .Where(x => string.IsNullOrEmpty(x.TypeCode) || x.TypeCode == installResult.TypeCode)
                                   .Where(x => string.IsNullOrEmpty(x.ErrorCode) || x.ErrorCode == installResult.ErrorCode)
                                   .Where(x => x.IsAuto == installResult.Auto)
                                   .Where(x => string.IsNullOrEmpty(x.Process) || x.Process == installResult.Process)
                                   .Where(x => x.IsSuccess == null || x.IsSuccess == installResult.Success)
                                   .ToList();
                    }
                });

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

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

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

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

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

                    using (Rms.Server.Core.DBAccessor.Models.RmsDbContext db = new Rms.Server.Core.DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var dbdata = db.MtEquipmentType.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("MT_EQUIPMENT_TYPEテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// DT_DELIVERY_MODELテーブルからDtDeliveryModelを取得する
        /// </summary>
        /// <param name="sid">取得するデータのSID</param>
        /// <returns>取得したデータ</returns>
        public DtDeliveryModel ReadDtDeliveryModel(long sid)
        {
            DtDeliveryModel model = null;

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

                Rms.Server.Core.DBAccessor.Models.DtDeliveryModel entity = null;
                _dbPolly.Execute(() =>
                {
                    using (Rms.Server.Core.DBAccessor.Models.RmsDbContext db = new Rms.Server.Core.DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.DtDeliveryModel.FirstOrDefault(x => x.Sid == sid);
                    }
                });

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

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DELIVERY_MODELテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// DT_ALARM_DEF_PANEL_DEFECT_PREMONITORテーブルからDtAlarmDefPanelDefectPremonitorを取得する
        /// </summary>
        /// <param name="panelDefectPredictiveResutLog">パネル欠陥予兆結果ログ</param>
        /// <returns>取得したデータ</returns>
        public IEnumerable <DtAlarmDefPanelDefectPremonitor> ReadDtAlarmDefPanelDefectPremonitor(PanelDefectPredictiveResutLog panelDefectPredictiveResutLog)
        {
            IEnumerable <DtAlarmDefPanelDefectPremonitor> models = null;

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

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

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

                return(models);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARM_DEF_PANEL_DEFECT_PREMONITORテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", models);
            }
        }
        /// <summary>
        /// DT_ALARM_DEF_TEMPERATURE_SENSOR_LOG_MONITORテーブルからDtAlarmDefTemperatureSensorLogMonitorを取得する
        /// </summary>
        /// <param name="temperatureSensorLog">温度センサログ</param>
        /// <returns>取得したデータ</returns>
        public IEnumerable <DtAlarmDefTemperatureSensorLogMonitor> ReadDtAlarmDefTemperatureSensorLogMonitor(TemperatureSensorLog temperatureSensorLog)
        {
            IEnumerable <DtAlarmDefTemperatureSensorLogMonitor> models = null;

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

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

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

                return(models);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_ALARM_DEF_TEMPERATURE_SENSOR_LOG_MONITORテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", models);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// DT_PARENT_CHILD_CONNECTテーブルにメッセージを追加またはメッセージの内容で更新処理を行う(親フラグ=trueの場合)
        /// </summary>
        /// <param name="inData">更新データ</param>
        /// <returns>追加または更新したデータ。「確認日時」が既存レコードより古く更新しなかった場合には、nullを返す</returns>
        public DtParentChildConnect Save(DtParentChildConnectFromParent inData)
        {
            DtParentChildConnect model = null;

            try
            {
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                        using (var tran = db.Database.BeginTransaction())
                        {
                            // 現在時刻を取得
                            var now = _timePrivder.Now;

                            // メッセージクラス→Modelクラス変換時に、通信が成功だった場合は最終接続日時にデータが格納される
                            // ここで初期値だった場合には通信失敗と判断できる
                            if (inData.ParentLastConnectDatetime == null || inData.ParentLastConnectDatetime == default(DateTime))
                            {
                                inData.ParentLastConnectDatetime = now;
                            }

                            // DB格納データクラス
                            DBAccessor.Models.DtParentChildConnect entity = CreateEntityFromParent(inData, db);

                            // 親機器 - 子機器 - 親機器確認結果の組み合わせをチェックする
                            // 3つの組み合わせでレコードを一意に決めることができる
                            var sids = CreateSqlParameterSet(entity.ParentDeviceSid, entity.ChildDeviceSid);
                            DBAccessor.Models.DtParentChildConnect targetRecord
                                = db.DtParentChildConnect.FromSql(SelectParentSqlCommand, sids).AsNoTracking().FirstOrDefault();

                            if (targetRecord == null || targetRecord.Sid == 0)
                            {
                                // 作成日時+更新日時
                                // 通常はSaveChangesにTimeProvideを渡し、DBが自動的に作成日時と更新日時を設定する。
                                // しかし親子間通信データについては、
                                // 通信失敗のケースにおいて最終更新日時にはレコード作成日時を格納する
                                // (nullを回避しつつ、通信失敗ケースであったことを後から判断できるようにするため)。
                                // DBが自動的に時刻を設定した場合に、リポジトリ内で取得した時刻と時間差が発生する可能性があるため、
                                // リポジトリ内で明示的に時刻を取得してDBにレコードを挿入する。
                                entity.CreateDatetime = now;
                                entity.UpdateDatetime = now;

                                // レコード追加
                                var dbdata = db.DtParentChildConnect.Add(entity).Entity;

                                // 最終日時更新データと作成日時・更新日時を一致させたいので、TimeProviderは渡さずに明示的な日時データを使う
                                db.SaveChanges();
                                model = dbdata.ToModel();
                            }
                            else
                            {
                                // データの時刻チェック: データがDBに格納されたデータよりも新しい場合のみ更新処理を行う
                                // DBよりも古い確認時刻だった場合には更新せずにnullを返す
                                DateTime?dbTime = targetRecord.ParentConfirmDatetime;

                                if (dbTime == null || inData.ParentConfirmDatetime.Value.CompareTo(dbTime.Value) > 0)
                                {
                                    // 更新対象のレコードのSIDを設定
                                    entity.Sid = targetRecord.Sid;

                                    db.DtParentChildConnect.Attach(entity);

                                    // 更新のあったデータのみを更新する
                                    db.Entry(entity).Property(x => x.ParentConfirmDatetime).IsModified = true;
                                    db.Entry(entity).Property(x => x.ParentResult).IsModified          = true;
                                    if (entity.ParentResult != null && entity.ParentResult.Value)
                                    {
                                        db.Entry(entity).Property(x => x.ParentLastConnectDatetime).IsModified = true;
                                    }

                                    db.SaveChanges(_timePrivder);
                                    model = entity.ToModel();
                                }
                            }

                            // トランザクション終了
                            tran.Commit();
                        }
                });

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_PARENT_CHILD_CONNECTテーブルの更新処理に失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 引数に指定したDtPlusServiceBillLogをDT_PLUS_SERVICE_BILL_LOGテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>追加したデータ。エラーが発生した場合には例外を投げるためnullを返さない</returns>
        public DtPlusServiceBillLog Upsert(DtPlusServiceBillLog inData)
        {
            DtPlusServiceBillLog model = null;

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

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

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // 重複チェック
                        var existing = db.DtPlusServiceBillLog
                                       .FirstOrDefault(x => x.StudyInstanceUid == inData.StudyInstanceUid && x.TypeName == inData.TypeName);

                        if (existing == null)
                        {
                            // 追加
                            db.DtPlusServiceBillLog.Add(entity);
                        }
                        else
                        {
                            // 計測日時が古いデータで更新しないようにする。
                            // 呼び出し側のパラメタチェックでかかるはずだが、
                            // 日時がnullableなので念のため既存日時がnullの場合は更新するようにしておく。
                            if (existing.MeasureDatetime < inData.MeasureDatetime || existing.MeasureDatetime == null)
                            {
                                // 更新処理
                                entity.Sid = existing.Sid;
                                db.DtPlusServiceBillLog.Attach(entity);
                                db.Entry(entity).Property(x => x.DeviceSid).IsModified          = true;
                                db.Entry(entity).Property(x => x.SourceEquipmentUid).IsModified = true;
                                //// db.Entry(entity).Property(x => x.TypeName).IsModified = true;
                                db.Entry(entity).Property(x => x.BillFlg).IsModified   = true;
                                db.Entry(entity).Property(x => x.PatientId).IsModified = true;
                                db.Entry(entity).Property(x => x.Sex).IsModified       = true;
                                db.Entry(entity).Property(x => x.Age).IsModified       = true;
                                //// db.Entry(entity).Property(x => x.StudyInstanceUid).IsModified = true;
                                db.Entry(entity).Property(x => x.SopInstanceUid).IsModified  = true;
                                db.Entry(entity).Property(x => x.StudyDatetime).IsModified   = true;
                                db.Entry(entity).Property(x => x.MeasureDatetime).IsModified = true;
                                db.Entry(entity).Property(x => x.CollectDatetime).IsModified = true;
                                db.Entry(entity).Property(x => x.UpdateDatetime).IsModified  = true;
                            }
                            else
                            {
                                // 古いデータでの更新を弾く、AlreadyExistとはニアリーイコールではあるが、丸める
                                new RmsAlreadyExistException(string.Format("StudyInstanceUid [{0}], TypeName[{1}] はすでに追加済みです。", inData.StudyInstanceUid, inData.TypeName));
                            }
                        }

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

                return(model);
            }
            catch (RmsAlreadyExistException)
            {
                throw;
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_PLUS_SERVICE_BILL_LOGテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 引数に指定したDtInstallResultをDT_INSTALL_RESULTテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <param name="state">状態。適用結果ステータスマスタテーブルのコード値が入る。</param>
        /// <returns>追加したデータ。配信グループデータテーブルの更新に失敗した場合はnullを返す。</returns>
        /// <remarks>
        /// すべての処理に成功した場合には適用結果データテーブルに登録したデータを返す。
        /// 配信グループデータテーブルの更新に失敗した場合はnullを返す。
        /// 適用結果データテーブルへの登録に失敗した場合には、例外を投げる。
        /// </remarks>
        public DtInstallResult CreateDtInstallResultIfAlreadyMessageThrowEx(DtInstallResult inData, string state)
        {
            DtInstallResult model = null;

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

                // グループステータス更新失敗フラグ
                bool failedToUpdateGroupStatus = false;

                DBAccessor.Models.DtDeliveryGroup deliveryGroupEntity = new DBAccessor.Models.DtDeliveryGroup
                {
                    DeliveryGroupStatusSid = 0
                };

                _dbPolly.Execute(() =>
                {
                    // メッセージIDがなければ追加
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // マスタテーブルから適用結果ステータスSIDを取得
                        var installResultStatus = db.MtInstallResultStatus.FirstOrDefault(x => x.Code == state);
                        if (installResultStatus == null || installResultStatus.Sid == 0)
                        {
                            throw new RmsException(string.Format("状態[{0}]がマスタテーブルに存在しません。", state));
                        }

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

                        // 適用結果データテーブルの更新処理
                        DBAccessor.Models.DtInstallResult dbdata;
                        {
                            // 適用結果ステータスSIDを設定
                            inData.InstallResultStatusSid            = installResultStatus.Sid;
                            DBAccessor.Models.DtInstallResult entity = new DBAccessor.Models.DtInstallResult(inData);

                            // メッセージを適用結果データテーブルに保存
                            // 適用結果データテーブルの更新は、配信グループデータテーブル更新の成功/失敗に依存しない仕様のため、先にDB保存処理を呼ぶ
                            dbdata = db.DtInstallResult.Add(entity).Entity;
                            db.SaveChanges(_timePrivder);
                        }

                        // 配信グループデータテーブルの更新処理
                        {
                            // 適用結果ステータスマスタテーブルから"completed"に該当するSIDを取得する
                            long completedStatusSid = db.MtDeliveryGroupStatus.FirstOrDefault(x => x.Code == Const.DeliveryGroupStatus.Completed).Sid;

                            // 更新された配信グループデータテーブルのレコード数
                            int affectedRows = 0;

                            // 適用結果データテーブルの配信結果SIDから配信結果データテーブルのレコードを抽出
                            var deliveryResult = db.DtDeliveryResult.FirstOrDefault(x => x.Sid == inData.DeliveryResultSid);
                            if (deliveryResult != null)
                            {
                                // メッセージが所属する配信グループのSID
                                long targetDeliveryGroupSid = deliveryResult.DeliveryGroupSid;

                                // SQL文を発行する
                                var sqlParamForSid            = new SqlParameter(SqlKeyForSid, targetDeliveryGroupSid);
                                var sqlParamForGroupStatusSid = new SqlParameter(SqlKeyForGroupStatusSid, completedStatusSid);
                                var sqlParams = new[] { sqlParamForGroupStatusSid, sqlParamForSid };

                                try
                                {
                                    affectedRows = db.Database.ExecuteSqlCommand(SqlCommandToUpdateDeliveryGroupStatus, sqlParams);
                                    if (affectedRows <= 0)
                                    {
                                        _logger.Debug(string.Format("メッセージ[{0}]が所属する配信グループIDのステータスに変更はありませんでした。", inData.MessageId));
                                    }
                                }
                                catch (Exception)
                                {
                                    // 配信グループデータ更新失敗フラグを立てる
                                    failedToUpdateGroupStatus = true;
                                    _logger.Debug(string.Format("メッセージ[{0}]が所属する配信グループIDのステータス更新に失敗しました。", inData.MessageId));
                                }
                            }
                            else
                            {
                                // 配信結果はメッセージの定義上null許可のため、配信結果が存在しないケースがある
                                _logger.Debug(string.Format("メッセージ[{0}]が所属する配信グループIDがnullであるため配信グループデータテーブルは更新しませんでした。", inData.MessageId));
                            }

                            db.SaveChanges(_timePrivder);
                        }

                        model = dbdata.ToModel();
                    }
                });

                if (failedToUpdateGroupStatus)
                {
                    // 配信グループデータ更新失敗時にはnullを返す
                    return(null);
                }

                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_INSTALL_RESULTテーブルへのInsertまたはDT_DELIVERY_GROUPのUpdateに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 引数に指定したDtDeviceFileをDT_DEVICE_FILEテーブルへ登録する
        /// 既にレコードが存在する場合は登録ではなく当該レコードの更新処理を行う
        /// また当該レコードに紐づいたDT_DEVICE_FILE_ATTRIBUTEテーブルの更新を行う
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>処理結果</returns>
        public DtDeviceFile CreateOrUpdateDtDeviceFile(DtDeviceFile inData)
        {
            DtDeviceFile model = null;

            // 更新日時
            // DtDeviceFileAttribute更新時に明示的に日時データを渡す必要があるため、
            // レコード作成および更新日時はすべて明示的に設定する
            var now = _timePrivder.UtcNow;

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

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                        using (var tran = db.Database.BeginTransaction())
                        {
                            string container = inData.Container;
                            string filePath  = inData.FilePath;

                            var deviceFileModel = db.DtDeviceFile.FirstOrDefault(
                                x => x.Container.Equals(container, StringComparison.OrdinalIgnoreCase) &&
                                x.FilePath.Equals(filePath, StringComparison.OrdinalIgnoreCase));

                            DBAccessor.Models.DtDeviceFile entity;

                            if (deviceFileModel == null || deviceFileModel.Sid == 0)
                            {
                                inData.CreateDatetime = now;
                                inData.UpdateDatetime = now;
                                entity = new DBAccessor.Models.DtDeviceFile(inData);

                                // コンテナ名とファイルパスをキーにして見つからなければレコード追加
                                entity = db.DtDeviceFile.Add(entity).Entity;
                            }
                            else
                            {
                                // 端末ファイル更新
                                deviceFileModel.SourceEquipmentUid = inData.SourceEquipmentUid;
                                deviceFileModel.CollectDatetime    = inData.CollectDatetime;
                                deviceFileModel.UpdateDatetime     = now;

                                entity = deviceFileModel;

                                // コンテナ名とファイルパスをキーにしてレコードが見つかった場合は、
                                // 端末ファイルデータおよび紐づく端末ファイル属性レコードの更新を行う
                                // 端末ファイル属性については、以下の処理を行う
                                // ・同じNameを持つレコードが存在しない場合はレコード追加
                                // ・同じNameを持つレコードが存在する場合はレコードを更新
                                // ・既に存在するレコードのNameが追加するレコードの中に存在しない場合は、当該レコードを削除

                                // 端末ファイル属性
                                var inDeviceFileAttributeModel     = inData.DtDeviceFileAttribute;
                                var actualDeviceFileAttributeModel = db.DtDeviceFileAttribute.Where(x => x.DeviceFileSid == deviceFileModel.Sid);

                                // 端末ファイル属性テーブルに存在するが、追加するレコードの中に存在しないものは削除する
                                foreach (var attr in actualDeviceFileAttributeModel)
                                {
                                    var inAttrData = inDeviceFileAttributeModel.FirstOrDefault(x => x.Name.Equals(attr.Name, StringComparison.OrdinalIgnoreCase));
                                    if (inAttrData == null)
                                    {
                                        db.DtDeviceFileAttribute.Remove(attr);
                                    }
                                }

                                // 端末ファイル属性テーブルに存在しないものは追加、存在するものは更新
                                foreach (var attr in inDeviceFileAttributeModel)
                                {
                                    var found = actualDeviceFileAttributeModel.FirstOrDefault(x => x.Name.Equals(attr.Name, StringComparison.OrdinalIgnoreCase));
                                    DBAccessor.Models.DtDeviceFileAttribute deviceFileAttributeEntity;

                                    if (found == null || found.Sid == 0)
                                    {
                                        attr.DeviceFileSid        = deviceFileModel.Sid;
                                        attr.CreateDatetime       = now;
                                        attr.UpdateDatetime       = now;
                                        deviceFileAttributeEntity = new DBAccessor.Models.DtDeviceFileAttribute(attr);

                                        // レコード追加
                                        _ = db.DtDeviceFileAttribute.Add(deviceFileAttributeEntity).Entity;
                                    }
                                    else
                                    {
                                        // レコード更新
                                        found.Value          = attr.Value;
                                        found.UpdateDatetime = now;
                                    }
                                }
                            }

                            db.SaveChanges();
                            model = entity.ToModel();

                            // トランザクション終了
                            tran.Commit();
                        }
                });

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DEVICE_FILEテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// DT_PARENT_CHILD_CONNECTテーブルからDtParentChildConnectを取得する
        /// </summary>
        /// <returns>取得したデータ</returns>
        public IEnumerable <DtParentChildConnect> ReadDtParentChildConnect()
        {
            IEnumerable <DtParentChildConnect> models = null;

            try
            {
                _logger.Enter();

                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        if (!db.DtParentChildConnect.Any())
                        {
                            // 親子間通信データテーブルにデータがない場合は正常系
                            models = new List <DtParentChildConnect>();
                        }
                        else
                        {
                            // インベントリデータテーブルは更新ではなく新規追加なので端末SID毎に最新のデータを取得して結合する
                            var inventoryLatests = db.DtInventory.GroupBy(x => x.DeviceSid).Select(y => y.OrderByDescending(z => z.CreateDatetime).FirstOrDefault());

                            var joinEntities = db.DtParentChildConnect
                                               .Join(
                                db.DtDevice,
                                x => x.ChildDeviceSid,
                                y => y.Sid,
                                (parentChildConnet, device) => new
                            {
                                ParentChildConnet         = parentChildConnet,
                                DeviceTableSid            = device.Sid,
                                DeviceTableEquipmentUid   = device.EquipmentUid,
                                DeviceTableInstallTypeSid = device.InstallTypeSid
                            })
                                               .Join(
                                db.MtInstallType,
                                x => x.DeviceTableInstallTypeSid,
                                y => y.Sid,
                                (joinTable, installType) => new
                            {
                                joinTable.ParentChildConnet,
                                joinTable.DeviceTableSid,
                                joinTable.DeviceTableEquipmentUid,
                                InstallTypeTableCode = installType.Code,
                            })
                                               .Join(
                                inventoryLatests,
                                x => x.ParentChildConnet.Sid,
                                y => y.DeviceSid,
                                (joinTable, inventory) => new
                            {
                                joinTable.ParentChildConnet,
                                joinTable.DeviceTableEquipmentUid,
                                joinTable.InstallTypeTableCode,
                                InventoryDetailInfo = inventory.DetailInfo
                            }).ToList();

                            if (!joinEntities.Any())
                            {
                                throw new RmsException("JoinによりDT_PARENT_CHILD_CONNECTテーブルのデータ抽出数が0になりました。");
                            }
                            else
                            {
                                models = new List <DtParentChildConnect>();

                                foreach (var entity in joinEntities)
                                {
                                    var detailInfo = JsonConvert.DeserializeObject <JObject>(entity.InventoryDetailInfo);

                                    // アラーム判定・アラーム情報の生成に必要な属性のみ取得
                                    var model = new DtParentChildConnect
                                    {
                                        EquipmentUid      = entity.DeviceTableEquipmentUid,
                                        TypeCode          = entity.InstallTypeTableCode,
                                        TemperatureSensor = (string)detailInfo[Utility.Const.InventoryAlSoftwareName][Utility.Const.InventorySettingInfoName][Utility.Const.InventoryOptionName][Utility.Const.InventoryTemperatureSensorName],
                                        Dxa = (string)detailInfo[Utility.Const.InventoryAlSoftwareName][Utility.Const.InventorySettingInfoName][Utility.Const.InventoryOptionName][Utility.Const.InventoryDxaName],
                                        ParentLastConnectDatetime = entity.ParentChildConnet.ParentLastConnectDatetime,
                                        ChildLastConnectDatetime  = entity.ParentChildConnet.ChildLastConnectDatetime
                                    };
                                    models.Append(model);
                                }
                            }
                        }
                    }
                });

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