コード例 #1
0
        protected AtomPersonMetadata ReadAtomPersonConstruct(EpmTargetPathSegment epmTargetPathSegment)
        {
            AtomPersonMetadata metadata = new AtomPersonMetadata();

            if (base.XmlReader.IsEmptyElement)
            {
                goto Label_011B;
            }
            base.XmlReader.Read();
Label_0022:
            switch (base.XmlReader.NodeType)
            {
            case XmlNodeType.Element:
                EpmTargetPathSegment segment;
                string str2;
                if ((base.XmlReader.NamespaceEquals(this.AtomNamespace) && this.ShouldReadElement(epmTargetPathSegment, base.XmlReader.LocalName, out segment)) && ((str2 = base.XmlReader.LocalName) != null))
                {
                    if (!(str2 == "name"))
                    {
                        if (str2 == "uri")
                        {
                            Uri    xmlBaseUri     = base.XmlReader.XmlBaseUri;
                            string uriFromPayload = this.ReadElementStringValue();
                            if (segment != null)
                            {
                                metadata.UriFromEpm = uriFromPayload;
                            }
                            if (this.ReadAtomMetadata)
                            {
                                metadata.Uri = base.ProcessUriFromPayload(uriFromPayload, xmlBaseUri);
                            }
                            goto Label_0109;
                        }
                        if (str2 == "email")
                        {
                            metadata.Email = this.ReadElementStringValue();
                            goto Label_0109;
                        }
                    }
                    else
                    {
                        metadata.Name = this.ReadElementStringValue();
                        goto Label_0109;
                    }
                }
                break;

            case XmlNodeType.EndElement:
                goto Label_0109;
            }
            base.XmlReader.Skip();
Label_0109:
            if (base.XmlReader.NodeType != XmlNodeType.EndElement)
            {
                goto Label_0022;
            }
Label_011B:
            base.XmlReader.Read();
            return(metadata);
        }
コード例 #2
0
 private void WriteParentSegment(EpmTargetPathSegment targetSegment, object epmValueCache, IEdmTypeReference typeReference)
 {
     if (targetSegment.SegmentName == "author")
     {
         AtomPersonMetadata item = this.WritePersonEpm(targetSegment, epmValueCache, typeReference);
         if (item != null)
         {
             List <AtomPersonMetadata> authors = (List <AtomPersonMetadata>) this.entryMetadata.Authors;
             if (authors == null)
             {
                 authors = new List <AtomPersonMetadata>();
                 this.entryMetadata.Authors = authors;
             }
             authors.Add(item);
         }
     }
     else
     {
         if (!(targetSegment.SegmentName == "contributor"))
         {
             throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_WriteParentSegment_TargetSegmentName));
         }
         AtomPersonMetadata metadata2 = this.WritePersonEpm(targetSegment, epmValueCache, typeReference);
         if (metadata2 != null)
         {
             List <AtomPersonMetadata> contributors = (List <AtomPersonMetadata>) this.entryMetadata.Contributors;
             if (contributors == null)
             {
                 contributors = new List <AtomPersonMetadata>();
                 this.entryMetadata.Contributors = contributors;
             }
             contributors.Add(metadata2);
         }
     }
 }
コード例 #3
0
        private void ReadParentSegment(EpmTargetPathSegment targetSegment, AtomEntryMetadata entryMetadata)
        {
            switch (targetSegment.SegmentName)
            {
            case "author":
            {
                AtomPersonMetadata personMetadata = entryMetadata.Authors.FirstOrDefault <AtomPersonMetadata>();
                if (personMetadata != null)
                {
                    this.ReadPersonEpm(ReaderUtils.GetPropertiesList(base.EntryState.Entry.Properties), base.EntryState.EntityType.ToTypeReference(), targetSegment, personMetadata);
                }
                return;
            }

            case "contributor":
            {
                AtomPersonMetadata metadata2 = entryMetadata.Contributors.FirstOrDefault <AtomPersonMetadata>();
                if (metadata2 != null)
                {
                    this.ReadPersonEpm(ReaderUtils.GetPropertiesList(base.EntryState.Entry.Properties), base.EntryState.EntityType.ToTypeReference(), targetSegment, metadata2);
                }
                return;
            }
            }
            throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationReader_ReadParentSegment_TargetSegmentName));
        }
