コード例 #1
0
        /// <summary>
        /// Turns the in-memory representations of the supported, OData-specific annotations into their serializable form.
        /// Assumes that the entity type and the model have been validated.
        /// </summary>
        /// <param name="model">The <see cref="IEdmModel"/> containing the annotations.</param>
        /// <param name="entityType">The <see cref="IEdmEntityType"/> to process.</param>
        private static void SaveODataAnnotationsImplementation(IEdmModel model, IEdmEntityType entityType)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(entityType != null, "entityType != null");

            // Get the cached EPM information for this entity type; if the mappings have changed this will update the cache;
            // if all the mappings have been removed, we will delete the cache.
            // Building the cache will also validate the EPM (since we don't want to save/write invalid EPM information).
            // NOTE: when saving annotations on a model we assume it is valid and thus pass int.MaxValue for the maxMappingCount.
            ODataEntityPropertyMappingCache epmCache = model.EnsureEpmCache(entityType, /*maxMappingCount*/ int.MaxValue);

            if (epmCache != null)
            {
                // write any mappings for properties that are not declared on this type on the entity type
                model.SaveEpmAnnotations(entityType, epmCache.MappingsForInheritedProperties, false, false);

                IEnumerable <IEdmProperty> declaredProperties = entityType.DeclaredProperties;
                if (declaredProperties != null)
                {
                    foreach (IEdmProperty property in declaredProperties)
                    {
                        if (property.Type.IsODataPrimitiveTypeKind() || property.Type.IsODataComplexTypeKind())
                        {
                            model.SaveEpmAnnotationsForProperty(property, epmCache);
                        }
                        else if (property.Type.IsNonEntityODataCollectionTypeKind())
                        {
                            model.SaveEpmAnnotationsForProperty(property, epmCache);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: ODataAtomReader.cs プロジェクト: modulexcite/pash-1
        private void ReadEntryStart()
        {
            ODataEntry entry = ReaderUtils.CreateNewEntry();

            if (this.atomInputContext.MessageReaderSettings.ReaderBehavior.EntryXmlCustomizationCallback != null)
            {
                this.atomEntryAndFeedDeserializer.VerifyEntryStart();
                Uri       xmlBaseUri = this.atomInputContext.XmlReader.XmlBaseUri;
                XmlReader objB       = this.atomInputContext.MessageReaderSettings.ReaderBehavior.EntryXmlCustomizationCallback(entry, this.atomInputContext.XmlReader, this.atomInputContext.XmlReader.ParentXmlBaseUri);
                if (objB != null)
                {
                    if (object.ReferenceEquals(this.atomInputContext.XmlReader, objB))
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomReader_EntryXmlCustomizationCallbackReturnedSameInstance);
                    }
                    this.atomInputContext.PushCustomReader(objB, xmlBaseUri);
                    this.atomEntryAndFeedDeserializer = new ODataAtomEntryAndFeedDeserializer(this.atomInputContext);
                    this.atomEntryAndFeedDeserializersStack.Push(this.atomEntryAndFeedDeserializer);
                }
                else
                {
                    this.atomInputContext.PushCustomReader(this.atomInputContext.XmlReader, null);
                }
            }
            this.atomEntryAndFeedDeserializer.ReadEntryStart(entry);
            this.EnterScope(ODataReaderState.EntryStart, entry, base.CurrentEntityType);
            AtomScope currentScope = (AtomScope)base.CurrentScope;

            currentScope.DuplicatePropertyNamesChecker = this.atomInputContext.CreateDuplicatePropertyNamesChecker();
            string entityTypeNameFromPayload = this.atomEntryAndFeedDeserializer.FindTypeName();

            base.ApplyEntityTypeNameFromPayload(entityTypeNameFromPayload);
            if (base.CurrentFeedValidator != null)
            {
                base.CurrentFeedValidator.ValidateEntry(base.CurrentEntityType);
            }
            ODataEntityPropertyMappingCache cache = this.atomInputContext.Model.EnsureEpmCache(this.CurrentEntryState.EntityType, 0x7fffffff);

            if (cache != null)
            {
                currentScope.CachedEpm = cache;
            }
            if (this.atomEntryAndFeedDeserializer.XmlReader.IsEmptyElement)
            {
                this.CurrentEntryState.EntryElementEmpty = true;
            }
            else
            {
                this.atomEntryAndFeedDeserializer.XmlReader.Read();
                if (this.atomInputContext.UseServerApiBehavior)
                {
                    this.CurrentEntryState.FirstNavigationLinkDescriptor = null;
                }
                else
                {
                    this.CurrentEntryState.FirstNavigationLinkDescriptor = this.atomEntryAndFeedDeserializer.ReadEntryContent(this.CurrentEntryState);
                }
            }
        }
コード例 #3
0
        internal static void CheckEntityPropertyMapping(ODataVersion version, IEdmEntityType entityType, IEdmModel model)
        {
            ODataEntityPropertyMappingCache epmCache = model.GetEpmCache(entityType);

            if ((epmCache != null) && (version < epmCache.EpmTargetTree.MinimumODataProtocolVersion))
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ODataVersionChecker_EpmVersionNotSupported(entityType.ODataFullName(), ODataUtils.ODataVersionToString(epmCache.EpmTargetTree.MinimumODataProtocolVersion), ODataUtils.ODataVersionToString(version)));
            }
        }
