/// <summary> /// This needs to be called immediately before writing to json, /// but immediately after preprocessing and buffer setup, so the model can be correctly validated. /// </summary> /// <param name="model">The model to validate.</param> private void _ValidateBeforeWriting(SCHEMA2 model) { if (_NoCloneWatchdog) { return; } if (this.Validation == SharpGLTF.Validation.ValidationMode.Skip) { return; } var vcontext = new Validation.ValidationResult(model, this.Validation); model.ValidateReferences(vcontext.GetContext()); var ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { throw ex; } model.ValidateContent(vcontext.GetContext()); ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { throw ex; } }
public static System.ComponentModel.DataAnnotations.ValidationResult ConvertToDataAnnotationsValidationResult( this Validation.ValidationResult result) { var errorMessages = result.ErrorList.Aggregate((x, y) => $"{x}{Environment.NewLine}{y}"); return(new System.ComponentModel.DataAnnotations.ValidationResult( $"The following parameters have failed validation{Environment.NewLine}{errorMessages}", result.ErrorList)); }
private (SCHEMA2 Model, Validation.ValidationResult Validation) _Read(BYTES jsonUtf8Bytes) { Guard.NotNull(jsonUtf8Bytes, nameof(jsonUtf8Bytes)); var root = new SCHEMA2(); var vcontext = new Validation.ValidationResult(root, this.Validation); var reader = new Utf8JsonReader(jsonUtf8Bytes); if (!reader.Read()) { vcontext.AddError(new Validation.ModelException(root, "Json is empty")); return(null, vcontext); } try { root.Deserialize(ref reader); root.OnDeserializationCompleted(); } catch (JsonException rex) { vcontext.AddError(new Validation.SchemaException(root, rex)); return(null, vcontext); } // schema validation root.ValidateReferences(vcontext.GetContext()); var ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { return(null, vcontext); } // resolve external dependencies root._ResolveSatelliteDependencies(this); // full validation if (this.Validation != VALIDATIONMODE.Skip) { root.Validate(vcontext.GetContext()); ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { return(null, vcontext); } } return(root, vcontext); }
private Validation.ValidationResult Validate(DataQueryRequest request) { var validator = new Validation.Validator(); var validation = new Validation.ValidationResult(); validator.ValidateInput("format", request.format, typeof(string), validation); validator.ValidateInput("sdi", request.sdi, "allnumbers", validation); validator.ValidateInput("svr", request.svr, typeof(string), validation); validator.ValidateInput("t1", request.t1, typeof(DateTime), validation); validator.ValidateInput("t2", request.t2, typeof(DateTime), validation); validator.ValidateInput("tstp", request.tstp, new List <string> { "HR", "DY", "MN", "YR" }, validation); return(validation); }
public virtual A.Core.Validation.ValidationResult ValidateInsert(TInsert request, TEntity entity) { A.Core.Validation.ValidationResult result = new Validation.ValidationResult(); var context = new ValidationContext(request, serviceProvider: null, items: null); var validationResults = new List <ValidationResult>(); bool isValid = Validator.TryValidateObject(request, context, validationResults, true); if (!isValid) { validationResults.ForEach(x => { result.ResultList.Add(new A.Core.Validation.ValidationResultItem() { Key = x.MemberNames.First(), Description = x.ErrorMessage }); }); } return(result); }
private void ViewModelValidated(object sender, Validation.ValidationResult res) { IsValidated = true; var builder = new StringBuilder(); if (res != null) { foreach (var error in res.Errors.GroupBy(b => b).Select(b => b.First())) { builder.Append($"(Error) {error}"); builder.Append("\n"); } foreach (var warning in res.Warnings.GroupBy(b => b).Select(b => b.First())) { builder.Append($"(Warning) {warning}"); builder.Append("\n"); } Message = builder.Length > 0 ? builder.ToString(0, builder.Length - "\n".Length) : null; IsValid = res.IsValid; } ValidationResult = res; }
private (SCHEMA2 Model, Validation.ValidationResult Validation) _ReadGLB(Stream stream) { Guard.NotNull(stream, nameof(stream)); IReadOnlyDictionary <uint, byte[]> chunks; try { chunks = BinarySerialization.ReadBinaryFile(stream); } catch (System.IO.EndOfStreamException ex) { var vr = new Validation.ValidationResult(null, this.Validation); vr.SetError(new Validation.SchemaException(null, ex.Message)); return(null, vr); } catch (Validation.SchemaException ex) { var vr = new Validation.ValidationResult(null, this.Validation); vr.SetError(ex); return(null, vr); } var context = this; if (chunks.ContainsKey(BinarySerialization.CHUNKBIN)) { // clone self var binChunk = chunks[BinarySerialization.CHUNKBIN]; context = new ReadContext(context); context._BinaryChunk = binChunk; } var jsonChunk = chunks[BinarySerialization.CHUNKJSON]; return(context._Read(jsonChunk)); }
private (SCHEMA2 Model, Validation.ValidationResult Validation) _Read(ReadOnlyMemory <Byte> jsonUtf8Bytes) { var root = new SCHEMA2(); var vcontext = new Validation.ValidationResult(root, this.Validation); #if !SUPRESSTRYCATCH try { #endif if (jsonUtf8Bytes.IsEmpty) { throw new System.Text.Json.JsonException("JSon is empty."); } var reader = new Utf8JsonReader(jsonUtf8Bytes.Span); if (!reader.Read()) { vcontext.SetError(new Validation.SchemaException(root, "Json is empty")); return(null, vcontext); } root.Deserialize(ref reader); root.OnDeserializationCompleted(); // binary chunk check foreach (var b in root.LogicalBuffers) { b.OnValidateBinaryChunk(vcontext.GetContext(), this._BinaryChunk); } // schema validation if (this._CheckSupportedExtensions) { root._ValidateExtensions(vcontext.GetContext()); var ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { return(null, vcontext); } } // we must do a basic validation before resolving external dependencies if (true) { root.ValidateReferences(vcontext.GetContext()); var ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { return(null, vcontext); } } // resolve external dependencies root._ResolveSatelliteDependencies(this); // full validation if (this.Validation != VALIDATIONMODE.Skip) { root.ValidateContent(vcontext.GetContext()); var ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { return(null, vcontext); } } #if !SUPRESSTRYCATCH } catch (JsonException rex) { vcontext.SetError(new Validation.SchemaException(root, rex)); return(null, vcontext); } catch (System.FormatException fex) { vcontext.SetError(new Validation.ModelException(null, fex)); return(null, vcontext); } catch (ArgumentException aex) { vcontext.SetError(new Validation.ModelException(root, aex)); return(null, vcontext); } catch (Validation.ModelException mex) { vcontext.SetError(mex); return(null, vcontext); } #endif return(root, vcontext); }
private static (MODEL Model, Validation.ValidationResult Validation) _Read(TextReader textReader, ReadSettings settings) { Guard.NotNull(textReader, nameof(textReader)); Guard.NotNull(settings, nameof(settings)); using (var reader = new JsonTextReader(textReader)) { var root = new MODEL(); var vcontext = new Validation.ValidationResult(root); if (!reader.Read()) { vcontext.AddError(new Validation.ModelException(root, "Json is empty")); return(null, vcontext); } try { root.Deserialize(reader); } catch (JsonReaderException rex) { vcontext.AddError(new Validation.SchemaException(root, rex)); return(null, vcontext); } // schema validation root.ValidateReferences(vcontext.GetContext(root)); var ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { return(null, vcontext); } // resolve external references foreach (var buffer in root._buffers) { buffer._ResolveUri(settings.FileReader); } foreach (var image in root._images) { image._ResolveUri(settings.FileReader); } // full validation if (!settings.SkipValidation) { root.Validate(vcontext.GetContext(root)); ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { return(null, vcontext); } } return(root, vcontext); } }
private async Task ValidateDateOfChange(UpdateApprenticeshipStatusCommand command, Validation.ValidationResult validationResult) { if (command.ChangeType == ChangeStatusType.Stop) // Only need to validate date for stop currently { var response = await _mediator.SendAsync(new GetApprenticeshipQueryRequest { AccountId = command.EmployerAccountId, ApprenticeshipId = command.ApprenticeshipId }); if (response.Apprenticeship.IsWaitingToStart(_currentDateTime)) { if (!command.DateOfChange.Equals(response.Apprenticeship.StartDate)) { validationResult.AddError(nameof(command.DateOfChange), "Date must the same as start date if training hasn't started"); throw new InvalidRequestException(validationResult.ValidationDictionary); } } else { if (command.DateOfChange > _currentDateTime.Now.Date) { validationResult.AddError(nameof(command.DateOfChange), "Date must be a date in the past"); throw new InvalidRequestException(validationResult.ValidationDictionary); } if (response.Apprenticeship.StartDate > command.DateOfChange) { validationResult.AddError(nameof(command.DateOfChange), "Date cannot be earlier than training start date"); throw new InvalidRequestException(validationResult.ValidationDictionary); } } } }
private (SCHEMA2 Model, Validation.ValidationResult Validation) _Read(ReadOnlyMemory <Byte> jsonUtf8Bytes) { var root = new SCHEMA2(); var vcontext = new Validation.ValidationResult(root, this.Validation); if (jsonUtf8Bytes.IsEmpty) { vcontext.AddError(new Validation.SchemaException(null, "JSon is empty.")); } var reader = new Utf8JsonReader(jsonUtf8Bytes.Span); try { if (!reader.Read()) { vcontext.AddError(new Validation.SchemaException(root, "Json is empty")); return(null, vcontext); } root.Deserialize(ref reader); root.OnDeserializationCompleted(); } catch (JsonException rex) { vcontext.AddError(new Validation.SchemaException(root, rex)); return(null, vcontext); } // binary chunk check foreach (var b in root.LogicalBuffers) { b.OnValidateBinaryChunk(vcontext.GetContext(root), this._BinaryChunk); } // schema validation root.ValidateReferences(vcontext.GetContext()); var ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { return(null, vcontext); } // resolve external dependencies root._ResolveSatelliteDependencies(this); // full validation if (this.Validation != VALIDATIONMODE.Skip) { root.Validate(vcontext.GetContext()); ex = vcontext.Errors.FirstOrDefault(); if (ex != null) { return(null, vcontext); } } return(root, vcontext); }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="entity">Instancia da entidade do evento.</param> /// <param name="validationResult">Resultado da validação.</param> public EntityValidatedEventArgs(IEntity entity, Validation.ValidationResult validationResult) { this.Entity = entity; this.ValidationResult = validationResult; }
public bool IsValid(IValidation <User> validation) { ResultValidation = validation.Validate(this); return(ResultValidation.IsValid); }
public MetadataGraphConfigurationWriteResultCTO(BaseEntityResultDTO entityResultDTO, Validation.ValidationResult validationResult) : base(entityResultDTO, validationResult) { }
public bool IsValid(IValidation <Participant> validation) { ResultValidation = validation.Validate(this); return(ResultValidation.IsValid); }