コード例 #4
0
        protected AtomPersonMetadata ReadAtomPersonConstruct(EpmTargetPathSegment epmTargetPathSegment)
        {
            AtomPersonMetadata metadata = new AtomPersonMetadata();
            if (base.XmlReader.IsEmptyElement)
            {
                goto Label_011B;
            }
            base.XmlReader.Read();
        Label_0022:
            switch (base.XmlReader.NodeType)
            {
                case XmlNodeType.Element:
                    EpmTargetPathSegment segment;
                    string str2;
                    if ((base.XmlReader.NamespaceEquals(this.AtomNamespace) && this.ShouldReadElement(epmTargetPathSegment, base.XmlReader.LocalName, out segment)) && ((str2 = base.XmlReader.LocalName) != null))
                    {
                        if (!(str2 == "name"))
                        {
                            if (str2 == "uri")
                            {
                                Uri xmlBaseUri = base.XmlReader.XmlBaseUri;
                                string uriFromPayload = this.ReadElementStringValue();
                                if (segment != null)
                                {
                                    metadata.UriFromEpm = uriFromPayload;
                                }
                                if (this.ReadAtomMetadata)
                                {
                                    metadata.Uri = base.ProcessUriFromPayload(uriFromPayload, xmlBaseUri);
                                }
                                goto Label_0109;
                            }
                            if (str2 == "email")
                            {
                                metadata.Email = this.ReadElementStringValue();
                                goto Label_0109;
                            }
                        }
                        else
                        {
                            metadata.Name = this.ReadElementStringValue();
                            goto Label_0109;
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    goto Label_0109;
            }
            base.XmlReader.Skip();
        Label_0109:
            if (base.XmlReader.NodeType != XmlNodeType.EndElement)
            {
                goto Label_0022;
            }
        Label_011B:
            base.XmlReader.Read();
            return metadata;
        }
コード例 #5
0
 internal static void AddAuthorToEntryMetadata(AtomEntryMetadata entryMetadata, AtomPersonMetadata authorMetadata)
 {
     if (object.ReferenceEquals(entryMetadata.Authors, EmptyPersonsList))
     {
         entryMetadata.Authors = new ReadOnlyEnumerable<AtomPersonMetadata>();
     }
     ReaderUtils.GetSourceListOfEnumerable<AtomPersonMetadata>(entryMetadata.Authors, "Authors").Add(authorMetadata);
 }
コード例 #6
0
 internal static void AddContributorToFeedMetadata(AtomFeedMetadata feedMetadata, AtomPersonMetadata contributorMetadata)
 {
     if (object.ReferenceEquals(feedMetadata.Contributors, EmptyPersonsList))
     {
         feedMetadata.Contributors = new ReadOnlyEnumerable<AtomPersonMetadata>();
     }
     ReaderUtils.GetSourceListOfEnumerable<AtomPersonMetadata>(feedMetadata.Contributors, "Contributors").Add(contributorMetadata);
 }
コード例 #7
0
        private AtomPersonMetadata WritePersonEpm(EpmTargetPathSegment targetSegment, object epmValueCache, IEdmTypeReference typeReference)
        {
            AtomPersonMetadata metadata = null;

            foreach (EpmTargetPathSegment segment in targetSegment.SubSegments)
            {
                string str = this.GetPropertyValueAsText(segment, epmValueCache, typeReference);
                if (str != null)
                {
                    switch (segment.EpmInfo.Attribute.TargetSyndicationItem)
                    {
                    case SyndicationItemProperty.AuthorEmail:
                    case SyndicationItemProperty.ContributorEmail:
                    {
                        if ((str != null) && (str.Length > 0))
                        {
                            if (metadata == null)
                            {
                                metadata = new AtomPersonMetadata();
                            }
                            metadata.Email = str;
                        }
                        continue;
                    }

                    case SyndicationItemProperty.AuthorName:
                    case SyndicationItemProperty.ContributorName:
                    {
                        if (str != null)
                        {
                            if (metadata == null)
                            {
                                metadata = new AtomPersonMetadata();
                            }
                            metadata.Name = str;
                        }
                        continue;
                    }

                    case SyndicationItemProperty.AuthorUri:
                    case SyndicationItemProperty.ContributorUri:
                    {
                        if ((str != null) && (str.Length > 0))
                        {
                            if (metadata == null)
                            {
                                metadata = new AtomPersonMetadata();
                            }
                            metadata.UriFromEpm = str;
                        }
                        continue;
                    }
                    }
                    throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_WritePersonEpm));
                }
            }
            return(metadata);
        }
