예제 #1
0
        /// <summary>
        /// Validate the given <paramref name="property"/> and adds it to the list of properties for this type
        /// </summary>
        /// <param name="property">property which needs to be added.</param>
        private void AddPropertyInternal(ResourceProperty property)
        {
            if (this.propertiesDeclaredOnThisType == null)
            {
                this.propertiesDeclaredOnThisType = new List<ResourceProperty>();
            }

            foreach (ResourceProperty resourceProperty in this.propertiesDeclaredOnThisType)
            {
                if (resourceProperty.Name == property.Name)
                {
                    throw new InvalidOperationException(Strings.ResourceType_PropertyWithSameNameAlreadyExists(resourceProperty.Name, this.FullName));
                }
            }

            if (property.IsOfKind(ResourcePropertyKind.Key))
            {
                if (this.baseType != null)
                {
                    throw new InvalidOperationException(Strings.ResourceType_NoKeysInDerivedTypes);
                }

                if (this.ResourceTypeKind != ResourceTypeKind.EntityType)
                {
                    throw new InvalidOperationException(Strings.ResourceType_KeyPropertiesOnlyOnEntityTypes);
                }

                Debug.Assert(property.TypeKind == ResourceTypeKind.Primitive, "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                Debug.Assert(!property.IsOfKind(ResourcePropertyKind.ETag), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                Debug.Assert(property.IsOfKind(ResourcePropertyKind.Primitive), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
            }

            if (property.IsOfKind(ResourcePropertyKind.ETag))
            {
                if (this.ResourceTypeKind != ResourceTypeKind.EntityType)
                {
                    throw new InvalidOperationException(Strings.ResourceType_ETagPropertiesOnlyOnEntityTypes);
                }
#if DEBUG

                Debug.Assert(property.TypeKind == ResourceTypeKind.Primitive, "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                Debug.Assert(property.IsOfKind(ResourcePropertyKind.Primitive), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                Debug.Assert(!property.IsOfKind(ResourcePropertyKind.Key), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
#endif
            }

            this.propertiesDeclaredOnThisType.Add(property);
        }
예제 #2
0
 private IEdmProperty CreateProperty(EdmStructuredType declaringType, ResourceProperty resourceProperty)
 {
     IEdmProperty property;
     List<KeyValuePair<string, object>> annotations = (resourceProperty.CustomAnnotations == null) ? null : resourceProperty.CustomAnnotations.ToList<KeyValuePair<string, object>>();
     ODataNullValueBehaviorKind nullValueReadBehaviorKind = ODataNullValueBehaviorKind.Default;
     if (resourceProperty.IsOfKind(ResourcePropertyKind.Primitive) || resourceProperty.IsOfKind(ResourcePropertyKind.Stream))
     {
         IEdmPrimitiveTypeReference typeReference = MetadataProviderUtils.CreatePrimitiveTypeReference(resourceProperty.ResourceType, annotations);
         if (resourceProperty.IsOfKind(ResourcePropertyKind.Key))
         {
             if (typeReference.IsNullable)
             {
                 typeReference = (IEdmPrimitiveTypeReference) typeReference.Clone(false);
             }
             nullValueReadBehaviorKind = ODataNullValueBehaviorKind.IgnoreValue;
         }
         else if (MetadataProviderUtils.ShouldDisablePrimitivePropertyNullValidation(resourceProperty, typeReference))
         {
             nullValueReadBehaviorKind = ODataNullValueBehaviorKind.DisableValidation;
         }
         string andRemoveDefaultValue = MetadataProviderUtils.GetAndRemoveDefaultValue(annotations);
         EdmConcurrencyMode concurrencyMode = resourceProperty.IsOfKind(ResourcePropertyKind.ETag) ? EdmConcurrencyMode.Fixed : EdmConcurrencyMode.None;
         property = declaringType.AddStructuralProperty(resourceProperty.Name, typeReference, andRemoveDefaultValue, concurrencyMode);
         string mimeType = resourceProperty.MimeType;
         if (!string.IsNullOrEmpty(mimeType))
         {
             this.SetMimeType(property, mimeType);
         }
     }
     else if (resourceProperty.IsOfKind(ResourcePropertyKind.ComplexType))
     {
         IEdmTypeReference reference2 = this.EnsureTypeReference(resourceProperty.ResourceType, annotations);
         string defaultValue = MetadataProviderUtils.GetAndRemoveDefaultValue(annotations);
         property = declaringType.AddStructuralProperty(resourceProperty.Name, reference2, defaultValue, EdmConcurrencyMode.None);
         if (this.metadataProvider.IsV1Provider && !reference2.IsNullable)
         {
             nullValueReadBehaviorKind = ODataNullValueBehaviorKind.DisableValidation;
         }
     }
     else if (resourceProperty.IsOfKind(ResourcePropertyKind.Collection))
     {
         string str4 = MetadataProviderUtils.GetAndRemoveDefaultValue(annotations);
         IEdmTypeReference reference3 = this.EnsureTypeReference(resourceProperty.ResourceType, annotations);
         property = declaringType.AddStructuralProperty(resourceProperty.Name, reference3, str4, EdmConcurrencyMode.None);
     }
     else
     {
         if (!resourceProperty.IsOfKind(ResourcePropertyKind.ResourceSetReference) && !resourceProperty.IsOfKind(ResourcePropertyKind.ResourceReference))
         {
             throw new InvalidOperationException(System.Data.Services.Strings.MetadataProviderEdmModel_UnsupportedResourcePropertyKind(resourceProperty.Kind.ToString()));
         }
         EdmEntityType type = (EdmEntityType) declaringType;
         IEdmTypeReference reference4 = resourceProperty.IsOfKind(ResourcePropertyKind.ResourceSetReference) ? this.EnsureEntityPrimitiveOrComplexCollectionTypeReference(resourceProperty.ResourceType, annotations) : this.EnsureTypeReference(resourceProperty.ResourceType, annotations);
         property = new MetadataProviderEdmNavigationProperty(type, resourceProperty.Name, reference4);
         type.AddProperty(property);
     }
     this.SetNullValueReaderBehavior(property, nullValueReadBehaviorKind);
     MetadataProviderUtils.ConvertCustomAnnotations(this, annotations, property);
     return property;
 }
예제 #3
0
        private static ExpandedProjectionNode ApplyProjectionForProperty(ExpandedProjectionNode parentNode, string propertyName, ResourceProperty property, ResourceType targetResourceType, bool lastPathSegment)
        {
            if (property != null)
            {
                switch (property.TypeKind)
                {
                    case ResourceTypeKind.ComplexType:
                        if (!lastPathSegment)
                        {
                            throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_ComplexPropertyAsInnerSelectSegment(targetResourceType.FullName, propertyName));
                        }
                        break;

                    case ResourceTypeKind.Primitive:
                        if (!lastPathSegment)
                        {
                            if (property.IsOfKind(ResourcePropertyKind.Stream))
                            {
                                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_NamedStreamMustBeLastSegmentInSelect(propertyName));
                            }
                            throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_PrimitivePropertyUsedAsNavigationProperty(targetResourceType.FullName, propertyName));
                        }
                        break;

                    case ResourceTypeKind.Collection:
                        if (!lastPathSegment)
                        {
                            throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_CollectionPropertyAsInnerSelectSegment(targetResourceType.FullName, propertyName));
                        }
                        break;
                }
            }
            ExpandedProjectionNode node = parentNode.AddProjectionNode(propertyName, property, targetResourceType, lastPathSegment);
            if (lastPathSegment && (node != null))
            {
                node.ProjectionFound = true;
                node.MarkSubtreeAsProjected();
            }
            return node;
        }
