コード例 #1
0
ファイル: ODataUri.cs プロジェクト: larsenjo/odata.net
 /// <summary>
 /// Create a new ODataUri. This contains the semantic meaning of the 
 /// entire uri.
 /// </summary>
 /// <param name="parameterAliasValueAccessor">The ParameterAliasValueAccessor.</param>
 /// <param name="path">The top level path for this uri.</param>
 /// <param name="customQueryOptions">Any custom query options for this uri. Can be null.</param>
 /// <param name="selectAndExpand">Any $select or $expand option for this uri. Can be null.</param>
 /// <param name="filter">Any $filter option for this uri. Can be null.</param>
 /// <param name="orderby">Any $orderby option for this uri. Can be null</param>
 /// <param name="search">Any $search option for this uri. Can be null</param>
 /// <param name="apply">Any $apply option for this uri. Can be null</param>
 /// <param name="skip">Any $skip option for this uri. Can be null.</param>
 /// <param name="top">Any $top option for this uri. Can be null.</param>
 /// <param name="queryCount">Any query $count option for this uri. Can be null.</param>
 internal ODataUri(
     ParameterAliasValueAccessor parameterAliasValueAccessor,
     ODataPath path,
     IEnumerable<QueryNode> customQueryOptions,
     SelectExpandClause selectAndExpand,
     FilterClause filter,
     OrderByClause orderby,
     SearchClause search,
     ApplyClause apply,
     long? skip,
     long? top,
     bool? queryCount)
 {
     this.ParameterAliasValueAccessor = parameterAliasValueAccessor;
     this.Path = path;
     this.CustomQueryOptions = new ReadOnlyCollection<QueryNode>(customQueryOptions.ToList());
     this.SelectAndExpand = selectAndExpand;
     this.Filter = filter;
     this.OrderBy = orderby;
     this.Search = search;
     this.Apply = apply;
     this.Skip = skip;
     this.Top = top;
     this.QueryCount = queryCount;
 }
コード例 #2
0
        public void FunctionParameterParserShouldHandleTheResolvedAliasBeingNull()
        {
            Dictionary<string, string> aliasValues = new Dictionary<string, string>()
            {
                { "@a", "null" }
            };
            ParameterAliasValueAccessor paramAliasAccessor = new ParameterAliasValueAccessor(aliasValues);
            ICollection<OperationSegmentParameter> parsedParameters;
            TryParseFunctionParameters("CanMoveToAddress", "address=@a", paramAliasAccessor, out parsedParameters).Should().BeTrue();
            parsedParameters.Should().HaveCount(1);
            parsedParameters.Single().ShouldHaveValueType<ParameterAliasNode>("address").And.Alias.Should().Be("@a");

            // verify alias value:
            paramAliasAccessor.ParameterAliasValueNodesCached["@a"].As<ConstantNode>().Value.Should().Be(null);
        }
コード例 #3
0
        public void FunctionParameterParserShouldResolveAliasesInPathIfParameterAliasAccessorProvided()
        {
            Dictionary<string, string> aliasValues = new Dictionary<string, string>()
            {
                { "@a", "true" }
            };
            ParameterAliasValueAccessor paramAliasAccessor = new ParameterAliasValueAccessor(aliasValues);
            ICollection<OperationSegmentParameter> parsedParameters;
            TryParseOperationParameters("HasDog", "inOffice=@a", paramAliasAccessor, HardCodedTestModel.GetHasDogOverloadForPeopleWithTwoParameters(), out parsedParameters).Should().BeTrue();
            parsedParameters.Should().HaveCount(1);
            parsedParameters.Single().Name.Should().Be("inOffice");
            parsedParameters.Single().Value.As<ConvertNode>().Source.As<ParameterAliasNode>().Alias.Should().Be("@a");

            // verify alias value node:
            paramAliasAccessor.ParameterAliasValueNodesCached["@a"].ShouldBeConstantQueryNode(true);
        }
コード例 #4
0
        public void FunctionParameterParserShouldResolveAliasesInFilterOrderby()
        {
            Dictionary<string, string> aliasValues = new Dictionary<string, string>()
            {
                { "@a", "null" }
            };
            ParameterAliasValueAccessor paramAliasAccessor = new ParameterAliasValueAccessor(aliasValues);
            ExpressionLexer lexer = new ExpressionLexer("address=@a)", true, false, true);
            ICollection<NamedFunctionParameterNode> parameterTokens;
            TryParseFunctionParameters(lexer, paramAliasAccessor, out parameterTokens).Should().BeTrue();
            parameterTokens.Should().HaveCount(1);
            parameterTokens.Single().ShouldHaveParameterAliasNode("address", "@a");

            // verify alias value node:
            paramAliasAccessor.ParameterAliasValueNodesCached["@a"].ShouldBeConstantQueryNode((object)null);
        }
