Exemple #1
0
        private static void AppendSchemaErrors(StringBuilder builder, MetadataItem item)
        {
            if (MetadataItemHelper.HasSchemaErrors(item))
            {
                builder.Append(Strings.MetadataItemErrorsFoundDuringGeneration);

                foreach (var error in MetadataItemHelper.GetSchemaErrors(item))
                {
                    builder.AppendLine();
                    builder.Append(error.ToString());
                }
            }
        }
Exemple #2
0
        protected internal override void VisitEdmAssociationType(AssociationType item)
        {
            var builder = new StringBuilder();

            AppendSchemaErrors(builder, item);

            if (MetadataItemHelper.IsInvalid(item))
            {
                AppendMetadataItem(builder, item, (v, i) => v.InternalVisitEdmAssociationType(i));

                WriteComment(builder.ToString());
            }
            else
            {
                WriteComment(builder.ToString());

                InternalVisitEdmAssociationType(item);
            }
        }
        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);
        }