コード例 #8
0
        /// <summary>
        /// Adds a new author to entry metadata.
        /// </summary>
        /// <param name="entryMetadata">The entry metadata to add the author to.</param>
        /// <param name="authorMetadata">The author metadata to add.</param>
        internal static void AddAuthorToEntryMetadata(AtomEntryMetadata entryMetadata, AtomPersonMetadata authorMetadata)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entryMetadata != null, "entryMetadata != null");
            Debug.Assert(authorMetadata != null, "authorMetadata != null");

            if (object.ReferenceEquals(entryMetadata.Authors, EmptyPersonsList))
            {
                entryMetadata.Authors = new ReadOnlyEnumerable<AtomPersonMetadata>();
            }

            ReaderUtils.GetSourceListOfEnumerable(entryMetadata.Authors, "Authors").Add(authorMetadata);
        }
コード例 #9
0
        /// <summary>
        /// Writes the specified start/end tags and the specified person metadata as content
        /// </summary>
        /// <param name="personMetadata">The person metadata to write.</param>
        internal void WritePersonMetadata(AtomPersonMetadata personMetadata)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(personMetadata != null, "Person metadata must not be null.");

            // <atom:name>name of person</atom:name>
            // NOTE: write an empty element if no name is specified because the element is required.
            this.WriteElementWithTextContent(
                AtomConstants.AtomNamespacePrefix,
                AtomConstants.AtomPersonNameElementName,
                AtomConstants.AtomNamespace,
                personMetadata.Name);

            string uriString = personMetadata.UriFromEpm;

            if (uriString != null)
            {
                Debug.Assert(
                    personMetadata.Uri == null,
                    "If the internal UriFromEpm was used, then the Uri property must be left null. The merge between custom and EPM is probably wrong.");
            }
            else
            {
                Uri uri = personMetadata.Uri;
                if (uri != null)
                {
                    uriString = this.UriToUrlAttributeValue(uri);
                }
            }

            if (uriString != null)
            {
                this.WriteElementWithTextContent(
                    AtomConstants.AtomNamespacePrefix,
                    AtomConstants.AtomPersonUriElementName,
                    AtomConstants.AtomNamespace,
                    uriString);
            }

            string email = personMetadata.Email;

            if (email != null)
            {
                this.WriteElementWithTextContent(
                    AtomConstants.AtomNamespacePrefix,
                    AtomConstants.AtomPersonEmailElementName,
                    AtomConstants.AtomNamespace,
                    email);
            }
        }
コード例 #10
0
        /// <summary>
        /// Writes a non-leaf segment which has sub segments.
        /// </summary>
        /// <param name="targetSegment">The segment being written</param>
        /// <param name="epmValueCache">EPM value cache to use to get property values, or a primitive value</param>
        /// <param name="typeReference">The type of the entry or collection item.</param>
        private void WriteParentSegment(EpmTargetPathSegment targetSegment, object epmValueCache, IEdmTypeReference typeReference)
        {
            Debug.Assert(targetSegment != null, "targetSegment != null");

            if (targetSegment.SegmentName == AtomConstants.AtomAuthorElementName)
            {
                AtomPersonMetadata authorMetadata = this.WritePersonEpm(targetSegment, epmValueCache, typeReference);

                if (authorMetadata != null)
                {
                    List <AtomPersonMetadata> authors = (List <AtomPersonMetadata>) this.entryMetadata.Authors;
                    if (authors == null)
                    {
                        authors = new List <AtomPersonMetadata>();
                        this.entryMetadata.Authors = authors;
                    }

                    authors.Add(authorMetadata);
                }
            }
            else if (targetSegment.SegmentName == AtomConstants.AtomContributorElementName)
            {
                AtomPersonMetadata contributorMetadata = this.WritePersonEpm(targetSegment, epmValueCache, typeReference);

                if (contributorMetadata != null)
                {
                    List <AtomPersonMetadata> contributors = (List <AtomPersonMetadata>) this.entryMetadata.Contributors;
                    if (contributors == null)
                    {
                        contributors = new List <AtomPersonMetadata>();
                        this.entryMetadata.Contributors = contributors;
                    }

                    contributors.Add(contributorMetadata);
                }
            }
            else
            {
                // Unhandled EpmTargetPathSegment.SegmentName.
                throw new ODataException(o.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_WriteParentSegment_TargetSegmentName));
            }
        }
