/// <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)
        {
            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();
        }
        /// <summary>
        /// Writes an Xml element with the specified primitive value as content.
        /// </summary>
        /// <param name="writer">The Xml writer to write to.</param>
        /// <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 static void WriteTextConstruct(XmlWriter writer, string prefix, string localName, string ns, AtomTextConstruct textConstruct)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(prefix != null, "prefix != null");
            Debug.Assert(!string.IsNullOrEmpty(localName), "!string.IsNullOrEmpty(localName)");
            Debug.Assert(!string.IsNullOrEmpty(ns), "!string.IsNullOrEmpty(ns)");

            writer.WriteStartElement(prefix, localName, ns);

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

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

                string textValue = textConstruct.Text ?? string.Empty;
                if (textKind == AtomTextConstructKind.Xhtml)
                {
                    writer.WriteRaw(textValue);
                }
                else
                {
                    writer.WriteString(textValue);
                }
            }

            writer.WriteEndElement();
        }
Exemple #3
0
        internal static string ToString(AtomTextConstructKind textConstructKind)
        {
            switch (textConstructKind)
            {
            case AtomTextConstructKind.Text:
                return("text");

            case AtomTextConstructKind.Html:
                return("html");

            case AtomTextConstructKind.Xhtml:
                return("xhtml");
            }
            throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataAtomConvert_ToString));
        }
        /// <summary>
        /// Converts a given <see cref="AtomTextConstructKind"/> to a string appropriate for Atom format.
        /// </summary>
        /// <param name="textConstructKind">The text construct kind to convert.</param>
        /// <returns>The string version of the text construct format in Atom format.</returns>
        internal static string ToString(AtomTextConstructKind textConstructKind)
        {
            DebugUtils.CheckNoExternalCallers();

            switch (textConstructKind)
            {
                case AtomTextConstructKind.Text:
                    return AtomConstants.AtomTextConstructTextKind;
                case AtomTextConstructKind.Html:
                    return AtomConstants.AtomTextConstructHtmlKind;
                case AtomTextConstructKind.Xhtml:
                    return AtomConstants.AtomTextConstructXHtmlKind;
                default:
                    throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataAtomConvert_ToString));
            }
        }
Exemple #5
0
        /// <summary>
        /// Converts a given <see cref="AtomTextConstructKind"/> to a string appropriate for Atom format.
        /// </summary>
        /// <param name="textConstructKind">The text construct kind to convert.</param>
        /// <returns>The string version of the text construct format in Atom format.</returns>
        internal static string ToString(AtomTextConstructKind textConstructKind)
        {
            switch (textConstructKind)
            {
            case AtomTextConstructKind.Text:
                return(AtomConstants.AtomTextConstructTextKind);

            case AtomTextConstructKind.Html:
                return(AtomConstants.AtomTextConstructHtmlKind);

            case AtomTextConstructKind.Xhtml:
                return(AtomConstants.AtomTextConstructXHtmlKind);

            default:
                throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataAtomConvert_ToString));
            }
        }
            /// <summary>
            /// Converts a given <see cref="AtomTextConstructKind"/> to a string appropriate for Atom format.
            /// </summary>
            /// <param name="textConstructKind">The text construct kind to convert.</param>
            /// <returns>The string version of the text construct format in Atom format.</returns>
            private static string ToString(AtomTextConstructKind textConstructKind)
            {
                // This code copied from product's internal AtomValueUtils.ToString method
                ExceptionUtilities.CheckArgumentNotNull(textConstructKind, "textConstructorKind");

                switch (textConstructKind)
                {
                case AtomTextConstructKind.Text:
                    return(TestAtomConstants.AtomTextConstructTextKind);

                case AtomTextConstructKind.Html:
                    return(TestAtomConstants.AtomTextConstructHtmlKind);

                case AtomTextConstructKind.Xhtml:
                    return(TestAtomConstants.AtomTextConstructXHtmlKind);

                default:
                    throw new TaupoArgumentException("Unknown AtomTextConstructKind " + textConstructKind.ToString());
                }
            }
 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();
 }