コード例 #4
0
        internal bool TryReadExtensionElementInEntryContent(IODataAtomReaderEntryState entryState)
        {
            ODataEntityPropertyMappingCache cachedEpm = entryState.CachedEpm;

            if (cachedEpm == null)
            {
                return(false);
            }
            EpmTargetPathSegment nonSyndicationRoot = cachedEpm.EpmTargetTree.NonSyndicationRoot;

            return(this.TryReadCustomEpmElement(entryState, nonSyndicationRoot));
        }
コード例 #5
0
ファイル: ValidationUtils.cs プロジェクト: modulexcite/pash-1
        internal static int ValidateTotalEntityPropertyMappingCount(ODataEntityPropertyMappingCache baseCache, ODataEntityPropertyMappingCollection mappings, int maxMappingCount)
        {
            int num  = (baseCache == null) ? 0 : baseCache.TotalMappingCount;
            int num2 = (mappings == null) ? 0 : mappings.Count;
            int num3 = num + num2;

            if (num3 > maxMappingCount)
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_MaxNumberOfEntityPropertyMappingsExceeded(num3, maxMappingCount));
            }
            return(num3);
        }
コード例 #6
0
ファイル: ValidationUtils.cs プロジェクト: tapika/swupd
        /// <summary>
        /// Validates that the total number of entity property mapping attributes on the base entity type and the current
        /// entity type does not exceed the specified security limit.
        /// </summary>
        /// <param name="baseCache">The EPM cache of the base entity type or null if no base entity type exists.</param>
        /// <param name="mappings">The EPM collection of the current entity type.</param>
        /// <param name="maxMappingCount">The maximum number of mappings allowed for an entity type (on the type itself and all its base types).</param>
        /// <returns>The total number of entity property mappings for the current entity type.</returns>
        internal static int ValidateTotalEntityPropertyMappingCount(ODataEntityPropertyMappingCache baseCache, ODataEntityPropertyMappingCollection mappings, int maxMappingCount)
        {
            DebugUtils.CheckNoExternalCallers();

            int countOfMappingsOnBaseTypes   = baseCache == null ? 0 : baseCache.TotalMappingCount;
            int countOfMappingsOnCurrentType = mappings == null ? 0 : mappings.Count;
            int totalMappingCount            = countOfMappingsOnBaseTypes + countOfMappingsOnCurrentType;

            if (totalMappingCount > maxMappingCount)
            {
                throw new ODataException(Strings.ValidationUtils_MaxNumberOfEntityPropertyMappingsExceeded(totalMappingCount, maxMappingCount));
            }

            return(totalMappingCount);
        }
コード例 #7
0
        /// <summary>
        /// Reads an extension element in non-ATOM namespace in the content of the entry element.
        /// </summary>
        /// <param name="entryState">The reader entry state for the entry being read.</param>
        /// <returns>true if a mapping for the current custom element was found and the element was read; otherwise false.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - the element in non-ATOM namespace to read.
        /// Post-Condition: Any                 - the node after the extension element which was read.
        /// </remarks>
        internal bool TryReadExtensionElementInEntryContent(IODataAtomReaderEntryState entryState)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entryState != null, "entryState != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.NamespaceURI != AtomConstants.AtomNamespace, "Only elements in non-ATOM namespace can be read by this method.");

            ODataEntityPropertyMappingCache cachedEpm = entryState.CachedEpm;

            if (cachedEpm == null)
            {
                return(false);
            }

            EpmTargetPathSegment epmTargetPathSegment = cachedEpm.EpmTargetTree.NonSyndicationRoot;

            return(this.TryReadCustomEpmElement(entryState, epmTargetPathSegment));
        }
コード例 #8
0
        /// <summary>
        /// Check whether the EPM on the specified entity type is supported in the specified version.
        /// </summary>
        /// <param name="version">The version to check.</param>
        /// <param name="entityType">The entity type to check.</param>
        /// <param name="model">The model containing annotations for the entity type.</param>
        internal static void CheckEntityPropertyMapping(ODataVersion version, IEdmEntityType entityType, IEdmModel model)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entityType != null, "entityType != null");
            Debug.Assert(model != null, "model != null");

            ODataEntityPropertyMappingCache epmCache = model.GetEpmCache(entityType);

            if (epmCache != null)
            {
                Debug.Assert(epmCache.EpmTargetTree != null, "If the EPM annotation is present the EPM tree must already be initialized.");
                if (version < epmCache.EpmTargetTree.MinimumODataProtocolVersion)
                {
                    throw new ODataException(
                              Strings.ODataVersionChecker_EpmVersionNotSupported(
                                  entityType.ODataFullName(),
                                  ODataUtils.ODataVersionToString(epmCache.EpmTargetTree.MinimumODataProtocolVersion),
                                  ODataUtils.ODataVersionToString(version)));
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Reads the atom:category element in the entry content.
        /// </summary>
        /// <param name="entryState">The reader entry state for the entry being read.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element (atom:category) - the atom:category element to read.
        /// Post-Condition: Any                                 - the node after the atom:category which was read.
        /// </remarks>
        internal void ReadAtomCategoryElementInEntryContent(IODataAtomReaderEntryState entryState)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entryState != null, "entryState != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace && this.XmlReader.LocalName == AtomConstants.AtomCategoryElementName,
                "Only atom:category element can be read by this method.");

            ODataEntityPropertyMappingCache cachedEpm            = entryState.CachedEpm;
            EpmTargetPathSegment            epmTargetPathSegment = null;

            if (cachedEpm != null)
            {
                epmTargetPathSegment = cachedEpm.EpmTargetTree.SyndicationRoot;
            }

            // Rough estimate if we will need the category for EPM - we can't tell for sure since we don't know the scheme value yet.
            bool hasCategoryEpm = epmTargetPathSegment != null && epmTargetPathSegment.SubSegments.Any(segment =>
                                                                                                       string.CompareOrdinal(segment.SegmentName, AtomConstants.AtomCategoryElementName) == 0);

            // Read the attributes and create the category metadata regardless if we will need it or not.
            // We can do this since there's no validation done on any of the values and thus this operation will never fail.
            // If we then decide we don't need it, we can safely throw it away.
            if (this.ReadAtomMetadata || hasCategoryEpm)
            {
                AtomCategoryMetadata categoryMetadata = this.ReadAtomCategoryElement();

                // No point in trying to figure out if we will need the category for EPM or not here.
                // Our EPM syndication reader must handle unneeded categories anyway (if ATOM metadata reading is on)
                // So instead of burning the cycles to compute if we need it, just store it anyway.
                AtomMetadataReaderUtils.AddCategoryToEntryMetadata(entryState.AtomEntryMetadata, categoryMetadata);
            }
            else
            {
                // Skip the element in any case (we only ever consume attributes on it anyway).
                this.XmlReader.Skip();
            }
        }
コード例 #10
0
        internal void ReadAtomCategoryElementInEntryContent(IODataAtomReaderEntryState entryState)
        {
            ODataEntityPropertyMappingCache cachedEpm       = entryState.CachedEpm;
            EpmTargetPathSegment            syndicationRoot = null;

            if (cachedEpm != null)
            {
                syndicationRoot = cachedEpm.EpmTargetTree.SyndicationRoot;
            }
            if (syndicationRoot == null)
            {
            }
            bool flag = syndicationRoot.SubSegments.Any <EpmTargetPathSegment>();

            if (base.ReadAtomMetadata || flag)
            {
                AtomCategoryMetadata categoryMetadata = this.ReadAtomCategoryElement();
                AtomMetadataReaderUtils.AddCategoryToEntryMetadata(entryState.AtomEntryMetadata, categoryMetadata);
            }
            else
            {
                base.XmlReader.Skip();
            }
        }
コード例 #11
0
ファイル: ODataUtils.cs プロジェクト: modulexcite/pash-1
        private static void SaveODataAnnotationsImplementation(IEdmModel model, IEdmEntityType entityType)
        {
            ODataEntityPropertyMappingCache epmCache = model.EnsureEpmCache(entityType, 0x7fffffff);

            if (epmCache != null)
            {
                model.SaveEpmAnnotations(entityType, epmCache.MappingsForInheritedProperties, false, false);
                IEnumerable <IEdmProperty> declaredProperties = entityType.DeclaredProperties;
                if (declaredProperties != null)
                {
                    foreach (IEdmProperty property in declaredProperties)
                    {
                        if (property.Type.IsODataPrimitiveTypeKind() || property.Type.IsODataComplexTypeKind())
                        {
                            model.SaveEpmAnnotationsForProperty(property, epmCache);
                        }
                        else if (property.Type.IsNonEntityODataCollectionTypeKind())
                        {
                            model.SaveEpmAnnotationsForProperty(property, epmCache);
                        }
                    }
                }
            }
        }
コード例 #12
0
        protected override void EndEntry(ODataEntry entry)
        {
            Debug.Assert(
                this.ParentNavigationLink == null || !this.ParentNavigationLink.IsCollection.Value,
                "We should have already verified that the IsCollection matches the actual content of the link (feed/entry).");

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

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

            IEdmEntityType entryType = this.EntryEntityType;

            // Initialize the property value cache and cache the entry properties.
            EntryPropertiesValueCache propertyValueCache = new EntryPropertiesValueCache(entry);

            // NOTE: when writing, we assume the model has been validated already and thus pass int.MaxValue for the maxMappingCount.
            ODataEntityPropertyMappingCache epmCache = this.atomOutputContext.Model.EnsureEpmCache(entryType, /*maxMappingCount*/ int.MaxValue);

            // Populate the property value cache based on the EPM source tree information.
            // We do this since we need to write custom EPM after the properties below and don't
            // want to cache all properties just for the case that they are used in a custom EPM.
            if (epmCache != null)
            {
                EpmWriterUtils.CacheEpmProperties(propertyValueCache, epmCache.EpmSourceTree);
            }

            // Get the projected properties annotation
            ProjectedPropertiesAnnotation projectedProperties = entry.GetAnnotation <ProjectedPropertiesAnnotation>();

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

            if (!currentEntryScope.IsElementWritten(AtomElement.Id))
            {
                // NOTE: We write even null id, in that case we generate an empty atom:id element.
                this.atomEntryAndFeedSerializer.WriteEntryId(entry.Id);
            }

            Uri editLink = entry.EditLink;

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

            Uri readLink = entry.ReadLink;

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

            // write entry metadata including syndication EPM
            AtomEntryMetadata epmEntryMetadata = null;

            if (epmCache != null)
            {
                ODataVersionChecker.CheckEntityPropertyMapping(this.atomOutputContext.Version, entryType, this.atomOutputContext.Model);

                epmEntryMetadata = EpmSyndicationWriter.WriteEntryEpm(
                    epmCache.EpmTargetTree,
                    propertyValueCache,
                    entryType.ToTypeReference().AsEntity(),
                    this.atomOutputContext);
            }

            this.atomEntryAndFeedSerializer.WriteEntryMetadata(entryMetadata, epmEntryMetadata, this.updatedTime);

            // stream properties
            IEnumerable <ODataProperty> streamProperties = propertyValueCache.EntryStreamProperties;

            if (streamProperties != null)
            {
                foreach (ODataProperty streamProperty in streamProperties)
                {
                    this.atomEntryAndFeedSerializer.WriteStreamProperty(
                        streamProperty,
                        entryType,
                        this.DuplicatePropertyNamesChecker,
                        projectedProperties);
                }
            }

            // association links
            IEnumerable <ODataAssociationLink> associationLinks = entry.AssociationLinks;

            if (associationLinks != null)
            {
                foreach (ODataAssociationLink associationLink in associationLinks)
                {
                    this.atomEntryAndFeedSerializer.WriteAssociationLink(
                        associationLink,
                        entryType,
                        this.DuplicatePropertyNamesChecker,
                        projectedProperties);
                }
            }

            // actions
            IEnumerable <ODataAction> actions = entry.Actions;

            if (actions != null)
            {
                foreach (ODataAction action in actions)
                {
                    ValidationUtils.ValidateOperationNotNull(action, true);
                    this.atomEntryAndFeedSerializer.WriteOperation(action);
                }
            }

            // functions
            IEnumerable <ODataFunction> functions = entry.Functions;

            if (functions != null)
            {
                foreach (ODataFunction function in functions)
                {
                    ValidationUtils.ValidateOperationNotNull(function, false);
                    this.atomEntryAndFeedSerializer.WriteOperation(function);
                }
            }

            // write the content
            this.WriteEntryContent(
                entry,
                entryType,
                propertyValueCache,
                epmCache == null ? null : epmCache.EpmSourceTree.Root,
                projectedProperties);

            // write custom EPM
            if (epmCache != null)
            {
                EpmCustomWriter.WriteEntryEpm(
                    this.atomOutputContext.XmlWriter,
                    epmCache.EpmTargetTree,
                    propertyValueCache,
                    entryType.ToTypeReference().AsEntity(),
                    this.atomOutputContext);
            }

            // </entry>
            this.atomOutputContext.XmlWriter.WriteEndElement();

            this.EndEntryXmlCustomization(entry);

            this.CheckAndWriteParentNavigationLinkEndForInlineElement();
        }
コード例 #13
0
ファイル: ODataAtomWriter.cs プロジェクト: modulexcite/pash-1
 protected override void EndEntry(ODataEntry entry)
 {
     if (entry == null)
     {
         this.CheckAndWriteParentNavigationLinkEndForInlineElement();
     }
     else
     {
         IEdmEntityType                  entryEntityType    = base.EntryEntityType;
         EntryPropertiesValueCache       propertyValueCache = new EntryPropertiesValueCache(entry);
         ODataEntityPropertyMappingCache cache2             = this.atomOutputContext.Model.EnsureEpmCache(entryEntityType, 0x7fffffff);
         if (cache2 != null)
         {
             EpmWriterUtils.CacheEpmProperties(propertyValueCache, cache2.EpmSourceTree);
         }
         ProjectedPropertiesAnnotation projectedProperties = entry.GetAnnotation <ProjectedPropertiesAnnotation>();
         AtomEntryScope    currentEntryScope = this.CurrentEntryScope;
         AtomEntryMetadata entryMetadata     = entry.Atom();
         if (!currentEntryScope.IsElementWritten(AtomElement.Id))
         {
             this.atomEntryAndFeedSerializer.WriteEntryId(entry.Id);
         }
         Uri editLink = entry.EditLink;
         if ((editLink != null) && !currentEntryScope.IsElementWritten(AtomElement.EditLink))
         {
             this.atomEntryAndFeedSerializer.WriteEntryEditLink(editLink, entryMetadata);
         }
         Uri readLink = entry.ReadLink;
         if ((readLink != null) && !currentEntryScope.IsElementWritten(AtomElement.ReadLink))
         {
             this.atomEntryAndFeedSerializer.WriteEntryReadLink(readLink, entryMetadata);
         }
         AtomEntryMetadata epmEntryMetadata = null;
         if (cache2 != null)
         {
             ODataVersionChecker.CheckEntityPropertyMapping(this.atomOutputContext.Version, entryEntityType, this.atomOutputContext.Model);
             epmEntryMetadata = EpmSyndicationWriter.WriteEntryEpm(cache2.EpmTargetTree, propertyValueCache, entryEntityType.ToTypeReference().AsEntity(), this.atomOutputContext);
         }
         this.atomEntryAndFeedSerializer.WriteEntryMetadata(entryMetadata, epmEntryMetadata, this.updatedTime);
         IEnumerable <ODataProperty> entryStreamProperties = propertyValueCache.EntryStreamProperties;
         if (entryStreamProperties != null)
         {
             foreach (ODataProperty property in entryStreamProperties)
             {
                 this.atomEntryAndFeedSerializer.WriteStreamProperty(property, entryEntityType, base.DuplicatePropertyNamesChecker, projectedProperties);
             }
         }
         IEnumerable <ODataAssociationLink> associationLinks = entry.AssociationLinks;
         if (associationLinks != null)
         {
             foreach (ODataAssociationLink link in associationLinks)
             {
                 this.atomEntryAndFeedSerializer.WriteAssociationLink(link, entryEntityType, base.DuplicatePropertyNamesChecker, projectedProperties);
             }
         }
         IEnumerable <ODataAction> actions = entry.Actions;
         if (actions != null)
         {
             foreach (ODataAction action in actions)
             {
                 ValidationUtils.ValidateOperationNotNull(action, true);
                 this.atomEntryAndFeedSerializer.WriteOperation(action);
             }
         }
         IEnumerable <ODataFunction> functions = entry.Functions;
         if (functions != null)
         {
             foreach (ODataFunction function in functions)
             {
                 ValidationUtils.ValidateOperationNotNull(function, false);
                 this.atomEntryAndFeedSerializer.WriteOperation(function);
             }
         }
         this.WriteEntryContent(entry, entryEntityType, propertyValueCache, (cache2 == null) ? null : cache2.EpmSourceTree.Root, projectedProperties);
         if (cache2 != null)
         {
             EpmCustomWriter.WriteEntryEpm(this.atomOutputContext.XmlWriter, cache2.EpmTargetTree, propertyValueCache, entryEntityType.ToTypeReference().AsEntity(), this.atomOutputContext);
         }
         this.atomOutputContext.XmlWriter.WriteEndElement();
         this.EndEntryXmlCustomization(entry);
         this.CheckAndWriteParentNavigationLinkEndForInlineElement();
     }
 }
