/// <summary>
        /// Writes an Xml element with the specified primitive value as content.
        /// </summary>
        /// <param name="prefix">The prefix for the element's namespace.</param>
        /// <param name="localName">The local name of the element.</param>
        /// <param name="ns">The namespace of the element.</param>
        /// <param name="textConstruct">The <see cref="AtomTextConstruct"/> value to be used as element content.</param>
        internal void WriteTextConstruct(string prefix, string localName, string ns, AtomTextConstruct textConstruct)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(prefix != null, "prefix != null");
            Debug.Assert(!string.IsNullOrEmpty(localName), "!string.IsNullOrEmpty(localName)");
            Debug.Assert(!string.IsNullOrEmpty(ns), "!string.IsNullOrEmpty(ns)");

            this.XmlWriter.WriteStartElement(prefix, localName, ns);

            if (textConstruct != null)
            {
                AtomTextConstructKind textKind = textConstruct.Kind;

                this.XmlWriter.WriteAttributeString(AtomConstants.AtomTypeAttributeName, AtomValueUtils.ToString(textConstruct.Kind));

                string textValue = textConstruct.Text;
                if (textValue == null)
                {
                    textValue = String.Empty;
                }

                if (textKind == AtomTextConstructKind.Xhtml)
                {
                    ODataAtomWriterUtils.WriteRaw(this.XmlWriter, textValue);
                }
                else
                {
                    ODataAtomWriterUtils.WriteString(this.XmlWriter, textValue);
                }
            }

            this.XmlWriter.WriteEndElement();
        }
        internal void WriteWorkspaceMetadata(ODataWorkspace workspace)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(workspace != null, "workspace != null");

            AtomWorkspaceMetadata metadata = workspace.GetAnnotation <AtomWorkspaceMetadata>();
            AtomTextConstruct     title    = null;

            if (metadata != null)
            {
                title = metadata.Title;
            }

            if (title == null)
            {
                title = new AtomTextConstruct {
                    Text = AtomConstants.AtomWorkspaceDefaultTitle
                };
            }

            if (this.UseServerFormatBehavior && title.Kind == AtomTextConstructKind.Text)
            {
                // For WCF DS server we must not write the type attribute, just a simple <atom:title>Default<atom:title>
                this.WriteElementWithTextContent(
                    AtomConstants.NonEmptyAtomNamespacePrefix,
                    AtomConstants.AtomTitleElementName,
                    AtomConstants.AtomNamespace,
                    title.Text);
            }
            else
            {
                // <atom:title>title</atom:title>
                this.WriteTextConstruct(AtomConstants.NonEmptyAtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace, title);
            }
        }
        /// <summary>
        /// Writes an Xml element with the specified primitive value as content.
        /// </summary>
        /// <param name="prefix">The prefix for the element's namespace.</param>
        /// <param name="localName">The local name of the element.</param>
        /// <param name="ns">The namespace of the element.</param>
        /// <param name="textConstruct">The <see cref="AtomTextConstruct"/> value to be used as element content.</param>
        internal void WriteTextConstruct(string prefix, string localName, string ns, AtomTextConstruct textConstruct)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(prefix != null, "prefix != null");
            Debug.Assert(!string.IsNullOrEmpty(localName), "!string.IsNullOrEmpty(localName)");
            Debug.Assert(!string.IsNullOrEmpty(ns), "!string.IsNullOrEmpty(ns)");

            this.XmlWriter.WriteStartElement(prefix, localName, ns);

            if (textConstruct != null)
            {
                AtomTextConstructKind textKind = textConstruct.Kind;

                this.XmlWriter.WriteAttributeString(AtomConstants.AtomTypeAttributeName, AtomValueUtils.ToString(textConstruct.Kind));

                string textValue = textConstruct.Text;
                if (textValue == null)
                {
                    textValue = String.Empty;
                }

                if (textKind == AtomTextConstructKind.Xhtml)
                {
                    ODataAtomWriterUtils.WriteRaw(this.XmlWriter, textValue);
                }
                else
                {
                    ODataAtomWriterUtils.WriteString(this.XmlWriter, textValue);
                }
            }

            this.XmlWriter.WriteEndElement();
        }
 private void ReadTextConstructEpm(EpmTargetPathSegment targetSegment, AtomTextConstruct textConstruct)
 {
     if ((textConstruct != null) && (textConstruct.Text != null))
     {
         base.SetEntryEpmValue(targetSegment.EpmInfo, textConstruct.Text);
     }
 }
        protected AtomTextConstruct ReadAtomTextConstruct()
        {
            AtomTextConstruct construct = new AtomTextConstruct();
            string            str       = null;

            while (base.XmlReader.MoveToNextAttribute())
            {
                if (base.XmlReader.NamespaceEquals(this.EmptyNamespace) && (string.CompareOrdinal(base.XmlReader.LocalName, "type") == 0))
                {
                    str = base.XmlReader.Value;
                }
            }
            base.XmlReader.MoveToElement();
            if (str == null)
            {
                construct.Kind = AtomTextConstructKind.Text;
            }
            else
            {
                string str2 = str;
                if (str2 == null)
                {
                    goto Label_00AE;
                }
                if (!(str2 == "text"))
                {
                    if (str2 == "html")
                    {
                        construct.Kind = AtomTextConstructKind.Html;
                        goto Label_00C5;
                    }
                    if (str2 == "xhtml")
                    {
                        construct.Kind = AtomTextConstructKind.Xhtml;
                        goto Label_00C5;
                    }
                    goto Label_00AE;
                }
                construct.Kind = AtomTextConstructKind.Text;
            }
            goto Label_00C5;
Label_00AE:
            throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomEntryMetadataDeserializer_InvalidTextConstructKind(str, base.XmlReader.LocalName));
