Exemple #1
0
        private DSResource GetOriginalResource()
        {
            DSResource dSResource;
            ICommand   command = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, this.resourceType, this.metadata, this.membershipId);

            using (command)
            {
                UriParametersHelper.AddParametersToCommand(command, DataServiceController.Current.GetCurrentResourceUri());
                CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(command);
                commandArgumentVisitor.Visit(this.query.Expression);
                List <DSResource> dSResources = new List <DSResource>();
                DataServiceController.Current.QuotaSystem.CheckCmdletExecutionQuota(this.userContext);
                IEnumerator <DSResource> enumerator = command.InvokeAsync(dSResources.AsQueryable <DSResource>().Expression, true);
                while (enumerator.MoveNext())
                {
                    dSResources.Add(enumerator.Current);
                }
                if (dSResources.Count != 0)
                {
                    dSResource = dSResources.First <DSResource>();
                }
                else
                {
                    throw new DataServiceException(0x194, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.NotFound, Resources.ResourceInstanceNotFound, new object[0]));
                }
            }
            return(dSResource);
        }
 internal bool TryAddingAllExpressions(Expression rootExpression, Expression baseExpression, ICommand command, DataServiceQueryProvider.ResultSet resultSet, out Expression nodeToReplace)
 {
     if (!ExpressionHelper.IsResourceRoot(baseExpression, this.initialQueryable))
     {
         MethodCallExpression methodCallExpression = baseExpression as MethodCallExpression;
         bool flag = this.TryAddingAllExpressions(rootExpression, methodCallExpression.Arguments[0], command, resultSet, out nodeToReplace);
         if (!flag)
         {
             return(false);
         }
         else
         {
             LambdaExpression operand = (LambdaExpression)((UnaryExpression)methodCallExpression.Arguments[1]).Operand;
             operand = (LambdaExpression)PartialEvaluator.Eval(operand);
             CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(command);
             operand = commandArgumentVisitor.VisitAndConvert <LambdaExpression>(operand, "TryAddingAllExpressions");
             if (!ExpressionHelper.IsConstantTrue(operand.Body))
             {
                 return(false);
             }
             else
             {
                 nodeToReplace = methodCallExpression;
                 return(true);
             }
         }
     }
     else
     {
         nodeToReplace = baseExpression;
         return(true);
     }
 }
        internal LambdaExpression InvokeFilteredGet(ICommand command, ResourceType originType, LambdaExpression filter, out DataServiceQueryProvider.ResultSet resultSet)
        {
            LambdaExpression lambdaExpression;

            using (OperationTracer operationTracer = new OperationTracer("ProcessExpression"))
            {
                LambdaExpression lambdaExpression1 = null;
                //this.schema.EntityMetadataDictionary[originType.FullName];
                resultSet = new DataServiceQueryProvider.ResultSet(originType);
                UriParametersHelper.AddParametersToCommand(command, DataServiceController.Current.GetCurrentResourceUri());
                if (filter != null)
                {
                    CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(command);
                    lambdaExpression1 = commandArgumentVisitor.VisitAndConvert <LambdaExpression>(filter, "InvokeFilteredGet");
                }
                this.InvokeCommandWithQuota(command, resultSet);
                lambdaExpression = lambdaExpression1;
            }
            return(lambdaExpression);
        }
Exemple #4
0
		public EntityUpdate(CommandType commandType, UserContext userContext, ResourceType type, EntityMetadata metadata, IQueryable query, string membershipId)
		{
			ExceptionHelpers.ThrowArgumentExceptionIf("commandType", commandType != CommandType.Update, Resources.InternalErrorOccurred, new object[0]);
			this.query = query;
			this.userContext = userContext;
			this.membershipId = membershipId;
			this.resourceType = type;
			this.metadata = metadata;
			this.commandType = commandType;
			this.propertyUpdates = new SortedDictionary<string, object>();
			this.updatedResource = null;
			this.resolveResource = null;
			CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(this);
			commandArgumentVisitor.Visit(query.Expression);
			if (this.AreAllKeyFieldsSpecified())
			{
				return;
			}
			else
			{
				throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.KeysMissingInQuery, new object[0]));
			}
		}
