protected override void ProcessVocabularyAnnotation(IEdmVocabularyAnnotation annotation)
        {
            EdmSchema edmSchema = null;

            if (!annotation.IsInline(this.Model))
            {
                string schemaNamespace = annotation.GetSchemaNamespace(this.Model);
                string empty           = schemaNamespace;
                if (schemaNamespace == null)
                {
                    Dictionary <string, EdmSchema> strs = this.modelSchemas;
                    string str = strs.Select <KeyValuePair <string, EdmSchema>, string>((KeyValuePair <string, EdmSchema> s) => s.Key).FirstOrDefault <string>();
                    empty = str;
                    if (str == null)
                    {
                        empty = string.Empty;
                    }
                }
                string str1 = empty;
                if (!this.modelSchemas.TryGetValue(str1, out edmSchema))
                {
                    edmSchema = new EdmSchema(str1);
                    this.modelSchemas.Add(edmSchema.Namespace, edmSchema);
                }
                edmSchema.AddVocabularyAnnotation(annotation);
                this.activeSchema = edmSchema;
            }
            if (annotation.Term != null)
            {
                this.CheckSchemaElementReference(annotation.Term);
            }
            base.ProcessVocabularyAnnotation(annotation);
        }
Пример #2
0
        internal void VisitEdmSchema(EdmSchema element, IEnumerable <KeyValuePair <string, string> > mappings)
        {
            string alias = null;

            if (this.namespaceAliasMappings != null)
            {
                this.namespaceAliasMappings.TryGetValue(element.Namespace, out alias);
            }

            this.schemaWriter.WriteSchemaElementHeader(element, alias, mappings);
            foreach (string usingNamespace in element.NamespaceUsings)
            {
                if (usingNamespace != element.Namespace)
                {
                    if (this.namespaceAliasMappings != null && this.namespaceAliasMappings.TryGetValue(usingNamespace, out alias))
                    {
                        this.schemaWriter.WriteNamespaceUsingElement(usingNamespace, alias);
                    }
                }
            }

            VisitSchemaElements(element.SchemaElements);
            foreach (IEdmNavigationProperty navigationProperty in element.AssociationNavigationProperties)
            {
                string associationName = this.Model.GetAssociationFullName(navigationProperty);
                List <IEdmNavigationProperty> handledNavigationProperties;
                if (!this.associations.TryGetValue(associationName, out handledNavigationProperties))
                {
                    handledNavigationProperties = new List <IEdmNavigationProperty>();
                    this.associations.Add(associationName, handledNavigationProperties);
                }

                // This prevents us from losing associations if they share the same name.
                if (!handledNavigationProperties.Any(np => this.SharesAssociation(np, navigationProperty)))
                {
                    handledNavigationProperties.Add(navigationProperty);
                    handledNavigationProperties.Add(navigationProperty.Partner);
                    this.ProcessAssociation(navigationProperty);
                }
            }

            // EntityContainers are excluded from the EdmSchema.SchemaElements property so they can be forced to the end.
            VisitCollection(element.EntityContainers, this.ProcessEntityContainer);
            foreach (KeyValuePair <string, List <IEdmVocabularyAnnotation> > annotationsForTarget in element.OutOfLineAnnotations)
            {
                this.schemaWriter.WriteAnnotationsElementHeader(annotationsForTarget.Key);
                VisitVocabularyAnnotations(annotationsForTarget.Value);
                this.schemaWriter.WriteEndElement();
            }

            this.schemaWriter.WriteEndElement();
        }
        internal void VisitEdmSchema(EdmSchema element, IEnumerable <KeyValuePair <string, string> > mappings)
        {
            string str = null;

            if (this.namespaceAliasMappings != null)
            {
                this.namespaceAliasMappings.TryGetValue(element.Namespace, out str);
            }
            this.schemaWriter.WriteSchemaElementHeader(element, str, mappings);
            foreach (string str2 in element.NamespaceUsings)
            {
                if (((str2 != element.Namespace) && (this.namespaceAliasMappings != null)) && this.namespaceAliasMappings.TryGetValue(str2, out str))
                {
                    this.schemaWriter.WriteNamespaceUsingElement(str2, str);
                }
            }
            base.VisitSchemaElements(element.SchemaElements);
            using (List <IEdmNavigationProperty> .Enumerator enumerator2 = element.AssociationNavigationProperties.GetEnumerator())
            {
                Func <IEdmNavigationProperty, bool> predicate = null;
                IEdmNavigationProperty navigationProperty;
                while (enumerator2.MoveNext())
                {
                    List <IEdmNavigationProperty> list;
                    navigationProperty = enumerator2.Current;
                    string associationFullName = base.Model.GetAssociationFullName(navigationProperty);
                    if (!this.associations.TryGetValue(associationFullName, out list))
                    {
                        list = new List <IEdmNavigationProperty>();
                        this.associations.Add(associationFullName, list);
                    }
                    if (predicate == null)
                    {
                        predicate = np => this.SharesAssociation(np, navigationProperty);
                    }
                    if (!list.Any <IEdmNavigationProperty>(predicate))
                    {
                        list.Add(navigationProperty);
                        list.Add(navigationProperty.Partner);
                        this.ProcessAssociation(navigationProperty);
                    }
                }
            }
            EdmModelVisitor.VisitCollection <IEdmEntityContainer>(element.EntityContainers, new Action <IEdmEntityContainer>(this.ProcessEntityContainer));
            foreach (KeyValuePair <string, List <IEdmVocabularyAnnotation> > pair in element.OutOfLineAnnotations)
            {
                this.schemaWriter.WriteAnnotationsElementHeader(pair.Key);
                base.VisitVocabularyAnnotations(pair.Value);
                this.schemaWriter.WriteEndElement();
            }
            this.schemaWriter.WriteEndElement();
        }
		protected override void ProcessEntityContainer(IEdmEntityContainer element)
		{
			EdmSchema edmSchema = null;
			string @namespace = element.Namespace;
			if (!this.modelSchemas.TryGetValue(@namespace, out edmSchema))
			{
				edmSchema = new EdmSchema(@namespace);
				this.modelSchemas.Add(edmSchema.Namespace, edmSchema);
			}
			edmSchema.AddEntityContainer(element);
			this.activeSchema = edmSchema;
			base.ProcessEntityContainer(element);
		}
        protected override void ProcessEntityContainer(IEdmEntityContainer element)
        {
            EdmSchema edmSchema  = null;
            string    @namespace = element.Namespace;

            if (!this.modelSchemas.TryGetValue(@namespace, out edmSchema))
            {
                edmSchema = new EdmSchema(@namespace);
                this.modelSchemas.Add(edmSchema.Namespace, edmSchema);
            }
            edmSchema.AddEntityContainer(element);
            this.activeSchema = edmSchema;
            base.ProcessEntityContainer(element);
        }
        internal void WriteSchemaElementHeader(EdmSchema schema, string alias, IEnumerable <KeyValuePair <string, string> > mappings)
        {
            string csdlNamespace = EdmModelCsdlSchemaWriter.GetCsdlNamespace(this.version);

            this.xmlWriter.WriteStartElement("Schema", csdlNamespace);
            this.WriteOptionalAttribute <string>("Namespace", schema.Namespace, string.Empty, new Func <string, string>(EdmValueWriter.StringAsXml));
            this.WriteOptionalAttribute <string>("Alias", alias, new Func <string, string>(EdmValueWriter.StringAsXml));
            if (mappings != null)
            {
                foreach (KeyValuePair <string, string> mapping in mappings)
                {
                    this.xmlWriter.WriteAttributeString("xmlns", mapping.Key, null, mapping.Value);
                }
            }
        }