Label_00C5:
            if (construct.Kind == AtomTextConstructKind.Xhtml)
            {
                construct.Text = base.XmlReader.ReadInnerXml();
                return(construct);
            }
            construct.Text = this.ReadElementStringValue();
            return(construct);
        }
        /// <summary>
        /// Reads the value of the ATOM text construct and sets it to the EPM.
        /// </summary>
        /// <param name="targetSegment">The EPM target segment for the value to read.</param>
        /// <param name="textConstruct">The text construct to read it from (can be null).</param>
        private void ReadTextConstructEpm(EpmTargetPathSegment targetSegment, AtomTextConstruct textConstruct)
        {
            Debug.Assert(targetSegment != null, "targetSegment != null");
            Debug.Assert(targetSegment.HasContent, "We can only read text construct values into segments which are mapped to a leaf property.");

            if (textConstruct != null)
            {
                if (textConstruct.Text != null)
                {
                    this.SetEntryEpmValue(targetSegment.EpmInfo, textConstruct.Text);
                }
            }
        }
        private static AtomTextConstruct MergeAtomTextValue(AtomTextConstruct customValue, AtomTextConstruct epmValue, string propertyName)
        {
            AtomTextConstruct construct;

            if (TryMergeIfNull <AtomTextConstruct>(customValue, epmValue, out construct))
            {
                return(construct);
            }
            if (customValue.Kind != epmValue.Kind)
            {
                throw new ODataException(Strings.ODataAtomMetadataEpmMerge_TextKindConflict(propertyName, customValue.Kind.ToString(), epmValue.Kind.ToString()));
            }
            if (string.CompareOrdinal(customValue.Text, epmValue.Text) != 0)
            {
                throw new ODataException(Strings.ODataAtomMetadataEpmMerge_TextValueConflict(propertyName, customValue.Text, epmValue.Text));
            }
            return(epmValue);
        }
 internal void WriteServiceDocument(DataServiceProviderWrapper provider)
 {
     ODataWorkspace defaultWorkspace = new ODataWorkspace {
         Collections = provider.GetResourceSets().Select<ResourceSetWrapper, ODataResourceCollectionInfo>(delegate (ResourceSetWrapper rs) {
             ODataResourceCollectionInfo info = new ODataResourceCollectionInfo {
                 Url = new Uri(rs.Name, UriKind.RelativeOrAbsolute)
             };
             AtomResourceCollectionMetadata annotation = new AtomResourceCollectionMetadata();
             AtomTextConstruct construct = new AtomTextConstruct {
                 Text = rs.Name
             };
             annotation.Title = construct;
             info.SetAnnotation<AtomResourceCollectionMetadata>(annotation);
             return info;
         })
     };
     this.writer.WriteServiceDocument(defaultWorkspace);
 }
 internal void WriteTextConstruct(string prefix, string localName, string ns, AtomTextConstruct textConstruct)
 {
     base.XmlWriter.WriteStartElement(prefix, localName, ns);
     if (textConstruct != null)
     {
         AtomTextConstructKind kind = textConstruct.Kind;
         base.XmlWriter.WriteAttributeString("type", AtomValueUtils.ToString(textConstruct.Kind));
         string text = textConstruct.Text;
         if (text == null)
         {
             text = string.Empty;
         }
         if (kind == AtomTextConstructKind.Xhtml)
         {
             ODataAtomWriterUtils.WriteRaw(base.XmlWriter, text);
         }
         else
         {
             ODataAtomWriterUtils.WriteString(base.XmlWriter, text);
         }
     }
     base.XmlWriter.WriteEndElement();
 }
