Esempio n. 1
0
        public IActionResult PostDevice(
            [RequestBodyType(typeof(DeviceAddRequestDto), "デバイス作成リクエスト")]
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "devices")]
            DeviceAddRequestDto request,
            ILogger log)
        {
            log.EnterJson("DeviceAddRequestDto: {0}", request);
            ActionResult response = null;

            try
            {
                // リクエストパラメータチェック
                string message = string.Empty;
                if (RequestValidator.IsBadRequestParameter(request, out message))
                {
                    log.Error(nameof(Resources.CO_API_DVC_002), new object[] { message });
                    return(new BadRequestObjectResult(string.Empty));
                }

                // DTOを設置設定インスタンスに変換する
                var baseConfig = request.ConvertDtoToInstallBaseConfig();

                // DTOをUtility型に変換する
                var utilParam = request.ConvertDtoToUtility();

                // 作成実行
                var resultParam = _deviceService.Create(utilParam, baseConfig);

                // Resultから返却ステータスを作成
                return(SqlResultConverter.ConvertToActionResult(
                           resultParam.ResultCode,
                           resultParam.Message,
                           resultParam.Entity.ConvertUtilityToResponseDto()));
            }
            catch (Exception e)
            {
                log.Error(e, nameof(Resources.CO_API_DVC_001));
                response = new StatusCodeResult(StatusCodes.Status500InternalServerError);
            }
            finally
            {
                log.Leave($"Response Status: {response}");
            }

            return(response);
        }
Esempio n. 2
0
 /// <summary>
 /// 追加リクエストのDtoクラスパラメータをUtilityのパラメータに変換する
 /// </summary>
 /// <param name="dto">Dtoクラスパラメータ</param>
 /// <returns>Utilityパラメータ</returns>
 public static DtDevice ConvertDtoToUtility(this DeviceAddRequestDto dto)
 {
     return(dto == null ?
            null :
            new DtDevice()
     {
         //// Sid
         EquipmentModelSid = dto.Device.Model.ModelSid,
         InstallTypeSid = dto.Device.InstallType.InstallTypeSid.Value,
         //// ConnectStatusSid
         //// EdgeId
         EquipmentUid = dto.Device.EquipmentUid,
         //// RemoteConnectUid
         //// RmsSoftVersion
         //// ConnectStartDatetime
         //// ConnectUpdateDatetime
         //// CreateDatetime
         //// UpdateDatetime
     });
 }
Esempio n. 3
0
        /// <summary>
        /// 機器登録DTOを設置設定インスタンスに変換する(エッジIDを除く)
        /// </summary>
        /// <param name="dto">機器登録DTO</param>
        /// <returns>設置設定インスタンス(エッジIDを除く)</returns>
        public static InstallBaseConfig ConvertDtoToInstallBaseConfig(this DeviceAddRequestDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            // 自身の機器情報
            InstallBaseDeviceConfig ownConfig = new InstallBaseDeviceConfig()
            {
                ////EdgeId
                InstallType           = dto.Device.InstallType.InstallTypeCode,
                EquipmentUid          = dto.Device.EquipmentUid,
                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
            });
        }
Esempio n. 4
0
        public void PostDeviceTest(
            string no,
            string in_InsertNewDataSqlPath,
            string in_DeleteNewDataSqlPath,
            string in_InputJsonDataPath,
            string in_InitialBlobFilePath,
            string in_DeliveringBlobContainerNameInstallbase,
            string in_DeliveringBlobInstallbaseFilePath,
            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/01 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) :
                                      "";

                // DTO変換できない場合は初期値とする(Azure Functionsと同様の挙動)
                DeviceAddRequestDto inputDto;
                try
                {
                    inputDto = JsonConvert.DeserializeObject <DeviceAddRequestDto>(inputDtoJson);
                }
                catch (Exception)
                {
                    inputDto = new DeviceAddRequestDto();
                }

                // アップロード予定の場所にあるBlobを削除する
                TryFormatDeliveringBlobInstallbaseFilePath(_appSettings.DeliveringBlobInstallbaseFilePath, inputDto.Device?.EquipmentUid, out string filePath);
                TryDeleteBlob(in_DeliveringBlobContainerNameInstallbase, filePath);

                // ログ格納用ロガーの用意
                var actualLogs = new List <TestLog>();
                var logger     = new TestLogger <DevicesController>(actualLogs);

                // WebApi実行
                string edgeId     = string.Empty;
                var    postResult = _controller.PostDevice(inputDto, logger);
                if (postResult is OkObjectResult)
                {
                    // 結果が流動的になる値は比較できないので固定値を入れる
                    var okDto = ((postResult as OkObjectResult).Value as DeviceResponseDto);
                    Assert.IsNotNull(okDto);
                    edgeId = okDto.EdgeId.ToString();
                }

                // レスポンスデータをチェックする
                CheckResponseDataEquals(postResult, 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;
            }
        }