コード例 #1
0
        //Named Resource using .NET Framework 4.0
        public Stream GetReadStream40(object entity, ResourceProperty resourceProperty, string etag, bool? checkETagForEquality, DataServiceOperationContext operationContext)
        {
            vProductCatalog image = entity as vProductCatalog;

            //ThumbnailPhoto and LargePhoto
            string imageFilePath = HostingEnvironment.MapPath("~/ProductImages/" + resourceProperty.Name);

            if (checkETagForEquality != null)
            {
                // This stream provider implementation does not support 
                // ETag headers for media resources. This means that we do not track 
                // concurrency for a media resource and last-in wins on updates.
                throw new DataServiceException(400, "This sample service does not support the ETag header for a media resource.");
            }

            if (image == null)
            {
                throw new DataServiceException(500, "Internal Server Error.");
            }

            // Build the full path to the stored image file, which includes the entity key.
            string fullImageFilePath = string.Format(@"{0}\{1}.gif", imageFilePath, this.ProductPhotoID(image.ProductID));

            if (!File.Exists(fullImageFilePath))
            {
                throw new DataServiceException(500, "The image could not be found.");
            }

            // Return a stream that contains the requested file.
            return new FileStream(fullImageFilePath, FileMode.Open);
        }
コード例 #2
0
		public PrimitiveTypeSerializer(ResourceType resourceType, ResourceProperty resourceProperty) : base(resourceType)
		{
			object defaultValue;
			object[] resourceTypeKind = new object[2];
			resourceTypeKind[0] = resourceType.ResourceTypeKind;
			resourceTypeKind[1] = ResourceTypeKind.Primitive;
			ExceptionHelpers.ThrowArgumentExceptionIf("resourceType", resourceType.ResourceTypeKind != ResourceTypeKind.Primitive, new ExceptionHelpers.MessageLoader(SerializerBase.GetInvalidArgMessage), resourceTypeKind);
			this.defaultValue = null;
			if (resourceProperty != null)
			{
				if ((resourceProperty.Kind & ResourcePropertyKind.Primitive) != ResourcePropertyKind.Primitive || resourceProperty.ResourceType.InstanceType != resourceType.InstanceType)
				{
					throw new ArgumentException("resourceProperty");
				}
				else
				{
					PropertyCustomState customState = resourceProperty.GetCustomState();
					PrimitiveTypeSerializer primitiveTypeSerializer = this;
					if (customState != null)
					{
						defaultValue = customState.DefaultValue;
					}
					else
					{
						defaultValue = null;
					}
					primitiveTypeSerializer.defaultValue = defaultValue;
					this.name = resourceProperty.Name;
				}
			}
		}
コード例 #3
0
        /// <summary>
        /// Gets the property info for the resource property declared on this type.
        /// </summary>
        /// <param name="resourceType">The resource type to get the property on.</param>
        /// <param name="resourceProperty">Resource property instance to get the property info for.</param>
        /// <returns>Returns the PropertyInfo object for the specified resource property.</returns>
        internal PropertyInfo GetPropertyInfo(ResourceType resourceType, ResourceProperty resourceProperty)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(resourceType != null, "resourceType != null");
            Debug.Assert(resourceProperty != null, "resourceProperty != null");
            Debug.Assert(resourceProperty.CanReflectOnInstanceTypeProperty, "resourceProperty.CanReflectOnInstanceTypeProperty");
            Debug.Assert(resourceType.Properties.Contains(resourceProperty), "The resourceType does not define the specified resourceProperty.");

            if (this.propertyInfosDeclaredOnThisType == null)
            {
                this.propertyInfosDeclaredOnThisType = new Dictionary<ResourceProperty, PropertyInfo>(ReferenceEqualityComparer<ResourceProperty>.Instance);
            }

            PropertyInfo propertyInfo;
            if (!this.propertyInfosDeclaredOnThisType.TryGetValue(resourceProperty, out propertyInfo))
            {
                BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance;
                propertyInfo = resourceType.InstanceType.GetProperty(resourceProperty.Name, bindingFlags);
                if (propertyInfo == null)
                {
                    throw new ODataException(Strings.PropertyInfoResourceTypeAnnotation_CannotFindProperty(resourceType.FullName, resourceType.InstanceType, resourceProperty.Name));
                }

                this.propertyInfosDeclaredOnThisType.Add(resourceProperty, propertyInfo);
            }

            Debug.Assert(propertyInfo != null, "propertyInfo != null");
            return propertyInfo;
        }