示例#10
0
        /// <summary>
        /// Reads an atom:title element and adds the new information to <paramref name="collectionInfo"/> and (if ATOM metadata reading is on) <paramref name="collectionMetadata"/>.
        /// </summary>
        /// <param name="collectionMetadata">The collection metadata object to augment, or null if metadata reading is not on.</param>
        /// <param name="collectionInfo">The non-null collection info object being populated.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - The start of the title element.
        /// Post-Condition: Any                 - The next node after the title element.
        /// </remarks>
        internal void ReadTitleElementInCollection(AtomResourceCollectionMetadata collectionMetadata, ODataResourceCollectionInfo collectionInfo)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(!this.ReadAtomMetadata || collectionMetadata != null, "collectionMetadata parameter should be non-null when ATOM metadata reading is enabled.");
            Debug.Assert(collectionInfo != null, "collectionInfo != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.LocalName == AtomConstants.AtomTitleElementName, "Expected element named 'title'.");
            Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Element 'title' should be in the atom namespace.");

            if (collectionInfo.Name != null)
            {
                throw new ODataException(Strings.ODataAtomServiceDocumentMetadataDeserializer_MultipleTitleElementsFound(AtomConstants.AtomPublishingCollectionElementName));
            }

            AtomTextConstruct titleTextConstruct = this.ReadTitleElement();

            collectionInfo.Name = titleTextConstruct.Text;

            if (this.ReadAtomMetadata)
            {
                collectionMetadata.Title = titleTextConstruct;
            }
        }
        internal void WriteWorkspaceMetadata(ODataWorkspace workspace)
        {
            AtomWorkspaceMetadata annotation    = workspace.GetAnnotation <AtomWorkspaceMetadata>();
            AtomTextConstruct     textConstruct = null;

            if (annotation != null)
            {
                textConstruct = annotation.Title;
            }
            if (textConstruct == null)
            {
                textConstruct = new AtomTextConstruct {
                    Text = "Default"
                };
            }
            if (base.UseServerFormatBehavior && (textConstruct.Kind == AtomTextConstructKind.Text))
            {
                base.WriteElementWithTextContent("atom", "title", "http://www.w3.org/2005/Atom", textConstruct.Text);
            }
            else
            {
                base.WriteTextConstruct("atom", "title", "http://www.w3.org/2005/Atom", textConstruct);
            }
        }