Exemple #5
0
        public EntityUpdate(CommandType commandType, UserContext userContext, ResourceType type, EntityMetadata metadata, IQueryable query, string membershipId)
        {
            ExceptionHelpers.ThrowArgumentExceptionIf("commandType", commandType != CommandType.Update, Resources.InternalErrorOccurred, new object[0]);
            this.query           = query;
            this.userContext     = userContext;
            this.membershipId    = membershipId;
            this.resourceType    = type;
            this.metadata        = metadata;
            this.commandType     = commandType;
            this.propertyUpdates = new SortedDictionary <string, object>();
            this.updatedResource = null;
            this.resolveResource = null;
            CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(this);

            commandArgumentVisitor.Visit(query.Expression);
            if (this.AreAllKeyFieldsSpecified())
            {
                return;
            }
            else
            {
                throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.KeysMissingInQuery, new object[0]));
            }
        }
Exemple #6
0
		private DSResource GetOriginalResource()
		{
			DSResource dSResource;
			ICommand command = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, this.resourceType, this.metadata, this.membershipId);
			using (command)
			{
				UriParametersHelper.AddParametersToCommand(command, DataServiceController.Current.GetCurrentResourceUri());
				CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(command);
				commandArgumentVisitor.Visit(this.query.Expression);
				List<DSResource> dSResources = new List<DSResource>();
				DataServiceController.Current.QuotaSystem.CheckCmdletExecutionQuota(this.userContext);
				IEnumerator<DSResource> enumerator = command.InvokeAsync(dSResources.AsQueryable<DSResource>().Expression, true);
				while (enumerator.MoveNext())
				{
					dSResources.Add(enumerator.Current);
				}
				if (dSResources.Count != 0)
				{
					dSResource = dSResources.First<DSResource>();
				}
				else
				{
					throw new DataServiceException(0x194, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.NotFound, Resources.ResourceInstanceNotFound, new object[0]));
				}
			}
			return dSResource;
		}
Exemple #7
0
        protected override Expression VisitBinary(BinaryExpression binaryExpr)
        {
            ResourceProperty resourceProperty = null;
            object           obj = null;

            if (binaryExpr.NodeType != ExpressionType.AndAlso)
            {
                if (binaryExpr.NodeType != ExpressionType.OrElse)
                {
                    if (!ExpressionHelper.IsPropertyEqualityCheck(binaryExpr, out resourceProperty, out obj))
                    {
                        this.binaryExpressionRoot = binaryExpr.NodeType;
                        return(binaryExpr);
                    }
                    else
                    {
                        if (this.binaryExpressionRoot != ExpressionType.OrElse)
                        {
                            if (this.binaryExpressionRoot == ExpressionType.AndAlso || this.binaryExpressionRoot == ExpressionType.Default)
                            {
                                bool flag = this.command.AddFieldParameter(resourceProperty.Name, obj);
                                if (!flag)
                                {
                                    return(base.VisitBinary(binaryExpr));
                                }
                                else
                                {
                                    return(Expression.Constant(true));
                                }
                            }
                            else
                            {
                                return(base.VisitBinary(binaryExpr));
                            }
                        }
                        else
                        {
                            this.parameterValues.Add(new KeyValuePair <string, object>(resourceProperty.Name, obj));
                            return(base.VisitBinary(binaryExpr));
                        }
                    }
                }
                else
                {
                    bool flag1 = false;
                    if (this.binaryExpressionRoot == ExpressionType.OrElse)
                    {
                        CommandArgumentVisitor commandArgumentVisitor = this;
                        commandArgumentVisitor.orElseNodeCount = commandArgumentVisitor.orElseNodeCount + 1;
                    }
                    else
                    {
                        this.binaryExpressionRoot = ExpressionType.OrElse;
                        this.parameterValues.Clear();
                        this.orElseNodeCount = 1;
                        flag1 = true;
                    }
                    Expression expression = base.VisitBinary(binaryExpr);
                    if (flag1)
                    {
                        this.HandleLastOrElse();
                    }
                    return(expression);
                }
            }
            else
            {
                this.binaryExpressionRoot = ExpressionType.AndAlso;
                return(base.VisitBinary(binaryExpr));
            }
        }