コード例 #4
0
		public ReferenceTypeSerializer(ResourceType referringResourceType, ResourceProperty resourceProperty) : base(resourceProperty.ResourceType)
		{
			if (resourceProperty.ResourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
			{
				object[] name = new object[1];
				name[0] = resourceProperty.Name;
				referringResourceType.ThrowIfNull("referringResourceType", new ParameterExtensions.MessageLoader(SerializerBase.GetReferringResourceTypeCannotNullMessage), name);
				DataContext currentContext = DataServiceController.Current.GetCurrentContext();
				if (currentContext != null)
				{
					PSEntityMetadata entityMetadata = currentContext.UserSchema.GetEntityMetadata(referringResourceType) as PSEntityMetadata;
					PSEntityMetadata.ReferenceSetCmdlets referenceSetCmdlet = null;
					if (!entityMetadata.CmdletsForReferenceSets.TryGetValue(resourceProperty.Name, out referenceSetCmdlet))
					{
						this.referencePropertyType = PSEntityMetadata.ReferenceSetCmdlets.ReferencePropertyType.Instance;
					}
					else
					{
						this.referencePropertyType = referenceSetCmdlet.PropertyType;
						return;
					}
				}
				return;
			}
			else
			{
				throw new ArgumentException("resourceType");
			}
		}
コード例 #5
0
		public bool Extract(Expression tree, IQueryable<DSResource> resourceRoot, ResourceType resourceType, EntityMetadata entityMetadata)
		{
			this.resourceRoot = resourceRoot;
			this.entityMetadata = entityMetadata;
			this.navigationProperty = null;
			this.referredEntityKeys = new Dictionary<string, object>();
			this.referringEntityKeys = new Dictionary<string, object>();
			this.currentState = ReferredResourceExtractor.ExtractionState.ExtractingReferredEntityInfo;
			this.Visit(tree);
			if (this.currentState == ReferredResourceExtractor.ExtractionState.ExtractingReferringEntityInfo)
			{
				DSResource dSResource = ResourceTypeExtensions.CreateKeyOnlyResource(resourceType, this.referringEntityKeys);
				if (dSResource != null)
				{
					this.ReferredResource = ResourceTypeExtensions.CreateKeyOnlyResource(this.navigationProperty.ResourceType, this.referredEntityKeys);
					if (this.ReferredResource != null)
					{
						this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionDone;
					}
				}
			}
			if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractionDone)
			{
				this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
			}
			return this.currentState == ReferredResourceExtractor.ExtractionState.ExtractionDone;
		}
コード例 #6
0
ファイル: ExpressionHelper.cs プロジェクト: nickchal/pash
		public static bool GetPropertyNameAndValue(BinaryExpression binaryExpr, out ResourceProperty property, out object value)
		{
			property = null;
			value = null;
			UnaryExpression left = binaryExpr.Left as UnaryExpression;
			MethodCallExpression operand = null;
			if (left != null)
			{
				operand = left.Operand as MethodCallExpression;
			}
			if (operand != null && binaryExpr.Left.NodeType == ExpressionType.Convert && operand.NodeType == ExpressionType.Call && binaryExpr.Right.NodeType == ExpressionType.Constant && (operand.Method == ExpressionHelper.GetValueMethodInfo || operand.Method == ExpressionHelper.GetSequenceValueMethodInfo))
			{
				ConstantExpression item = operand.Arguments[1] as ConstantExpression;
				if (item != null)
				{
					property = item.Value as ResourceProperty;
				}
				ConstantExpression right = binaryExpr.Right as ConstantExpression;
				if (right != null)
				{
					value = right.Value;
				}
			}
			return property != null;
		}
コード例 #7
0
 public ResourceAssociationSet GetResourceAssociationSet(
     ResourceSet resourceSet,
     ResourceType resourceType,
     ResourceProperty resourceProperty)
 {
     // resourceProperty.GetAnnotation().ResourceAssociationSet;
     return resourceProperty.CustomState as ResourceAssociationSet;
 } 