예제 #4
0
 private void AddPropertyInternal(ResourceProperty property)
 {
     if (this.propertiesDeclaredOnThisType == null)
     {
         this.propertiesDeclaredOnThisType = new List<ResourceProperty>();
     }
     foreach (ResourceProperty property2 in this.propertiesDeclaredOnThisType)
     {
         if (property2.Name == property.Name)
         {
             throw new InvalidOperationException(System.Data.Services.Strings.ResourceType_PropertyWithSameNameAlreadyExists(property2.Name, this.FullName));
         }
     }
     if (property.IsOfKind(ResourcePropertyKind.Stream))
     {
         if (this.ResourceTypeKind != System.Data.Services.Providers.ResourceTypeKind.EntityType)
         {
             throw new InvalidOperationException(System.Data.Services.Strings.ResourceType_NamedStreamsOnlyApplyToEntityType(this.FullName));
         }
     }
     else
     {
         if (property.IsOfKind(ResourcePropertyKind.Key))
         {
             if (this.baseType != null)
             {
                 throw new InvalidOperationException(System.Data.Services.Strings.ResourceType_NoKeysInDerivedTypes);
             }
             if (this.ResourceTypeKind != System.Data.Services.Providers.ResourceTypeKind.EntityType)
             {
                 throw new InvalidOperationException(System.Data.Services.Strings.ResourceType_KeyPropertiesOnlyOnEntityTypes);
             }
             if (typeof(ISpatial).IsAssignableFrom(property.ResourceType.type))
             {
                 throw new InvalidOperationException(System.Data.Services.Strings.ResourceType_SpatialKeyOrETag(property.Name, this.name));
             }
         }
         if (property.IsOfKind(ResourcePropertyKind.ETag))
         {
             if (this.ResourceTypeKind != System.Data.Services.Providers.ResourceTypeKind.EntityType)
             {
                 throw new InvalidOperationException(System.Data.Services.Strings.ResourceType_ETagPropertiesOnlyOnEntityTypes);
             }
             if (typeof(ISpatial).IsAssignableFrom(property.ResourceType.type))
             {
                 throw new InvalidOperationException(System.Data.Services.Strings.ResourceType_SpatialKeyOrETag(property.Name, this.name));
             }
         }
     }
     this.propertiesDeclaredOnThisType.Add(property);
 }