コード例 #11
0
ファイル: EpmSyndicationReader.cs プロジェクト: nickchal/pash
 private void ReadPersonEpm(IList targetList, IEdmTypeReference targetTypeReference, EpmTargetPathSegment targetSegment, AtomPersonMetadata personMetadata)
 {
     foreach (EpmTargetPathSegment segment in targetSegment.SubSegments)
     {
         switch (segment.EpmInfo.Attribute.TargetSyndicationItem)
         {
             case SyndicationItemProperty.AuthorEmail:
             case SyndicationItemProperty.ContributorEmail:
             {
                 string email = personMetadata.Email;
                 if (email != null)
                 {
                     base.SetEpmValue(targetList, targetTypeReference, segment.EpmInfo, email);
                 }
                 break;
             }
             case SyndicationItemProperty.AuthorName:
             case SyndicationItemProperty.ContributorName:
             {
                 string name = personMetadata.Name;
                 if (name != null)
                 {
                     base.SetEpmValue(targetList, targetTypeReference, segment.EpmInfo, name);
                 }
                 break;
             }
             case SyndicationItemProperty.AuthorUri:
             case SyndicationItemProperty.ContributorUri:
             {
                 string uriFromEpm = personMetadata.UriFromEpm;
                 if (uriFromEpm != null)
                 {
                     base.SetEpmValue(targetList, targetTypeReference, segment.EpmInfo, uriFromEpm);
                 }
                 break;
             }
             default:
                 throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationReader_ReadPersonEpm));
         }
     }
 }
コード例 #12
0
        /// <summary>
        /// Reads a non-leaf segment which has sub segments.
        /// </summary>
        /// <param name="targetSegment">The segment being read.</param>
        /// <param name="entryMetadata">The ATOM entry metadata to read from.</param>
        private void ReadParentSegment(EpmTargetPathSegment targetSegment, AtomEntryMetadata entryMetadata)
        {
            Debug.Assert(targetSegment != null, "targetSegment != null");
            Debug.Assert(entryMetadata != null, "entryMetadata != null");
            switch (targetSegment.SegmentName)
            {
            case AtomConstants.AtomAuthorElementName:
                // If a singleton property (non-collection) is mapped to author and there are multiple authors
                // EPM uses the first author.
                AtomPersonMetadata authorMetadata = entryMetadata.Authors.FirstOrDefault();
                if (authorMetadata != null)
                {
                    this.ReadPersonEpm(
                        ReaderUtils.GetPropertiesList(this.EntryState.Entry.Properties),
                        this.EntryState.EntityType.ToTypeReference(),
                        targetSegment,
                        authorMetadata);
                }

                break;

            case AtomConstants.AtomContributorElementName:
                // If a singleton property (non-collection) is mapped to contributor and there are multiple contributors
                // EPM uses the first contributor.
                AtomPersonMetadata contributorMetadata = entryMetadata.Contributors.FirstOrDefault();
                if (contributorMetadata != null)
                {
                    this.ReadPersonEpm(
                        ReaderUtils.GetPropertiesList(this.EntryState.Entry.Properties),
                        this.EntryState.EntityType.ToTypeReference(),
                        targetSegment,
                        contributorMetadata);
                }

                break;

            default:
                throw new ODataException(o.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationReader_ReadParentSegment_TargetSegmentName));
            }
        }
コード例 #13
0
        internal void WritePersonMetadata(AtomPersonMetadata personMetadata)
        {
            base.WriteElementWithTextContent("", "name", "http://www.w3.org/2005/Atom", personMetadata.Name);
            string uriFromEpm = personMetadata.UriFromEpm;

            if (uriFromEpm == null)
            {
                Uri uri = personMetadata.Uri;
                if (uri != null)
                {
                    uriFromEpm = base.UriToUrlAttributeValue(uri);
                }
            }
            if (uriFromEpm != null)
            {
                base.WriteElementWithTextContent("", "uri", "http://www.w3.org/2005/Atom", uriFromEpm);
            }
            string email = personMetadata.Email;

            if (email != null)
            {
                base.WriteElementWithTextContent("", "email", "http://www.w3.org/2005/Atom", email);
            }
        }
コード例 #14
0
        /// <summary>
        /// Writes EPM value to a person construct (author or contributor).
        /// </summary>
        /// <param name="targetSegment">The target segment which points to either author or contributor element.</param>
        /// <param name="epmValueCache">EPM value cache to use to get property values, or a primitive value</param>
        /// <param name="typeReference">The type of the entry or collection item.</param>
        /// <returns>The person metadata or null if no person metadata should be written for this mapping.</returns>
        private AtomPersonMetadata WritePersonEpm(EpmTargetPathSegment targetSegment, object epmValueCache, IEdmTypeReference typeReference)
        {
            Debug.Assert(targetSegment != null, "targetSegment != null");
            Debug.Assert(
                targetSegment.SegmentName == AtomConstants.AtomAuthorElementName || targetSegment.SegmentName == AtomConstants.AtomContributorElementName,
                "targetSegment must be author or contributor.");

            AtomPersonMetadata personMetadata = null;

            foreach (EpmTargetPathSegment subSegment in targetSegment.SubSegments)
            {
                Debug.Assert(subSegment.HasContent, "sub segment of author segment must have content, there are no subsegments which don't have content under author.");
                Debug.Assert(
                    subSegment.EpmInfo != null && subSegment.EpmInfo.Attribute != null && subSegment.EpmInfo.Attribute.TargetSyndicationItem != SyndicationItemProperty.CustomProperty,
                    "We should never find a subsegment without EPM attribute or for custom mapping when writing syndication person EPM.");
                string textPropertyValue = this.GetPropertyValueAsText(subSegment, epmValueCache, typeReference);

                if (textPropertyValue == null)
                {
                    // In V2 we write the mapped properties always in-content when the value is null.
                    continue;
                }

                // Initialize the person element only if we actually need to write something to it.
                Debug.Assert(subSegment.EpmInfo != null && subSegment.EpmInfo.Attribute != null, "The author subsegment must have EPM info and EPM attribute.");
                switch (subSegment.EpmInfo.Attribute.TargetSyndicationItem)
                {
                case SyndicationItemProperty.AuthorName:
                case SyndicationItemProperty.ContributorName:
                    if (textPropertyValue != null)
                    {
                        if (personMetadata == null)
                        {
                            personMetadata = new AtomPersonMetadata();
                        }

                        personMetadata.Name = textPropertyValue;
                    }

                    break;

                case SyndicationItemProperty.AuthorEmail:
                case SyndicationItemProperty.ContributorEmail:
                    if (textPropertyValue != null && textPropertyValue.Length > 0)
                    {
                        if (personMetadata == null)
                        {
                            personMetadata = new AtomPersonMetadata();
                        }

                        personMetadata.Email = textPropertyValue;
                    }

                    break;

                case SyndicationItemProperty.AuthorUri:
                case SyndicationItemProperty.ContributorUri:
                    if (textPropertyValue != null && textPropertyValue.Length > 0)
                    {
                        if (personMetadata == null)
                        {
                            personMetadata = new AtomPersonMetadata();
                        }

                        personMetadata.UriFromEpm = textPropertyValue;
                    }

                    break;

                default:
                    throw new ODataException(o.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_WritePersonEpm));
                }
            }

            return(personMetadata);
        }
コード例 #15
0
ファイル: EpmSyndicationWriter.cs プロジェクト: nickchal/pash
 private AtomPersonMetadata WritePersonEpm(EpmTargetPathSegment targetSegment, object epmValueCache, IEdmTypeReference typeReference)
 {
     AtomPersonMetadata metadata = null;
     foreach (EpmTargetPathSegment segment in targetSegment.SubSegments)
     {
         string str = this.GetPropertyValueAsText(segment, epmValueCache, typeReference);
         if (str != null)
         {
             switch (segment.EpmInfo.Attribute.TargetSyndicationItem)
             {
                 case SyndicationItemProperty.AuthorEmail:
                 case SyndicationItemProperty.ContributorEmail:
                 {
                     if ((str != null) && (str.Length > 0))
                     {
                         if (metadata == null)
                         {
                             metadata = new AtomPersonMetadata();
                         }
                         metadata.Email = str;
                     }
                     continue;
                 }
                 case SyndicationItemProperty.AuthorName:
                 case SyndicationItemProperty.ContributorName:
                 {
                     if (str != null)
                     {
                         if (metadata == null)
                         {
                             metadata = new AtomPersonMetadata();
                         }
                         metadata.Name = str;
                     }
                     continue;
                 }
                 case SyndicationItemProperty.AuthorUri:
                 case SyndicationItemProperty.ContributorUri:
                 {
                     if ((str != null) && (str.Length > 0))
                     {
                         if (metadata == null)
                         {
                             metadata = new AtomPersonMetadata();
                         }
                         metadata.UriFromEpm = str;
                     }
                     continue;
                 }
             }
             throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_WritePersonEpm));
         }
     }
     return metadata;
 }