コード例 #8
0
        /// <summary>Creates new instance of <see cref="ProjectionNode"/> which represents a simple projected property.</summary>
        /// <param name="propertyName">The name of the property to project.</param>
        /// <param name="property">The <see cref="ResourceProperty"/> for the property to project. If an open property
        /// is to be projected, specify null.</param>
        internal ProjectionNode(string propertyName, ResourceProperty property)
        {
            Debug.Assert(propertyName != null, "propertyName != null");
            Debug.Assert(property == null || property.Name == propertyName, "If the property is specified its name must match.");

            this.propertyName = propertyName;
            this.property = property;
        }
コード例 #9
0
        /// <summary>
        /// Creates a new instance of EndInfo.
        /// </summary>
        /// <param name="name">name of the end.</param>
        /// <param name="resourceType">resource type that the end refers to.</param>
        /// <param name="resourceProperty">property of the end.</param>
        /// <param name="fromProperty">Property on the related end that points to this end. The multiplicity of this end is determined from the fromProperty.</param>
        internal ResourceAssociationTypeEnd(string name, ResourceType resourceType, ResourceProperty resourceProperty, ResourceProperty fromProperty)
        {
            Debug.Assert(!String.IsNullOrEmpty(name), "!String.IsNullOrEmpty(name)");
            Debug.Assert(resourceType != null, "type != null");

            this.name = name;
            this.resourceType = resourceType;
            this.resourceProperty = resourceProperty;
            this.fromProperty = fromProperty;
        }
コード例 #10
0
        /// <summary>
        /// Gets the property info for the resource property on the specified resource type.
        /// </summary>
        /// <param name="resourceType">The resource type to get the property on.</param>
        /// <param name="resourceProperty">Resource property instance to get the property info for.</param>
        /// <returns>Returns the PropertyInfo object for the specified resource property.</returns>
        /// <remarks>The method searches this type as well as all its base types for the property.</remarks>
        internal static PropertyInfo GetPropertyInfo(this ResourceType resourceType, ResourceProperty resourceProperty)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(resourceType != null, "resourceType != null");
            Debug.Assert(resourceProperty != null, "resourceProperty != null");
            Debug.Assert(resourceProperty.CanReflectOnInstanceTypeProperty, "resourceProperty.CanReflectOnInstanceTypeProperty");
            Debug.Assert(resourceType.Properties.Contains(resourceProperty), "The resourceType does not define the specified resourceProperty.");

            return PropertyInfoResourceTypeAnnotation.GetPropertyInfoResourceTypeAnnotation(resourceType).GetPropertyInfo(resourceType, resourceProperty);
        }
コード例 #11
0
		internal static bool IsReference(ResourceProperty property)
		{
			if (property.Kind == ResourcePropertyKind.ResourceReference)
			{
				return true;
			}
			else
			{
				return property.Kind == ResourcePropertyKind.ResourceSetReference;
			}
		}
コード例 #12
0
 internal ResourceAssociationTypeEnd GetResourceAssociationTypeEnd(ResourceType resourceType, ResourceProperty resourceProperty)
 {
     foreach (ResourceAssociationTypeEnd end in new ResourceAssociationTypeEnd[] { this.end1, this.end2 })
     {
         if ((end.ResourceType == resourceType) && (end.ResourceProperty == resourceProperty))
         {
             return end;
         }
     }
     return null;
 }
コード例 #13
0
 public override object GetPropertyValue(object target, ResourceProperty resourceProperty)
 {
     if (target is DSPResource)
     {
         return (target as DSPResource).GetValue(resourceProperty.Name);
     }
     else
     {
         throw new NotSupportedException("Unrecognized resource type.");
     }
 }
コード例 #14
0
ファイル: ExpandSegment.cs プロジェクト: nickchal/pash
 internal ExpandSegment(string name, Expression filter, int maxResultsExpected, ResourceSetWrapper container, ResourceType targetResourceType, ResourceProperty expandedProperty, System.Data.Services.Providers.OrderingInfo orderingInfo)
 {
     WebUtil.CheckArgumentNull<string>(name, "name");
     CheckFilterType(filter);
     this.name = name;
     this.filter = filter;
     this.container = container;
     this.maxResultsExpected = maxResultsExpected;
     this.expandedProperty = expandedProperty;
     this.orderingInfo = orderingInfo;
     this.targetResourceType = targetResourceType;
 }
コード例 #15
0
		public void GetValue ()
		{
			var rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
			var rp = new ResourceProperty ("Length", ResourcePropertyKind.ComplexType, rt);
			AssertExtensions.Throws<NotImplementedException> (() => {
				DataServiceProviderMethods.GetValue ("test", rp);
			}, "#A1");

			AssertExtensions.Throws<NotImplementedException> (() => {
				DataServiceProviderMethods.GetValue (null, null);
			}, "#A2");
		}
コード例 #16
0
 internal ExpandedProjectionNode(string propertyName, ResourceProperty property, System.Data.Services.Providers.ResourceType targetResourceType, System.Data.Services.Providers.ResourceSetWrapper resourceSetWrapper, System.Data.Services.Providers.OrderingInfo orderingInfo, Expression filter, int? skipCount, int? takeCount, int? maxResultsExpected) : base(propertyName, property, targetResourceType)
 {
     this.resourceSetWrapper = resourceSetWrapper;
     this.orderingInfo = orderingInfo;
     this.filter = filter;
     this.skipCount = skipCount;
     this.takeCount = takeCount;
     this.maxResultsExpected = maxResultsExpected;
     this.nodes = new List<ProjectionNode>();
     this.operations = new List<OperationWrapper>();
     this.hasExpandedPropertyOnDerivedType = false;
 }
コード例 #17
0
 internal ResourceAssociationSetEnd GetRelatedResourceAssociationSetEnd(ResourceSetWrapper resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
 {
     ResourceAssociationSetEnd end = this.GetResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty);
     if (end == null)
     {
         return null;
     }
     if (end != this.End1)
     {
         return this.End1;
     }
     return this.End2;
 }
コード例 #18
0
        /// <summary>
        /// Retrieve the end for the given resource set, type and property.
        /// </summary>
        /// <param name="resourceType">resource type for the end</param>
        /// <param name="resourceProperty">resource property for the end</param>
        /// <returns>Association type end for the given parameters</returns>
        internal ResourceAssociationTypeEnd GetResourceAssociationTypeEnd(ResourceType resourceType, ResourceProperty resourceProperty)
        {
            Debug.Assert(resourceType != null, "resourceType != null");

            foreach (ResourceAssociationTypeEnd end in new[] { this.end1, this.end2 })
            {
                if (end.ResourceType == resourceType && end.ResourceProperty == resourceProperty)
                {
                    return end;
                }
            }

            return null;
        }
コード例 #19
0
 internal ExpandedProjectionNode AddProjectionNode(string propertyName, ResourceProperty property, System.Data.Services.Providers.ResourceType targetResourceType, bool lastPathSegment)
 {
     ProjectionNode existingNode = this.FindNode(propertyName);
     if ((existingNode == null) || !ApplyPropertyToExistingNode(existingNode, property, targetResourceType))
     {
         if (!lastPathSegment)
         {
             throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_ProjectedPropertyWithoutMatchingExpand(base.PropertyName));
         }
         existingNode = new ProjectionNode(propertyName, property, targetResourceType);
         this.AddNode(existingNode);
     }
     return (existingNode as ExpandedProjectionNode);
 }
コード例 #20
0
ファイル: NeedSkipTokenVisitor.cs プロジェクト: nickchal/pash
 internal override Expression VisitMemberAccess(MemberExpression m)
 {
     if ((m.Member.MemberType != MemberTypes.Property) || (m.Expression.NodeType != ExpressionType.Parameter))
     {
         this.NeedSkipToken = true;
         return m;
     }
     if (this.rt != null)
     {
         ResourcePropertyKind stream = ResourcePropertyKind.Stream;
         this.property = this.rt.TryResolvePropertyName(m.Member.Name, stream);
     }
     return base.VisitMemberAccess(m);
 }
コード例 #21
0
 internal ResourceAssociationTypeEnd GetRelatedResourceAssociationSetEnd(ResourceType resourceType, ResourceProperty resourceProperty)
 {
     ResourceAssociationTypeEnd resourceAssociationTypeEnd = this.GetResourceAssociationTypeEnd(resourceType, resourceProperty);
     if (resourceAssociationTypeEnd != null)
     {
         foreach (ResourceAssociationTypeEnd end2 in new ResourceAssociationTypeEnd[] { this.end1, this.end2 })
         {
             if (end2 != resourceAssociationTypeEnd)
             {
                 return end2;
             }
         }
     }
     return null;
 }
コード例 #22
0
		public ReferenceSetSerializer(ResourceType referringResourceType, ResourceProperty resourceProperty) : base(resourceProperty.ResourceType)
		{
			if (resourceProperty.ResourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
			{
				object[] name = new object[1];
				name[0] = resourceProperty.Name;
				referringResourceType.ThrowIfNull("referringResourceType", new ParameterExtensions.MessageLoader(SerializerBase.GetReferringResourceTypeCannotNullMessage), name);
				this.resourceProperty = resourceProperty;
				this.referringResourceType = referringResourceType;
				return;
			}
			else
			{
				throw new ArgumentException("resourceType");
			}
		}
コード例 #23
0
 internal ResourceAssociationSetEnd GetResourceAssociationSetEnd(ResourceSetWrapper resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
 {
     foreach (ResourceAssociationSetEnd end in new ResourceAssociationSetEnd[] { this.end1, this.end2 })
     {
         if ((end.ResourceSet.Name == resourceSet.Name) && end.ResourceType.IsAssignableFrom(resourceType))
         {
             if ((end.ResourceProperty == null) && (resourceProperty == null))
             {
                 return end;
             }
             if (((end.ResourceProperty != null) && (resourceProperty != null)) && (end.ResourceProperty.Name == resourceProperty.Name))
             {
                 return end;
             }
         }
     }
     return null;
 }
コード例 #24
0
        //Named Resource using .NET Framework 4.5
        public Stream GetReadStream(object entity, ResourceProperty resourceProperty, string etag, bool? checkETagForEquality, DataServiceOperationContext operationContext)
        {
            vProductCatalog image = entity as vProductCatalog;

            if (checkETagForEquality != null)
            {
                // This stream provider implementation does not support 
                // ETag headers for media resources. This means that we do not track 
                // concurrency for a media resource and last-in wins on updates.
                throw new DataServiceException(400, "This sample service does not support the ETag header for a media resource.");
            }

            if (image == null)
            {
                throw new DataServiceException(500, "Internal Server Error.");
            }

            // Return a stream that contains the requested ThumbnailPhoto or LargePhoto
            return ProductPhoto(image.ProductID, resourceProperty.Name);
        }
コード例 #25
0
ファイル: SerializerBase.cs プロジェクト: nickchal/pash
		public static SerializerBase CreateSerializer(ResourceType referringResourceType, ResourceProperty resourceProperty)
		{
			if ((resourceProperty.Kind & ResourcePropertyKind.Primitive) != ResourcePropertyKind.Primitive)
			{
				if ((resourceProperty.Kind & ResourcePropertyKind.ComplexType) != ResourcePropertyKind.ComplexType)
				{
					if ((resourceProperty.Kind & ResourcePropertyKind.Collection) != ResourcePropertyKind.Collection)
					{
						if ((resourceProperty.Kind & ResourcePropertyKind.ResourceReference) != ResourcePropertyKind.ResourceReference)
						{
							if ((resourceProperty.Kind & ResourcePropertyKind.ResourceSetReference) != ResourcePropertyKind.ResourceSetReference)
							{
								object[] str = new object[1];
								str[0] = resourceProperty.Kind.ToString();
								throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidResourceProperty, str), "resourceProperty");
							}
							else
							{
								return new ReferenceSetSerializer(referringResourceType, resourceProperty);
							}
						}
						else
						{
							return new ReferenceTypeSerializer(referringResourceType, resourceProperty);
						}
					}
					else
					{
						return new CollectionResourceTypeSerializer(resourceProperty.ResourceType);
					}
				}
				else
				{
					return new ComplexTypeSerializer(resourceProperty.ResourceType);
				}
			}
			else
			{
				return new PrimitiveTypeSerializer(resourceProperty.ResourceType, resourceProperty);
			}
		}
コード例 #26
0
        /// <summary>
        /// Constructs a ResourceAssociationEnd instance.
        /// </summary>
        /// <param name="resourceSet">Resource set of the association end.</param>
        /// <param name="resourceType">Resource type of the association end.</param>
        /// <param name="resourceProperty">Resource property of the association end.</param>
        public ResourceAssociationSetEnd(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            WebUtil.CheckArgumentNull(resourceSet, "resourceSet");
            WebUtil.CheckArgumentNull(resourceType, "resourceType");

            if (resourceProperty != null && (resourceType.TryResolvePropertyName(resourceProperty.Name) == null || resourceProperty.TypeKind != ResourceTypeKind.EntityType))
            {
                throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourcePropertyMustBeNavigationPropertyOnResourceType);
            }

            if (!resourceSet.ResourceType.IsAssignableFrom(resourceType) && !resourceType.IsAssignableFrom(resourceSet.ResourceType))
            {
                throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourceTypeMustBeAssignableToResourceSet);
            }

            this.resourceSet = resourceSet;
            this.resourceType = resourceType;

            // Note that for the TargetEnd, resourceProperty can be null.
            this.resourceProperty = resourceProperty;
        }