예제 #5
0
		/// <summary>
		/// Validate the given <paramref name="property"/> and adds it to the list of properties for this type
		/// </summary>
		/// <param name="property">property which needs to be added.</param>
		private void AddPropertyImplementation(ResourceProperty property)
		{
			if (this.propertiesDeclaredOnThisType == null)
			{
				this.propertiesDeclaredOnThisType = new List<ResourceProperty>();
			}

			foreach (ResourceProperty resourceProperty in this.propertiesDeclaredOnThisType)
			{
				if (resourceProperty.Name == property.Name)
				{
					throw new InvalidOperationException(Strings.ResourceType_PropertyWithSameNameAlreadyExists(resourceProperty.Name, this.FullName));
				}
			}

			if (property.IsOfKind(ResourcePropertyKind.Stream))
			{
				// NamedStream Property
				// Can only add named streams to entity types.
				if (this.ResourceTypeKind != Providers.ResourceTypeKind.EntityType)
				{
					throw new InvalidOperationException(Strings.ResourceType_NamedStreamsOnlyApplyToEntityType(this.FullName));
				}

				// NamedStream cannot be used as key or etag (you cannot create a property with a mixed flag that contains stream)
				Debug.Assert(!property.IsOfKind(ResourcePropertyKind.Key) && !property.IsOfKind(ResourcePropertyKind.ETag), "NamedStream property kind must be used alone");
				Debug.Assert(!property.CanReflectOnInstanceTypeProperty, "NamedStream properties must not be able to reflect");
			}
			else
			{
				if (property.IsOfKind(ResourcePropertyKind.Key))
				{
					if (this.baseType != null)
					{
						throw new InvalidOperationException(Strings.ResourceType_NoKeysInDerivedTypes);
					}

					if (this.ResourceTypeKind != ResourceTypeKind.EntityType)
					{
						throw new InvalidOperationException(Strings.ResourceType_KeyPropertiesOnlyOnEntityTypes);
					}

					Debug.Assert(property.ResourceType.ResourceTypeKind == ResourceTypeKind.Primitive, "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
					Debug.Assert(!property.IsOfKind(ResourcePropertyKind.ETag), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
					Debug.Assert(property.IsOfKind(ResourcePropertyKind.Primitive), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
				}

				if (property.IsOfKind(ResourcePropertyKind.ETag))
				{
					if (this.ResourceTypeKind != ResourceTypeKind.EntityType)
					{
						throw new InvalidOperationException(Strings.ResourceType_ETagPropertiesOnlyOnEntityTypes);
					}

					Debug.Assert(property.ResourceType.ResourceTypeKind == ResourceTypeKind.Primitive, "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
					Debug.Assert(property.IsOfKind(ResourcePropertyKind.Primitive), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
					Debug.Assert(!property.IsOfKind(ResourcePropertyKind.Key), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
				}

				Debug.Assert(property.ResourceType != GetPrimitiveResourceType(typeof(System.IO.Stream)), "Non NamedStream resource using Stream type");
			}

			this.propertiesDeclaredOnThisType.Add(property);
		}
예제 #6
0
        /// <summary>
        /// Write the facets for clr types
        /// </summary>
        /// <param name="xmlWriter">XmlWriter in which facets needs to be written</param>
        /// <param name="resourceProperty">property which contains the primitive type for which facets needs to be written</param>
        private static void WritePrimitivePropertyFacets(XmlWriter xmlWriter, ResourceProperty resourceProperty)
        {
            Debug.Assert(resourceProperty.IsOfKind(ResourcePropertyKind.Primitive), "property must be of primitive type");

            bool nullable = true;
            if (resourceProperty.IsOfKind(ResourcePropertyKind.Key) || (resourceProperty.Type.IsValueType && Nullable.GetUnderlyingType(resourceProperty.Type) == null))
            {
                nullable = false;
            }

            xmlWriter.WriteAttributeString(XmlConstants.Nullable, nullable ? XmlConstants.XmlTrueLiteral : XmlConstants.XmlFalseLiteral);
        }
예제 #7
0
        private IEdmProperty CreateProperty(EdmStructuredType declaringType, ResourceProperty resourceProperty)
        {
            IEdmProperty property;
            List <KeyValuePair <string, object> > annotations = (resourceProperty.CustomAnnotations == null) ? null : resourceProperty.CustomAnnotations.ToList <KeyValuePair <string, object> >();
            ODataNullValueBehaviorKind            nullValueReadBehaviorKind = ODataNullValueBehaviorKind.Default;

            if (resourceProperty.IsOfKind(ResourcePropertyKind.Primitive) || resourceProperty.IsOfKind(ResourcePropertyKind.Stream))
            {
                IEdmPrimitiveTypeReference typeReference = MetadataProviderUtils.CreatePrimitiveTypeReference(resourceProperty.ResourceType, annotations);
                if (resourceProperty.IsOfKind(ResourcePropertyKind.Key))
                {
                    if (typeReference.IsNullable)
                    {
                        typeReference = (IEdmPrimitiveTypeReference)typeReference.Clone(false);
                    }
                    nullValueReadBehaviorKind = ODataNullValueBehaviorKind.IgnoreValue;
                }
                else if (MetadataProviderUtils.ShouldDisablePrimitivePropertyNullValidation(resourceProperty, typeReference))
                {
                    nullValueReadBehaviorKind = ODataNullValueBehaviorKind.DisableValidation;
                }
                string             andRemoveDefaultValue = MetadataProviderUtils.GetAndRemoveDefaultValue(annotations);
                EdmConcurrencyMode concurrencyMode       = resourceProperty.IsOfKind(ResourcePropertyKind.ETag) ? EdmConcurrencyMode.Fixed : EdmConcurrencyMode.None;
                property = declaringType.AddStructuralProperty(resourceProperty.Name, typeReference, andRemoveDefaultValue, concurrencyMode);
                string mimeType = resourceProperty.MimeType;
                if (!string.IsNullOrEmpty(mimeType))
                {
                    this.SetMimeType(property, mimeType);
                }
            }
            else if (resourceProperty.IsOfKind(ResourcePropertyKind.ComplexType))
            {
                IEdmTypeReference reference2   = this.EnsureTypeReference(resourceProperty.ResourceType, annotations);
                string            defaultValue = MetadataProviderUtils.GetAndRemoveDefaultValue(annotations);
                property = declaringType.AddStructuralProperty(resourceProperty.Name, reference2, defaultValue, EdmConcurrencyMode.None);
                if (this.metadataProvider.IsV1Provider && !reference2.IsNullable)
                {
                    nullValueReadBehaviorKind = ODataNullValueBehaviorKind.DisableValidation;
                }
            }
            else if (resourceProperty.IsOfKind(ResourcePropertyKind.Collection))
            {
                string            str4       = MetadataProviderUtils.GetAndRemoveDefaultValue(annotations);
                IEdmTypeReference reference3 = this.EnsureTypeReference(resourceProperty.ResourceType, annotations);
                property = declaringType.AddStructuralProperty(resourceProperty.Name, reference3, str4, EdmConcurrencyMode.None);
            }
            else
            {
                if (!resourceProperty.IsOfKind(ResourcePropertyKind.ResourceSetReference) && !resourceProperty.IsOfKind(ResourcePropertyKind.ResourceReference))
                {
                    throw new InvalidOperationException(System.Data.Services.Strings.MetadataProviderEdmModel_UnsupportedResourcePropertyKind(resourceProperty.Kind.ToString()));
                }
                EdmEntityType     type       = (EdmEntityType)declaringType;
                IEdmTypeReference reference4 = resourceProperty.IsOfKind(ResourcePropertyKind.ResourceSetReference) ? this.EnsureEntityPrimitiveOrComplexCollectionTypeReference(resourceProperty.ResourceType, annotations) : this.EnsureTypeReference(resourceProperty.ResourceType, annotations);
                property = new MetadataProviderEdmNavigationProperty(type, resourceProperty.Name, reference4);
                type.AddProperty(property);
            }
            this.SetNullValueReaderBehavior(property, nullValueReadBehaviorKind);
            MetadataProviderUtils.ConvertCustomAnnotations(this, annotations, property);
            return(property);
        }
예제 #8
0
 /// <summary>
 /// return true if this property is of the given kind
 /// </summary>
 /// <param name="checkKind">flag which needs to be checked on the current property kind</param>
 /// <returns>true if the current property is of the given kind</returns>
 internal bool IsOfKind(ResourcePropertyKind checkKind)
 {
     return(ResourceProperty.IsOfKind(this.kind, checkKind));
 }
예제 #9
0
        /// <summary>
        /// Return true if this property is of the given kind.
        /// </summary>
        /// <param name="checkKind">Flag which needs to be checked on the current property kind.</param>
        /// <returns>true if the current property is of the given kind.</returns>
        internal bool IsOfKind(ResourcePropertyKind checkKind)
        {
            DebugUtils.CheckNoExternalCallers();

            return(ResourceProperty.IsOfKind(this.kind, checkKind));
        }
예제 #10
0
        /// <summary>
        /// Validate the given <paramref name="property"/> and adds it to the list of properties for this type
        /// </summary>
        /// <param name="property">property which needs to be added.</param>
        private void AddPropertyImplementation(ResourceProperty property)
        {
            if (this.propertiesDeclaredOnThisType == null)
            {
                this.propertiesDeclaredOnThisType = new List <ResourceProperty>();
            }

            foreach (ResourceProperty resourceProperty in this.propertiesDeclaredOnThisType)
            {
                if (resourceProperty.Name == property.Name)
                {
                    throw new InvalidOperationException(Strings.ResourceType_PropertyWithSameNameAlreadyExists(resourceProperty.Name, this.FullName));
                }
            }

            if (property.IsOfKind(ResourcePropertyKind.Stream))
            {
                // NamedStream Property
                // Can only add named streams to entity types.
                if (this.ResourceTypeKind != Providers.ResourceTypeKind.EntityType)
                {
                    throw new InvalidOperationException(Strings.ResourceType_NamedStreamsOnlyApplyToEntityType(this.FullName));
                }

                // NamedStream cannot be used as key or etag (you cannot create a property with a mixed flag that contains stream)
                Debug.Assert(!property.IsOfKind(ResourcePropertyKind.Key) && !property.IsOfKind(ResourcePropertyKind.ETag), "NamedStream property kind must be used alone");
                Debug.Assert(!property.CanReflectOnInstanceTypeProperty, "NamedStream properties must not be able to reflect");
            }
            else
            {
                if (property.IsOfKind(ResourcePropertyKind.Key))
                {
                    if (this.baseType != null)
                    {
                        throw new InvalidOperationException(Strings.ResourceType_NoKeysInDerivedTypes);
                    }

                    if (this.ResourceTypeKind != ResourceTypeKind.EntityType)
                    {
                        throw new InvalidOperationException(Strings.ResourceType_KeyPropertiesOnlyOnEntityTypes);
                    }

                    Debug.Assert(property.ResourceType.ResourceTypeKind == ResourceTypeKind.Primitive, "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                    Debug.Assert(!property.IsOfKind(ResourcePropertyKind.ETag), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                    Debug.Assert(property.IsOfKind(ResourcePropertyKind.Primitive), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                }

                if (property.IsOfKind(ResourcePropertyKind.ETag))
                {
                    if (this.ResourceTypeKind != ResourceTypeKind.EntityType)
                    {
                        throw new InvalidOperationException(Strings.ResourceType_ETagPropertiesOnlyOnEntityTypes);
                    }

                    Debug.Assert(property.ResourceType.ResourceTypeKind == ResourceTypeKind.Primitive, "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                    Debug.Assert(property.IsOfKind(ResourcePropertyKind.Primitive), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                    Debug.Assert(!property.IsOfKind(ResourcePropertyKind.Key), "This check must have been done in ResourceProperty.ValidatePropertyParameters method");
                }

                Debug.Assert(property.ResourceType != GetPrimitiveResourceType(typeof(System.IO.Stream)), "Non NamedStream resource using Stream type");
            }

            this.propertiesDeclaredOnThisType.Add(property);
        }
예제 #11
0
 private ODataProperty GetODataPropertyForEntityProperty(object customObject, ResourceType currentResourceType, Uri relativeUri, ResourceProperty property)
 {
     object obj2;
     if (property.IsOfKind(ResourcePropertyKind.Stream))
     {
         obj2 = this.GetNamedStreamPropertyValue(customObject, property, relativeUri);
     }
     else
     {
         object propertyValue = WebUtil.GetPropertyValue(base.Provider, customObject, currentResourceType, property, null);
         obj2 = base.GetPropertyValue(property.Name, property.ResourceType, propertyValue, property == null);
     }
     return new ODataProperty { Name = property.Name, Value = obj2 };
 }