コード例 #16
0
        /// <summary>
        /// Writes the specified start/end tags and the specified person metadata as content
        /// </summary>
        /// <param name="personMetadata">The person metadata to write.</param>
        internal void WritePersonMetadata(AtomPersonMetadata personMetadata)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(personMetadata != null, "Person metadata must not be null.");

            // <atom:name>name of person</atom:name>
            // NOTE: write an empty element if no name is specified because the element is required.
            this.WriteElementWithTextContent(
                AtomConstants.AtomNamespacePrefix,
                AtomConstants.AtomPersonNameElementName,
                AtomConstants.AtomNamespace,
                personMetadata.Name);

            string uriString = personMetadata.UriFromEpm;
            if (uriString != null)
            {
                Debug.Assert(
                    personMetadata.Uri == null,
                    "If the internal UriFromEpm was used, then the Uri property must be left null. The merge between custom and EPM is probably wrong.");
            }
            else
            {
                Uri uri = personMetadata.Uri;
                if (uri != null)
                {
                    uriString = this.UriToUrlAttributeValue(uri);
                }
            }

            if (uriString != null)
            {
                this.WriteElementWithTextContent(
                    AtomConstants.AtomNamespacePrefix,
                    AtomConstants.AtomPersonUriElementName,
                    AtomConstants.AtomNamespace,
                    uriString);
            }

            string email = personMetadata.Email;
            if (email != null)
            {
                this.WriteElementWithTextContent(
                    AtomConstants.AtomNamespacePrefix,
                    AtomConstants.AtomPersonEmailElementName,
                    AtomConstants.AtomNamespace,
                    email);
            }
        }
コード例 #17
0
        private void ReadPersonEpm(IList targetList, IEdmTypeReference targetTypeReference, EpmTargetPathSegment targetSegment, AtomPersonMetadata personMetadata)
        {
            foreach (EpmTargetPathSegment segment in targetSegment.SubSegments)
            {
                switch (segment.EpmInfo.Attribute.TargetSyndicationItem)
                {
                case SyndicationItemProperty.AuthorEmail:
                case SyndicationItemProperty.ContributorEmail:
                {
                    string email = personMetadata.Email;
                    if (email != null)
                    {
                        base.SetEpmValue(targetList, targetTypeReference, segment.EpmInfo, email);
                    }
                    break;
                }

                case SyndicationItemProperty.AuthorName:
                case SyndicationItemProperty.ContributorName:
                {
                    string name = personMetadata.Name;
                    if (name != null)
                    {
                        base.SetEpmValue(targetList, targetTypeReference, segment.EpmInfo, name);
                    }
                    break;
                }

                case SyndicationItemProperty.AuthorUri:
                case SyndicationItemProperty.ContributorUri:
                {
                    string uriFromEpm = personMetadata.UriFromEpm;
                    if (uriFromEpm != null)
                    {
                        base.SetEpmValue(targetList, targetTypeReference, segment.EpmInfo, uriFromEpm);
                    }
                    break;
                }

                default:
                    throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationReader_ReadPersonEpm));
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// Reads EPM values from a person construct (author or contributor).
        /// </summary>
        /// <param name="targetList">The target list, this can be either a list of properties (on entry or complex value),
        /// or a list of items (for a collection of primitive types).</param>
        /// <param name="targetTypeReference">The type of the value on which to set the property (can be entity, complex or primitive).</param>
        /// <param name="targetSegment">The target segment which points to either author or contributor element.</param>
        /// <param name="personMetadata">The person ATOM metadata to read from.</param>
        private void ReadPersonEpm(IList targetList, IEdmTypeReference targetTypeReference, EpmTargetPathSegment targetSegment, AtomPersonMetadata personMetadata)
        {
            Debug.Assert(targetList != null, "targetList != null");
            Debug.Assert(targetTypeReference != null, "targetTypeReference != null");
            Debug.Assert(targetSegment != null, "targetSegment != null");
            Debug.Assert(
                targetSegment.SegmentName == AtomConstants.AtomAuthorElementName || targetSegment.SegmentName == AtomConstants.AtomContributorElementName,
                "targetSegment must be author or contributor.");
            Debug.Assert(personMetadata != null, "personMetadata != null");

            foreach (EpmTargetPathSegment subSegment in targetSegment.SubSegments)
            {
                Debug.Assert(subSegment.HasContent, "sub segment of author segment must have content, there are no subsegments which don't have content under author.");
                Debug.Assert(
                    subSegment.EpmInfo != null && subSegment.EpmInfo.Attribute != null && subSegment.EpmInfo.Attribute.TargetSyndicationItem != SyndicationItemProperty.CustomProperty,
                    "We should never find a subsegment without EPM attribute or for custom mapping when writing syndication person EPM.");
                switch (subSegment.EpmInfo.Attribute.TargetSyndicationItem)
                {
                case SyndicationItemProperty.AuthorName:
                case SyndicationItemProperty.ContributorName:
                    // Note that person name can never specify true null in EPM, since it can't have the m:null attribute on it.
                    string personName = personMetadata.Name;
                    if (personName != null)
                    {
                        this.SetEpmValue(targetList, targetTypeReference, subSegment.EpmInfo, personName);
                    }

                    break;

                case SyndicationItemProperty.AuthorEmail:
                case SyndicationItemProperty.ContributorEmail:
                    string personEmail = personMetadata.Email;
                    if (personEmail != null)
                    {
                        this.SetEpmValue(targetList, targetTypeReference, subSegment.EpmInfo, personEmail);
                    }

                    break;

                case SyndicationItemProperty.AuthorUri:
                case SyndicationItemProperty.ContributorUri:
                    string personUri = personMetadata.UriFromEpm;
                    if (personUri != null)
                    {
                        this.SetEpmValue(targetList, targetTypeReference, subSegment.EpmInfo, personUri);
                    }

                    break;

                default:
                    // Unhandled EpmTargetPathSegment.SegmentName.
                    throw new ODataException(o.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationReader_ReadPersonEpm));
                }
            }
        }