Пример #7
0
        internal void WriteSchemaElementHeader(EdmSchema schema, string alias, IEnumerable <KeyValuePair <string, string> > mappings)
        {
            string xmlNamespace = GetCsdlNamespace(this.version);

            this.xmlWriter.WriteStartElement(CsdlConstants.Element_Schema, xmlNamespace);
            this.WriteOptionalAttribute(CsdlConstants.Attribute_Namespace, schema.Namespace, string.Empty, EdmValueWriter.StringAsXml);
            this.WriteOptionalAttribute(CsdlConstants.Attribute_Alias, alias, EdmValueWriter.StringAsXml);
            if (mappings != null)
            {
                foreach (KeyValuePair <string, string> mapping in mappings)
                {
                    this.xmlWriter.WriteAttributeString(EdmConstants.XmlNamespacePrefix, mapping.Key, null, mapping.Value);
                }
            }
        }
        protected override void ProcessNavigationProperty(IEdmNavigationProperty property)
        {
            EdmSchema edmSchema            = null;
            string    associationNamespace = this.Model.GetAssociationNamespace(property);

            if (!this.modelSchemas.TryGetValue(associationNamespace, out edmSchema))
            {
                edmSchema = new EdmSchema(associationNamespace);
                this.modelSchemas.Add(edmSchema.Namespace, edmSchema);
            }
            edmSchema.AddAssociatedNavigationProperty(property);
            edmSchema.AddNamespaceUsing(property.DeclaringEntityType().Namespace);
            edmSchema.AddNamespaceUsing(property.Partner.DeclaringEntityType().Namespace);
            this.activeSchema.AddNamespaceUsing(associationNamespace);
            base.ProcessNavigationProperty(property);
        }
