Exemple #1
0
        public ActionResult ValidateModule([FromForm] ValidationRequestModel fd)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(InvalidModelErrors));
            }

            if (string.IsNullOrWhiteSpace(fd.ModuleName))
            {
                _response.MessageBody = "Module name must be provided.";
                return(BadRequest(_response));
            }

            try
            {
                var validationStates = _licenseManager.ValidateModule(fd.ModuleName, fd.Email, fd.ClientGuid);

                if (validationStates.Any())
                {
                    _response.ContentBody = validationStates;
                    return(StatusCode((int)HttpStatusCode.PaymentRequired, _response));
                }

                // indicating the valid license
                return(Ok(new { ContentBody = true }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
        // POST api/validation
        public HttpResponseMessage Post(ValidationRequestModel model)
        {
            RepositoryType repositoryType = null;

            try
            {
                Guard.AssertNotNull(model, "The request is empty.");
                Guard.AssertNotNullOrEmpty(model.Url, "A valid URL was not supplied");
                Guard.AssertNotNullOrEmpty(model.RepositoryType, "A valid online repositoryValue was not supplied");
                repositoryType = RepositoryType.SelectRepositoryTypeByValue(model.RepositoryType);
                Guard.AssertNotNull(repositoryType, "Online repositoryValue could not be found.");
            }
            catch (Exception e) {
                return(Request.CreateResponse(HttpStatusCode.OK, new ValidationResultModel {
                    IsValid = false, Message = e.Message
                }));
            }
            var result = ValidationHelper.ValidateRepositoryUrl(model.Url, repositoryType);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemple #3
0
        public ActionResult Validate([FromForm] ValidationRequestModel fd)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(InvalidModelErrors));
            }

            if (fd.LicenseFile is null && string.IsNullOrWhiteSpace(fd.LicenseCode))
            {
                _response.MessageBody = "Either license code or a license file is missing.";
                return(BadRequest(_response));
            }

            try
            {
                // extract license node for either license file or the license code.
                var licenseInfoXmlNode = string.IsNullOrWhiteSpace(fd.LicenseCode)
                    ? _licenseManager.ExtractLicenseInfo(fd.LicenseFile, fd.Email, fd.ClientGuid)
                    : _licenseManager.ExtractLicenseInfo(fd.LicenseCode, fd.Email, fd.ClientGuid);

                var validationStates = _licenseManager.Validate(licenseInfoXmlNode, fd.Email, fd.ClientGuid);

                if (validationStates.Any())
                {
                    return(StatusCode((int)HttpStatusCode.PaymentRequired, validationStates));
                }

                // indicating the valid license
                return(Ok(new { ContentBody = true }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }