private bool ShouldWritePropertyInContent(IEdmStructuredType owningType, ProjectedPropertiesAnnotation projectedProperties, string propertyName, object propertyValue, EpmSourcePathSegment epmSourcePathSegment)
 {
     bool flag = !projectedProperties.ShouldSkipProperty(propertyName);
     if ((((base.MessageWriterSettings.WriterBehavior != null) && base.MessageWriterSettings.WriterBehavior.UseV1ProviderBehavior) && (owningType != null)) && owningType.IsODataComplexTypeKind())
     {
         IEdmComplexType complexType = (IEdmComplexType) owningType;
         CachedPrimitiveKeepInContentAnnotation annotation = base.Model.EpmCachedKeepPrimitiveInContent(complexType);
         if ((annotation != null) && annotation.IsKeptInContent(propertyName))
         {
             return flag;
         }
     }
     if ((propertyValue == null) && (epmSourcePathSegment != null))
     {
         return true;
     }
     EntityPropertyMappingAttribute entityPropertyMapping = EpmWriterUtils.GetEntityPropertyMapping(epmSourcePathSegment);
     if (entityPropertyMapping == null)
     {
         return flag;
     }
     string str = propertyValue as string;
     if ((str != null) && (str.Length == 0))
     {
         switch (entityPropertyMapping.TargetSyndicationItem)
         {
             case SyndicationItemProperty.AuthorEmail:
             case SyndicationItemProperty.AuthorUri:
             case SyndicationItemProperty.ContributorEmail:
             case SyndicationItemProperty.ContributorUri:
                 return true;
         }
     }
     return (entityPropertyMapping.KeepInContent && flag);
 }
Exemple #2
0
        /// <summary>
        /// Determines if the property with the specified value should be written into content or not.
        /// </summary>
        /// <param name="owningType">The owning type of the property to be checked.</param>
        /// <param name="projectedProperties">The set of projected properties for the <paramref name="owningType"/></param>
        /// <param name="propertyName">The name of the property to be checked.</param>
        /// <param name="propertyValue">The property value to write.</param>
        /// <param name="epmSourcePathSegment">The EPM source path segment for the property being written.</param>
        /// <returns>true if the property should be written into content, or false otherwise</returns>
        private bool ShouldWritePropertyInContent(
            IEdmStructuredType owningType,
            ProjectedPropertiesAnnotation projectedProperties,
            string propertyName,
            object propertyValue,
            EpmSourcePathSegment epmSourcePathSegment)
        {
            // check whether the property is projected; if no EPM is specified for the property the projection decides
            bool propertyProjected = !projectedProperties.ShouldSkipProperty(propertyName);

            bool useV1ProviderBehavior = this.MessageWriterSettings.WriterBehavior == null ? false : this.MessageWriterSettings.WriterBehavior.UseV1ProviderBehavior;

            if (useV1ProviderBehavior && owningType != null && owningType.IsODataComplexTypeKind())
            {
                IEdmComplexType owningComplexType = (IEdmComplexType)owningType;
                CachedPrimitiveKeepInContentAnnotation keepInContentAnnotation = this.Model.EpmCachedKeepPrimitiveInContent(owningComplexType);
                if (keepInContentAnnotation != null && keepInContentAnnotation.IsKeptInContent(propertyName))
                {
                    return(propertyProjected);
                }
            }

            // We sometimes write properties into content even if asked not to.
            // If the property value is null and the property (or one of its descendant properties) is mapped,
            // we always write into content, even if the property was not projected.
            if (propertyValue == null && epmSourcePathSegment != null)
            {
                return(true);
            }

            EntityPropertyMappingAttribute entityPropertyMapping = EpmWriterUtils.GetEntityPropertyMapping(epmSourcePathSegment);

            if (entityPropertyMapping == null)
            {
                return(propertyProjected);
            }

            string stringPropertyValue = propertyValue as string;

            if (stringPropertyValue != null && stringPropertyValue.Length == 0)
            {
                // If the property value is an empty string and we should be writing it into an ATOM element which does not allow empty string
                // we write it into content as well, also even if the property was not projected.
                switch (entityPropertyMapping.TargetSyndicationItem)
                {
                case SyndicationItemProperty.AuthorEmail:
                case SyndicationItemProperty.AuthorUri:
                case SyndicationItemProperty.ContributorEmail:
                case SyndicationItemProperty.ContributorUri:
                    return(true);

                default:
                    break;
                }
            }

            return(entityPropertyMapping.KeepInContent && propertyProjected);
        }
Exemple #3
0
 internal static bool IsAssignableFrom(this IEdmStructuredType baseType, IEdmStructuredType subtype)
 {
     if (baseType.TypeKind == subtype.TypeKind)
     {
         if (!baseType.IsODataEntityTypeKind() && !baseType.IsODataComplexTypeKind())
         {
             return(false);
         }
         for (IEdmStructuredType type = subtype; type != null; type = type.BaseType)
         {
             if (type.IsEquivalentTo(baseType))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        /// <summary>
        /// Creates an instance of <see cref="ODataResourceTypeContext"/>.
        /// </summary>
        /// <param name="serializationInfo">The serialization info from the resource set or resource instance.</param>
        /// <param name="navigationSource">The navigation source of the resource set or resource.</param>
        /// <param name="navigationSourceEntityType">The entity type of the navigation source.</param>
        /// <param name="expectedResourceType">The expected structured type of the resource set or resource.</param>
        /// <param name="throwIfMissingTypeInfo">If true, throw if any of the set or type name cannot be determined; if false, return null when any of the set or type name cannot determined.</param>
        /// <returns>A new instance of <see cref="ODataResourceTypeContext"/>.</returns>
        internal static ODataResourceTypeContext Create(ODataResourceSerializationInfo serializationInfo, IEdmNavigationSource navigationSource, IEdmEntityType navigationSourceEntityType, IEdmStructuredType expectedResourceType, bool throwIfMissingTypeInfo)
        {
            if (serializationInfo != null)
            {
                return(new ODataResourceTypeContextWithoutModel(serializationInfo));
            }

            // We are creating an ODataResourceTypeContext for a complex item with navigation source is null.
            if (expectedResourceType != null && expectedResourceType.IsODataComplexTypeKind())
            {
                return(new ODataResourceTypeContextWithModel(null, null, expectedResourceType));
            }

            // We are creating an ODataResourceTypeContext for an item in Navigation Source(e.g. an entity set).
            if (navigationSource != null && expectedResourceType != null)
            {
                return(new ODataResourceTypeContextWithModel(navigationSource, navigationSourceEntityType, expectedResourceType));
            }

            return(new ODataResourceTypeContext(expectedResourceType, throwIfMissingTypeInfo));
        }
            /// <summary>
            /// Constructs an instance of <see cref="ODataResourceTypeContext"/>.
            /// </summary>
            /// <param name="navigationSource">The navigation source of the resource set or resource.</param>
            /// <param name="navigationSourceEntityType">The entity type of the navigation source.</param>
            /// <param name="expectedResourceType">The expected resource type of the resource set or resource.</param>
            internal ODataResourceTypeContextWithModel(IEdmNavigationSource navigationSource, IEdmEntityType navigationSourceEntityType, IEdmStructuredType expectedResourceType)
                : base(expectedResourceType, /*throwIfMissingTypeInfo*/ false)
            {
                Debug.Assert(expectedResourceType != null, "expectedResourceType != null");
                Debug.Assert(navigationSource != null &&
                             navigationSourceEntityType != null ||
                             expectedResourceType.IsODataComplexTypeKind(),
                             "navigationSource != null && navigationSourceEntityType != null || expectedResourceType.IsODataComplexTypeKind()");

                this.navigationSource           = navigationSource;
                this.navigationSourceEntityType = navigationSourceEntityType;

                IEdmContainedEntitySet containedEntitySet = navigationSource as IEdmContainedEntitySet;

                if (containedEntitySet != null)
                {
                    if (containedEntitySet.NavigationProperty.Type.TypeKind() == EdmTypeKind.Collection)
                    {
                        this.isFromCollection = true;
                    }
                }

                IEdmUnknownEntitySet unknownEntitySet = navigationSource as IEdmUnknownEntitySet;

                if (unknownEntitySet != null)
                {
                    if (unknownEntitySet.Type.TypeKind == EdmTypeKind.Collection)
                    {
                        this.isFromCollection = true;
                    }
                }

                this.navigationSourceName = this.navigationSource == null ? null : this.navigationSource.Name;
                var entityType = this.expectedResourceType as IEdmEntityType;

                this.isMediaLinkEntry = entityType == null ? false : entityType.HasStream;
            }
Exemple #6
0
        private bool ShouldWritePropertyInContent(IEdmStructuredType owningType, ProjectedPropertiesAnnotation projectedProperties, string propertyName, object propertyValue, EpmSourcePathSegment epmSourcePathSegment)
        {
            bool flag = !projectedProperties.ShouldSkipProperty(propertyName);

            if ((((base.MessageWriterSettings.WriterBehavior != null) && base.MessageWriterSettings.WriterBehavior.UseV1ProviderBehavior) && (owningType != null)) && owningType.IsODataComplexTypeKind())
            {
                IEdmComplexType complexType = (IEdmComplexType)owningType;
                CachedPrimitiveKeepInContentAnnotation annotation = base.Model.EpmCachedKeepPrimitiveInContent(complexType);
                if ((annotation != null) && annotation.IsKeptInContent(propertyName))
                {
                    return(flag);
                }
            }
            if ((propertyValue == null) && (epmSourcePathSegment != null))
            {
                return(true);
            }
            EntityPropertyMappingAttribute entityPropertyMapping = EpmWriterUtils.GetEntityPropertyMapping(epmSourcePathSegment);

            if (entityPropertyMapping == null)
            {
                return(flag);
            }
            string str = propertyValue as string;

            if ((str != null) && (str.Length == 0))
            {
                switch (entityPropertyMapping.TargetSyndicationItem)
                {
                case SyndicationItemProperty.AuthorEmail:
                case SyndicationItemProperty.AuthorUri:
                case SyndicationItemProperty.ContributorEmail:
                case SyndicationItemProperty.ContributorUri:
                    return(true);
                }
            }
            return(entityPropertyMapping.KeepInContent && flag);
        }
        /// <summary>
        /// Determines if the property with the specified value should be written into content or not.
        /// </summary>
        /// <param name="owningType">The owning type of the property to be checked.</param>
        /// <param name="projectedProperties">The set of projected properties for the <paramref name="owningType"/></param>
        /// <param name="propertyName">The name of the property to be checked.</param>
        /// <param name="propertyValue">The property value to write.</param>
        /// <param name="epmSourcePathSegment">The EPM source path segment for the property being written.</param>
        /// <returns>true if the property should be written into content, or false otherwise</returns>
        private bool ShouldWritePropertyInContent(
            IEdmStructuredType owningType,
            ProjectedPropertiesAnnotation projectedProperties,
            string propertyName,
            object propertyValue,
            EpmSourcePathSegment epmSourcePathSegment)
        {
            // check whether the property is projected; if no EPM is specified for the property the projection decides 
            bool propertyProjected = !projectedProperties.ShouldSkipProperty(propertyName);

            bool useV1ProviderBehavior = this.MessageWriterSettings.WriterBehavior == null ? false : this.MessageWriterSettings.WriterBehavior.UseV1ProviderBehavior;
            if (useV1ProviderBehavior && owningType != null && owningType.IsODataComplexTypeKind())
            {
                IEdmComplexType owningComplexType = (IEdmComplexType)owningType;
                CachedPrimitiveKeepInContentAnnotation keepInContentAnnotation = this.Model.EpmCachedKeepPrimitiveInContent(owningComplexType);
                if (keepInContentAnnotation != null && keepInContentAnnotation.IsKeptInContent(propertyName))
                {
                    return propertyProjected;
                }
            }

            // We sometimes write properties into content even if asked not to.
            // If the property value is null and the property (or one of its descendant properties) is mapped, 
            // we always write into content, even if the property was not projected.
            if (propertyValue == null && epmSourcePathSegment != null)
            {
                return true;
            }

            EntityPropertyMappingAttribute entityPropertyMapping = EpmWriterUtils.GetEntityPropertyMapping(epmSourcePathSegment);
            if (entityPropertyMapping == null)
            {
                return propertyProjected;
            }

            string stringPropertyValue = propertyValue as string;
            if (stringPropertyValue != null && stringPropertyValue.Length == 0)
            {
                // If the property value is an empty string and we should be writing it into an ATOM element which does not allow empty string
                // we write it into content as well, also even if the property was not projected.
                switch (entityPropertyMapping.TargetSyndicationItem)
                {
                    case SyndicationItemProperty.AuthorEmail:
                    case SyndicationItemProperty.AuthorUri:
                    case SyndicationItemProperty.ContributorEmail:
                    case SyndicationItemProperty.ContributorUri:
                        return true;

                    default:
                        break;
                }
            }

            return entityPropertyMapping.KeepInContent && propertyProjected;
        }