示例#12
0
        /// <summary>
        /// Read the ATOM text construct element.
        /// </summary>
        /// <returns>The element read represented as ATOM text construct.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - the element to read.
        /// Post-Condition: Any                 - the node after the element.
        /// </remarks>
        protected AtomTextConstruct ReadAtomTextConstruct()
        {
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "The element must be in ATOM namespace for this method to work.");
            Debug.Assert(
                this.XmlReader.LocalName == AtomConstants.AtomRightsElementName ||
                this.XmlReader.LocalName == AtomConstants.AtomSummaryElementName ||
                this.XmlReader.LocalName == AtomConstants.AtomSubtitleElementName ||
                this.XmlReader.LocalName == AtomConstants.AtomTitleElementName,
                "Only atom:rights, atom:summary, atom:subtitle, and atom:title elements are supported by this method.");

            AtomTextConstruct textConstruct = new AtomTextConstruct();

            string typeValue = null;

            while (this.XmlReader.MoveToNextAttribute())
            {
                if (this.XmlReader.NamespaceEquals(this.EmptyNamespace) && string.CompareOrdinal(this.XmlReader.LocalName, AtomConstants.AtomTypeAttributeName) == 0)
                {
                    // type attribute
                    typeValue = this.XmlReader.Value;
                }
            }

            this.XmlReader.MoveToElement();
            if (typeValue == null)
            {
                textConstruct.Kind = AtomTextConstructKind.Text;
            }
            else
            {
                switch (typeValue)
                {
                case AtomConstants.AtomTextConstructTextKind:
                    textConstruct.Kind = AtomTextConstructKind.Text;
                    break;

                case AtomConstants.AtomTextConstructHtmlKind:
                    textConstruct.Kind = AtomTextConstructKind.Html;
                    break;

                case AtomConstants.AtomTextConstructXHtmlKind:
                    textConstruct.Kind = AtomTextConstructKind.Xhtml;
                    break;

                default:
                    throw new ODataException(Strings.ODataAtomEntryMetadataDeserializer_InvalidTextConstructKind(typeValue, this.XmlReader.LocalName));
                }
            }

            if (textConstruct.Kind == AtomTextConstructKind.Xhtml)
            {
                this.XmlReader.AssertNotBuffering();
                textConstruct.Text = this.XmlReader.ReadInnerXml();
            }
            else
            {
                textConstruct.Text = this.ReadElementStringValue();
            }

            return(textConstruct);
        }
        internal void WriteResourceCollectionMetadata(ODataResourceCollectionInfo collection)
        {
            AtomResourceCollectionMetadata annotation = collection.GetAnnotation <AtomResourceCollectionMetadata>();
            AtomTextConstruct textConstruct           = null;

            if (annotation != null)
            {
                textConstruct = annotation.Title;
            }
            if (base.UseServerFormatBehavior && (textConstruct.Kind == AtomTextConstructKind.Text))
            {
                base.WriteElementWithTextContent("atom", "title", "http://www.w3.org/2005/Atom", textConstruct.Text);
            }
            else
            {
                base.WriteTextConstruct("atom", "title", "http://www.w3.org/2005/Atom", textConstruct);
            }
            if (annotation != null)
            {
                string accept = annotation.Accept;
                if (accept != null)
                {
                    base.WriteElementWithTextContent(string.Empty, "accept", "http://www.w3.org/2007/app", accept);
                }
                AtomCategoriesMetadata categories = annotation.Categories;
                if (categories != null)
                {
                    base.XmlWriter.WriteStartElement(string.Empty, "categories", "http://www.w3.org/2007/app");
                    Uri    href   = categories.Href;
                    bool?  @fixed = categories.Fixed;
                    string scheme = categories.Scheme;
                    IEnumerable <AtomCategoryMetadata> source = categories.Categories;
                    if (href != null)
                    {
                        if ((@fixed.HasValue || (scheme != null)) || ((source != null) && source.Any <AtomCategoryMetadata>()))
                        {
                            throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomWriterMetadataUtils_CategoriesHrefWithOtherValues);
                        }
                        base.XmlWriter.WriteAttributeString("href", base.UriToUrlAttributeValue(href));
                    }
                    else
                    {
                        if (@fixed.HasValue)
                        {
                            base.XmlWriter.WriteAttributeString("fixed", @fixed.Value ? "yes" : "no");
                        }
                        if (scheme != null)
                        {
                            base.XmlWriter.WriteAttributeString("scheme", scheme);
                        }
                        if (source != null)
                        {
                            foreach (AtomCategoryMetadata metadata3 in source)
                            {
                                base.WriteCategory("atom", metadata3.Term, metadata3.Scheme, metadata3.Label);
                            }
                        }
                    }
                    base.XmlWriter.WriteEndElement();
                }
            }
        }
        /// <summary>
        /// Writes the ATOM metadata for a single (resource) collection element.
        /// </summary>
        /// <param name="collection">The collection element to get the metadata for and write it.</param>
        internal void WriteResourceCollectionMetadata(ODataResourceCollectionInfo collection)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(collection != null, "collection != null");
            Debug.Assert(collection.Url != null, "collection.Url should have been validated at this point");

            AtomResourceCollectionMetadata metadata = collection.GetAnnotation <AtomResourceCollectionMetadata>();

            AtomTextConstruct title = null;

            if (metadata != null)
            {
                title = metadata.Title;
            }

            // The ATOMPUB specification requires a title.
            // <atom:title>title</atom:title>
            // Note that this will write an empty atom:title element even if the title is null.
            if (this.UseServerFormatBehavior && title.Kind == AtomTextConstructKind.Text)
            {
                // For WCF DS server we must not write the type attribute, just a simple <atom:title>title<atom:title>
                this.WriteElementWithTextContent(
                    AtomConstants.NonEmptyAtomNamespacePrefix,
                    AtomConstants.AtomTitleElementName,
                    AtomConstants.AtomNamespace,
                    title.Text);
            }
            else
            {
                this.WriteTextConstruct(AtomConstants.NonEmptyAtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace, title);
            }

            if (metadata != null)
            {
                string accept = metadata.Accept;
                if (accept != null)
                {
                    // <app:accept>accept</app:accept>
                    this.WriteElementWithTextContent(
                        string.Empty,
                        AtomConstants.AtomPublishingAcceptElementName,
                        AtomConstants.AtomPublishingNamespace,
                        accept);
                }

                AtomCategoriesMetadata categories = metadata.Categories;
                if (categories != null)
                {
                    // <app:categories>
                    this.XmlWriter.WriteStartElement(string.Empty, AtomConstants.AtomPublishingCategoriesElementName, AtomConstants.AtomPublishingNamespace);

                    Uri    href       = categories.Href;
                    bool?  fixedValue = categories.Fixed;
                    string scheme     = categories.Scheme;
                    IEnumerable <AtomCategoryMetadata> categoriesCollection = categories.Categories;
                    if (href != null)
                    {
                        // Out of line categories document
                        if (fixedValue.HasValue || scheme != null ||
                            (categoriesCollection != null && categoriesCollection.Any()))
                        {
                            throw new ODataException(o.Strings.ODataAtomWriterMetadataUtils_CategoriesHrefWithOtherValues);
                        }

                        this.XmlWriter.WriteAttributeString(AtomConstants.AtomHRefAttributeName, this.UriToUrlAttributeValue(href));
                    }
                    else
                    {
                        // Inline categories document

                        // fixed='yes|no'
                        if (fixedValue.HasValue)
                        {
                            this.XmlWriter.WriteAttributeString(
                                AtomConstants.AtomPublishingFixedAttributeName,
                                fixedValue.Value ? AtomConstants.AtomPublishingFixedYesValue : AtomConstants.AtomPublishingFixedNoValue);
                        }

                        // scheme='scheme'
                        if (scheme != null)
                        {
                            this.XmlWriter.WriteAttributeString(AtomConstants.AtomCategorySchemeAttributeName, scheme);
                        }

                        if (categoriesCollection != null)
                        {
                            foreach (AtomCategoryMetadata category in categoriesCollection)
                            {
                                // <atom:category/>
                                this.WriteCategory(AtomConstants.NonEmptyAtomNamespacePrefix, category.Term, category.Scheme, category.Label);
                            }
                        }
                    }

                    // </app:categories>
                    this.XmlWriter.WriteEndElement();
                }
            }
        }
 protected AtomTextConstruct ReadAtomTextConstruct()
 {
     AtomTextConstruct construct = new AtomTextConstruct();
     string str = null;
     while (base.XmlReader.MoveToNextAttribute())
     {
         if (base.XmlReader.NamespaceEquals(this.EmptyNamespace) && (string.CompareOrdinal(base.XmlReader.LocalName, "type") == 0))
         {
             str = base.XmlReader.Value;
         }
     }
     base.XmlReader.MoveToElement();
     if (str == null)
     {
         construct.Kind = AtomTextConstructKind.Text;
     }
     else
     {
         string str2 = str;
         if (str2 == null)
         {
             goto Label_00AE;
         }
         if (!(str2 == "text"))
         {
             if (str2 == "html")
             {
                 construct.Kind = AtomTextConstructKind.Html;
                 goto Label_00C5;
             }
             if (str2 == "xhtml")
             {
                 construct.Kind = AtomTextConstructKind.Xhtml;
                 goto Label_00C5;
             }
             goto Label_00AE;
         }
         construct.Kind = AtomTextConstructKind.Text;
     }
     goto Label_00C5;
 Label_00AE:
     throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomEntryMetadataDeserializer_InvalidTextConstructKind(str, base.XmlReader.LocalName));
 Label_00C5:
     if (construct.Kind == AtomTextConstructKind.Xhtml)
     {
         construct.Text = base.XmlReader.ReadInnerXml();
         return construct;
     }
     construct.Text = this.ReadElementStringValue();
     return construct;
 }
 internal void WriteWorkspaceMetadata(ODataWorkspace workspace)
 {
     AtomWorkspaceMetadata annotation = workspace.GetAnnotation<AtomWorkspaceMetadata>();
     AtomTextConstruct textConstruct = null;
     if (annotation != null)
     {
         textConstruct = annotation.Title;
     }
     if (textConstruct == null)
     {
         textConstruct = new AtomTextConstruct {
             Text = "Default"
         };
     }
     if (base.UseServerFormatBehavior && (textConstruct.Kind == AtomTextConstructKind.Text))
     {
         base.WriteElementWithTextContent("atom", "title", "http://www.w3.org/2005/Atom", textConstruct.Text);
     }
     else
     {
         base.WriteTextConstruct("atom", "title", "http://www.w3.org/2005/Atom", textConstruct);
     }
 }
