コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
ファイル: EdmModel.cs プロジェクト: hallco978/entityframework
        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);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: CsdlSerializer.cs プロジェクト: dotnet/ef6tools
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: EdmModel.cs プロジェクト: Cireson/EntityFramework6
        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);
            }
        }
コード例 #10
0
        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;
        }