コード例 #27
0
ファイル: PSCommandManager.cs プロジェクト: nickchal/pash
		public IReferenceSetCommand GetReferenceSetCommand(CommandType commandType, UserContext userContext, ResourceProperty property, EntityMetadata entityMetadata, string membershipId, ResourceType resourceType)
		{
			Envelope<PSRunspace, UserContext> envelope = this.runspaceStore.Borrow(userContext, membershipId);
			PSReferenceSetCmdletInfo item = null;
			try
			{
				item = ((PSEntityMetadata)entityMetadata).CmdletsForReferenceSets[property.Name].Cmdlets[commandType];
			}
			catch (KeyNotFoundException keyNotFoundException)
			{
				Tracer tracer = new Tracer();
				tracer.DebugMessage(string.Concat("GetCommand cannot find commandType: ", commandType.ToString()));
				object[] fullName = new object[3];
				fullName[0] = property.ResourceType.FullName;
				fullName[1] = property.Name;
				fullName[2] = commandType.ToString();
				string str = string.Format(CultureInfo.CurrentCulture, Resources.PropertyDoesNotHaveCommand, fullName);
				throw new InvalidOperationException(str);
			}
			return new PSReferenceCommand(envelope, resourceType, item);
		}
コード例 #28
0
        /// <summary>
        /// Gets the ResourceAssociationSet instance when given the source association end.
        /// </summary>
        /// <param name="resourceSet">Resource set of the source association end.</param>
        /// <param name="resourceType">Resource type of the source association end.</param>
        /// <param name="resourceProperty">Resource property of the source association end.</param>
        /// <returns>ResourceAssociationSet instance.</returns>
        public override ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            Debug.Assert(resourceSet != null, "resourceSet != null");
            Debug.Assert(resourceType != null, "resourceType != null");
            Debug.Assert(resourceProperty != null, "resourceProperty != null");
            Debug.Assert(resourceType == DataServiceProviderWrapper.GetDeclaringTypeForProperty(resourceType, resourceProperty), "resourceType should be the declaring type for resourceProperty");

            ResourceType targetType = resourceProperty.ResourceType;
            Debug.Assert(targetType != null && targetType.ResourceTypeKind == ResourceTypeKind.EntityType, "targetType != null && targetType.ResourceTypeKind == ResourceTypeKind.EntityType");

            ResourceSet targetSet = InternalGetContainerForResourceType(targetType.InstanceType, this.EntitySets.Values);
            Debug.Assert(targetSet != null, "targetSet != null");

            string associationName = resourceType.Name + '_' + resourceProperty.Name;

            // EF associations are first-class, navigation properties come second. So you actually
            // define the two-way association first, then say that the nav props "go through" them.
            // For CLR, however, there is no such constraint - in fact, we're very happy with one-way (link) associations.
            // For one-way associations, the target property is always null.
            ResourceAssociationSetEnd sourceEnd = new ResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty);
            ResourceAssociationSetEnd targetEnd = new ResourceAssociationSetEnd(targetSet, targetType, null);
            return new ResourceAssociationSet(associationName, sourceEnd, targetEnd);
        }