示例#17
0
 private void WriteFeedElements(IExpandedResult expanded, IEnumerator elements, ResourceType expectedType, string title, Uri relativeUri, Uri absoluteUri, bool hasMoved, bool topLevel)
 {
     ODataFeed feed = new ODataFeed {
         Id = absoluteUri.AbsoluteUri
     };
     AtomFeedMetadata annotation = new AtomFeedMetadata();
     feed.SetAnnotation<AtomFeedMetadata>(annotation);
     AtomTextConstruct construct = new AtomTextConstruct {
         Text = title
     };
     annotation.Title = construct;
     AtomLinkMetadata metadata2 = new AtomLinkMetadata {
         Href = relativeUri,
         Title = title
     };
     annotation.SelfLink = metadata2;
     bool flag = false;
     if (topLevel && (base.RequestDescription.CountOption == RequestQueryCountOption.Inline))
     {
         flag = this.contentFormat == ODataFormat.VerboseJson;
         if (!flag)
         {
             feed.Count = new long?(base.RequestDescription.CountValue);
         }
     }
     this.odataWriter.WriteStart(feed);
     try
     {
         object lastObject = null;
         IExpandedResult skipTokenExpandedResult = null;
         while (hasMoved)
         {
             object current = elements.Current;
             IExpandedResult skipToken = base.GetSkipToken(expanded);
             if (current != null)
             {
                 IExpandedResult result3 = current as IExpandedResult;
                 if (result3 != null)
                 {
                     expanded = result3;
                     current = Serializer.GetExpandedElement(expanded);
                     skipToken = base.GetSkipToken(expanded);
                 }
                 this.WriteEntry(expanded, current, true, expectedType);
             }
             hasMoved = elements.MoveNext();
             lastObject = current;
             skipTokenExpandedResult = skipToken;
         }
         if (flag)
         {
             feed.Count = new long?(base.RequestDescription.CountValue);
         }
         if (base.NeedNextPageLink(elements))
         {
             feed.NextPageLink = base.GetNextLinkUri(lastObject, skipTokenExpandedResult, absoluteUri);
         }
     }
     finally
     {
         if (!topLevel)
         {
             WebUtil.Dispose(elements);
         }
     }
     this.odataWriter.WriteEnd();
 }
 internal void WriteTextConstruct(string prefix, string localName, string ns, AtomTextConstruct textConstruct)
 {
     base.XmlWriter.WriteStartElement(prefix, localName, ns);
     if (textConstruct != null)
     {
         AtomTextConstructKind kind = textConstruct.Kind;
         base.XmlWriter.WriteAttributeString("type", AtomValueUtils.ToString(textConstruct.Kind));
         string text = textConstruct.Text;
         if (text == null)
         {
             text = string.Empty;
         }
         if (kind == AtomTextConstructKind.Xhtml)
         {
             ODataAtomWriterUtils.WriteRaw(base.XmlWriter, text);
         }
         else
         {
             ODataAtomWriterUtils.WriteString(base.XmlWriter, text);
         }
     }
     base.XmlWriter.WriteEndElement();
 }
        internal void WriteEntryMetadata(AtomEntryMetadata entryMetadata, AtomEntryMetadata epmEntryMetadata, string updatedTime)
        {
            AtomEntryMetadata metadata = ODataAtomWriterMetadataEpmMergeUtils.MergeCustomAndEpmEntryMetadata(entryMetadata, epmEntryMetadata, base.MessageWriterSettings.WriterBehavior);

            if (metadata == null)
            {
                base.WriteEmptyElement("", "title", "http://www.w3.org/2005/Atom");
                base.WriteElementWithTextContent("", "updated", "http://www.w3.org/2005/Atom", updatedTime);
                base.WriteEmptyAuthor();
            }
            else
            {
                base.WriteTextConstruct("", "title", "http://www.w3.org/2005/Atom", metadata.Title);
                AtomTextConstruct summary = metadata.Summary;
                if (summary != null)
                {
                    base.WriteTextConstruct("", "summary", "http://www.w3.org/2005/Atom", summary);
                }
                string textContent = base.UseClientFormatBehavior ? metadata.PublishedString : (metadata.Published.HasValue ? ODataAtomConvert.ToAtomString(metadata.Published.Value) : null);
                if (textContent != null)
                {
                    base.WriteElementWithTextContent("", "published", "http://www.w3.org/2005/Atom", textContent);
                }
                string str2 = base.UseClientFormatBehavior ? metadata.UpdatedString : (metadata.Updated.HasValue ? ODataAtomConvert.ToAtomString(metadata.Updated.Value) : null);
                str2 = str2 ?? updatedTime;
                base.WriteElementWithTextContent("", "updated", "http://www.w3.org/2005/Atom", str2);
                bool flag = false;
                IEnumerable <AtomPersonMetadata> authors = metadata.Authors;
                if (authors != null)
                {
                    foreach (AtomPersonMetadata metadata2 in authors)
                    {
                        if (metadata2 == null)
                        {
                            throw new ODataException(Strings.ODataAtomWriterMetadataUtils_AuthorMetadataMustNotContainNull);
                        }
                        base.XmlWriter.WriteStartElement("", "author", "http://www.w3.org/2005/Atom");
                        base.WritePersonMetadata(metadata2);
                        base.XmlWriter.WriteEndElement();
                        flag = true;
                    }
                }
                if (!flag)
                {
                    base.WriteEmptyAuthor();
                }
                IEnumerable <AtomPersonMetadata> contributors = metadata.Contributors;
                if (contributors != null)
                {
                    foreach (AtomPersonMetadata metadata3 in contributors)
                    {
                        if (metadata3 == null)
                        {
                            throw new ODataException(Strings.ODataAtomWriterMetadataUtils_ContributorMetadataMustNotContainNull);
                        }
                        base.XmlWriter.WriteStartElement("", "contributor", "http://www.w3.org/2005/Atom");
                        base.WritePersonMetadata(metadata3);
                        base.XmlWriter.WriteEndElement();
                    }
                }
                IEnumerable <AtomLinkMetadata> links = metadata.Links;
                if (links != null)
                {
                    foreach (AtomLinkMetadata metadata4 in links)
                    {
                        if (metadata4 == null)
                        {
                            throw new ODataException(Strings.ODataAtomWriterMetadataUtils_LinkMetadataMustNotContainNull);
                        }
                        base.WriteAtomLink(metadata4, null);
                    }
                }
                IEnumerable <AtomCategoryMetadata> categories = metadata.Categories;
                if (categories != null)
                {
                    foreach (AtomCategoryMetadata metadata5 in categories)
                    {
                        if (metadata5 == null)
                        {
                            throw new ODataException(Strings.ODataAtomWriterMetadataUtils_CategoryMetadataMustNotContainNull);
                        }
                        base.WriteCategory(metadata5);
                    }
                }
                if (metadata.Rights != null)
                {
                    base.WriteTextConstruct("", "rights", "http://www.w3.org/2005/Atom", metadata.Rights);
                }
                AtomFeedMetadata source = metadata.Source;
                if (source != null)
                {
                    bool flag2;
                    base.XmlWriter.WriteStartElement("", "source", "http://www.w3.org/2005/Atom");
                    this.SourceMetadataSerializer.WriteFeedMetadata(source, null, updatedTime, out flag2);
                    base.XmlWriter.WriteEndElement();
                }
            }
        }