コード例 #19
0
 internal void WritePersonMetadata(AtomPersonMetadata personMetadata)
 {
     base.WriteElementWithTextContent("", "name", "http://www.w3.org/2005/Atom", personMetadata.Name);
     string uriFromEpm = personMetadata.UriFromEpm;
     if (uriFromEpm == null)
     {
         Uri uri = personMetadata.Uri;
         if (uri != null)
         {
             uriFromEpm = base.UriToUrlAttributeValue(uri);
         }
     }
     if (uriFromEpm != null)
     {
         base.WriteElementWithTextContent("", "uri", "http://www.w3.org/2005/Atom", uriFromEpm);
     }
     string email = personMetadata.Email;
     if (email != null)
     {
         base.WriteElementWithTextContent("", "email", "http://www.w3.org/2005/Atom", email);
     }
 }
コード例 #20
0
        /// <summary>
        /// Writes EPM value to a person construct (author or contributor).
        /// </summary>
        /// <param name="targetSegment">The target segment which points to either author or contributor element.</param>
        /// <param name="epmValueCache">EPM value cache to use to get property values, or a primitive value</param>
        /// <param name="typeReference">The type of the entry or collection item.</param>
        /// <returns>The person metadata or null if no person metadata should be written for this mapping.</returns>
        private AtomPersonMetadata WritePersonEpm(EpmTargetPathSegment targetSegment, object epmValueCache, IEdmTypeReference typeReference)
        {
            Debug.Assert(targetSegment != null, "targetSegment != null");
            Debug.Assert(
                targetSegment.SegmentName == AtomConstants.AtomAuthorElementName || targetSegment.SegmentName == AtomConstants.AtomContributorElementName, 
                "targetSegment must be author or contributor.");

            AtomPersonMetadata personMetadata = null;
            foreach (EpmTargetPathSegment subSegment in targetSegment.SubSegments)
            {
                Debug.Assert(subSegment.HasContent, "sub segment of author segment must have content, there are no subsegments which don't have content under author.");
                Debug.Assert(
                    subSegment.EpmInfo != null && subSegment.EpmInfo.Attribute != null && subSegment.EpmInfo.Attribute.TargetSyndicationItem != SyndicationItemProperty.CustomProperty,
                    "We should never find a subsegment without EPM attribute or for custom mapping when writing syndication person EPM.");
                string textPropertyValue = this.GetPropertyValueAsText(subSegment, epmValueCache, typeReference);

                if (textPropertyValue == null)
                {
                    // In V2 we write the mapped properties always in-content when the value is null.
                    continue;
                }

                // Initialize the person element only if we actually need to write something to it.
                Debug.Assert(subSegment.EpmInfo != null && subSegment.EpmInfo.Attribute != null, "The author subsegment must have EPM info and EPM attribute.");
                switch (subSegment.EpmInfo.Attribute.TargetSyndicationItem)
                {
                    case SyndicationItemProperty.AuthorName:
                    case SyndicationItemProperty.ContributorName:
                        if (textPropertyValue != null)
                        {
                            if (personMetadata == null)
                            {
                                personMetadata = new AtomPersonMetadata();
                            }

                            personMetadata.Name = textPropertyValue;
                        }

                        break;
                    case SyndicationItemProperty.AuthorEmail:
                    case SyndicationItemProperty.ContributorEmail:
                        if (textPropertyValue != null && textPropertyValue.Length > 0)
                        {
                            if (personMetadata == null)
                            {
                                personMetadata = new AtomPersonMetadata();
                            }

                            personMetadata.Email = textPropertyValue;
                        }

                        break;
                    case SyndicationItemProperty.AuthorUri:
                    case SyndicationItemProperty.ContributorUri:
                        if (textPropertyValue != null && textPropertyValue.Length > 0)
                        {
                            if (personMetadata == null)
                            {
                                personMetadata = new AtomPersonMetadata();
                            }

                            personMetadata.UriFromEpm = textPropertyValue;
                        }

                        break;
                    default:
                        throw new ODataException(o.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_WritePersonEpm));
                }
            }

            return personMetadata;
        }