コード例 #29
0
		protected override Expression VisitMethodCall(MethodCallExpression expression)
		{
			if (expression.Method.Name != "Where")
			{
				if (expression.Method.Name != "Select")
				{
					if (expression.Method.Name != "SelectMany")
					{
						this.navigationProperty = null;
					}
					else
					{
						this.cmdletExpression = expression;
						this.category = ExpressionCategory.SelectNavProperty;
						this.navigationProperty = ExpressionHelper.GetResourcePropertyFromSequence(expression.Arguments[1]);
					}
				}
				else
				{
					this.cmdletExpression = expression;
					this.category = ExpressionCategory.SelectExpansion;
					this.navigationProperty = null;
				}
			}
			else
			{
				if (!ExpressionHelper.IsResourceRoot(expression.Arguments[0], this.resourceRoot))
				{
					if (!ExpressionHelper.IsNestedWhereClause(expression.Arguments[0], this.resourceRoot) || !ExpressionHelper.IsPropertyComparisonPredicate(expression.Arguments[1]))
					{
						this.cmdletExpression = expression;
						this.category = ExpressionCategory.WhereOfResultSet;
						this.navigationProperty = null;
					}
					else
					{
						this.cmdletExpression = expression;
						if (this.navigationProperty.IsNavPropertyHasGetReferenceCmdlet(this.entityMetadata))
						{
							this.category = ExpressionCategory.NestedPropertyComparisonsInsideNavPropertyWithGetRefCmdlet;
						}
						else
						{
							this.category = ExpressionCategory.NestedPropertyComparisons;
						}
						return expression;
					}
				}
				else
				{
					this.cmdletExpression = expression;
					if (this.navigationProperty.IsNavPropertyHasGetReferenceCmdlet(this.entityMetadata))
					{
						this.category = ExpressionCategory.WhereInsideNavPropertyWithGetRefCmdlet;
					}
					else
					{
						this.category = ExpressionCategory.WhereOfResourceRoot;
					}
					return expression;
				}
			}
			this.Visit(expression.Arguments[0]);
			return expression;
		}
コード例 #30
0
        /// <summary>
        /// Retrieve the end for the given resource set, type and property.
        /// </summary>
        /// <param name="resourceType">resource type for the end</param>
        /// <param name="resourceProperty">resource property for the end</param>
        /// <returns>Association type end for the given parameters</returns>
        internal ResourceAssociationTypeEnd GetResourceAssociationTypeEnd(ResourceType resourceType, ResourceProperty resourceProperty)
        {
            Debug.Assert(resourceType != null, "resourceType != null");

            foreach (ResourceAssociationTypeEnd end in new[] { this.end1, this.end2 })
            {
                if (end.ResourceType == resourceType && end.ResourceProperty == resourceProperty)
                {
                    return(end);
                }
            }

            return(null);
        }
コード例 #31
0
 /// <summary>
 /// Gets the ResourceAssociationSet instance when given the source association end.
 /// </summary>
 /// <param name="resourceSet">Resource set of the source association end.</param>
 /// <param name="resourceType">Resource type of the source association end.</param>
 /// <param name="resourceProperty">Resource property of the source association end.</param>
 /// <returns>ResourceAssociationSet instance.</returns>
 public abstract ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty);
コード例 #32
0
 /// <summary>Initializes a new <see cref="ExpandSegment"/> instance.</summary>
 /// <param name="name">Segment name.</param>
 /// <param name="filter">Filter expression for segment, possibly null.</param>
 /// <param name="maxResultsExpected">
 /// Expand providers may choose to return at most MaxResultsExpected + 1 elements to allow the
 /// data service to detect a failure to meet this constraint.
 /// </param>
 /// <param name="container">Container to which the segment belongs; possibly null.</param>
 /// <param name="expandedProperty">Property expanded by this expand segment</param>
 /// <param name="orderingInfo">Collection of ordering information for this segment, used for paging</param>
 internal ExpandSegment(
     string name, 
     Expression filter, 
     int maxResultsExpected, 
     ResourceSetWrapper container, 
     ResourceProperty expandedProperty, 
     OrderingInfo orderingInfo)
 {
     WebUtil.CheckArgumentNull(name, "name");
     CheckFilterType(filter);
     this.name = name;
     this.filter = filter;
     this.container = container;
     this.maxResultsExpected = maxResultsExpected;
     this.expandedProperty = expandedProperty;
     this.orderingInfo = orderingInfo;
 }
コード例 #33
0
        /// <summary>
        /// Retrieve the related end for the given resource set, type and property.
        /// </summary>
        /// <param name="resourceType">resource type for the source end</param>
        /// <param name="resourceProperty">resource property for the source end</param>
        /// <returns>Related association type end for the given parameters</returns>
        internal ResourceAssociationTypeEnd GetRelatedResourceAssociationSetEnd(ResourceType resourceType, ResourceProperty resourceProperty)
        {
            Debug.Assert(resourceType != null, "resourceType != null");

            ResourceAssociationTypeEnd thisEnd = this.GetResourceAssociationTypeEnd(resourceType, resourceProperty);

            if (thisEnd != null)
            {
                foreach (ResourceAssociationTypeEnd end in new[] { this.end1, this.end2 })
                {
                    if (end != thisEnd)
                    {
                        return(end);
                    }
                }
            }

            return(null);
        }