Exemplo n.º 1
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);
 }
Exemplo n.º 2
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;
		}
Exemplo n.º 3
0
        protected override Expression VisitMethodCall(MethodCallExpression expression)
        {
            ResourceProperty resourceProperty = null;
            object           obj = null;

            if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractionFailed)
            {
                if (expression.Method.Name != "Where")
                {
                    if (expression.Method.Name != "SelectMany")
                    {
                        this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
                    }
                    else
                    {
                        if (this.currentState == ReferredResourceExtractor.ExtractionState.ExtractingReferredEntityInfo)
                        {
                            this.navigationProperty = ExpressionHelper.GetResourcePropertyFromSequence(expression.Arguments[1]);
                            if (!this.navigationProperty.IsReferenceSetProperty())
                            {
                                this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
                            }
                            else
                            {
                                this.currentState = ReferredResourceExtractor.ExtractionState.ExtractingReferringEntityInfo;
                            }
                        }
                        else
                        {
                            this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
                            return(expression);
                        }
                    }
                }
                else
                {
                    if (ExpressionHelper.IsResourceRoot(expression.Arguments[0], this.resourceRoot) || ExpressionHelper.IsNestedWhereClause(expression.Arguments[0], this.resourceRoot))
                    {
                        if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractingReferringEntityInfo || this.navigationProperty == null)
                        {
                            this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
                            return(expression);
                        }
                    }
                    else
                    {
                        if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractingReferredEntityInfo || this.navigationProperty != null)
                        {
                            this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
                            return(expression);
                        }
                    }
                    if (ExpressionHelper.GetResourcePropertyAndValueFromLambda(expression.Arguments[1], out resourceProperty, out obj))
                    {
                        if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractingReferringEntityInfo)
                        {
                            this.referredEntityKeys.Add(resourceProperty.Name, obj);
                        }
                        else
                        {
                            this.referringEntityKeys.Add(resourceProperty.Name, obj);
                        }
                    }
                    else
                    {
                        this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
                        return(expression);
                    }
                }
                this.Visit(expression.Arguments[0]);
                return(expression);
            }
            else
            {
                return(expression);
            }
        }
Exemplo n.º 4
0
		protected override Expression VisitMethodCall(MethodCallExpression expression)
		{
			ResourceProperty resourceProperty = null;
			object obj = null;
			if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractionFailed)
			{
				if (expression.Method.Name != "Where")
				{
					if (expression.Method.Name != "SelectMany")
					{
						this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
					}
					else
					{
						if (this.currentState == ReferredResourceExtractor.ExtractionState.ExtractingReferredEntityInfo)
						{
							this.navigationProperty = ExpressionHelper.GetResourcePropertyFromSequence(expression.Arguments[1]);
							if (!this.navigationProperty.IsReferenceSetProperty())
							{
								this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
							}
							else
							{
								this.currentState = ReferredResourceExtractor.ExtractionState.ExtractingReferringEntityInfo;
							}
						}
						else
						{
							this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
							return expression;
						}
					}
				}
				else
				{
					if (ExpressionHelper.IsResourceRoot(expression.Arguments[0], this.resourceRoot) || ExpressionHelper.IsNestedWhereClause(expression.Arguments[0], this.resourceRoot))
					{
						if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractingReferringEntityInfo || this.navigationProperty == null)
						{
							this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
							return expression;
						}
					}
					else
					{
						if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractingReferredEntityInfo || this.navigationProperty != null)
						{
							this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
							return expression;
						}
					}
					if (ExpressionHelper.GetResourcePropertyAndValueFromLambda(expression.Arguments[1], out resourceProperty, out obj))
					{
						if (this.currentState != ReferredResourceExtractor.ExtractionState.ExtractingReferringEntityInfo)
						{
							this.referredEntityKeys.Add(resourceProperty.Name, obj);
						}
						else
						{
							this.referringEntityKeys.Add(resourceProperty.Name, obj);
						}
					}
					else
					{
						this.currentState = ReferredResourceExtractor.ExtractionState.ExtractionFailed;
						return expression;
					}
				}
				this.Visit(expression.Arguments[0]);
				return expression;
			}
			else
			{
				return expression;
			}
		}