Пример #9
0
        /// <summary>
        /// When we see an entity container, we see if it has <see cref="CsdlConstants.SchemaNamespaceAnnotation"/>.
        /// If it does, then we attach it to that schema, otherwise we attached to the first existing schema.
        /// If there are no schemas, we create the one named "Default" and attach container to it.
        /// </summary>
        /// <param name="element">The entity container being processed.</param>
        protected override void ProcessEntityContainer(IEdmEntityContainer element)
        {
            var containerSchemaNamespace = element.Namespace;

            EdmSchema containerSchema;

            if (!this.modelSchemas.TryGetValue(containerSchemaNamespace, out containerSchema))
            {
                containerSchema = new EdmSchema(containerSchemaNamespace);
                this.modelSchemas.Add(containerSchema.Namespace, containerSchema);
            }

            containerSchema.AddEntityContainer(element);
            this.activeSchema = containerSchema;

            base.ProcessEntityContainer(element);
        }
        protected override void ProcessSchemaElement(IEdmSchemaElement element)
        {
            EdmSchema edmSchema  = null;
            string    @namespace = element.Namespace;

            if (EdmUtil.IsNullOrWhiteSpaceInternal(@namespace))
            {
                @namespace = string.Empty;
            }
            if (!this.modelSchemas.TryGetValue(@namespace, out edmSchema))
            {
                edmSchema = new EdmSchema(@namespace);
                this.modelSchemas.Add(@namespace, edmSchema);
            }
            edmSchema.AddSchemaElement(element);
            this.activeSchema = edmSchema;
            base.ProcessSchemaElement(element);
        }
