コード例 #1
0
 public static LockerDto ToError(this LockerDto model)
 {
     return(new LockerDto()
     {
         StatusCode = model.StatusCode,
         Error = model.Error
     });
 }
コード例 #2
0
        /// <summary>
        /// Gets the open compartment parameters with Json web token credentials and MongoDB database credentials.
        /// Json web token credentials contains enable or disable, if enable then need to provide jwt secret and token.
        /// </summary>
        /// <returns>
        ///  List of compartment open status with object detection, LED status by requested compartment id's.
        /// </returns>
        public LockerDto OpenCompartment(Compartment model)
        {
            var lockerDto = new LockerDto();

            Log.Information("[HCM][Open Compartment][Req]" + "[" + JsonSerializer.Serialize(model) + "]");

            try {
                if (!PortsHealthCheck.IsLockPortAvailable && !PortsHealthCheck.IsDetectionPortAvailable)
                {
                    return(OpenCompartmentMapper.ToError(new LockerDto {
                        StatusCode = StatusCode.Status503ServiceUnavailable, Error = new Common.Exceptions.ApplicationException(ApplicationErrorCodes.BrokenComPort, ApplicationErrorCodes.GetMessage(ApplicationErrorCodes.BrokenComPort))
                    }));
                }

                var(statusCode, errorResult) = LockerManagementValidator.PayloadValidator(LockerConfiguration, model.JwtCredentials.IsEnabled, model.JwtCredentials.Secret, model.JwtCredentials.Token, PayloadTypes.OpenCompartment, model.LockerId, model.TransactionId, model.CompartmentIds, null);
                if (statusCode != StatusCode.Status200OK)
                {
                    return(OpenCompartmentMapper.ToError(new LockerDto {
                        StatusCode = statusCode, Error = errorResult
                    }));
                }

                var result = CompartmentManager.CompartmentOpen(model, LockerConfiguration);
                lockerDto = OpenCompartmentMapper.ToObject(result);
                Log.Information("[HCM][Open Compartment][Res]" + "[" + JsonSerializer.Serialize(result) + "]");
            }
            catch (Exception ex)
            {
                Log.Error("[HCM][Open Compartment]" + "[" + ex + "]");
                return(OpenCompartmentMapper.ToError(new LockerDto {
                    StatusCode = StatusCode.Status500InternalServerError, Error = new Common.Exceptions.ApplicationException(ApplicationErrorCodes.InternalServerError, ex.Message)
                }));
            }

            return(lockerDto);
        }