Exemplo n.º 1
0
        /// <summary>
        /// Annotates the resource collection with out-of-line app:categories values.
        /// </summary>
        /// <param name="resourceCollection">The resource collection to annotate.</param>
        /// <param name="uri">The value of the app:categories href property.</param>
        /// <returns>The resource collection with the annotation applied.</returns>
        public static ResourceCollectionInstance AppOutOfLineCategories(this ResourceCollectionInstance resourceCollection, string uri)
        {
            ExceptionUtilities.CheckArgumentNotNull(resourceCollection, "resourceCollection");

            resourceCollection.AddAnnotation(CreateAppElement("categories", null, XmlTreeAnnotation.AtomAttribute(TestAtomConstants.AtomHRefAttributeName, uri)));
            return(resourceCollection);
        }
Exemplo n.º 2
0
        private static T WithDefaultAtomTitleAnnotation <T>(this T payloadElement)
            where T : ODataPayloadElement
        {
            XmlTreeAnnotation title = XmlTreeAnnotation.Atom("title", null);

            title.Children.Add(XmlTreeAnnotation.AtomAttribute("type", "text"));
            payloadElement.Annotations.Add(title);
            return(payloadElement);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the XmlTreeAnnotation annotations that represent the attributes with non-null values.
        /// </summary>
        /// <param name="attributeNameValuePairs">The attribute name-value pairs to convert to Atom attribute annotations.</param>
        /// <returns>An XmlTreeAnnotation for each non-null value attribute.</returns>
        private static XmlTreeAnnotation[] CreateAtomAttributes(params KeyValuePair <string, string>[] attributeNameValuePairs)
        {
            var atomAttributes = new List <XmlTreeAnnotation>();

            foreach (var attribute in attributeNameValuePairs.Where(p => p.Value != null))
            {
                atomAttributes.Add(XmlTreeAnnotation.AtomAttribute(attribute.Key, attribute.Value));
            }
            return(atomAttributes.ToArray());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Computes the XmlTreeAnnotation for a stream property from the <see cref="NamedStreamAtomLinkMetadataAnnotation"/>.
        /// </summary>
        /// <param name="streampProperty">The stream property to compute the Xml annotation for.</param>
        /// <param name="relation">The relation of the link we are converting</param>
        /// <returns>The <see cref="XmlTreeAnnotation"/> for the link with the specified <paramref name="relation"/>.</returns>
        private XmlTreeAnnotation GetStreamPropertyLinkXmlTreeAnnotation(NamedStreamInstance streampProperty, string relation)
        {
            // Look it up again since it was created above.
            NamedStreamAtomLinkMetadataAnnotation linkAnnotation = streampProperty.Annotations.OfType <NamedStreamAtomLinkMetadataAnnotation>().SingleOrDefault(a => a.Relation == relation);

            if (linkAnnotation == null)
            {
                return(null);
            }

            List <XmlTreeAnnotation> attributes = new List <XmlTreeAnnotation>();

            if (linkAnnotation.Href != null)
            {
                attributes.Add(XmlTreeAnnotation.AtomAttribute(TestAtomConstants.AtomLinkHrefAttributeName, linkAnnotation.Href));
            }

            if (linkAnnotation.HrefLang != null)
            {
                attributes.Add(XmlTreeAnnotation.AtomAttribute(TestAtomConstants.AtomLinkHrefLangAttributeName, linkAnnotation.HrefLang));
            }

            if (linkAnnotation.Length != null)
            {
                attributes.Add(XmlTreeAnnotation.AtomAttribute(TestAtomConstants.AtomLinkLengthAttributeName, linkAnnotation.Length));
            }

            if (linkAnnotation.Relation != null)
            {
                attributes.Add(XmlTreeAnnotation.AtomAttribute(TestAtomConstants.AtomLinkRelationAttributeName, linkAnnotation.Relation));
            }

            if (linkAnnotation.Title != null)
            {
                attributes.Add(XmlTreeAnnotation.AtomAttribute(TestAtomConstants.AtomLinkTitleAttributeName, linkAnnotation.Title));
            }

            if (linkAnnotation.Type != null)
            {
                attributes.Add(XmlTreeAnnotation.AtomAttribute(TestAtomConstants.AtomLinkTypeAttributeName, linkAnnotation.Type));
            }

            return(XmlTreeAnnotation.Atom(TestAtomConstants.AtomLinkElementName, null, attributes.ToArray()));
        }
        /// <summary>
        /// Normalizes an Atom link property value between an XmlTreeAnnotation and another property.
        /// </summary>
        /// <typeparam name="T">The type of payload element.</typeparam>
        /// <param name="payloadElement">The payload element to normalize.</param>
        /// <param name="relationValue">The relation value of the link to normalize.</param>
        /// <param name="attributeName">The name of the link attribute to normalize.</param>
        /// <param name="getOtherLinkValue">Function for retrieving the other value for the link property.</param>
        /// <param name="setOtherLinkValue">Delegate for setting the other value for the link property.</param>
        private void NormalizeLinkValue <T>(T payloadElement, string relationValue, string attributeName, Func <T, string> getOtherLinkValue, Action <T, string> setOtherLinkValue) where T : ODataPayloadElement
        {
            string            otherLinkValue        = getOtherLinkValue(payloadElement);
            XmlTreeAnnotation linkXmlTreeAnnotation = payloadElement.Annotations
                                                      .OfType <XmlTreeAnnotation>()
                                                      .SingleOrDefault(a => a.LocalName.Equals(TestAtomConstants.AtomLinkElementName) && HasAttribute(a, TestAtomConstants.AtomLinkRelationAttributeName, relationValue));

            if (otherLinkValue != null)
            {
                if (linkXmlTreeAnnotation != null)
                {
                    var linkAttribute = GetAttributeAnnotation(linkXmlTreeAnnotation, attributeName);
                    if (linkAttribute == null)
                    {
                        linkXmlTreeAnnotation.Children.Add(XmlTreeAnnotation.AtomAttribute(attributeName, otherLinkValue));
                    }
                    else if (linkAttribute.PropertyValue != otherLinkValue)
                    {
                        ExceptionUtilities.Assert(otherLinkValue.Equals(linkAttribute.PropertyValue), attributeName + " value for link '" + relationValue + "' does not match value on Xml Tree");
                    }
                }
                else
                {
                    // Add an xml tree annotation to match the value from the other source.
                    payloadElement.Add(
                        XmlTreeAnnotation.Atom(
                            TestAtomConstants.AtomLinkElementName,
                            null,
                            XmlTreeAnnotation.AtomAttribute(TestAtomConstants.AtomLinkRelationAttributeName, relationValue),
                            XmlTreeAnnotation.AtomAttribute(attributeName, otherLinkValue)));
                }
            }
            else if (linkXmlTreeAnnotation != null)
            {
                // Set the other source to match the atom:link href value of the annotation
                var linkAttribute = GetAttributeAnnotation(linkXmlTreeAnnotation, attributeName);
                if (linkAttribute != null)
                {
                    setOtherLinkValue(payloadElement, linkAttribute.PropertyValue);
                }
            }
        }