Exemple #8
0
        private static AtomFeedMetadata CreateFeedMetadata(IEnumerable <XmlTreeAnnotation> children, ODataFeed feed)
        {
            AtomFeedMetadata metadata = null;

            foreach (XmlTreeAnnotation epmTree in children)
            {
                if (epmTree.NamespaceName == TestAtomConstants.AtomNamespace)
                {
                    if (metadata == null)
                    {
                        metadata = new AtomFeedMetadata();
                    }

                    string localName = epmTree.LocalName;
                    if (localName == TestAtomConstants.AtomAuthorElementName)
                    {
                        AtomPersonMetadata author = CreateAuthorMetadata(epmTree.Children);

                        List <AtomPersonMetadata> authors;
                        if (metadata.Authors == null)
                        {
                            authors          = new List <AtomPersonMetadata>();
                            metadata.Authors = authors;
                        }
                        else
                        {
                            authors = (List <AtomPersonMetadata>)metadata.Authors;
                        }
                        authors.Add(author);
                    }
                    else if (localName == TestAtomConstants.AtomCategoryElementName)
                    {
                        AtomCategoryMetadata category = CreateCategoryMetadata(epmTree.Children);

                        List <AtomCategoryMetadata> categories;
                        if (metadata.Categories == null)
                        {
                            categories          = new List <AtomCategoryMetadata>();
                            metadata.Categories = categories;
                        }
                        else
                        {
                            categories = (List <AtomCategoryMetadata>)metadata.Categories;
                        }
                        categories.Add(category);
                    }
                    else if (localName == TestAtomConstants.AtomContributorElementName)
                    {
                        AtomPersonMetadata contributor = CreateAuthorMetadata(epmTree.Children);

                        List <AtomPersonMetadata> contributors;
                        if (metadata.Contributors == null)
                        {
                            contributors          = new List <AtomPersonMetadata>();
                            metadata.Contributors = contributors;
                        }
                        else
                        {
                            contributors = (List <AtomPersonMetadata>)metadata.Contributors;
                        }
                        contributors.Add(contributor);
                    }
                    else if (localName == TestAtomConstants.AtomGeneratorElementName)
                    {
                        metadata.Generator = CreateGeneratorMetadata(epmTree);
                    }
                    else if (localName == TestAtomConstants.AtomIconElementName)
                    {
                        metadata.Icon = string.IsNullOrEmpty(epmTree.PropertyValue) ? null : new Uri(epmTree.PropertyValue);
                    }
                    else if (localName == TestAtomConstants.AtomIdElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        Uri id = string.IsNullOrEmpty(epmTree.PropertyValue) ? null : new Uri(epmTree.PropertyValue, UriKind.Absolute);
                        if (feed == null)
                        {
                            // we are creating the metadata for an entry's 'source' metadata;
                            // we don't have a feed to store the Id on so it has to go into metadata
                            metadata.SourceId = id;
                        }
                        else
                        {
                            feed.Id = id;
                        }
                    }
                    else if (localName == TestAtomConstants.AtomLinkElementName)
                    {
                        AtomLinkMetadata link = CreateLinkMetadata(epmTree.Children);

                        List <AtomLinkMetadata> links;
                        if (metadata.Links == null)
                        {
                            links          = new List <AtomLinkMetadata>();
                            metadata.Links = links;
                        }
                        else
                        {
                            links = (List <AtomLinkMetadata>)metadata.Contributors;
                        }
                        links.Add(link);
                    }
                    else if (localName == TestAtomConstants.AtomLogoElementName)
                    {
                        metadata.Logo = string.IsNullOrEmpty(epmTree.PropertyValue) ? null : new Uri(epmTree.PropertyValue);
                    }
                    else if (localName == TestAtomConstants.AtomRightsElementName)
                    {
                        AtomTextConstructKind atomConstructKind = GetAtomConstructKind(epmTree.Children);
                        metadata.Rights = new AtomTextConstruct {
                            Kind = atomConstructKind, Text = epmTree.PropertyValue
                        };
                    }
                    else if (localName == TestAtomConstants.AtomSubtitleElementName)
                    {
                        AtomTextConstructKind atomConstructKind = GetAtomConstructKind(epmTree.Children);
                        metadata.Subtitle = new AtomTextConstruct {
                            Kind = atomConstructKind, Text = epmTree.PropertyValue
                        };
                    }
                    else if (localName == TestAtomConstants.AtomTitleElementName)
                    {
                        AtomTextConstructKind atomConstructKind = GetAtomConstructKind(epmTree.Children);
                        metadata.Title = new AtomTextConstruct {
                            Kind = atomConstructKind, Text = epmTree.PropertyValue
                        };
                    }
                    else if (localName == TestAtomConstants.AtomUpdatedElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        metadata.Updated = string.IsNullOrEmpty(epmTree.PropertyValue) ? (DateTimeOffset?)null : DateTimeOffset.Parse(epmTree.PropertyValue);
                    }
                    else
                    {
                        throw new NotSupportedException("Unsupported atom metadata found!");
                    }
                }
            }

            return(metadata);
        }
