public bool Serialize(EdmModel model, XmlWriter xmlWriter, string modelNamespace = null) { Check.NotNull <EdmModel>(model, nameof(model)); Check.NotNull <XmlWriter>(xmlWriter, nameof(xmlWriter)); bool modelIsValid = true; Action <DataModelErrorEventArgs> onErrorAction = (Action <DataModelErrorEventArgs>)(e => { modelIsValid = false; if (this.OnError == null) { return; } this.OnError((object)this, e); }); if (model.NamespaceNames.Count <string>() > 1 || model.Containers.Count <EntityContainer>() != 1) { onErrorAction(new DataModelErrorEventArgs() { ErrorMessage = Strings.Serializer_OneNamespaceAndOneContainer }); } DataModelValidator dataModelValidator = new DataModelValidator(); dataModelValidator.OnError += (EventHandler <DataModelErrorEventArgs>)((_, e) => onErrorAction(e)); dataModelValidator.Validate(model, true); if (!modelIsValid) { return(false); } new EdmSerializationVisitor(xmlWriter, model.SchemaVersion, false).Visit(model, modelNamespace); return(true); }
private bool ValidateModel(EdmModel model) { bool modelIsValid = true; Action <DataModelErrorEventArgs> onErrorAction = (Action <DataModelErrorEventArgs>)(e => { MetadataItem instance = e.Item; if (instance != null && MetadataItemHelper.IsInvalid(instance)) { return; } modelIsValid = false; if (this.OnError == null) { return; } this.OnError((object)this, e); }); if (model.NamespaceNames.Count <string>() > 1 || model.Containers.Count <EntityContainer>() != 1) { onErrorAction(new DataModelErrorEventArgs() { ErrorMessage = Strings.Serializer_OneNamespaceAndOneContainer }); } DataModelValidator dataModelValidator = new DataModelValidator(); dataModelValidator.OnError += (EventHandler <DataModelErrorEventArgs>)((_, e) => onErrorAction(e)); dataModelValidator.Validate(model, true); return(modelIsValid); }
internal virtual void Validate() { List <DataModelErrorEventArgs> validationErrors = new List <DataModelErrorEventArgs>(); DataModelValidator dataModelValidator = new DataModelValidator(); dataModelValidator.OnError += (EventHandler <DataModelErrorEventArgs>)((_, e) => validationErrors.Add(e)); dataModelValidator.Validate(this, true); if (validationErrors.Count > 0) { throw new ModelValidationException((IEnumerable <DataModelErrorEventArgs>)validationErrors); } }
internal virtual void Validate() { var validationErrors = new List <DataModelErrorEventArgs>(); var validator = new DataModelValidator(); validator.OnError += (_, e) => validationErrors.Add(e); validator.Validate(this, true); if (validationErrors.Count > 0) { throw new ModelValidationException(validationErrors); } }
public void When_store_function_name_has_a_dot() { var errors = new List<DataModelErrorEventArgs>(); var validator = new DataModelValidator(); validator.OnError += (s, a) => errors.Add(a); var model = new EdmModel(DataSpace.SSpace); model.AddItem(new EdmFunction("Has.Dots", "N", DataSpace.SSpace)); validator.Validate(model, validateSyntax: true); var error = errors.Single(); Assert.Equal("Name", error.PropertyName); Assert.Equal(Strings.EdmModel_Validator_Syntactic_EdmModel_NameIsNotAllowed("Has.Dots"), error.ErrorMessage); }
public void When_store_function_name_has_a_dot() { var errors = new List <DataModelErrorEventArgs>(); var validator = new DataModelValidator(); validator.OnError += (s, a) => errors.Add(a); var model = new EdmModel(DataSpace.SSpace); model.AddItem(new EdmFunction("Has.Dots", "N", DataSpace.SSpace)); validator.Validate(model, validateSyntax: true); var error = errors.Single(); Assert.Equal("Name", error.PropertyName); Assert.Equal(Strings.EdmModel_Validator_Syntactic_EdmModel_NameIsNotAllowed("Has.Dots"), error.ErrorMessage); }
public bool Serialize(EdmModel model, XmlWriter xmlWriter, string modelNamespace = null) { Check.NotNull(model, "model"); Check.NotNull(xmlWriter, "xmlWriter"); bool modelIsValid = true; Action <DataModelErrorEventArgs> onErrorAction = e => { modelIsValid = false; if (OnError != null) { OnError(this, e); } }; if (model.NamespaceNames.Count() > 1 || model.Containers.Count() != 1) { onErrorAction( new DataModelErrorEventArgs { ErrorMessage = Strings.Serializer_OneNamespaceAndOneContainer, }); } // validate the model first var validator = new DataModelValidator(); validator.OnError += (_, e) => onErrorAction(e); validator.Validate(model, true); if (modelIsValid) { new EdmSerializationVisitor(xmlWriter, model.SchemaVersion).Visit(model, modelNamespace); return(true); } return(false); }
private bool ValidateModel(EdmModel model) { bool modelIsValid = true; Action <DataModelErrorEventArgs> onErrorAction = e => { // Ssdl serializer writes metadata items marked as invalid as comments // therefore we should not report errors for those. var metadataItem = e.Item as MetadataItem; if (metadataItem == null || !MetadataItemHelper.IsInvalid(metadataItem)) { modelIsValid = false; if (OnError != null) { OnError(this, e); } } }; if (model.NamespaceNames.Count() > 1 || model.Containers.Count() != 1) { onErrorAction( new DataModelErrorEventArgs { ErrorMessage = Strings.Serializer_OneNamespaceAndOneContainer, }); } var validator = new DataModelValidator(); validator.OnError += (_, e) => onErrorAction(e); validator.Validate(model, true); return(modelIsValid); }
internal virtual void Validate() { var validationErrors = new List<DataModelErrorEventArgs>(); var validator = new DataModelValidator(); validator.OnError += (_, e) => validationErrors.Add(e); validator.Validate(this, true); if (validationErrors.Count > 0) { throw new ModelValidationException(validationErrors); } }
private bool ValidateModel(EdmModel model) { bool modelIsValid = true; Action<DataModelErrorEventArgs> onErrorAction = e => { // Ssdl serializer writes metadata items marked as invalid as comments // therefore we should not report errors for those. var metadataItem = e.Item as MetadataItem; if (metadataItem == null || !MetadataItemHelper.IsInvalid(metadataItem)) { modelIsValid = false; if (OnError != null) { OnError(this, e); } } }; if (model.NamespaceNames.Count() > 1 || model.Containers.Count() != 1) { onErrorAction( new DataModelErrorEventArgs { ErrorMessage = Strings.Serializer_OneNamespaceAndOneContainer, }); } var validator = new DataModelValidator(); validator.OnError += (_, e) => onErrorAction(e); validator.Validate(model, true); return modelIsValid; }