public override ValidationResult Validate()
        {
            string message = _validationObject switch
            {
                GetDataTransferMethodModel model => ValidateGetDataTransferMethodModel(model),
                EndDataTransferModel model => ValidateEndDataTransferModel(model),
                HttpGetToJobNodeModel model => ValidateHttpGetToJobNodeModel(model),
                HttpPostToJobNodeModel model => ValidateHttpPostToJobNodeModel(model),
                _ => string.Empty
            };

            return(new ValidationResult(string.IsNullOrEmpty(message), message));
        }
示例#2
0
        public async Task <IActionResult> HttpPostToJobNodeAsync(HttpPostToJobNodeModel model)
        {
            try
            {
                _logger.LogDebug($"Endpoint: \"DataTransfer\" Method: \"HttpPostToJobNode\" Parameters: \"{model}\"");
                ValidationResult validationResult = new DataTransferValidator(model).Validate();
                if (!validationResult.IsValid)
                {
                    ExceptionHandler.ThrowProperExternalException(new InputValidationException(validationResult.Message));
                }

                return(Ok(await _service.HttpPostToJobNodeAsync(model.HttpRequest, model.HttpHeaders, model.HttpPayload, model.SubmittedJobInfoId, model.NodeIPAddress, model.NodePort, model.SessionCode)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        private string ValidateHttpPostToJobNodeModel(HttpPostToJobNodeModel model)
        {
            if (string.IsNullOrEmpty(model.HttpRequest))
            {
                _messageBuilder.AppendLine("HttpRequest must be set");
            }

            if (model.HttpHeaders.Any(httpHeader => string.IsNullOrEmpty(httpHeader.Name) || string.IsNullOrEmpty(httpHeader.Value)))
            {
                _messageBuilder.AppendLine("HttpHeader cannot be empty");
            }

            if (string.IsNullOrEmpty(model.HttpPayload))
            {
                _messageBuilder.AppendLine("HttpPayload must be set");
            }

            ValidatePort(model.NodePort);
            ValidateId(model.SubmittedJobInfoId, nameof(model.SubmittedJobInfoId));

            if (string.IsNullOrEmpty(model.NodeIPAddress))
            {
                _messageBuilder.AppendLine("IpAddress must be set");
            }
            else if (!IsIpAddress(model.NodeIPAddress))
            {
                _messageBuilder.AppendLine("Ip address has unknown format. If using ipv6, please try to specify 'full address' without shortening.");
            }

            ValidationResult sessionCodeValidation = new SessionCodeValidator(model.SessionCode).Validate();

            if (!sessionCodeValidation.IsValid)
            {
                _messageBuilder.AppendLine(sessionCodeValidation.Message);
            }

            return(_messageBuilder.ToString());
        }