public IActionResult PutDevice( [RequestBodyType(typeof(DeviceUpdateRequestDto), "デバイス更新リクエスト")] [HttpTrigger(AuthorizationLevel.Function, "put", Route = "devices/{deviceId}")] DeviceUpdateRequestDto request, long deviceId, ILogger log) { log.EnterJson("DeviceUpdateRequestDto: {0}", request); ActionResult response = null; try { // リクエストパラメータチェック string message = string.Empty; if (RequestValidator.IsBadRequestParameter(request, out message)) { log.Error(nameof(Resources.CO_API_DVU_002), new object[] { message }); return(new BadRequestObjectResult(string.Empty)); } // DTOを設置設定インスタンスに変換する var baseConfig = request.ConvertDtoToInstallBaseConfig(); // DTOをUtility型に変換する(SIDも含める) var utilParam = request.ConvertDtoToUtility(); utilParam.Sid = deviceId; // 更新実行 var resultParam = _deviceService.Update(utilParam, baseConfig); // Resultから返却ステータスを作成 return(SqlResultConverter.ConvertToActionResult( resultParam.ResultCode, resultParam.Message, resultParam.Entity.ConvertUtilityToResponseDto())); } catch (Exception e) { log.Error(e, nameof(Resources.CO_API_DVU_001)); response = new StatusCodeResult(StatusCodes.Status500InternalServerError); } finally { log.Leave($"Response Status: {response}"); } return(response); }
/// <summary> /// 更新リクエストのDtoクラスパラメータをUtilityのパラメータに変換する /// </summary> /// <param name="dto">Dtoクラスパラメータ</param> /// <returns>Utilityパラメータ</returns> public static DtDevice ConvertDtoToUtility(this DeviceUpdateRequestDto dto) { return(dto == null ? null : new DtDevice() { //// Sid EquipmentModelSid = dto.Device.Model.ModelSid, InstallTypeSid = dto.Device.InstallType.InstallTypeSid.Value, //// ConnectStatusSid //// EdgeId //// EquipmentUid //// RemoteConnectUid //// RmsSoftVersion //// ConnectStartDatetime //// ConnectUpdateDatetime //// CreateDatetime //// UpdateDatetime }); }
/// <summary> /// 機器更新DTOを設置設定インスタンスに変換する(エッジID・機器UIDを除く) /// </summary> /// <param name="dto">機器更新DTO</param> /// <returns>設置設定インスタンス(エッジID・機器UIDを除く)</returns> public static InstallBaseConfig ConvertDtoToInstallBaseConfig(this DeviceUpdateRequestDto dto) { if (dto == null) { return(null); } // 自身の機器情報 InstallBaseDeviceConfig ownConfig = new InstallBaseDeviceConfig() { ////EdgeId InstallType = dto.Device.InstallType.InstallTypeCode, ////DeviceUid EquipmentName = dto.Device.EquipmentName, EquipmentSerialNumber = dto.Device.EquipmentSerialNumber, InstallFeatures = dto.Device.InstallFeatures, IpAddress = dto.Device.IpAddress, HostName = dto.Device.HostName, Model = dto.Device.Model.ModelCode, NetworkRoute = dto.Device.NetworkRoute }; // 親機の機器情報 InstallBaseDeviceConfig parentConfig = dto.Parent == null ? null : new InstallBaseDeviceConfig() { EdgeId = dto.Parent.EdgeId?.ToString(), InstallType = dto.Parent.InstallType?.InstallTypeCode, EquipmentUid = dto.Parent.EquipmentUid, EquipmentName = dto.Parent.EquipmentName, EquipmentSerialNumber = dto.Parent.EquipmentSerialNumber, InstallFeatures = dto.Parent.InstallFeatures, IpAddress = dto.Parent.IpAddress, HostName = dto.Parent.HostName, Model = dto.Parent.Model?.ModelCode, NetworkRoute = dto.Parent.NetworkRoute }; // 子機の機器情報 List <InstallBaseDeviceConfig> childrenConfg = dto.Children == null ? null : dto.Children.Select( x => new InstallBaseDeviceConfig() { EdgeId = x.EdgeId?.ToString(), InstallType = x.InstallType?.InstallTypeCode, EquipmentUid = x.EquipmentUid, EquipmentName = x.EquipmentName, EquipmentSerialNumber = x.EquipmentSerialNumber, InstallFeatures = x.InstallFeatures, IpAddress = x.IpAddress, HostName = x.HostName, Model = x.Model?.ModelCode, NetworkRoute = x.NetworkRoute }) .ToList(); // 設置設定ファイル情報にまとめて返却 return(new InstallBaseConfig() { OwnConfig = ownConfig, ParentConfig = parentConfig, ChildrenConfig = childrenConfg }); }
public void PutDeviceTest( string no, string in_InsertNewDataSqlPath, string in_DeleteNewDataSqlPath, string in_InputJsonDataPath, string in_InitialBlobFilePath, string in_DeliveringBlobContainerNameInstallbase, string in_DeliveringBlobInstallbaseFilePath, string in_SidFormat, string in_InvalidDbConnectionString, string in_InvalidBlobConnectionString, string in_ServiceException, string expected_DataJsonPath, string expected_LogMessagesPath, string expected_UploadedDeliveringBlobPath, string expected_DtDevice_TableDataPath, string remarks) { string configContents; try { bool didUploadInitialBlob = CommonPreset( DateTime.Parse("2020/04/30 09:00:00.0000000"), in_InvalidDbConnectionString, in_InvalidBlobConnectionString, in_ServiceException, in_DeliveringBlobContainerNameInstallbase, in_DeliveringBlobInstallbaseFilePath, in_InsertNewDataSqlPath, in_InitialBlobFilePath, out configContents); // 投入JSONをDTOに変換する string inputDtoJson = (!string.IsNullOrEmpty(in_InputJsonDataPath) && File.Exists(in_InputJsonDataPath)) ? File.ReadAllText(in_InputJsonDataPath) : ""; // SID, RowVersionの取得 DataTable inputDataTable = DbTestHelper.SelectTable("SELECT SID, EDGE_ID, EQUIPMENT_UID FROM core.DT_DEVICE"); long sid = 1; string edgeId = string.Empty; string equipmentUid = string.Empty; if (inputDataTable.Rows.Count > 0) { sid = (long)inputDataTable.Rows[0].ItemArray[0]; edgeId = ((Guid)inputDataTable.Rows[0].ItemArray[1]).ToString(); equipmentUid = (string)inputDataTable.Rows[0].ItemArray[2]; } // 投入するSIDを設定 long inputSid = long.Parse(string.Format(in_SidFormat, sid)); // DTO変換できない場合は初期値とする(Azure Functionsと同様の挙動) DeviceUpdateRequestDto inputDto; try { inputDto = JsonConvert.DeserializeObject <DeviceUpdateRequestDto>(inputDtoJson); } catch (Exception) { inputDto = new DeviceUpdateRequestDto(); } // アップロード予定の場所にあるBlobを削除する TryFormatDeliveringBlobInstallbaseFilePath(_appSettings.DeliveringBlobInstallbaseFilePath, equipmentUid, out string filePath); if (didUploadInitialBlob && (!_appSettings.DeliveringBlobContainerNameInstallbase.Equals(_initialBlobContainerName) || !filePath.Equals(_initialBlobFilePath))) { // 事前Blobがアップロードされている場合は違うパスの時のみ削除する TryDeleteBlob(in_DeliveringBlobContainerNameInstallbase, filePath); } // ログ格納用ロガーの用意 var actualLogs = new List <TestLog>(); var logger = new TestLogger <DevicesController>(actualLogs); // WebApi実行 var putResult = _controller.PutDevice(inputDto, inputSid, logger); // レスポンスデータをチェックする CheckResponseDataEquals(putResult, expected_DataJsonPath, edgeId); // ログの出力をチェックする CheckLogMessagesContains(expected_LogMessagesPath, actualLogs, edgeId); // DB内容をチェックする CheckDbDataEquals(expected_DtDevice_TableDataPath); // アップロードしたBlobの内容をチェックし、削除する CheckBlobsEqualsAndCleanBlobs( didUploadInitialBlob, edgeId, configContents, _appSettings.DeliveringBlobContainerNameInstallbase, filePath, expected_UploadedDeliveringBlobPath); // 後処理 DbTestHelper.ExecSqlFromFilePath(in_DeleteNewDataSqlPath); } catch { throw; } }