コード例 #14
0
        internal void ReadAtomElementInEntryContent(IODataAtomReaderEntryState entryState)
        {
            EpmTargetPathSegment            segment2;
            ODataEntityPropertyMappingCache cachedEpm     = entryState.CachedEpm;
            EpmTargetPathSegment            parentSegment = null;

            if (cachedEpm != null)
            {
                parentSegment = cachedEpm.EpmTargetTree.SyndicationRoot;
            }
            if (base.ShouldReadElement(parentSegment, base.XmlReader.LocalName, out segment2))
            {
                switch (base.XmlReader.LocalName)
                {
                case "author":
                    this.ReadAuthorElement(entryState, segment2);
                    return;

                case "contributor":
                    this.ReadContributorElement(entryState, segment2);
                    return;

                case "updated":
                {
                    AtomEntryMetadata atomEntryMetadata = entryState.AtomEntryMetadata;
                    if (!base.UseClientFormatBehavior)
                    {
                        if (!this.ShouldReadSingletonElement(atomEntryMetadata.Updated.HasValue))
                        {
                            break;
                        }
                        atomEntryMetadata.Updated = base.ReadAtomDateConstruct();
                        return;
                    }
                    if (!this.ShouldReadSingletonElement(atomEntryMetadata.UpdatedString != null))
                    {
                        break;
                    }
                    atomEntryMetadata.UpdatedString = base.ReadAtomDateConstructAsString();
                    return;
                }

                case "published":
                {
                    AtomEntryMetadata metadata2 = entryState.AtomEntryMetadata;
                    if (!base.UseClientFormatBehavior)
                    {
                        if (this.ShouldReadSingletonElement(metadata2.Published.HasValue))
                        {
                            metadata2.Published = base.ReadAtomDateConstruct();
                            return;
                        }
                        break;
                    }
                    if (!this.ShouldReadSingletonElement(metadata2.PublishedString != null))
                    {
                        break;
                    }
                    metadata2.PublishedString = base.ReadAtomDateConstructAsString();
                    return;
                }

                case "rights":
                    if (!this.ShouldReadSingletonElement(entryState.AtomEntryMetadata.Rights != null))
                    {
                        break;
                    }
                    entryState.AtomEntryMetadata.Rights = base.ReadAtomTextConstruct();
                    return;

                case "source":
                    if (!this.ShouldReadSingletonElement(entryState.AtomEntryMetadata.Source != null))
                    {
                        break;
                    }
                    entryState.AtomEntryMetadata.Source = this.ReadAtomSourceInEntryContent();
                    return;

                case "summary":
                    if (!this.ShouldReadSingletonElement(entryState.AtomEntryMetadata.Summary != null))
                    {
                        break;
                    }
                    entryState.AtomEntryMetadata.Summary = base.ReadAtomTextConstruct();
                    return;

                case "title":
                    if (!this.ShouldReadSingletonElement(entryState.AtomEntryMetadata.Title != null))
                    {
                        break;
                    }
                    entryState.AtomEntryMetadata.Title = base.ReadAtomTextConstruct();
                    return;
                }
            }
            base.XmlReader.Skip();
        }