コード例 #21
0
        /// <summary>
        /// Reads a person (author/contributor) element.
        /// </summary>
        /// <param name="epmTargetPathSegment">The EPM target path segment for the element to read, or null if no EPM for that element is defined.</param>
        /// <returns>The person metadata object with the read values.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element (atom:contributor/atom:author) - the atom:author/atom:contributor element to read.
        /// Post-Condition: Any                                                - the node after the atom:author/atom:contributor element which was read.
        /// </remarks>
        protected AtomPersonMetadata ReadAtomPersonConstruct(EpmTargetPathSegment epmTargetPathSegment)
        {
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                (this.XmlReader.LocalName == AtomConstants.AtomAuthorElementName || this.XmlReader.LocalName == AtomConstants.AtomContributorElementName) &&
                this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace,
                "Only atom:author or atom:contributor elements can be read by this method.");

            EpmTargetPathSegment subSegment;
            AtomPersonMetadata   personMetadata = new AtomPersonMetadata();

            if (!this.XmlReader.IsEmptyElement)
            {
                // Move to the first child
                this.XmlReader.Read();

                do
                {
                    switch (this.XmlReader.NodeType)
                    {
                    case XmlNodeType.EndElement:
                        // End of the atom:author/atom:contributor element
                        continue;

                    case XmlNodeType.Element:
                        if (this.XmlReader.NamespaceEquals(this.AtomNamespace))
                        {
                            if (this.ShouldReadElement(epmTargetPathSegment, this.XmlReader.LocalName, out subSegment))
                            {
                                switch (this.XmlReader.LocalName)
                                {
                                case AtomConstants.AtomPersonNameElementName:
                                    personMetadata.Name = this.ReadElementStringValue();
                                    continue;

                                case AtomConstants.AtomPersonUriElementName:
                                    // NOTE: get the base URI here before we read the content as string; reading the content as string will move the
                                    //       reader to the end element and thus we lose the xml:base definition on the element.
                                    Uri    xmlBaseUri = this.XmlReader.XmlBaseUri;
                                    string textValue  = this.ReadElementStringValue();
                                    if (subSegment != null)
                                    {
                                        personMetadata.UriFromEpm = textValue;
                                    }

                                    if (this.ReadAtomMetadata)
                                    {
                                        personMetadata.Uri = this.ProcessUriFromPayload(textValue, xmlBaseUri);
                                    }

                                    continue;

                                case AtomConstants.AtomPersonEmailElementName:
                                    personMetadata.Email = this.ReadElementStringValue();
                                    continue;

                                default:
                                    break;
                                }
                            }
                        }

                        break;

                    default:
                        break;
                    }

                    // Skip everything we haven't read yet.
                    this.XmlReader.Skip();
                }while (this.XmlReader.NodeType != XmlNodeType.EndElement);
            }

            // Read over the end element or the empty start element.
            this.AssertXmlCondition(true, XmlNodeType.EndElement);
            Debug.Assert(
                (this.XmlReader.LocalName == AtomConstants.AtomAuthorElementName || this.XmlReader.LocalName == AtomConstants.AtomContributorElementName) &&
                this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace,
                "Only atom:author or atom:contributor elements can be read by this method.");
            this.XmlReader.Read();

            return(personMetadata);
        }
コード例 #22
0
        /// <summary>
        /// Adds a new contributor to feed metadata.
        /// </summary>
        /// <param name="feedMetadata">The feed metadata to add the contributor to.</param>
        /// <param name="contributorMetadata">The author metadata to add.</param>
        internal static void AddContributorToFeedMetadata(AtomFeedMetadata feedMetadata, AtomPersonMetadata contributorMetadata)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(feedMetadata != null, "feedMetadata != null");
            Debug.Assert(contributorMetadata != null, "contributorMetadata != null");

            if (object.ReferenceEquals(feedMetadata.Contributors, EmptyPersonsList))
            {
                feedMetadata.Contributors = new ReadOnlyEnumerable<AtomPersonMetadata>();
            }

            ReaderUtils.GetSourceListOfEnumerable(feedMetadata.Contributors, "Contributors").Add(contributorMetadata);
        }