コード例 #5
0
        private static bool TryParseFunctionParameters(ExpressionLexer lexer, ParameterAliasValueAccessor paramAliasAccessor, out ICollection<NamedFunctionParameterNode> parsedParameterNodes)
        {
            UriQueryExpressionParser parser = new UriQueryExpressionParser(345, lexer);
            ICollection<FunctionParameterToken> splitParameters;
            parsedParameterNodes = null;
            if (parser.TrySplitFunctionParameters(out splitParameters))
            {
                var parsedParameters = FunctionCallBinder.BindSegmentParameters(new ODataUriParserConfiguration(HardCodedTestModel.TestModel) { ParameterAliasValueAccessor = paramAliasAccessor }, HardCodedTestModel.GetFunctionImportIsAddressGood().Function, splitParameters);
                parsedParameterNodes = parsedParameters.Select(s => new NamedFunctionParameterNode(s.Name, s.Value as QueryNode)).ToList();
                return true;
            }

            return false;
        }
コード例 #6
0
 private static bool TryParseFunctionParameters(string functionName, string parenthesisExpression, ParameterAliasValueAccessor paramAliasAccessor, IEdmOperationImport operationImport, out ICollection<OperationSegmentParameter> parsedSegementParameters)
 {
     return TryParseOperationParameters(functionName, parenthesisExpression, paramAliasAccessor, operationImport.Operation, out parsedSegementParameters);
 }
コード例 #7
0
        private static bool TryParseOperationParameters(string functionName, string parenthesisExpression, ParameterAliasValueAccessor paramAliasAccessor, IEdmOperation operation, out ICollection<OperationSegmentParameter> parsedSegementParameters)
        {
            ICollection<FunctionParameterToken> splitParameters;
            parsedSegementParameters = null;
            ODataUriParserConfiguration configuration = new ODataUriParserConfiguration(HardCodedTestModel.TestModel) { ParameterAliasValueAccessor = paramAliasAccessor };
            if (FunctionParameterParser.TrySplitOperationParameters(parenthesisExpression, configuration, out splitParameters))
            {
                parsedSegementParameters = FunctionCallBinder.BindSegmentParameters(configuration, operation, splitParameters);
                return true;
            }

            return false;
        }
コード例 #8
0
 private static bool TryParsOperationParameters(string functionName, string parenthesisExpression, ParameterAliasValueAccessor paramAliasAccessor, out ICollection<OperationSegmentParameter> parsedParameters)
 {
     return TryParseOperationParameters(functionName, parenthesisExpression, paramAliasAccessor, HardCodedTestModel.GetFunctionForCanMoveToAddress(), out parsedParameters);
 }
コード例 #9
0
ファイル: ODataUriParser.cs プロジェクト: TomDu/odata.net
        /// <summary>
        /// Initialize a UriParser. We have to initialize UriParser seperately for parsing path, because we may set BatchReferenceCallback before ParsePath.
        /// </summary>
        private void Initialize()
        {
            if (this.odataPath != null)
            {
                return;
            }

            // When parse path failed first time, the alias node would be not null, but already removed from query options, so do not set it in this case.
            if (this.ParameterAliasValueAccessor == null)
            {
                this.ParameterAliasValueAccessor = new ParameterAliasValueAccessor(queryOptions.GetParameterAliases());
            }

            this.odataPath = this.ParsePathImplementation();
            ODataPathSegment lastSegment = this.odataPath.LastSegment;
            ODataPathSegment previous = null;
            var segs = odataPath.GetEnumerator();
            int count = 0;
            while (++count < odataPath.Count && segs.MoveNext())
            {
            }

            previous = segs.Current;
            if (lastSegment != null)
            {
                // use previous segment if the last one is Key or Count Segment
                if (lastSegment is KeySegment || lastSegment is CountSegment)
                {
                    lastSegment = previous;
                }

                this.targetNavigationSource = lastSegment.TargetEdmNavigationSource;
                this.targetEdmType = lastSegment.TargetEdmType;
                if (this.targetEdmType != null)
                {
                    IEdmCollectionType collectionType = this.targetEdmType as IEdmCollectionType;
                    if (collectionType != null)
                    {
                        this.targetEdmType = collectionType.ElementType.Definition;
                    }
                }
            }

            InitQueryOptionDic();

            this.queryOptionParser = new ODataQueryOptionParser(this.Model, this.targetEdmType, this.targetNavigationSource, queryOptionDic)
                                        {
                                            Configuration = this.configuration
                                        };
        }