コード例 #15
0
        /// <summary>
        /// Reads an element in ATOM namespace in the content of the entry element.
        /// </summary>
        /// <param name="entryState">The reader entry state for the entry being read.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element (atom:*) - the ATOM element to read.
        /// Post-Condition: Any                          - the node after the ATOM element which was read.
        /// </remarks>
        internal void ReadAtomElementInEntryContent(IODataAtomReaderEntryState entryState)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(entryState != null, "entryState != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Only atom:* elements can be read by this method.");

            ODataEntityPropertyMappingCache cachedEpm            = entryState.CachedEpm;
            EpmTargetPathSegment            epmTargetPathSegment = null;

            if (cachedEpm != null)
            {
                epmTargetPathSegment = cachedEpm.EpmTargetTree.SyndicationRoot;
            }

            EpmTargetPathSegment subSegment;

            if (this.ShouldReadElement(epmTargetPathSegment, this.XmlReader.LocalName, out subSegment))
            {
                switch (this.XmlReader.LocalName)
                {
                case AtomConstants.AtomAuthorElementName:
                    this.ReadAuthorElement(entryState, subSegment);
                    return;

                case AtomConstants.AtomContributorElementName:
                    this.ReadContributorElement(entryState, subSegment);
                    return;

                case AtomConstants.AtomUpdatedElementName:
                {
                    AtomEntryMetadata entryMetadata = entryState.AtomEntryMetadata;
                    if (this.UseClientFormatBehavior)
                    {
                        if (this.ShouldReadSingletonElement(entryMetadata.UpdatedString != null))
                        {
                            entryMetadata.UpdatedString = this.ReadAtomDateConstructAsString();
                            return;
                        }
                    }
                    else
                    {
                        if (this.ShouldReadSingletonElement(entryMetadata.Updated.HasValue))
                        {
                            entryMetadata.Updated = this.ReadAtomDateConstruct();
                            return;
                        }
                    }
                }

                break;

                case AtomConstants.AtomPublishedElementName:
                {
                    AtomEntryMetadata entryMetadata = entryState.AtomEntryMetadata;
                    if (this.UseClientFormatBehavior)
                    {
                        if (this.ShouldReadSingletonElement(entryMetadata.PublishedString != null))
                        {
                            entryMetadata.PublishedString = this.ReadAtomDateConstructAsString();
                            return;
                        }
                    }
                    else
                    {
                        if (this.ShouldReadSingletonElement(entryMetadata.Published.HasValue))
                        {
                            entryMetadata.Published = this.ReadAtomDateConstruct();
                            return;
                        }
                    }
                }

                break;

                case AtomConstants.AtomRightsElementName:
                    if (this.ShouldReadSingletonElement(entryState.AtomEntryMetadata.Rights != null))
                    {
                        entryState.AtomEntryMetadata.Rights = this.ReadAtomTextConstruct();
                        return;
                    }

                    break;

                case AtomConstants.AtomSourceElementName:
                    if (this.ShouldReadSingletonElement(entryState.AtomEntryMetadata.Source != null))
                    {
                        entryState.AtomEntryMetadata.Source = this.ReadAtomSourceInEntryContent();
                        return;
                    }

                    break;

                case AtomConstants.AtomSummaryElementName:
                    if (this.ShouldReadSingletonElement(entryState.AtomEntryMetadata.Summary != null))
                    {
                        entryState.AtomEntryMetadata.Summary = this.ReadAtomTextConstruct();
                        return;
                    }

                    break;

                case AtomConstants.AtomTitleElementName:
                    if (this.ShouldReadSingletonElement(entryState.AtomEntryMetadata.Title != null))
                    {
                        entryState.AtomEntryMetadata.Title = this.ReadAtomTextConstruct();
                        return;
                    }

                    break;

                default:
                    break;
                }
            }

            // Skip everything we didn't read.
            this.XmlReader.Skip();
        }