Exemple #9
0
        private static void AddEntryMetadata(EntityInstance payloadElement, ODataEntry entry)
        {
            AtomEntryMetadata metadata = null;

            foreach (XmlTreeAnnotation epmTree in payloadElement.Annotations.OfType <XmlTreeAnnotation>())
            {
                if (epmTree.NamespaceName == TestAtomConstants.AtomNamespace)
                {
                    if (metadata == null)
                    {
                        metadata = new AtomEntryMetadata();
                    }

                    string localName = epmTree.LocalName;
                    if (localName == TestAtomConstants.AtomAuthorElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        AtomPersonMetadata author = CreateAuthorMetadata(epmTree.Children);

                        List <AtomPersonMetadata> authors;
                        if (metadata.Authors == null)
                        {
                            authors          = new List <AtomPersonMetadata>();
                            metadata.Authors = authors;
                        }
                        else
                        {
                            authors = (List <AtomPersonMetadata>)metadata.Authors;
                        }
                        authors.Add(author);
                    }
                    else if (localName == TestAtomConstants.AtomCategoryElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        AtomCategoryMetadata category = CreateCategoryMetadata(epmTree.Children);

                        List <AtomCategoryMetadata> categories;
                        if (metadata.Categories == null)
                        {
                            categories          = new List <AtomCategoryMetadata>();
                            metadata.Categories = categories;
                        }
                        else
                        {
                            categories = (List <AtomCategoryMetadata>)metadata.Categories;
                        }
                        categories.Add(category);
                    }
                    else if (localName == TestAtomConstants.AtomContributorElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        AtomPersonMetadata contributor = CreateAuthorMetadata(epmTree.Children);

                        List <AtomPersonMetadata> contributors;
                        if (metadata.Contributors == null)
                        {
                            contributors          = new List <AtomPersonMetadata>();
                            metadata.Contributors = contributors;
                        }
                        else
                        {
                            contributors = (List <AtomPersonMetadata>)metadata.Contributors;
                        }
                        contributors.Add(contributor);
                    }
                    else if (localName == TestAtomConstants.AtomIdElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        entry.Id = string.IsNullOrEmpty(epmTree.PropertyValue) ? null : new Uri(epmTree.PropertyValue);
                    }
                    else if (localName == TestAtomConstants.AtomLinkElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        AtomLinkMetadata link = CreateLinkMetadata(epmTree.Children);

                        List <AtomLinkMetadata> links;
                        if (metadata.Links == null)
                        {
                            links          = new List <AtomLinkMetadata>();
                            metadata.Links = links;
                        }
                        else
                        {
                            links = (List <AtomLinkMetadata>)metadata.Links;
                        }
                        links.Add(link);
                    }
                    else if (localName == TestAtomConstants.AtomPublishedElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        metadata.Published = string.IsNullOrEmpty(epmTree.PropertyValue) ? (DateTimeOffset?)null : DateTimeOffset.Parse(epmTree.PropertyValue);
                    }
                    else if (localName == TestAtomConstants.AtomRightsElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        AtomTextConstructKind atomConstructKind = GetAtomConstructKind(epmTree.Children);
                        metadata.Rights = new AtomTextConstruct {
                            Kind = atomConstructKind, Text = epmTree.PropertyValue
                        };
                    }
                    else if (localName == TestAtomConstants.AtomSourceElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        metadata.Source = CreateFeedMetadata(epmTree.Children, null);
                    }
                    else if (localName == TestAtomConstants.AtomSummaryElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        AtomTextConstructKind atomConstructKind = GetAtomConstructKind(epmTree.Children);
                        metadata.Summary = new AtomTextConstruct {
                            Kind = atomConstructKind, Text = epmTree.PropertyValue
                        };
                    }
                    else if (localName == TestAtomConstants.AtomTitleElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        AtomTextConstructKind atomConstructKind = GetAtomConstructKind(epmTree.Children);
                        metadata.Title = new AtomTextConstruct {
                            Kind = atomConstructKind, Text = epmTree.PropertyValue
                        };
                    }
                    else if (localName == TestAtomConstants.AtomUpdatedElementName)
                    {
                        Debug.Assert(!epmTree.IsAttribute);
                        metadata.Updated = string.IsNullOrEmpty(epmTree.PropertyValue) ? (DateTimeOffset?)null : DateTimeOffset.Parse(epmTree.PropertyValue);
                    }
                    else
                    {
                        throw new NotSupportedException("Unsupported atom metadata '" + localName + "' found for entry!");
                    }
                }
            }

            // Fix up metadata for baselining
            metadata = metadata.Fixup();

            if (metadata != null)
            {
                entry.SetAnnotation <AtomEntryMetadata>(metadata);
            }
        }
            /// <summary>
            /// Converts a given <see cref="AtomTextConstructKind"/> to a string appropriate for Atom format.
            /// </summary>
            /// <param name="textConstructKind">The text construct kind to convert.</param>
            /// <returns>The string version of the text construct format in Atom format.</returns>
            private static string ToString(AtomTextConstructKind textConstructKind)
            {
                // This code copied from product's internal AtomValueUtils.ToString method
                ExceptionUtilities.CheckArgumentNotNull(textConstructKind, "textConstructorKind");

                switch (textConstructKind)
                {
                    case AtomTextConstructKind.Text:
                        return TestAtomConstants.AtomTextConstructTextKind;
                    case AtomTextConstructKind.Html:
                        return TestAtomConstants.AtomTextConstructHtmlKind;
                    case AtomTextConstructKind.Xhtml:
                        return TestAtomConstants.AtomTextConstructXHtmlKind;
                    default:
                        throw new TaupoArgumentException("Unknown AtomTextConstructKind " + textConstructKind.ToString());
                }
            }
Exemple #11
0
        internal static string ToString(AtomTextConstructKind textConstructKind)
        {
            switch (textConstructKind)
            {
                case AtomTextConstructKind.Text:
                    return "text";

                case AtomTextConstructKind.Html:
                    return "html";

                case AtomTextConstructKind.Xhtml:
                    return "xhtml";
            }
            throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataAtomConvert_ToString));
        }