private void btnSubmit_Click(object sender, EventArgs e) { try { if (_isConfigured) { txtResult.Text = ""; string transactionId = txtTransactionId.Text; string lockerId = txtLockerId.Text; string token = txtJwtToken.Text; string jwtSecret = txtJwtSecret.Text; string[] validCompartmentIds = txtCompartmentId.Text.Split(','); bool flag = jwtEnable.Checked; var compartment = new Compartment(transactionId, lockerId, validCompartmentIds, flag, jwtSecret, token); if (radioOpenCompartment.Checked) { var result = _lockerManager.OpenCompartment(compartment); txtResult.Text = JsonConvert.SerializeObject(result, Formatting.Indented); } else if (radioCompartmentStatus.Checked) { var result = _lockerManager.CompartmentStatus(compartment); txtResult.Text = JsonConvert.SerializeObject(result, Formatting.Indented); } else if (radioCaptureImage.Checked) { var requestCapture = new Capture(transactionId, lockerId, flag, jwtSecret, token); var result = _lockerManager.CaptureImage(requestCapture); txtResult.Text = JsonConvert.SerializeObject(result, Formatting.Indented); } } } catch (System.IO.FileNotFoundException) { txtResult.Text = "Please ensure valid configuration file path."; } catch (ArgumentException) { txtResult.Text = "Please ensure valid configuration file path."; } catch (System.IO.DirectoryNotFoundException) { txtResult.Text = "Please ensure valid configuration file path."; } catch (Exception ex) { txtResult.Text = ex.ToString(); } }
/// <summary> /// Gets the compartment status with Json web token credentials. /// Json web token credentials contains enable or disable, if enable then need to provide jwt secret and token. /// </summary> /// <returns> /// List of compartment status with object detection and LED status based requested compartment id's. /// </returns> public CompartmentStatusDto CompartmentStatus(Compartment model) { var compartmentStatusDto = new CompartmentStatusDto(); Log.Information("[HCM][Compartment Status][Req]" + "[" + JsonSerializer.Serialize(model) + "]"); try { if (!PortsHealthCheck.IsLockPortAvailable && !PortsHealthCheck.IsDetectionPortAvailable) { return(CompartmentStatusMapper.ToError(new CompartmentStatusDto { 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.CompartmentStatus, model.LockerId, model.TransactionId, model.CompartmentIds, null); if (statusCode != StatusCode.Status200OK) { return(CompartmentStatusMapper.ToError(new CompartmentStatusDto { StatusCode = statusCode, Error = errorResult })); } var result = CompartmentManager.CompartmentStatus(model, LockerConfiguration); compartmentStatusDto = CompartmentStatusMapper.ToObject(result); Log.Information("[HCM][Compartment Status][Res]" + "[" + JsonSerializer.Serialize(result) + "]"); } catch (Exception ex) { Log.Error("[HCM][Compartment Status]" + "[" + ex + "]"); return(CompartmentStatusMapper.ToError(new CompartmentStatusDto { StatusCode = StatusCode.Status500InternalServerError, Error = new Common.Exceptions.ApplicationException(ApplicationErrorCodes.InternalServerError, ex.Message) })); } return(compartmentStatusDto); }