Пример #11
0
        protected override void ProcessNavigationProperty(IEdmNavigationProperty property)
        {
            var associationNamespace = SerializationExtensionMethods.GetAssociationNamespace(Model, property);

            EdmSchema associationSchema;

            if (!this.modelSchemas.TryGetValue(associationNamespace, out associationSchema))
            {
                associationSchema = new EdmSchema(associationNamespace);
                this.modelSchemas.Add(associationSchema.Namespace, associationSchema);
            }

            associationSchema.AddAssociatedNavigationProperty(property);
            associationSchema.AddNamespaceUsing(property.DeclaringEntityType().Namespace);
            associationSchema.AddNamespaceUsing(property.Partner.DeclaringEntityType().Namespace);
            this.activeSchema.AddNamespaceUsing(associationNamespace);

            base.ProcessNavigationProperty(property);
        }
        protected override void ProcessSchemaElement(IEdmSchemaElement element)
        {
            string namespaceName = element.Namespace;

            // Put all of the namespaceless stuff into one schema.
            if (EdmUtil.IsNullOrWhiteSpaceInternal(namespaceName))
            {
                namespaceName = string.Empty;
            }

            EdmSchema schema;
            if (!this.modelSchemas.TryGetValue(namespaceName, out schema))
            {
                schema = new EdmSchema(namespaceName);
                this.modelSchemas.Add(namespaceName, schema);
            }
            
            schema.AddSchemaElement(element);
            this.activeSchema = schema;
            
            base.ProcessSchemaElement(element);
        }
Пример #13
0
        protected override void ProcessSchemaElement(IEdmSchemaElement element)
        {
            string namespaceName = element.Namespace;

            // Put all of the namespaceless stuff into one schema.
            if (EdmUtil.IsNullOrWhiteSpaceInternal(namespaceName))
            {
                namespaceName = string.Empty;
            }

            EdmSchema schema;

            if (!this.modelSchemas.TryGetValue(namespaceName, out schema))
            {
                schema = new EdmSchema(namespaceName);
                this.modelSchemas.Add(namespaceName, schema);
            }

            schema.AddSchemaElement(element);
            this.activeSchema = schema;

            base.ProcessSchemaElement(element);
        }
