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); } } }
/// <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) { 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); }
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); VisitSchemaElements(element.SchemaElements); // 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(); }
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); }