/// <summary> /// データの更新(配信ステータスを指定SIDのものにする) /// </summary> /// <param name="sid">更新する配信グループデータのSID</param> /// <returns>更新されたDB内容</returns> public DtDeliveryGroup UpdateDtDeliveryGroupStatusStarted(long sid) { DtDeliveryGroup model = null; try { _logger.Enter($"{nameof(sid)}: {sid}"); _dbPolly.Execute( () => { model = UpdateStatusStarted(sid); }); return(model); } catch (RmsException) { throw; } catch (Exception e) { throw new RmsException("DT_DELIVERY_GROUPテーブルのUpdateに失敗しました。", e); } finally { _logger.LeaveJson("{0}", model); } }
/// <summary> /// データの更新(配信ステータスが「配信前」の時のみ) /// </summary> /// <param name="inData">更新データ</param> /// <returns>更新されたDB内容</returns> public DtDeliveryGroup UpdateDtDeliveryGroupIfDeliveryNotStart(DtDeliveryGroup inData) { DtDeliveryGroup model = null; try { _logger.EnterJson("inData: {0}", inData); _dbPolly.Execute( () => { model = UpdateIfNotStart(inData); }); return(model); } catch (RmsException) { throw; } catch (Exception e) { throw new RmsException("DT_DELIVERY_GROUPテーブルのUpdateに失敗しました。", e); } finally { _logger.LeaveJson("{0}", model); } }
/// <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); } }
/// <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); } }
/// <summary> /// 配信グループを更新する /// </summary> /// <remarks>sd 01-2.配信グループ更新</remarks> /// <param name="utilParam">配信グループパラメータ</param> /// <returns>DB更新したパラメータ(Result付き)</returns> public Result <DtDeliveryGroup> Update(DtDeliveryGroup utilParam) { Result <DtDeliveryGroup> result = null; try { _logger.EnterJson("In Param: {0}", utilParam); // Sq1.1.1 配信グループを更新する DtDeliveryGroup model = _dtDeliveryGroupRepository.UpdateDtDeliveryGroupIfDeliveryNotStart(utilParam); if (model == null) { _logger.Error(nameof(Resources.CO_API_DGU_005)); result = new Result <DtDeliveryGroup>(ResultCode.NotFound, Resources.CO_API_DGU_005, utilParam); } else { _logger.Info(nameof(Resources.CO_API_DGU_007)); result = new Result <DtDeliveryGroup>(ResultCode.Succeed, Resources.CO_API_DGU_007, model); } return(result); } catch (RmsParameterException e) { _logger.Error(e, nameof(Resources.CO_API_DGU_002), new object[] { e.Message }); result = new Result <DtDeliveryGroup>(ResultCode.ParameterError, string.Format(Resources.CO_API_DGU_002, e.Message), utilParam); return(result); } catch (RmsCannotChangeDeliveredFileException e) { _logger.Error(e, nameof(Resources.CO_API_DGU_003)); result = new Result <DtDeliveryGroup>(ResultCode.DoStartedDelivery, Resources.CO_API_DGU_003, utilParam); return(result); } catch (RmsConflictException e) { _logger.Error(e, nameof(Resources.CO_API_DGU_004)); result = new Result <DtDeliveryGroup>(ResultCode.Conflict, Resources.CO_API_DGU_004, utilParam); return(result); } catch (Exception e) { _logger.Error(e, nameof(Resources.CO_API_DGU_006)); result = new Result <DtDeliveryGroup>(ResultCode.ServerEerror, Resources.CO_API_DGU_006, utilParam); return(result); } finally { _logger.LeaveJson("Result Param: {0}", result); } }
/// <summary> /// 配信メッセージオブジェクトを作成する(配信対象以外) /// </summary> /// <param name="deliveryGroup">配信グループデータ</param> /// <returns>配信メッセージオブジェクト</returns> /// <remarks>配信対象プロパティは別途設定する必要がある</remarks> public static RequestDelivery CreateDeliveryMessageObject(DtDeliveryGroup deliveryGroup) { Assert.IfNull(deliveryGroup); RequestDelivery request = new RequestDelivery(); // ファイルパスの取得 request.FilePath = deliveryGroup.DtDeliveryFile?.FilePath; // 配信ファイル種別の取得 request.DeliveryFileType = deliveryGroup.DtDeliveryFile?.MtDeliveryFileType?.Code; // 機種コードの取得 switch (deliveryGroup.DtDeliveryFile?.MtDeliveryFileType?.Code) { // 配信ファイル種別によって集めるコードを変える case Const.DeliveryFileType.AlSoft: // インストールタイプコード(1個) request.TypeCodes = new string[] { deliveryGroup.DtDeliveryFile?.MtInstallType?.Code }; break; case Const.DeliveryFileType.HotFixConsole: case Const.DeliveryFileType.HotFixHobbit: // 機器型式のコード request.TypeCodes = deliveryGroup.DtDeliveryFile?.DtDeliveryModel ?.Where(x => x.MtEquipmentModel != null) .Select(x => x.MtEquipmentModel.Code) .ToArray(); break; case Const.DeliveryFileType.Package: // 空配列 request.TypeCodes = new string[0]; break; default: // 想定外のパラメータはnullを設定 request.TypeCodes = null; break; } // バージョンの取得 request.Version = deliveryGroup.DtDeliveryFile?.Version; // 適用(インストール)可能バージョンの取得 request.InstallableVersions = deliveryGroup.DtDeliveryFile?.InstallableVersion?.Split(','); // ダウンロード遅延時間の取得 request.DownloadDelayTime = (ushort)deliveryGroup.DownloadDelayTime.GetValueOrDefault(); return(request); }
/// <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; } } }
public void DeleteDtDeliveryGroupTest( string no, string in_InsertNewDataSqlPath, string in_DeleteNewDataSqlPath, string expected_DataJsonPath, string expected_ExceptionType, string expected_ExceptionMessage, string remarks) { byte[] rowVersion = new byte[] { }; DtDeliveryGroup readModel = null; bool canDelete = false; // 初期データ挿入 if (RepositoryTestHelper.ExecInsertSql(in_InsertNewDataSqlPath)) { canDelete = true; // RowVersion取得のため読み出す readModel = _deliveryGroupRepository.ReadDtDeliveryGroup(1); Assert.IsNotNull(readModel); rowVersion = readModel.RowVersion; } string exceptionName = ""; string exceptionMessage = ""; try { // データを削除する var deletedModel = _deliveryGroupRepository.DeleteDtDeliveryGroup(1, rowVersion); Assert.IsTrue((deletedModel != null) == canDelete); // 削除データを読み出せないことを確認する readModel = _deliveryGroupRepository.ReadDtDeliveryGroup(1); Assert.IsNull(readModel); } catch (RmsCannotChangeDeliveredFileException e) { exceptionName = e.GetType().FullName; exceptionMessage = e.Message; } // 例外発生チェック Assert.AreEqual(expected_ExceptionType, exceptionName); Assert.AreEqual(expected_ExceptionMessage, exceptionMessage); // 後処理 RepositoryTestHelper.ExecDeleteSql(in_DeleteNewDataSqlPath); }
/// <summary> /// 配信グループを追加する /// </summary> /// <remarks>sd 01-2.配信グループ登録</remarks> /// <param name="utilParam">配信グループパラメータ</param> /// <returns>DBに追加したパラメータ(Result付き)</returns> public Result <DtDeliveryGroup> Create(DtDeliveryGroup utilParam) { Result <DtDeliveryGroup> result = null; try { _logger.EnterJson("In Param: {0}", utilParam); // 適用結果ステータス(notstart)のSIDを取得する MtInstallResultStatus status = _mtInstallResultStatusRepository.ReadMtInstallResultStatus(Const.InstallResultStatus.NotStarted); // 配信結果に適用結果履歴の初期値を設定する foreach (var deliveryResult in utilParam.DtDeliveryResult) { deliveryResult.DtInstallResult.Add(new DtInstallResult() { DeviceSid = deliveryResult.DeviceSid, ////DeliveryResultSid InstallResultStatusSid = status.Sid, CollectDatetime = _timeProvider.UtcNow }); } // Sq1.1.1 配信グループを登録する DtDeliveryGroup model = _dtDeliveryGroupRepository.CreateDtDeliveryGroup(utilParam); _logger.Info(nameof(Resources.CO_API_DGC_004)); result = new Result <DtDeliveryGroup>(ResultCode.Succeed, Resources.CO_API_DGC_004, model); return(result); } catch (RmsParameterException e) { _logger.Error(e, nameof(Resources.CO_API_DGC_002), new object[] { e.Message }); result = new Result <DtDeliveryGroup>(ResultCode.ParameterError, string.Format(Resources.CO_API_DGC_002, e.Message), utilParam); return(result); } catch (Exception e) { _logger.Error(e, nameof(Resources.CO_API_DGC_003)); result = new Result <DtDeliveryGroup>(ResultCode.ServerEerror, Resources.CO_API_DGC_003, utilParam); return(result); } finally { _logger.LeaveJson("Result Param: {0}", result); } }
/// <summary> /// 配信グループに属し、オンラインとなっているゲートウェイ機器を取得する(ラッパー) /// </summary> /// <param name="group">配信グループ</param> /// <returns>オンラインなゲートウェイ機器</returns> private IEnumerable <DtDevice> ReadDtDeviceOnlineGatewayWrapper(DtDeliveryGroup group) { IEnumerable <DtDevice> models = new List <DtDevice>(); try { models = _deviceRepository.ReadDtDeviceOnlineGateway(group); } catch (Exception e) { // Sq1.3 _logger.Error(e, nameof(Resources.CO_DLV_DLV_011), new object[] { group.Sid, e.Message }); } return(models); }
/// <summary> /// ゲートウェイ機器を持つ配信機器の配信結果ステータスを更新する(messagesent)(ラッパー) /// </summary> /// <param name="includedGroup">配信結果情報をもつ配信グループ</param> /// <param name="gatewayDevice">ゲートウェイ機器</param> /// <returns>更新した適用結果</returns> private IEnumerable <DtInstallResult> CreateDtInstallResultStatusSentWrapper(DtDeliveryGroup includedGroup, DtDevice gatewayDevice) { IEnumerable <DtInstallResult> models = new List <DtInstallResult>(); try { models = _installResultRepository.CreateDtInstallResultStatusSent(includedGroup, gatewayDevice.Sid); } catch (Exception e) { // Sq1.7 _logger.Error(e, nameof(Resources.CO_DLV_DLV_016), new object[] { gatewayDevice.EdgeId, gatewayDevice.EquipmentUid, e.Message }); } return(models); }
/// <summary> /// 開始可能な配信グループの配信結果ステータスをstartedにする(ラッパー) /// </summary> /// <param name="sid">配信グループSID</param> /// <returns>更新されたDBデータ</returns> private DtDeliveryGroup UpdateDtDeliveryGroupStatusStartedWrapper(long sid) { DtDeliveryGroup model = null; try { model = _deliveryGroupRepository.UpdateDtDeliveryGroupStatusStarted(sid); } catch (Exception e) { // Sq1.2 _logger.Error(e, nameof(Resources.CO_DLV_DLV_010), new object[] { sid, e.Message }); } return(model); }
/// <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); } }
/// <summary> /// UtilityモデルをレスポンスDTOに変換する /// </summary> /// <param name="utilParam">Utilityのパラメータ</param> /// <returns>レスポンス用Dto</returns> public static DeliveryGroupResponseDto ConvertUtilityToResponseDto(this DtDeliveryGroup utilParam) { return(utilParam == null ? null : new DeliveryGroupResponseDto() { Sid = utilParam.Sid, DeliveryFileSid = utilParam.DeliveryFileSid, DeliveryGroupStatusSid = utilParam.DeliveryGroupStatusSid, Name = utilParam.Name, StartDatetime = utilParam.StartDatetime.Value, DownloadDelayTime = utilParam.DownloadDelayTime, CreateDatetime = utilParam.CreateDatetime, UpdateDatetime = utilParam.UpdateDatetime, RowVersion = WebApiHelper.ConvertByteArrayToLong(utilParam.RowVersion), DeliveryDestinations = utilParam.DtDeliveryResult.Select(x => x.ConvertUtilityToResponseDto()).ToArray() }); }
/// <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); } }
public void UpdateDeviceInfoByTwinChangedTest( string no, string in_InsertNewDataSqlPath, string in_DeleteNewDataSqlPath, string expected_DataJsonPath, string expected_ExceptionType, string expected_ExceptionMessage, string remarks) { DtDeliveryGroup readDeliveryGroup = new DtDeliveryGroup() { Sid = 0 }; DtTwinChanged twinChangedData = new DtTwinChanged() { RemoteConnectionUid = RepositoryTestHelper.CreateSpecifiedNumberString(64), SoftVersion = RepositoryTestHelper.CreateSpecifiedNumberString(30), }; if (expected_ExceptionType == typeof(RmsParameterException).FullName) { if (expected_ExceptionMessage.Contains("RemoteConnectUid")) { twinChangedData.RemoteConnectionUid = RepositoryTestHelper.CreateSpecifiedNumberString(65); // 上限値+1 } else if (expected_ExceptionMessage.Contains("RmsSoftVersion")) { twinChangedData.SoftVersion = RepositoryTestHelper.CreateSpecifiedNumberString(31); // 上限値+1 } } // 初期データ挿入 RepositoryTestHelper.ExecInsertSql(in_InsertNewDataSqlPath); string exceptionName = ""; string exceptionMessage = ""; try { if (expected_ExceptionType == typeof(ArgumentNullException).FullName) { twinChangedData = null; } // データを取得する(配信結果付き) var readModel = _deviceRepository.UpdateDeviceInfoByTwinChanged(2, twinChangedData); if (readModel != null) { readModel.UpdateDatetime = DateTime.Parse("2020/4/1 0:00:00"); } // データのjson化 string readJson = Utility.ObjectExtensions.ToStringJson(readModel); string expectJson = null; if (File.Exists(expected_DataJsonPath)) { expectJson = File.ReadAllText(expected_DataJsonPath); } // データの比較 Assert.AreEqual(expectJson, readJson); // TODO DBデータ内容をチェックする } catch (RmsParameterException e) { exceptionName = e.GetType().FullName; exceptionMessage = e.Message; } catch (ArgumentNullException e) { exceptionName = e.GetType().FullName; exceptionMessage = typeof(DtDevice).FullName + " is null."; // HACK ←の部分をメッセージから抽出できれば... } // 例外発生チェック Assert.AreEqual(expected_ExceptionType, exceptionName); Assert.AreEqual(expected_ExceptionMessage, exceptionMessage); // 後処理 RepositoryTestHelper.ExecDeleteSql(in_DeleteNewDataSqlPath); }
public void ReadDtDeviceOnlineGatewayTest( string no, string in_InsertNewDataSqlPath, string in_DeleteNewDataSqlPath, string expected_DataJsonPath, string expected_ExceptionType, string expected_ExceptionMessage, string remarks) { DtDeliveryGroup readDeliveryGroup = new DtDeliveryGroup() { Sid = 0 }; // 初期データ挿入 if (RepositoryTestHelper.ExecInsertSql(in_InsertNewDataSqlPath)) { // 配信グループを取得する readDeliveryGroup = _deliveryGroupRepository.ReadDtDeliveryGroup(1); Assert.IsNotNull(readDeliveryGroup); } string exceptionName = ""; string exceptionMessage = ""; try { if (expected_ExceptionType == typeof(ArgumentNullException).FullName) { readDeliveryGroup = null; } // データを取得する(配信結果付き) var readModel = _deviceRepository.ReadDtDeviceOnlineGateway(readDeliveryGroup); if (readModel.Count() != 0) { // 比較に使用しないパラメータはnull or 固定値にする readModel.ToList()[0].MtConnectStatus.CreateDatetime = DateTime.Parse("2020/4/1 0:00:00"); } // データのjson化 string readJson = Utility.ObjectExtensions.ToStringJson(readModel); string expectJson = null; if (File.Exists(expected_DataJsonPath)) { expectJson = File.ReadAllText(expected_DataJsonPath); } // データの比較 Assert.AreEqual(expectJson, readJson); } catch (ArgumentNullException e) { exceptionName = e.GetType().FullName; exceptionMessage = typeof(DtDevice).FullName + " is null."; // HACK ←の部分をメッセージから抽出できれば... } // 例外発生チェック Assert.AreEqual(expected_ExceptionType, exceptionName); Assert.AreEqual(expected_ExceptionMessage, exceptionMessage); // 後処理 RepositoryTestHelper.ExecDeleteSql(in_DeleteNewDataSqlPath); }
/// <summary> /// 配信ファイルを更新する /// </summary> /// <param name="utilParam">配信ファイルパラメータ</param> /// <returns>DB更新したパラメータ(Result付き)</returns> public Result <DtDeliveryGroup> Update(DtDeliveryGroup utilParam) { throw new Exception(); }
/// <summary> /// 配信グループを削除する /// </summary> /// <param name="sid">削除する配信グループのSID</param> /// <param name="rowVersion">削除する配信グループのRowVersion</param> /// <returns>DB削除したパラメータ(Result付き)</returns> public Result <DtDeliveryGroup> Delete(long sid, byte[] rowVersion) { Result <DtDeliveryGroup> result = null; try { _logger.Enter($"{nameof(sid)}: {sid} {nameof(rowVersion)}: {rowVersion}"); // DBから指定SIDのデータ削除を依頼する DtDeliveryGroup model = _dtDeliveryGroupRepository.DeleteDtDeliveryGroup(sid, rowVersion); if (model == null) { _logger.Error(nameof(Resources.CO_API_DGD_005)); result = new Result <DtDeliveryGroup>(ResultCode.NotFound, Resources.CO_API_DGD_005, new DtDeliveryGroup() { Sid = sid, RowVersion = rowVersion }); } else { _logger.Info(nameof(Resources.CO_API_DGD_007)); result = new Result <DtDeliveryGroup>(ResultCode.Succeed, Resources.CO_API_DGD_007, model); } return(result); } catch (RmsParameterException e) { _logger.Error(e, nameof(Resources.CO_API_DGD_002), new object[] { e.Message }); result = new Result <DtDeliveryGroup>(ResultCode.ParameterError, string.Format(Resources.CO_API_DGD_002, e.Message), new DtDeliveryGroup() { Sid = sid, RowVersion = rowVersion }); return(result); } catch (RmsCannotChangeDeliveredFileException e) { _logger.Error(e, nameof(Resources.CO_API_DGD_003)); result = new Result <DtDeliveryGroup>(ResultCode.DoStartedDelivery, Resources.CO_API_DGD_003, new DtDeliveryGroup() { Sid = sid, RowVersion = rowVersion }); return(result); } catch (RmsConflictException e) { _logger.Error(e, nameof(Resources.CO_API_DGD_004)); result = new Result <DtDeliveryGroup>(ResultCode.Conflict, Resources.CO_API_DGD_004, new DtDeliveryGroup() { Sid = sid, RowVersion = rowVersion }); return(result); } catch (Exception e) { _logger.Error(e, nameof(Resources.CO_API_DGD_006)); result = new Result <DtDeliveryGroup>(ResultCode.ServerEerror, Resources.CO_API_DGD_006, new DtDeliveryGroup() { Sid = sid, RowVersion = rowVersion }); return(result); } finally { _logger.LeaveJson("Result Param: {0}", result); } }
/// <summary> /// 引数指定グループ内の配信結果内で、ゲートウェイ機器SIDをもつデータの適用結果ステータスをmessagesentにして作成する /// </summary> /// <remarks>配信グループデータは参照のみ行い、メンバを変更しない</remarks> /// <param name="inData">配信グループデータ</param> /// <param name="gatewaySid">ゲートウェイ機器SID</param> /// <returns>追加した適用結果データ群</returns> public IEnumerable <DtInstallResult> CreateDtInstallResultStatusSent(DtDeliveryGroup inData, long gatewaySid) { Assert.IfNull(inData); Assert.IfNull(inData.DtDeliveryResult); IEnumerable <DtInstallResult> models = new List <DtInstallResult>(); try { _logger.EnterJson("{0}", inData); // 現在時刻はここで記録 DateTime nowTime = _timePrivder.UtcNow; // 指定したゲートウェイ機器SIDをもつ配信結果を抽出する var results = inData.DtDeliveryResult.Where(x => x.GwDeviceSid == gatewaySid); if (!results.Any()) { // 空データを返却 return(models); } _dbPolly.Execute(() => { using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings)) { List <DBAccessor.Models.DtInstallResult> dbModels = new List <DBAccessor.Models.DtInstallResult>(); // 「送信済」の適用結果ステータスSIDを取得する var sentData = db.MtInstallResultStatus.Where(x => x.Code.Equals(InstallResultStatus.MessageSent)).FirstOrDefault(); if (sentData == null) { // 値を設定せずに返却 return; } // 各配信結果SID・端末SIDをもつ適用結果データを作成する foreach (var result in results) { var installResult = new DBAccessor.Models.DtInstallResult() { DeviceSid = result.DeviceSid, DeliveryResultSid = result.Sid, InstallResultStatusSid = sentData.Sid, CollectDatetime = nowTime }; var dbData = db.DtInstallResult.Add(installResult).Entity; dbModels.Add(dbData); } db.SaveChanges(_timePrivder); models = dbModels.Select(x => x.ToModel()); } }); return(models); } catch (ValidationException e) { throw new RmsParameterException(e.ValidationResult.ErrorMessage, e); } catch (Exception e) { throw new RmsException("DT_INSTALL_RESULTテーブルへのInsertに失敗しました。", e); } finally { _logger.LeaveJson("{0}", models); } }
public void UpdateDtDeliveryGroupIfDeliveryNotStartTest( string no, string in_InsertNewDataSqlPath, string in_DeleteNewDataSqlPath, string expected_DataJsonPath, string expected_ExceptionType, string expected_ExceptionMessage, string remarks) { DtDeliveryGroup changedModel = new DtDeliveryGroup() { Sid = 0 }; bool canDelete = false; // 初期データ挿入 if (RepositoryTestHelper.ExecInsertSql(in_InsertNewDataSqlPath)) { canDelete = true; // RowVersion取得のため読み出す var readModel = _deliveryGroupRepository.ReadDtDeliveryGroup(1); Assert.IsNotNull(readModel); // データを更新する(SIDは変更すると動作しないので変更しない) changedModel.Sid = readModel.Sid; changedModel.DeliveryGroupStatusSid = 999; changedModel.MtDeliveryGroupStatus = null; changedModel.DeliveryFileSid = 999; changedModel.Name = RepositoryTestHelper.CreateSpecifiedNumberString(100); changedModel.StartDatetime = DateTime.Parse("2020/4/2 0:00:00"); changedModel.DownloadDelayTime = 10; changedModel.CreateDatetime = DateTime.UtcNow; if (expected_ExceptionType.Equals(typeof(RmsParameterException).FullName)) { // 異常値を設定する changedModel.Name = RepositoryTestHelper.CreateSpecifiedNumberString(101); } } string exceptionName = ""; string exceptionMessage = ""; try { // データを更新する var updatedModel = _deliveryGroupRepository.UpdateDtDeliveryGroupIfDeliveryNotStart(changedModel); Assert.IsTrue((updatedModel != null) == canDelete); if (updatedModel != null) { // 比較に使用しないパラメータはnull or 固定値にする updatedModel.UpdateDatetime = DateTime.Parse("2020/4/1 0:00:00"); updatedModel.RowVersion = null; updatedModel.MtDeliveryGroupStatus.CreateDatetime = DateTime.Parse("2020/4/1 0:00:00"); } // データのjson化 string readJson = Utility.ObjectExtensions.ToStringJson(updatedModel); string expectJson = null; if (File.Exists(expected_DataJsonPath)) { expectJson = File.ReadAllText(expected_DataJsonPath); } // データの比較 Assert.AreEqual(expectJson, readJson); // TODO DBデータ内容をチェックする } catch (RmsCannotChangeDeliveredFileException e) { exceptionName = e.GetType().FullName; exceptionMessage = e.Message; } catch (RmsParameterException e) { exceptionName = e.GetType().FullName; exceptionMessage = e.Message; } // 例外発生チェック Assert.AreEqual(expected_ExceptionType, exceptionName); Assert.AreEqual(expected_ExceptionMessage, exceptionMessage); // 後処理 RepositoryTestHelper.ExecDeleteSql(in_DeleteNewDataSqlPath); }
/// <summary> /// データの削除 /// </summary> /// <param name="sid">削除するデータのSID</param> /// <param name="rowVersion">rowversion</param> /// <returns>削除したデータ</returns> public DtDeliveryGroup DeleteDtDeliveryGroup(long sid, byte[] rowVersion) { DtDeliveryGroup model = null; try { _logger.Enter($"{nameof(sid)}={sid} {nameof(rowVersion)}={rowVersion}"); DBAccessor.Models.DtDeliveryGroup entity = new DBAccessor.Models.DtDeliveryGroup() { Sid = sid, RowVersion = rowVersion }; _dbPolly.Execute(() => { using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings)) { // 指定した配信ステータスSIDを検索し、未配信状態であるかチェックする // 備考:該当する配信グループが0個(Whereの結果が空のリスト)の場合、Allは必ずtrueを返す // そのためすべての配信ステータスが未配信状態であると見なされ、isNotStart=trueとなることに注意 var isNotStart = db.DtDeliveryGroup .Where(x => x.Sid == sid) .Include(x => x.DeliveryGroupStatusS) .All(x => x.DeliveryGroupStatusS.Code.Equals(Utility.Const.DeliveryGroupStatus.NotStarted)); if (!isNotStart) { throw new RmsCannotChangeDeliveredFileException(string.Format("配信前状態ではないDT_DELIVERY_GROUPテーブルのレコードをDeleteしようとしました。(DT_DELIVERY_GROUP.SID = {0})", sid)); } // SIDが一致するレコードが存在しない場合はDeleteを実行しない // (存在しないSIDに対してDeleteを実行してしまうと、DbUpdateConcurrencyExceptionが発生してしまい、 // RowVersion競合とNot Foundとの区別ができないため) if (db.DtDeliveryGroup.Any(x => x.Sid == sid)) { db.DtDeliveryGroup.Attach(entity); db.DtDeliveryGroup.Remove(entity); if (db.SaveChanges() > 0) { model = entity.ToModel(); } } } }); return(model); } catch (DbUpdateConcurrencyException e) { // RowVersion衝突が起きた throw new RmsConflictException("DT_DELIVERY_GROUPテーブルのDeleteで競合が発生しました。", e); } catch (RmsException) { throw; } catch (Exception e) { throw new RmsException("DT_DELIVERY_GROUPテーブルのDeleteに失敗しました。", e); } finally { _logger.LeaveJson("{0}", model); } }