Exemple #1
0
        public static CompileResult ValidateJsonConfig(ValidateConfigRequestModel requestModel)
        {
            try
            {
                JToken jsonToValidate = JToken.Parse(requestModel.File.Content);
#if DEBUG
                var Validator = ProjectConfigValidator.GetInstance(new Uri("https://s3.ap-south-1.amazonaws.com/kitsune-resources-dev/schema.json"));
#else
                var Validator = ProjectConfigValidator.GetInstance(new Uri("https://s3.ap-south-1.amazonaws.com/kitsune-resources/schema.json"));
#endif
                var result = Validator.ValidateJson(jsonToValidate);
                if (result.IsError && result.Errors != null && result.Errors.Any())
                {
                    return(new CompileResult
                    {
                        Success = false,
                        ErrorMessages = result.Errors.Select(x => new CompilerError
                        {
                            LineNumber = x.LineNumber,
                            LinePosition = x.LinePosition,
                            Message = x.ToString()
                        }).ToList()
                    });
                }
            }
            catch (JsonReaderException ex)
            {
                return(new CompileResult
                {
                    Success = false,
                    ErrorMessages = new List <CompilerError>
                    {
                        new CompilerError
                        {
                            LineNumber = ex.LineNumber,
                            LinePosition = ex.LinePosition,
                            Message = ex.Message
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(new CompileResult {
                Success = true, CompiledString = requestModel?.File?.Content
            });
        }
Exemple #2
0
 public static ProjectConfigValidator GetInstance(Uri SchemaUri)
 {
     if (JsonValidatorInsatnce == null)
     {
         try
         {
             JsonValidatorInsatnce = new ProjectConfigValidator(SchemaUri);
             if (JsonValidatorInsatnce == null)
             {
                 throw new Exception("Error Generating ProjectConfigValidatorObject");
             }
         }
         catch (Exception ex)
         {
             throw new Exception("Error Creating Schema Object of Project Configuration", ex);
         }
     }
     return(JsonValidatorInsatnce);
 }
Exemple #3
0
 public static ProjectConfigValidator GetInstance(string schema)
 {
     if (String.IsNullOrEmpty(schema))
     {
         throw new ArgumentNullException(nameof(schema));
     }
     if (JsonValidatorInsatnce == null)
     {
         try
         {
             JsonValidatorInsatnce = new ProjectConfigValidator(schema);
             if (JsonValidatorInsatnce == null)
             {
                 throw new Exception("Error Generating ProjectConfigValidatorObject");
             }
         }
         catch (Exception ex)
         {
             new Exception("Error Creating Schema Object of Project Configuration", ex);
         }
     }
     return(JsonValidatorInsatnce);
 }