示例#20
0
        internal void WriteEntryMetadata(AtomEntryMetadata entryMetadata, AtomEntryMetadata epmEntryMetadata, string updatedTime)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(!string.IsNullOrEmpty(updatedTime), "!string.IsNullOrEmpty(updatedTime)");
#if DEBUG
            DateTimeOffset tempDateTimeOffset;
            Debug.Assert(DateTimeOffset.TryParse(updatedTime, out tempDateTimeOffset), "DateTimeOffset.TryParse(updatedTime, out tempDateTimeOffset)");
#endif

            // TODO: implement the rule around authors (an entry has to have an author directly or in the <entry:source> unless the feed has an author).
            //               currently we make all entries have an author.
            AtomEntryMetadata mergedEntryMetadata = ODataAtomWriterMetadataEpmMergeUtils.MergeCustomAndEpmEntryMetadata(entryMetadata, epmEntryMetadata, this.MessageWriterSettings.WriterBehavior);
            if (mergedEntryMetadata == null)
            {
                // write all required metadata elements with default content

                // <atom:title></atom:title>
                this.WriteEmptyElement(
                    AtomConstants.AtomNamespacePrefix,
                    AtomConstants.AtomTitleElementName,
                    AtomConstants.AtomNamespace);

                // <atom:updated>dateTimeOffset</atom:updated>
                // NOTE: the <updated> element is required and if not specified we use a single 'default/current' date/time for the whole payload.
                this.WriteElementWithTextContent(
                    AtomConstants.AtomNamespacePrefix,
                    AtomConstants.AtomUpdatedElementName,
                    AtomConstants.AtomNamespace,
                    updatedTime);

                this.WriteEmptyAuthor();
            }
            else
            {
                // <atom:title>text</atom:title>
                // NOTE: writes an empty element even if no title was specified since the title is required
                this.WriteTextConstruct(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace, mergedEntryMetadata.Title);

                AtomTextConstruct summary = mergedEntryMetadata.Summary;
                if (summary != null)
                {
                    // <atom:summary>text</atom:summary>
                    this.WriteTextConstruct(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomSummaryElementName, AtomConstants.AtomNamespace, summary);
                }

                string published = this.UseClientFormatBehavior
                    ? mergedEntryMetadata.PublishedString
                    : mergedEntryMetadata.Published.HasValue
                        ? ODataAtomConvert.ToAtomString(mergedEntryMetadata.Published.Value)
                        : null;
                if (published != null)
                {
                    // <atom:published>dateTimeOffset</atom:published>
                    this.WriteElementWithTextContent(
                        AtomConstants.AtomNamespacePrefix,
                        AtomConstants.AtomPublishedElementName,
                        AtomConstants.AtomNamespace,
                        published);
                }

                // <atom:updated>date</atom:updated>
                string updated = this.UseClientFormatBehavior
                    ? mergedEntryMetadata.UpdatedString
                    : mergedEntryMetadata.Updated.HasValue
                        ? ODataAtomConvert.ToAtomString(mergedEntryMetadata.Updated.Value)
                        : null;

                // NOTE: the <updated> element is required and if not specified we use a single 'default/current' date/time for the whole payload.
                updated = updated ?? updatedTime;
                this.WriteElementWithTextContent(
                    AtomConstants.AtomNamespacePrefix,
                    AtomConstants.AtomUpdatedElementName,
                    AtomConstants.AtomNamespace,
                    updated);

                bool wroteAuthor = false;
                IEnumerable <AtomPersonMetadata> authors = mergedEntryMetadata.Authors;
                if (authors != null)
                {
                    foreach (AtomPersonMetadata author in authors)
                    {
                        if (author == null)
                        {
                            throw new ODataException(ODataErrorStrings.ODataAtomWriterMetadataUtils_AuthorMetadataMustNotContainNull);
                        }

                        // <atom:author>author data</atom:author>
                        this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomAuthorElementName, AtomConstants.AtomNamespace);
                        this.WritePersonMetadata(author);
                        this.XmlWriter.WriteEndElement();
                        wroteAuthor = true;
                    }
                }

                if (!wroteAuthor)
                {
                    // write empty authors since they are required
                    this.WriteEmptyAuthor();
                }

                IEnumerable <AtomPersonMetadata> contributors = mergedEntryMetadata.Contributors;
                if (contributors != null)
                {
                    foreach (AtomPersonMetadata contributor in contributors)
                    {
                        if (contributor == null)
                        {
                            throw new ODataException(ODataErrorStrings.ODataAtomWriterMetadataUtils_ContributorMetadataMustNotContainNull);
                        }

                        // <atom:contributor>contributor data</atom:contributor>
                        this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomContributorElementName, AtomConstants.AtomNamespace);
                        this.WritePersonMetadata(contributor);
                        this.XmlWriter.WriteEndElement();
                    }
                }

                IEnumerable <AtomLinkMetadata> links = mergedEntryMetadata.Links;
                if (links != null)
                {
                    foreach (AtomLinkMetadata link in links)
                    {
                        if (link == null)
                        {
                            throw new ODataException(ODataErrorStrings.ODataAtomWriterMetadataUtils_LinkMetadataMustNotContainNull);
                        }

                        // <atom:link>...</atom:link>
                        this.WriteAtomLink(link, null /*edit-link-etag*/);
                    }
                }

                IEnumerable <AtomCategoryMetadata> categories = mergedEntryMetadata.Categories;
                if (categories != null)
                {
                    foreach (AtomCategoryMetadata category in categories)
                    {
                        if (category == null)
                        {
                            throw new ODataException(ODataErrorStrings.ODataAtomWriterMetadataUtils_CategoryMetadataMustNotContainNull);
                        }

                        // <atom:category term="..." scheme="..." label="..."></atom:category>
                        this.WriteCategory(category);
                    }
                }

                if (mergedEntryMetadata.Rights != null)
                {
                    // <atom:rights>rights</atom:rights>
                    this.WriteTextConstruct(
                        AtomConstants.AtomNamespacePrefix,
                        AtomConstants.AtomRightsElementName,
                        AtomConstants.AtomNamespace,
                        mergedEntryMetadata.Rights);
                }

                AtomFeedMetadata source = mergedEntryMetadata.Source;
                if (source != null)
                {
                    // <atom:source>
                    this.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomSourceElementName, AtomConstants.AtomNamespace);

                    bool authorWritten;
                    this.SourceMetadataSerializer.WriteFeedMetadata(source, null /* feed */, updatedTime, out authorWritten);

                    // </atom:source>
                    this.XmlWriter.WriteEndElement();
                }
            }
        }
示例#21
0
 private void ReadTextConstructEpm(EpmTargetPathSegment targetSegment, AtomTextConstruct textConstruct)
 {
     if ((textConstruct != null) && (textConstruct.Text != null))
     {
         base.SetEntryEpmValue(targetSegment.EpmInfo, textConstruct.Text);
     }
 }