Ejemplo n.º 1
0
        /// <summary>
        /// DT_DEVICEテーブルからDtDeviceを取得する
        /// </summary>
        /// <param name="sid">取得するデータのSID</param>
        /// <returns>取得したデータ</returns>
        public DtDevice ReadDtDevice(long sid)
        {
            DtDevice model = null;

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

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

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

                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DEVICEテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// DT_DEVICEテーブルからDtDeviceを取得する
        /// </summary>
        /// <param name="equipmentUidOrEdgeId">取得するデータの機器UIDまたはエッジID</param>
        /// <returns>取得したデータ</returns>
        public DtDevice ReadDtDevice(string equipmentUidOrEdgeId)
        {
            DtDevice model = null;

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

                DBAccessor.Models.DtDevice entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.DtDevice.FirstOrDefault(x => x.EquipmentUid == equipmentUidOrEdgeId);
                        if (entity == null && Guid.TryParse(equipmentUidOrEdgeId, out Guid edgeId))
                        {
                            entity = db.DtDevice.FirstOrDefault(x => x.EdgeId == edgeId);
                        }
                    }
                });

                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_DEVICEテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// DT_DEVICEテーブルからDtDeviceを削除する
        /// </summary>
        /// <param name="sid">削除するデータのSID</param>
        /// <param name="equipmentUid">削除するデータのデバイスUID</param>
        /// <param name="remoteConnectUid">削除するデータのリモート接続UID</param>
        /// <returns>削除したデータ</returns>
        public DtDevice DeleteDtDevice(long sid, string equipmentUid, string remoteConnectUid)
        {
            DtDevice model = null;

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

                DBAccessor.Models.DtDevice entity = new DBAccessor.Models.DtDevice()
                {
                    Sid = sid, EquipmentUid = equipmentUid, RemoteConnectUid = remoteConnectUid
                };
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        db.DtDevice.Attach(entity);
                        db.DtDevice.Remove(entity);

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

                return(model);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DEVICEテーブルのDeleteに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 端末テーブルの接続ステータスを更新する
        /// </summary>
        /// <param name="sid">端末SID</param>
        /// <param name="connectionEventTimeInfo">接続/切断イベント時刻情報</param>
        /// <returns>更新したデータ。ステータスに変更がなかった場合にはnullを返す</returns>
        public DtDevice UpdateDeviceConnectionStatus(long sid, ConnectionEventTimeInfo connectionEventTimeInfo)
        {
            DtDevice model = null;

            try
            {
                _logger.EnterJson("{0}", sid);
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // 該当するステータスSIDをマスタテーブルから取得する
                        var record = db.MtConnectStatus.FirstOrDefault(x => x.Code == connectionEventTimeInfo.Status);
                        if (record == null || record.Sid == 0)
                        {
                            throw new RmsException("接続ステータスマスターテーブルに該当するステータスが存在しませんでした。");
                        }

                        // ステータスSID, 接続開始日時, 接続更新日時
                        DtDevice inData = new DtDevice()
                        {
                            Sid = sid,
                            ConnectStatusSid      = record.Sid,
                            ConnectStartDatetime  = connectionEventTimeInfo.EventTime,
                            ConnectUpdateDatetime = connectionEventTimeInfo.EventTime
                        };

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

                        // 接続ステータスが更新されるのでステータスSIDと接続更新日時は更新対象
                        db.Entry(entity).Property(x => x.ConnectStatusSid).IsModified      = true;
                        db.Entry(entity).Property(x => x.ConnectUpdateDatetime).IsModified = true;

                        // 初回接続フラグがtrueのときは接続開始日時も更新対象
                        if (connectionEventTimeInfo.IsFirstConnection)
                        {
                            db.Entry(entity).Property(x => x.ConnectStartDatetime).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);
            }
        }