Пример #14
0
        protected override void ProcessVocabularyAnnotation(IEdmVocabularyAnnotation annotation)
        {
            if (!annotation.IsInline(this.Model))
            {
                var annotationSchemaNamespace = annotation.GetSchemaNamespace(this.Model) ?? this.modelSchemas.Select(s => s.Key).FirstOrDefault() ?? string.Empty;

                EdmSchema annotationSchema;
                if (!this.modelSchemas.TryGetValue(annotationSchemaNamespace, out annotationSchema))
                {
                    annotationSchema = new EdmSchema(annotationSchemaNamespace);
                    this.modelSchemas.Add(annotationSchema.Namespace, annotationSchema);
                }

                annotationSchema.AddVocabularyAnnotation(annotation);
                this.activeSchema = annotationSchema;
            }

            if (annotation.Term != null)
            {
                this.CheckSchemaElementReference(annotation.Term);
            }

            base.ProcessVocabularyAnnotation(annotation);
        }
		protected override void ProcessSchemaElement(IEdmSchemaElement element)
		{
			EdmSchema edmSchema = null;
			string @namespace = element.Namespace;
			if (EdmUtil.IsNullOrWhiteSpaceInternal(@namespace))
			{
				@namespace = string.Empty;
			}
			if (!this.modelSchemas.TryGetValue(@namespace, out edmSchema))
			{
				edmSchema = new EdmSchema(@namespace);
				this.modelSchemas.Add(@namespace, edmSchema);
			}
			edmSchema.AddSchemaElement(element);
			this.activeSchema = edmSchema;
			base.ProcessSchemaElement(element);
		}
        protected override void ProcessVocabularyAnnotation(IEdmVocabularyAnnotation annotation)
        {
            if (!annotation.IsInline(this.Model))
            {
                var annotationSchemaNamespace = annotation.GetSchemaNamespace(this.Model) ?? this.modelSchemas.Select(s => s.Key).FirstOrDefault() ?? string.Empty;

                EdmSchema annotationSchema;
                if (!this.modelSchemas.TryGetValue(annotationSchemaNamespace, out annotationSchema))
                {
                    annotationSchema = new EdmSchema(annotationSchemaNamespace);
                    this.modelSchemas.Add(annotationSchema.Namespace, annotationSchema);
                }

                annotationSchema.AddVocabularyAnnotation(annotation);
                this.activeSchema = annotationSchema;
            }

            if (annotation.Term != null)
            {
                this.CheckSchemaElementReference(annotation.Term);
            }

            base.ProcessVocabularyAnnotation(annotation);
        }
        protected override void ProcessNavigationProperty(IEdmNavigationProperty property)
        {
            var associationNamespace = SerializationExtensionMethods.GetAssociationNamespace(Model, property);

            EdmSchema associationSchema;
            if (!this.modelSchemas.TryGetValue(associationNamespace, out associationSchema))
            {
                associationSchema = new EdmSchema(associationNamespace);
                this.modelSchemas.Add(associationSchema.Namespace, associationSchema);
            }

            associationSchema.AddAssociatedNavigationProperty(property);
            associationSchema.AddNamespaceUsing(property.DeclaringEntityType().Namespace);
            associationSchema.AddNamespaceUsing(property.Partner.DeclaringEntityType().Namespace);
            this.activeSchema.AddNamespaceUsing(associationNamespace);

            base.ProcessNavigationProperty(property);
        }
		protected override void ProcessNavigationProperty(IEdmNavigationProperty property)
		{
			EdmSchema edmSchema = null;
			string associationNamespace = this.Model.GetAssociationNamespace(property);
			if (!this.modelSchemas.TryGetValue(associationNamespace, out edmSchema))
			{
				edmSchema = new EdmSchema(associationNamespace);
				this.modelSchemas.Add(edmSchema.Namespace, edmSchema);
			}
			edmSchema.AddAssociatedNavigationProperty(property);
			edmSchema.AddNamespaceUsing(property.DeclaringEntityType().Namespace);
			edmSchema.AddNamespaceUsing(property.Partner.DeclaringEntityType().Namespace);
			this.activeSchema.AddNamespaceUsing(associationNamespace);
			base.ProcessNavigationProperty(property);
		}
		protected override void ProcessVocabularyAnnotation(IEdmVocabularyAnnotation annotation)
		{
			EdmSchema edmSchema = null;
			if (!annotation.IsInline(this.Model))
			{
				string schemaNamespace = annotation.GetSchemaNamespace(this.Model);
				string empty = schemaNamespace;
				if (schemaNamespace == null)
				{
					Dictionary<string, EdmSchema> strs = this.modelSchemas;
					string str = strs.Select<KeyValuePair<string, EdmSchema>, string>((KeyValuePair<string, EdmSchema> s) => s.Key).FirstOrDefault<string>();
					empty = str;
					if (str == null)
					{
						empty = string.Empty;
					}
				}
				string str1 = empty;
				if (!this.modelSchemas.TryGetValue(str1, out edmSchema))
				{
					edmSchema = new EdmSchema(str1);
					this.modelSchemas.Add(edmSchema.Namespace, edmSchema);
				}
				edmSchema.AddVocabularyAnnotation(annotation);
				this.activeSchema = edmSchema;
			}
			if (annotation.Term != null)
			{
				this.CheckSchemaElementReference(annotation.Term);
			}
			base.ProcessVocabularyAnnotation(annotation);
		}
        /// <summary>
        /// When we see an entity container, we see if it has <see cref="CsdlConstants.SchemaNamespaceAnnotation"/>.
        /// If it does, then we attach it to that schema, otherwise we attached to the first existing schema.
        /// If there are no schemas, we create the one named "Default" and attach container to it.
        /// </summary>
        /// <param name="element">The entity container being processed.</param>
        protected override void ProcessEntityContainer(IEdmEntityContainer element)
        {
            var containerSchemaNamespace = element.Namespace;

            EdmSchema containerSchema;
            if (!this.modelSchemas.TryGetValue(containerSchemaNamespace, out containerSchema))
            {
                containerSchema = new EdmSchema(containerSchemaNamespace);
                this.modelSchemas.Add(containerSchema.Namespace, containerSchema);
            }

            containerSchema.AddEntityContainer(element);
            this.activeSchema = containerSchema;

            base.ProcessEntityContainer(element);
        }