Esempio n. 1
0
 protected override void StartEntry(ODataEntry entry)
 {
     this.CheckAndWriteParentNavigationLinkStartForInlineElement();
     if (entry != null)
     {
         this.StartEntryXmlCustomization(entry);
         this.atomOutputContext.XmlWriter.WriteStartElement("", "entry", "http://www.w3.org/2005/Atom");
         if (base.IsTopLevel)
         {
             this.atomEntryAndFeedSerializer.WriteBaseUriAndDefaultNamespaceAttributes();
         }
         string eTag = entry.ETag;
         if (eTag != null)
         {
             ODataAtomWriterUtils.WriteETag(this.atomOutputContext.XmlWriter, eTag);
         }
         AtomEntryScope    currentEntryScope = this.CurrentEntryScope;
         AtomEntryMetadata entryMetadata     = entry.Atom();
         string            id = entry.Id;
         if (id != null)
         {
             this.atomEntryAndFeedSerializer.WriteEntryId(id);
             currentEntryScope.SetWrittenElement(AtomElement.Id);
         }
         string typeName = entry.TypeName;
         SerializationTypeNameAnnotation annotation = entry.GetAnnotation <SerializationTypeNameAnnotation>();
         if (annotation != null)
         {
             typeName = annotation.TypeName;
         }
         this.atomEntryAndFeedSerializer.WriteEntryTypeName(typeName, entryMetadata);
         Uri editLink = entry.EditLink;
         if (editLink != null)
         {
             this.atomEntryAndFeedSerializer.WriteEntryEditLink(editLink, entryMetadata);
             currentEntryScope.SetWrittenElement(AtomElement.EditLink);
         }
         Uri readLink = entry.ReadLink;
         if (readLink != null)
         {
             this.atomEntryAndFeedSerializer.WriteEntryReadLink(readLink, entryMetadata);
             currentEntryScope.SetWrittenElement(AtomElement.ReadLink);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Start writing an entry.
        /// </summary>
        /// <param name="entry">The entry to write.</param>
        protected override void StartEntry(ODataEntry entry)
        {
            this.CheckAndWriteParentNavigationLinkStartForInlineElement();
            Debug.Assert(
                this.ParentNavigationLink == null || !this.ParentNavigationLink.IsCollection.Value,
                "We should have already verified that the IsCollection matches the actual content of the link (feed/entry).");

            if (entry == null)
            {
                Debug.Assert(this.ParentNavigationLink != null, "When entry == null, it has to be an expanded single entry navigation.");

                // this is a null expanded single entry and it is null, an empty <m:inline /> will be written.
                return;
            }

            this.StartEntryXmlCustomization(entry);

            // <entry>
            this.atomOutputContext.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomEntryElementName, AtomConstants.AtomNamespace);

            if (this.IsTopLevel)
            {
                this.atomEntryAndFeedSerializer.WriteBaseUriAndDefaultNamespaceAttributes();
            }

            string etag = entry.ETag;

            if (etag != null)
            {
                // TODO, ckerer: if this is a top-level entry also put the ETag into the headers.
                ODataAtomWriterUtils.WriteETag(this.atomOutputContext.XmlWriter, etag);
            }

            AtomEntryScope    currentEntryScope = this.CurrentEntryScope;
            AtomEntryMetadata entryMetadata     = entry.Atom();

            // Write the id if it's available here.
            // If it's not available here we will try to write it at the end of the entry again.
            string entryId = entry.Id;

            if (entryId != null)
            {
                this.atomEntryAndFeedSerializer.WriteEntryId(entryId);
                currentEntryScope.SetWrittenElement(AtomElement.Id);
            }

            // <category term="type" scheme="odatascheme"/>
            // If no type information is provided, don't include the category element for type at all
            // NOTE: the validation of the type name is done by the core writer.
            string typeName = entry.TypeName;
            SerializationTypeNameAnnotation serializationTypeNameAnnotation = entry.GetAnnotation <SerializationTypeNameAnnotation>();

            if (serializationTypeNameAnnotation != null)
            {
                typeName = serializationTypeNameAnnotation.TypeName;
            }

            this.atomEntryAndFeedSerializer.WriteEntryTypeName(typeName, entryMetadata);

            // Write the edit link if it's available here.
            // If it's not available here we will try to write it at the end of the entry again.
            Uri editLink = entry.EditLink;

            if (editLink != null)
            {
                this.atomEntryAndFeedSerializer.WriteEntryEditLink(editLink, entryMetadata);
                currentEntryScope.SetWrittenElement(AtomElement.EditLink);
            }

            // Write the self link if it's available here.
            // If it's not available here we will try to write it at the end of the entry again.
            Uri readLink = entry.ReadLink;

            if (readLink != null)
            {
                this.atomEntryAndFeedSerializer.WriteEntryReadLink(readLink, entryMetadata);
                currentEntryScope.SetWrittenElement(AtomElement.ReadLink);
            }
        }